Skip to content

Commit 7eb9a1c

Browse files
author
Thiago Milczarek Sayao
committed
8306121: Scene not rendered initially when changing scenes after fix for JDK-8296621
Reviewed-by: jpereda, kcr
1 parent 8d13ba9 commit 7eb9a1c

File tree

8 files changed

+115
-15
lines changed

8 files changed

+115
-15
lines changed

modules/javafx.controls/src/test/java/test/com/sun/javafx/scene/control/infrastructure/MouseEventFirerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2023, 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
@@ -274,7 +274,7 @@ public void setup() {
274274
setBottomAnchor(bottomRight, 0.);
275275
setLeftAnchor(bottomRight, 0.);
276276

277-
content = new AnchorPane(topLeft, center, bottomRight);
277+
content = new AnchorPane(center, topLeft, bottomRight);
278278
scene = new Scene(content);
279279
stage = new Stage();
280280
stage.setScene(scene);

modules/javafx.controls/src/test/java/test/javafx/scene/control/ComboBoxTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2023, 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
@@ -1128,7 +1128,13 @@ public void defaultConverterCanHandleIncorrectType_2() {
11281128

11291129
comboBox.requestFocus();
11301130

1131-
new KeyEventFirer(comboBox).doKeyPress(KeyCode.ENTER);
1131+
var kFirer = new KeyEventFirer(comboBox);
1132+
// Open selection
1133+
kFirer.doKeyPress(KeyCode.DOWN, KeyModifier.ALT);
1134+
// Select first
1135+
kFirer.doKeyPress(KeyCode.DOWN);
1136+
// Commit selection
1137+
kFirer.doKeyPress(KeyCode.ENTER);
11321138
}
11331139

11341140
@Test public void test_rt31479() {

modules/javafx.graphics/src/main/java/com/sun/glass/ui/gtk/GtkWindow.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ public GtkWindow(Window owner, Screen screen, int styleMask) {
4646
@Override
4747
protected native boolean _setView(long ptr, View view);
4848

49-
// empty - not needed by this implementation
5049
@Override
51-
protected void _updateViewSize(long ptr) {}
50+
protected native void _updateViewSize(long ptr);
5251

5352
@Override
5453
protected boolean _setMenubar(long ptr, long menubarPtr) {

modules/javafx.graphics/src/main/java/javafx/stage/Stage.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2023, 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
@@ -1187,6 +1187,10 @@ private void doVisibleChanged(boolean value) {
11871187
peer.setMaximized(isMaximized());
11881188
peer.setTitle(getTitle());
11891189

1190+
if (!isIconified()) {
1191+
peer.requestFocus();
1192+
}
1193+
11901194
List<Object> platformImages = new ArrayList<>();
11911195
for (Image icon : icons) {
11921196
platformImages.add(Toolkit.getImageAccessor().getPlatformImage(icon));

modules/javafx.graphics/src/main/native-glass/gtk/GlassWindow.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,20 @@ JNIEXPORT void JNICALL Java_com_sun_glass_ui_gtk_GtkWindow__1showOrHideChildren
139139
ctx->show_or_hide_children(show);
140140
}
141141

142+
/*
143+
* Class: com_sun_glass_ui_gtk_GtkWindow
144+
* Method: _updateViewSize
145+
* Signature: (J)V
146+
*/
147+
JNIEXPORT void JNICALL Java_com_sun_glass_ui_gtk_GtkWindow__1updateViewSize
148+
(JNIEnv * env, jobject obj, jlong ptr) {
149+
(void)env;
150+
(void)obj;
151+
152+
WindowContext* ctx = JLONG_TO_WINDOW_CTX(ptr);
153+
ctx->update_view_size();
154+
}
155+
142156
/*
143157
* Class: com_sun_glass_ui_gtk_GtkWindow
144158
* Method: minimizeImpl

modules/javafx.graphics/src/main/native-glass/gtk/glass_window.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2023, 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
@@ -1322,14 +1322,16 @@ void WindowContextTop::set_owner(WindowContext * owner_ctx) {
13221322
owner = owner_ctx;
13231323
}
13241324

1325-
void WindowContextTop::notify_window_resize() {
1326-
int w = geometry_get_window_width(&geometry);
1327-
int h = geometry_get_window_height(&geometry);
1325+
void WindowContextTop::update_view_size() {
1326+
// Notify the view size only if size is oriented by WINDOW, otherwise it knows its own size
1327+
if (geometry.final_width.type == BOUNDSTYPE_WINDOW
1328+
|| geometry.final_height.type == BOUNDSTYPE_WINDOW) {
13281329

1329-
mainEnv->CallVoidMethod(jwindow, jWindowNotifyResize,
1330-
com_sun_glass_events_WindowEvent_RESIZE, w, h);
1331-
CHECK_JNI_EXCEPTION(mainEnv)
1330+
notify_view_resize();
1331+
}
1332+
}
13321333

1334+
void WindowContextTop::notify_view_resize() {
13331335
if (jview) {
13341336
int cw = geometry_get_content_width(&geometry);
13351337
int ch = geometry_get_content_height(&geometry);
@@ -1339,6 +1341,17 @@ void WindowContextTop::notify_window_resize() {
13391341
}
13401342
}
13411343

1344+
void WindowContextTop::notify_window_resize() {
1345+
int w = geometry_get_window_width(&geometry);
1346+
int h = geometry_get_window_height(&geometry);
1347+
1348+
mainEnv->CallVoidMethod(jwindow, jWindowNotifyResize,
1349+
com_sun_glass_events_WindowEvent_RESIZE, w, h);
1350+
CHECK_JNI_EXCEPTION(mainEnv)
1351+
1352+
notify_view_resize();
1353+
}
1354+
13421355
void WindowContextTop::notify_window_move() {
13431356
if (jwindow) {
13441357
mainEnv->CallVoidMethod(jwindow, jWindowNotifyMove,

modules/javafx.graphics/src/main/native-glass/gtk/glass_window.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2023, 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
@@ -145,6 +145,8 @@ class WindowContext {
145145

146146
virtual void notify_state(jint) = 0;
147147
virtual void notify_on_top(bool) {}
148+
virtual void update_view_size() = 0;
149+
virtual void notify_view_resize() = 0;
148150

149151
virtual void add_child(WindowContextTop* child) = 0;
150152
virtual void remove_child(WindowContextTop* child) = 0;
@@ -302,6 +304,8 @@ class WindowContextTop: public WindowContextBase {
302304
void set_level(int);
303305
void set_visible(bool);
304306
void notify_on_top(bool);
307+
void update_view_size();
308+
void notify_view_resize();
305309

306310
void enter_fullscreen();
307311
void exit_fullscreen();
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (c) 2023, 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+
27+
import javafx.application.Application;
28+
import javafx.scene.text.Text;
29+
import javafx.stage.Stage;
30+
import javafx.scene.Scene;
31+
import javafx.scene.layout.StackPane;
32+
33+
/***
34+
* Stage must initially only show on the OS taskbar, but not on the Screen.
35+
* If the stage pops on the Screen and then iconifies, it's wrong.
36+
*
37+
* Note: Will not work on MacOS until https://bugs.openjdk.org/browse/JDK-8305675 is fixed
38+
*/
39+
public class StartIconified extends Application {
40+
41+
@Override
42+
public void start(Stage primaryStage) {
43+
primaryStage.setTitle("Iconified Window Test");
44+
primaryStage.setWidth(600);
45+
primaryStage.setHeight(150);
46+
primaryStage.setIconified(true);
47+
48+
Text text = new Text("""
49+
1. The stage must initially appear on the OS taskbar (iconified), but not on the Screen
50+
2. Observe if the stage pops and then iconifies (wrong)""");
51+
52+
Scene scene = new Scene(new StackPane(text));
53+
primaryStage.setScene(scene);
54+
primaryStage.show();
55+
}
56+
57+
public static void main(String[] args) {
58+
launch(StartIconified.class, args);
59+
}
60+
}

0 commit comments

Comments
 (0)