Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinrushforth committed Jul 17, 2020
2 parents f056d24 + 2f4666a commit 9260fd1
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 1 deletion.
18 changes: 17 additions & 1 deletion modules/javafx.graphics/src/main/native-glass/mac/GlassWindow.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2020, 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
Expand Down Expand Up @@ -1405,6 +1405,16 @@ static jlong _createWindowCommonDo(JNIEnv *env, jobject jWindow, jlong jOwnerPtr
{
GlassWindow *window = getGlassWindow(env, jPtr);

NSUInteger styleMask = [window->nsWindow styleMask];
BOOL isMiniaturizable = (styleMask & NSMiniaturizableWindowMask) != 0;

// if the window does not have NSMiniaturizableWindowMask set
// we need to temporarily set it to allow the window to
// be programmatically minimized or restored.
if (!isMiniaturizable) {
[window->nsWindow setStyleMask: styleMask | NSMiniaturizableWindowMask];
}

if (jMiniaturize == JNI_TRUE)
{
[window->nsWindow miniaturize:nil];
Expand All @@ -1413,6 +1423,12 @@ static jlong _createWindowCommonDo(JNIEnv *env, jobject jWindow, jlong jOwnerPtr
{
[window->nsWindow deminiaturize:nil];
}

// Restore the state of NSMiniaturizableWindowMask
if (!isMiniaturizable) {
[window->nsWindow setStyleMask: styleMask];
}

}
GLASS_POOL_EXIT;
GLASS_CHECK_EXCEPTION(env);
Expand Down
118 changes: 118 additions & 0 deletions tests/system/src/test/java/test/robot/javafx/stage/IconifyTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* Copyright (c) 2020, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/

package test.robot.javafx.stage;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import org.junit.Test;
import test.robot.testharness.VisualTestBase;

import static org.junit.Assert.assertTrue;
import static test.util.Util.TIMEOUT;

/**
* Test ability to programmatically iconify UNDECORATED and TRANSPARENT stages
*/
public class IconifyTest extends VisualTestBase {

private static final int WIDTH = 300;
private static final int HEIGHT = 300;

private static final Color BOTTOM_COLOR = Color.LIME;
private static final Color TOP_COLOR = Color.RED;

private static final double TOLERANCE = 0.07;

private Stage bottomStage;
private Stage topStage;

public void canIconifyStage(StageStyle stageStyle) throws Exception {
final CountDownLatch shownLatch = new CountDownLatch(2);

runAndWait(() -> {
// Bottom stage, should be visible after top stage is iconified
bottomStage = getStage(true);
Scene bottomScene = new Scene(new Pane(), WIDTH, HEIGHT);
bottomScene.setFill(BOTTOM_COLOR);
bottomStage.setScene(bottomScene);
bottomStage.setX(0);
bottomStage.setY(0);
bottomStage.setOnShown(e -> Platform.runLater(shownLatch::countDown));
bottomStage.show();

// Top stage, will be inconified
topStage = getStage(true);
topStage.initStyle(stageStyle);
Scene topScene = new Scene(new Pane(), WIDTH, HEIGHT);
topScene.setFill(TOP_COLOR);
topStage.setScene(topScene);
topStage.setX(0);
topStage.setY(0);
topStage.setOnShown(e -> Platform.runLater(shownLatch::countDown));
topStage.show();
});

assertTrue("Timeout waiting for stages to be shown",
shownLatch.await(TIMEOUT, TimeUnit.MILLISECONDS));

runAndWait(() -> {
topStage.toFront();
});

sleep(500);
runAndWait(() -> {
Color color = getColor(100, 100);
assertColorEquals(TOP_COLOR, color, TOLERANCE);
});

runAndWait(() -> {
topStage.setIconified(true);
});

sleep(500);
runAndWait(() -> {
Color color = getColor(100, 100);
assertColorEquals(BOTTOM_COLOR, color, TOLERANCE);
});
}

@Test(timeout = 15000)
public void canIconifyUndecoratedStage() throws Exception {
canIconifyStage(StageStyle.UNDECORATED);
}

@Test(timeout = 15000)
public void canIconifyTransparentStage() throws Exception {
canIconifyStage(StageStyle.TRANSPARENT);
}

}

0 comments on commit 9260fd1

Please sign in to comment.