Skip to content

Commit 1a2a50b

Browse files
author
Michael Strauß
committed
8362095: HeaderButtonMetrics should not be used across toolkit boundary
Reviewed-by: jhendrikx, kcr
1 parent a574d92 commit 1a2a50b

File tree

7 files changed

+57
-8
lines changed

7 files changed

+57
-8
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
package com.sun.glass.ui;
2727

2828
import javafx.geometry.Dimension2D;
29-
import javafx.scene.layout.HeaderBar;
3029
import javafx.stage.StageStyle;
3130
import java.util.Objects;
3231

@@ -37,7 +36,6 @@
3736
* @param rightInset the size of the right inset
3837
* @param minHeight the minimum height of the window buttons
3938
* @see HeaderButtonOverlay
40-
* @see HeaderBar
4139
*/
4240
public record HeaderButtonMetrics(Dimension2D leftInset, Dimension2D rightInset, double minHeight) {
4341

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) 2025, 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 com.sun.javafx.stage;
27+
28+
import javafx.geometry.Dimension2D;
29+
import javafx.scene.layout.HeaderBar;
30+
import javafx.stage.StageStyle;
31+
import java.util.Objects;
32+
33+
/**
34+
* Provides metrics about the header buttons of {@link StageStyle#EXTENDED} windows.
35+
*
36+
* @param leftInset the size of the left inset
37+
* @param rightInset the size of the right inset
38+
* @param minHeight the minimum height of the window buttons
39+
* @see HeaderBar
40+
*/
41+
public record HeaderButtonMetrics(Dimension2D leftInset, Dimension2D rightInset, double minHeight) {
42+
43+
public HeaderButtonMetrics {
44+
Objects.requireNonNull(leftInset);
45+
Objects.requireNonNull(rightInset);
46+
47+
if (minHeight < 0) {
48+
throw new IllegalArgumentException("minHeight cannot be negative");
49+
}
50+
}
51+
}

modules/javafx.graphics/src/main/java/com/sun/javafx/stage/StageHelper.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
package com.sun.javafx.stage;
2727

28-
import com.sun.glass.ui.HeaderButtonMetrics;
2928
import com.sun.javafx.util.Utils;
3029
import javafx.beans.value.ObservableValue;
3130
import javafx.stage.Stage;

modules/javafx.graphics/src/main/java/com/sun/javafx/stage/StagePeerListener.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@
2525

2626
package com.sun.javafx.stage;
2727

28-
import com.sun.glass.ui.HeaderButtonMetrics;
2928
import javafx.stage.Stage;
3029

31-
3230
public class StagePeerListener extends WindowPeerListener {
3331
private final Stage stage;
3432
private final StageAccessor stageAccessor;

modules/javafx.graphics/src/main/java/com/sun/javafx/tk/quantum/WindowStage.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import com.sun.javafx.PlatformUtil;
4343
import com.sun.javafx.iio.common.PushbroomScaler;
4444
import com.sun.javafx.iio.common.ScalerFactory;
45+
import com.sun.javafx.stage.HeaderButtonMetrics;
4546
import com.sun.javafx.stage.StagePeerListener;
4647
import com.sun.javafx.tk.FocusCause;
4748
import com.sun.javafx.tk.TKScene;
@@ -227,7 +228,9 @@ private void computeAndSetBackground(List<javafx.scene.paint.Stop> stops) {
227228

228229
private void notifyHeaderButtonMetricsChanged() {
229230
if (stageListener instanceof StagePeerListener listener && platformWindow != null) {
230-
listener.changedHeaderButtonMetrics(platformWindow.headerButtonMetricsProperty().get());
231+
var metrics = platformWindow.headerButtonMetricsProperty().get();
232+
listener.changedHeaderButtonMetrics(
233+
new HeaderButtonMetrics(metrics.leftInset(), metrics.rightInset(), metrics.minHeight()));
231234
}
232235
}
233236

modules/javafx.graphics/src/main/java/javafx/scene/layout/HeaderBar.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525

2626
package javafx.scene.layout;
2727

28-
import com.sun.glass.ui.HeaderButtonMetrics;
2928
import com.sun.javafx.PreviewFeature;
3029
import com.sun.javafx.geom.Vec2d;
3130
import com.sun.javafx.scene.layout.HeaderButtonBehavior;
31+
import com.sun.javafx.stage.HeaderButtonMetrics;
3232
import com.sun.javafx.stage.StageHelper;
3333
import javafx.beans.property.BooleanProperty;
3434
import javafx.beans.property.BooleanPropertyBase;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@
4141
import javafx.scene.input.KeyCombination;
4242
import javafx.scene.layout.HeaderBar;
4343

44-
import com.sun.glass.ui.HeaderButtonMetrics;
4544
import com.sun.javafx.PreviewFeature;
4645
import com.sun.javafx.collections.VetoableListDecorator;
4746
import com.sun.javafx.collections.TrackableObservableList;
4847
import com.sun.javafx.scene.SceneHelper;
48+
import com.sun.javafx.stage.HeaderButtonMetrics;
4949
import com.sun.javafx.stage.StageHelper;
5050
import com.sun.javafx.stage.StagePeerListener;
5151
import com.sun.javafx.tk.TKStage;

0 commit comments

Comments
 (0)