Skip to content

Commit 9260fd1

Browse files
Merge
2 parents f056d24 + 2f4666a commit 9260fd1

File tree

2 files changed

+135
-1
lines changed

2 files changed

+135
-1
lines changed

modules/javafx.graphics/src/main/native-glass/mac/GlassWindow.m

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -1405,6 +1405,16 @@ static jlong _createWindowCommonDo(JNIEnv *env, jobject jWindow, jlong jOwnerPtr
14051405
{
14061406
GlassWindow *window = getGlassWindow(env, jPtr);
14071407

1408+
NSUInteger styleMask = [window->nsWindow styleMask];
1409+
BOOL isMiniaturizable = (styleMask & NSMiniaturizableWindowMask) != 0;
1410+
1411+
// if the window does not have NSMiniaturizableWindowMask set
1412+
// we need to temporarily set it to allow the window to
1413+
// be programmatically minimized or restored.
1414+
if (!isMiniaturizable) {
1415+
[window->nsWindow setStyleMask: styleMask | NSMiniaturizableWindowMask];
1416+
}
1417+
14081418
if (jMiniaturize == JNI_TRUE)
14091419
{
14101420
[window->nsWindow miniaturize:nil];
@@ -1413,6 +1423,12 @@ static jlong _createWindowCommonDo(JNIEnv *env, jobject jWindow, jlong jOwnerPtr
14131423
{
14141424
[window->nsWindow deminiaturize:nil];
14151425
}
1426+
1427+
// Restore the state of NSMiniaturizableWindowMask
1428+
if (!isMiniaturizable) {
1429+
[window->nsWindow setStyleMask: styleMask];
1430+
}
1431+
14161432
}
14171433
GLASS_POOL_EXIT;
14181434
GLASS_CHECK_EXCEPTION(env);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
26+
package test.robot.javafx.stage;
27+
28+
import java.util.concurrent.CountDownLatch;
29+
import java.util.concurrent.TimeUnit;
30+
import javafx.application.Platform;
31+
import javafx.scene.Scene;
32+
import javafx.scene.layout.Pane;
33+
import javafx.scene.paint.Color;
34+
import javafx.stage.Stage;
35+
import javafx.stage.StageStyle;
36+
import org.junit.Test;
37+
import test.robot.testharness.VisualTestBase;
38+
39+
import static org.junit.Assert.assertTrue;
40+
import static test.util.Util.TIMEOUT;
41+
42+
/**
43+
* Test ability to programmatically iconify UNDECORATED and TRANSPARENT stages
44+
*/
45+
public class IconifyTest extends VisualTestBase {
46+
47+
private static final int WIDTH = 300;
48+
private static final int HEIGHT = 300;
49+
50+
private static final Color BOTTOM_COLOR = Color.LIME;
51+
private static final Color TOP_COLOR = Color.RED;
52+
53+
private static final double TOLERANCE = 0.07;
54+
55+
private Stage bottomStage;
56+
private Stage topStage;
57+
58+
public void canIconifyStage(StageStyle stageStyle) throws Exception {
59+
final CountDownLatch shownLatch = new CountDownLatch(2);
60+
61+
runAndWait(() -> {
62+
// Bottom stage, should be visible after top stage is iconified
63+
bottomStage = getStage(true);
64+
Scene bottomScene = new Scene(new Pane(), WIDTH, HEIGHT);
65+
bottomScene.setFill(BOTTOM_COLOR);
66+
bottomStage.setScene(bottomScene);
67+
bottomStage.setX(0);
68+
bottomStage.setY(0);
69+
bottomStage.setOnShown(e -> Platform.runLater(shownLatch::countDown));
70+
bottomStage.show();
71+
72+
// Top stage, will be inconified
73+
topStage = getStage(true);
74+
topStage.initStyle(stageStyle);
75+
Scene topScene = new Scene(new Pane(), WIDTH, HEIGHT);
76+
topScene.setFill(TOP_COLOR);
77+
topStage.setScene(topScene);
78+
topStage.setX(0);
79+
topStage.setY(0);
80+
topStage.setOnShown(e -> Platform.runLater(shownLatch::countDown));
81+
topStage.show();
82+
});
83+
84+
assertTrue("Timeout waiting for stages to be shown",
85+
shownLatch.await(TIMEOUT, TimeUnit.MILLISECONDS));
86+
87+
runAndWait(() -> {
88+
topStage.toFront();
89+
});
90+
91+
sleep(500);
92+
runAndWait(() -> {
93+
Color color = getColor(100, 100);
94+
assertColorEquals(TOP_COLOR, color, TOLERANCE);
95+
});
96+
97+
runAndWait(() -> {
98+
topStage.setIconified(true);
99+
});
100+
101+
sleep(500);
102+
runAndWait(() -> {
103+
Color color = getColor(100, 100);
104+
assertColorEquals(BOTTOM_COLOR, color, TOLERANCE);
105+
});
106+
}
107+
108+
@Test(timeout = 15000)
109+
public void canIconifyUndecoratedStage() throws Exception {
110+
canIconifyStage(StageStyle.UNDECORATED);
111+
}
112+
113+
@Test(timeout = 15000)
114+
public void canIconifyTransparentStage() throws Exception {
115+
canIconifyStage(StageStyle.TRANSPARENT);
116+
}
117+
118+
}

0 commit comments

Comments
 (0)