--- old/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java 2018-10-04 17:48:31.000000000 +0530 +++ new/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java 2018-10-04 17:48:30.000000000 +0530 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -276,6 +276,8 @@ private Rectangle normalBounds = null; // not-null only for undecorated maximized windows private CPlatformResponder responder; private long lastBecomeMainTime; // this is necessary to preserve right siblings order + private boolean maximizedBothState = false; + private boolean frameResizibilityChanged = false; public CPlatformWindow() { super(0, true); @@ -378,7 +380,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(); styleBits = SET(styleBits, RESIZABLE, resizable); if (!resizable) { styleBits = SET(styleBits, ZOOMABLE, false); @@ -580,6 +582,8 @@ setBounds(maximizedBounds.x, maximizedBounds.y, maximizedBounds.width, maximizedBounds.height); } + setFrameResizibilityChanged(true); + updateResizableAndMaximizeState(true); } private void unmaximize() { @@ -676,11 +680,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 resizable and Frame state is not MAXIMIZED_BOTH or Dialog is resizable. **/ - final boolean resizable = (target instanceof Frame) ? ((Frame)target).isResizable() : - ((target instanceof Dialog) ? ((Dialog)target).isResizable() : false); - if (resizable) { + if (isTargetResizable()) { setCanFullscreen(true); } @@ -695,6 +697,12 @@ // Treat all state bit masks with ICONIFIED bit as ICONIFIED state. frameState = Frame.ICONIFIED; } + + if (isFrameResizibilityChanged()) { + updateResizableAndMaximizeState(false); + setFrameResizibilityChanged(false); + } + switch (frameState) { case Frame.ICONIFIED: execute(CWrapper.NSWindow::miniaturize); @@ -814,9 +822,10 @@ @Override public void setResizable(final boolean resizable) { - setCanFullscreen(resizable); - setStyleBits(RESIZABLE, resizable); - setStyleBits(ZOOMABLE, resizable); + boolean windowResizable = resizable && !isMaximizedBoth(); + setCanFullscreen(windowResizable); + setStyleBits(RESIZABLE, windowResizable); + setStyleBits(ZOOMABLE, windowResizable); } @Override @@ -924,6 +933,12 @@ // Treat all state bit masks with ICONIFIED bit as ICONIFIED state. windowState = Frame.ICONIFIED; } + + if (isFrameResizibilityChanged()) { + updateResizableAndMaximizeState(false); + setFrameResizibilityChanged(false); + } + switch (windowState) { case Frame.ICONIFIED: if (prevWindowState == Frame.MAXIMIZED_BOTH) { @@ -1127,6 +1142,21 @@ } /* + * Resizibility of frame with state MAXIMIZED_BOTH is set to true to zoom + * the frame on double click on title bar and set to false later. This is + * required as frame won't zoom if resizibility of frame is false. + */ + private void deliverDoubleClickOnTitlebar() { + if ((peer != null) && (target instanceof Frame)) { + if (isMaximizedBoth()) { + updateResizableAndMaximizeState(false); + execute(CWrapper.NSWindow::zoom); + updateResizableAndMaximizeState(true); + } + } + } + + /* * Our focus model is synthetic and only non-simple window * may become natively focusable window. */ @@ -1301,6 +1331,32 @@ return false; } + private boolean isTargetResizable() { + if (target instanceof Frame) { + return ((Frame)target).isResizable() && !isMaximizedBoth(); + } else if (target instanceof Dialog) { + return ((Dialog)target).isResizable(); + } + return false; + } + + private void updateResizableAndMaximizeState(boolean maximizeState) { + maximizedBothState = maximizeState; + setResizable(!maximizeState); + } + + private boolean isMaximizedBoth() { + return maximizedBothState; + } + + private void setFrameResizibilityChanged(boolean resize) { + frameResizibilityChanged = resize; + } + + private boolean isFrameResizibilityChanged() { + return frameResizibilityChanged; + } + // ---------------------------------------------------------------------- // NATIVE CALLBACKS // ---------------------------------------------------------------------- --- old/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m 2018-10-04 17:48:32.000000000 +0530 +++ new/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m 2018-10-04 17:48:31.000000000 +0530 @@ -950,6 +950,11 @@ // Currently, no need to deliver the whole NSEvent. static JNF_MEMBER_CACHE(jm_deliverNCMouseDown, jc_CPlatformWindow, "deliverNCMouseDown", "()V"); JNFCallVoidMethod(env, platformWindow, jm_deliverNCMouseDown); + // Deliver double click on title bar + if ([event clickCount] > 1) { + static JNF_MEMBER_CACHE(jm_deliverDoubleClickOnTitlebar, jc_CPlatformWindow, "deliverDoubleClickOnTitlebar", "()V"); + JNFCallVoidMethod(env, platformWindow, jm_deliverDoubleClickOnTitlebar); + } (*env)->DeleteLocalRef(env, platformWindow); } } --- /dev/null 2018-10-04 17:48:33.000000000 +0530 +++ new/test/jdk/java/awt/Frame/MaximizedFrameResizibility/MaximizedFrameResizibility.java 2018-10-04 17:48:33.000000000 +0530 @@ -0,0 +1,178 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + @test + @key headful + @bug 8209123 + @summary Maximized frame is resizable on Mac but not on Windows and Ubuntu + @compile MaximizedFrameResizibility.java + @run main MaximizedFrameResizibility +*/ + +import java.awt.Toolkit; +import java.awt.Frame; +import java.awt.Rectangle; +import java.awt.AWTException; +import java.awt.event.InputEvent; +import java.awt.Robot; + +public class MaximizedFrameResizibility { + + private static Frame frame; + private static Robot robot; + private static boolean isProgInterruption = false; + private static Thread mainThread = null; + private static int sleepTime = 300000; + + private static void createAndShowFrame() { + + //The MAXIMIZED_BOTH state is not supported by the toolkit. Nothing to test. + if (!Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.MAXIMIZED_BOTH)) { + return; + } + + //Case 1: Setting state to MAXIMIZED_BOTH for resizable frame. + frame = new Frame("MAXIMIZED_BOTH Resizable frame"); + setFrameState(Frame.MAXIMIZED_BOTH); + frame.setResizable(true); + frame.setVisible(true); + resizeFrame(); + + //Case 2: Setting state to MAXIMIZED_BOTH from NORMAL for non-resizable frame. + frame = new Frame("MAXIMIZED_BOTH non-Resizable frame"); + setFrameState(Frame.NORMAL); + setFrameState(Frame.MAXIMIZED_BOTH); + frame.setResizable(false); + frame.setVisible(true); + resizeFrame(); + + //Case 3: Setting resizable frame state to MAXIMIZED_BOTH from NORMAL state. + frame = new Frame("Resizable MAXIMIZED_BOTH frame"); + setFrameState(Frame.NORMAL); + frame.setResizable(true); + setFrameState(Frame.MAXIMIZED_BOTH); + frame.setVisible(true); + resizeFrame(); + + //Case 4: Setting non-resizable frame state to MAXIMIZED_BOTH from NORMAL state. + frame = new Frame("Non-resizable MAXIMIZED_BOTH frame"); + setFrameState(Frame.NORMAL); + frame.setResizable(false); + setFrameState(Frame.MAXIMIZED_BOTH); + frame.setVisible(true); + resizeFrame(); + + cleanup(); + } + + private static void setFrameState(int frameState) { + frame.setSize(200, 200); + + switch(frameState) { + case Frame.MAXIMIZED_BOTH: + frame.setMaximizedBounds(new Rectangle(0, 0, 400, 400)); + frame.setExtendedState(Frame.MAXIMIZED_BOTH); + break; + case Frame.NORMAL: + frame.setExtendedState(Frame.NORMAL); + default: + } + } + + private static void resizeFrame() { + try { + robot = new Robot(); + robot.delay(2000); + + // The initial bounds of the frame + final Rectangle bounds = frame.getBounds(); + + // Move the mouse pointer to the bottom-right corner of the frame + robot.mouseMove(bounds.x + bounds.width - 2, bounds.y + bounds.height - 2); + robot.waitForIdle(); + + robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); + robot.waitForIdle(); + robot.mouseMove(bounds.x + bounds.width + 20, bounds.y + bounds.height + 15); + robot.waitForIdle(); + + robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); + robot.waitForIdle(); + + // The bounds of the frame after the attempt of resizing is made + final Rectangle finalBounds = frame.getBounds(); + + int frameState = frame.getExtendedState(); + if ((frameState & Frame.ICONIFIED) != 0) { + // Treat all state bit masks with ICONIFIED bit as ICONIFIED state. + frameState = Frame.ICONIFIED; + } + switch (frameState) { + case Frame.MAXIMIZED_BOTH: + if (!finalBounds.equals(bounds)) { + throw new RuntimeException("MAXIMIZED_BOTH frame is resizable"); + } + break; + case Frame.NORMAL: + if (!frame.isResizable() && !finalBounds.equals(bounds)) { + throw new RuntimeException("NORMAL non-resizable frame is resizable"); + } + if (frame.isResizable() && finalBounds.equals(bounds)) { + throw new RuntimeException("NORMAL resizable frame is not resizable"); + } + break; + default: //ICONIFIED + break; + } + } catch (AWTException e) { + throw new RuntimeException("Robot creation failed"); + } finally { + frame.dispose(); + } + } + + private static void cleanup() { + isProgInterruption = true; + mainThread.interrupt(); + } + + public static void main(String args[]) throws InterruptedException { + + mainThread = Thread.currentThread(); + try { + createAndShowFrame(); + mainThread.sleep(sleepTime); + } catch (InterruptedException e) { + if (!isProgInterruption) { + throw e; + } + } + + if (!isProgInterruption) { + throw new RuntimeException("Timed out after " + sleepTime / 1000 + + " seconds"); + } + } +} +