Skip to content

8313424: JavaFX controls in the title bar (Preview) #1605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 93 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
3d19b87
WIP
mstr2 Oct 19, 2024
0ddd63d
doc change
mstr2 Oct 20, 2024
7969622
revert unintended change
mstr2 Oct 20, 2024
a289572
Merge branch 'master' into feature/extended-window
mstr2 Oct 23, 2024
ba02e8f
Improve HeaderBar documentation
mstr2 Oct 24, 2024
f973e8c
improve documentation
mstr2 Oct 25, 2024
f02e7e9
Windows: add system menu
mstr2 Oct 25, 2024
fef8cfc
Windows: custom context menu overrides system menu
mstr2 Oct 26, 2024
778e6c1
GTK: prevent resizing below window button size, fix crash
mstr2 Oct 26, 2024
3b468fe
GTK: add system menu
mstr2 Oct 26, 2024
0526edb
small code changes
mstr2 Oct 28, 2024
95736df
remove unused code
mstr2 Oct 28, 2024
d9c0fe2
Merge branch 'master' into feature/extended-window
mstr2 Oct 28, 2024
c0b588f
set minHeight to native height of title bar
mstr2 Oct 28, 2024
d7f88c3
better documentation
mstr2 Oct 28, 2024
9de4694
macOS: hide window title
mstr2 Oct 28, 2024
cd5d443
improve title text documentation
mstr2 Oct 28, 2024
bc48ae0
fix peer access outside of synchronizer
mstr2 Oct 28, 2024
804d0be
NPE
mstr2 Oct 28, 2024
f5e3121
fix header bar height flicker
mstr2 Oct 28, 2024
1c4ecc1
macOS: dynamically adapt toolbar style to headerbar height
mstr2 Oct 29, 2024
15dc3ff
Merge branch 'master' into feature/extended-window
mstr2 Oct 31, 2024
9b63892
Merge branch 'master' into feature/extended-window
mstr2 Nov 1, 2024
e7febc5
fix mirroring/unmirroring of X coord in win-glass
mstr2 Nov 5, 2024
d1c388b
stylistic changes
mstr2 Nov 5, 2024
8c9fbbd
use CsvSource in HeaderBarTest
mstr2 Nov 5, 2024
3660a29
EMPTY Dimension2D constant
mstr2 Nov 5, 2024
8974c14
HeaderBar changes
mstr2 Nov 5, 2024
ca9b325
refactor performWindowDrag
mstr2 Nov 6, 2024
8e77a22
HeaderBar javadoc change
mstr2 Nov 7, 2024
4336735
WindowControlsOverlay snapping
mstr2 Nov 7, 2024
a9178b7
add system menu documentation
mstr2 Nov 7, 2024
6a16536
Merge branch 'master' into feature/extended-window
mstr2 Nov 7, 2024
65f095e
Merge branch 'master' into feature/extended-window
mstr2 Nov 9, 2024
d5afc7d
Merge branch 'master' into feature/extended-window
mstr2 Nov 14, 2024
26b81b8
remove unneeded dll
mstr2 Nov 14, 2024
003e9d5
macOS: double-click action + fullscreen toolbar
mstr2 Nov 14, 2024
485a9d9
Merge branch 'master' into feature/extended-window
mstr2 Nov 14, 2024
743626f
Merge branch 'master' into feature/extended-window
mstr2 Dec 6, 2024
d9b82c8
Add HeaderBar.overlappingSystemInset property
mstr2 Dec 6, 2024
8649f91
StyleableBooleanProperty -> BooleanProperty
mstr2 Dec 6, 2024
af35dce
Merge branch 'master' into feature/extended-window
mstr2 Dec 10, 2024
6523073
fix system menu for non-resizeable extended window
mstr2 Dec 10, 2024
8d5d7b8
add StageStyle.EXTENDED_UTILITY
mstr2 Dec 10, 2024
eaafd9f
fix resizable states for GTK windows
mstr2 Dec 10, 2024
cbb3216
Merge branch 'master' into feature/extended-window
mstr2 Jan 15, 2025
63bd058
Refactoring, added HeaderBar.leadingSystemPadding/trailingSystemPadding
mstr2 Jan 25, 2025
8c33b3c
Merge branch 'master' into feature/extended-window
mstr2 Jan 25, 2025
49a81d3
added custom header buttons
mstr2 Jan 27, 2025
356a78e
fix line endings
mstr2 Jan 27, 2025
fcec7c8
update javadoc
mstr2 Jan 27, 2025
2ab1294
hide default window buttons on macOS
mstr2 Jan 27, 2025
8a73f5e
typo
mstr2 Jan 28, 2025
e874d21
add samples in MonkeyTester
mstr2 Jan 28, 2025
3efd782
small MonkeyTester refactor
mstr2 Jan 28, 2025
cadf1c2
added StageTester to MonkeyTester
mstr2 Feb 1, 2025
600c721
macOS bugfixes, default button behavior
mstr2 Feb 3, 2025
7cb591f
move StageTester to Tools menu
mstr2 Feb 4, 2025
c30eb60
add "maximized" pseudo-class for custom maximize button
mstr2 Feb 4, 2025
94ce7d4
Added HeaderBarBase.prefButtonHeight, removed Stage.initDefaultHeader…
mstr2 Feb 13, 2025
a04d946
Remove HeaderBarBase
mstr2 Feb 13, 2025
00b9be7
Merge branch 'master' into feature/extended-window
mstr2 Feb 13, 2025
9a7246b
update copyright headers
mstr2 Feb 13, 2025
1f95e9d
typo
mstr2 Feb 13, 2025
cd9c2a9
minify button glyphs
mstr2 Feb 14, 2025
394c95f
remove HeaderButtonOverlay.allowRtl
mstr2 Feb 21, 2025
e6e8100
Merge branch 'master' into feature/extended-window
mstr2 Mar 11, 2025
df90ca1
tweak header button glyph scaling
mstr2 Mar 12, 2025
31fa310
Merge branch 'master' into feature/extended-window
mstr2 Mar 17, 2025
0985e9c
add preview feature
mstr2 Mar 17, 2025
8a5defd
add preview feature
mstr2 Mar 17, 2025
30eb29b
enable preview features in tests
mstr2 Mar 17, 2025
f870493
tweak header button scaling at 100%
mstr2 Mar 23, 2025
a2b5df1
documentation
mstr2 Mar 23, 2025
50f9c75
documentation
mstr2 Mar 23, 2025
305b1aa
Merge branch 'master' into feature/extended-window
mstr2 Apr 6, 2025
88e5016
doc update
mstr2 Apr 6, 2025
63215fc
remove import
mstr2 Apr 7, 2025
a3497b2
Remove StageStyle.EXTENDED_UTILITY
mstr2 Apr 9, 2025
3622b05
Merge branch 'master' into feature/extended-window
mstr2 Apr 11, 2025
e9aeaef
don't show a right-click system menu in full-screen mode
mstr2 Apr 12, 2025
379c01e
documentation
mstr2 Apr 15, 2025
0969239
Merge branch 'master' into feature/extended-window
mstr2 Apr 24, 2025
394a039
review comments
mstr2 Apr 24, 2025
b6f8f9b
documentation
mstr2 Apr 25, 2025
7dc8f5f
add MenuBar to stage tester
mstr2 Apr 25, 2025
d1aa6b3
add HeaderDragType
mstr2 Apr 26, 2025
94d61ef
doc change
mstr2 Apr 28, 2025
6a2f05d
Merge branch 'master' into feature/extended-window
mstr2 Apr 28, 2025
544d62e
Fix top resize border on Windows
mstr2 Apr 29, 2025
c602f50
simplify header area picking
mstr2 May 2, 2025
5e857f1
Merge branch 'master' into feature/extended-window
mstr2 May 2, 2025
18ab411
reapply overlay CSS
mstr2 May 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public enum PreviewFeature {

// Add preview feature constants here:
// TEST_FEATURE("Test Feature")
;
STAGE_STYLE_EXTENDED("StageStyle.EXTENDED"),
HEADER_BAR("HeaderBar");

PreviewFeature(String featureName) {
this.featureName = featureName;
Expand All @@ -52,6 +53,16 @@ public enum PreviewFeature {
private static final boolean enabled = Boolean.getBoolean(ENABLE_PREVIEW_PROPERTY);
private static final boolean suppressWarning = Boolean.getBoolean(SUPPRESS_WARNING_PROPERTY);
private static final Set<PreviewFeature> enabledFeatures = new HashSet<>();
private static boolean enabledForTesting;

/**
* Enables preview features and suppresses the warning.
* <p>
* This method is only used for testing purposes.
*/
public static void enableForTesting() {
enabledForTesting = true;
}

/**
* Verifies that preview features are enabled, and throws an exception otherwise.
Expand All @@ -62,7 +73,9 @@ public enum PreviewFeature {
* @throws RuntimeException if preview features are not enabled
*/
public void checkEnabled() {
if (!enabled) {
if (enabledForTesting) {
// do nothing
} else if (!enabled) {
throw new RuntimeException("""
%s is a preview feature of JavaFX %s.
Preview features may be removed in a future release, or upgraded to permanent features of JavaFX.
Expand Down
48 changes: 45 additions & 3 deletions modules/javafx.base/src/test/java/test/util/ReflectionUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2025, 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 All @@ -26,15 +26,20 @@
package test.util;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.function.Function;

public final class ReflectionUtils {

private ReflectionUtils() {}

/**
* Returns the value of a potentially private field of the specified object.
* The field can be declared on any of the object's inherited classes.
*/
public static Object getFieldValue(Object object, String fieldName) {
@SuppressWarnings("unchecked")
public static <T> T getFieldValue(Object object, String fieldName) {
Function<Class<?>, Field> getField = cls -> {
try {
var field = cls.getDeclaredField(fieldName);
Expand All @@ -50,7 +55,7 @@ public static Object getFieldValue(Object object, String fieldName) {
Field field = getField.apply(cls);
if (field != null) {
try {
return field.get(object);
return (T)field.get(object);
} catch (IllegalAccessException e) {
throw new AssertionError(e);
}
Expand All @@ -61,4 +66,41 @@ public static Object getFieldValue(Object object, String fieldName) {

throw new AssertionError("Field not found: " + fieldName);
}

/**
* Invokes the specified method on the object, and returns a value.
* The method can be declared on any of the object's inherited classes.
*
* @param object the object on which the method will be invoked
* @param methodName the method name
* @param args the arguments
* @return the return value
*/
public static Object invokeMethod(Object object, String methodName, Class<?>[] parameterTypes, Object... args) {
Function<Class<?>, Method> getMethod = cls -> {
try {
var method = cls.getDeclaredMethod(methodName, parameterTypes);
method.setAccessible(true);
return method;
} catch (NoSuchMethodException e) {
return null;
}
};

Class<?> cls = object.getClass();
while (cls != null) {
Method method = getMethod.apply(cls);
if (method != null) {
try {
return method.invoke(object, args);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new AssertionError(e);
}
}

cls = cls.getSuperclass();
}

throw new AssertionError("Method not found: " + methodName);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2025, 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 @@ -711,6 +711,12 @@ public final boolean supportsUnifiedWindows() {
return _supportsUnifiedWindows();
}

protected abstract boolean _supportsExtendedWindows();
public final boolean supportsExtendedWindows() {
checkEventThread();
return _supportsExtendedWindows();
}

protected boolean _supportsSystemMenu() {
// Overridden in subclasses
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2025, 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 com.sun.glass.ui;

import javafx.geometry.Dimension2D;
import javafx.scene.layout.HeaderBar;
import javafx.stage.StageStyle;
import java.util.Objects;

/**
* Provides metrics about the header buttons of {@link StageStyle#EXTENDED} windows.
*
* @param leftInset the size of the left inset
* @param rightInset the size of the right inset
* @param minHeight the minimum height of the window buttons
* @see HeaderButtonOverlay
* @see HeaderBar
*/
public record HeaderButtonMetrics(Dimension2D leftInset, Dimension2D rightInset, double minHeight) {

public static HeaderButtonMetrics EMPTY = new HeaderButtonMetrics(new Dimension2D(0, 0), new Dimension2D(0, 0), 0);

public HeaderButtonMetrics {
Objects.requireNonNull(leftInset);
Objects.requireNonNull(rightInset);

if (minHeight < 0) {
throw new IllegalArgumentException("minHeight cannot be negative");
}
}

public double totalInsetWidth() {
return leftInset.getWidth() + rightInset.getWidth();
}

public double maxInsetHeight() {
return Math.max(leftInset.getHeight(), rightInset.getHeight());
}
}
Loading