changeset 50985:20a772d8ded0

8204860: The frame could be resized by dragging a corner of the frame with the mouse Reviewed-by: prr, psadhukhan
author mhalder
date Thu, 12 Jul 2018 15:17:18 +0530
parents 1a89ca728abd
children 5bf28fee65c1
files src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java test/jdk/java/awt/Frame/UnfocusableMaximizedFrameResizablity/UnfocusableMaximizedFrameResizablity.java
diffstat 2 files changed, 81 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java	Thu Jul 12 09:13:55 2018 +0200
+++ b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java	Thu Jul 12 15:17:18 2018 +0530
@@ -378,7 +378,7 @@
 
         // Either java.awt.Frame or java.awt.Dialog can be resizable, however java.awt.Window is never resizable
         {
-            final boolean resizable = isFrame ? ((Frame)target).isResizable() : (isDialog ? ((Dialog)target).isResizable() : false);
+            final boolean resizable = isTargetResizable() && isNativelyFocusableWindow();
             styleBits = SET(styleBits, RESIZABLE, resizable);
             if (!resizable) {
                 styleBits = SET(styleBits, ZOOMABLE, false);
@@ -482,6 +482,16 @@
         return styleBits;
     }
 
+    private boolean isTargetResizable() {
+        if (target instanceof Frame) {
+            return ((Frame)target).isResizable();
+        } else if (target instanceof Dialog) {
+            return ((Dialog)target).isResizable();
+        }
+
+        return false;
+    }
+
     // this is the counter-point to -[CWindow _nativeSetStyleBit:]
     private void setStyleBits(final int mask, final boolean value) {
         execute(ptr -> nativeSetNSWindowStyleBits(ptr, mask, value ? mask : 0));
@@ -676,10 +686,9 @@
         // Manage the extended state when showing
         if (visible) {
             /* Frame or Dialog should be set property WINDOW_FULLSCREENABLE to true if the
-            Frame or Dialog is resizable.
+            Frame or Dialog is resizable and focusable.
             **/
-            final boolean resizable = (target instanceof Frame) ? ((Frame)target).isResizable() :
-            ((target instanceof Dialog) ? ((Dialog)target).isResizable() : false);
+            final boolean resizable = isTargetResizable() && isNativelyFocusableWindow();
             if (resizable) {
                 setCanFullscreen(true);
             }
@@ -814,9 +823,10 @@
 
     @Override
     public void setResizable(final boolean resizable) {
-        setCanFullscreen(resizable);
-        setStyleBits(RESIZABLE, resizable);
-        setStyleBits(ZOOMABLE, resizable);
+        final boolean windowResizable = resizable && isNativelyFocusableWindow();
+        setCanFullscreen(windowResizable);
+        setStyleBits(RESIZABLE, windowResizable);
+        setStyleBits(ZOOMABLE, windowResizable);
     }
 
     @Override
@@ -858,8 +868,8 @@
 
     @Override
     public void updateFocusableWindowState() {
-        final boolean isFocusable = isNativelyFocusableWindow();
-        setStyleBits(SHOULD_BECOME_KEY | SHOULD_BECOME_MAIN | RESIZABLE, isFocusable); // set bits at once
+        setStyleBits(SHOULD_BECOME_KEY | SHOULD_BECOME_MAIN | RESIZABLE,
+                (isNativelyFocusableWindow() && isTargetResizable()));
     }
 
     @Override
--- a/test/jdk/java/awt/Frame/UnfocusableMaximizedFrameResizablity/UnfocusableMaximizedFrameResizablity.java	Thu Jul 12 09:13:55 2018 +0200
+++ b/test/jdk/java/awt/Frame/UnfocusableMaximizedFrameResizablity/UnfocusableMaximizedFrameResizablity.java	Thu Jul 12 15:17:18 2018 +0530
@@ -24,7 +24,7 @@
 /*
   @test
   @key headful
-  @bug 4980161 7158623
+  @bug 4980161 7158623 8204860
   @summary Setting focusable window state to false makes the maximized frame resizable
   @compile UnfocusableMaximizedFrameResizablity.java
   @run main UnfocusableMaximizedFrameResizablity
@@ -36,29 +36,84 @@
 import java.awt.AWTException;
 import java.awt.event.InputEvent;
 import java.awt.Robot;
+import javax.swing.JFrame;
+import javax.swing.SwingUtilities;
 
 public class UnfocusableMaximizedFrameResizablity {
 
     private static Frame frame;
+    private static JFrame jframe;
     private static Robot robot;
     private static boolean isProgInterruption = false;
     private static Thread mainThread = null;
     private static int sleepTime = 300000;
 
-    private static void createAndShowFrame() {
+    private static void createAndShowFrame() throws Exception {
 
         //The MAXIMIZED_BOTH state is not supported by the toolkit. Nothing to test.
         if (!Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.MAXIMIZED_BOTH)) {
             return;
         }
 
-        frame = new Frame("Unfocusable frame");
+        //Case 1: Setting frame resizable to true followed by focusable to false
+        frame = createFrame("Resizable Unfocusable frame");
+        frame.setResizable(true);
+        frame.setFocusableWindowState(false);
+        tryToResizeFrame(frame);
+
+        //Case 2: Setting frame focusable to false followed by resizable to true
+        frame = createFrame("Unfocusable Resizable frame");
+        frame.setFocusableWindowState(false);
+        frame.setResizable(true);
+        tryToResizeFrame(frame);
+
+        //Case 3: Testing JFrame fullscreen behaviour only on Mac OS
+        if (System.getProperty("os.name").toLowerCase().startsWith("mac")) {
+            SwingUtilities.invokeAndWait(new Runnable() {
+
+                Override
+                public void run() {
+                    jframe = createJFrame("Unfocusable Resizable JFrame");
+                    jframe.setFocusableWindowState(false);
+                    jframe.setResizable(true);
+                    Object prop1 = jframe.getRootPane().getClientProperty("apple.awt.fullscreenable");
+                    jframe.setVisible(false);
+                    jframe.setVisible(true);
+                    Object prop2 = jframe.getRootPane().getClientProperty("apple.awt.fullscreenable");
+
+                    if((prop1 != null && prop2 != null) && (!prop1.equals(prop2))) {
+                        jframe.dispose();
+                        cleanup();
+                        throw new RuntimeException("Non-focusable resizable JFrame is fullscreenable!!");
+                    }
+                }
+            });
+        }
+
+        cleanup();
+    }
+
+    private static JFrame createJFrame(String title) {
+        JFrame jframe = new JFrame(title);
+        jframe.setMaximizedBounds(new Rectangle(0, 0, 300, 300));
+        jframe.setSize(200, 200);
+        jframe.setVisible(true);
+        jframe.setExtendedState(Frame.MAXIMIZED_BOTH);
+
+        return jframe;
+    }
+
+    private static Frame createFrame(String title) {
+        Frame frame = new Frame(title);
         frame.setMaximizedBounds(new Rectangle(0, 0, 300, 300));
         frame.setSize(200, 200);
         frame.setVisible(true);
         frame.setExtendedState(Frame.MAXIMIZED_BOTH);
-        frame.setFocusableWindowState(false);
 
+        return frame;
+    }
+
+    private static void tryToResizeFrame(Frame frame) {
         try {
             robot = new Robot();
         } catch (AWTException e) {
@@ -89,16 +144,16 @@
             cleanup();
             throw new RuntimeException("The maximized unfocusable frame can be resized.");
         }
-        cleanup();
+
+        frame.dispose();
     }
 
     private static void cleanup() {
-        frame.dispose();
         isProgInterruption = true;
         mainThread.interrupt();
     }
 
-    public static void main(String args[]) throws InterruptedException {
+    public static void main(String args[]) throws Exception {
 
         mainThread = Thread.currentThread();