Skip to content
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

8313424: JavaFX controls in the title bar #1605

Open
wants to merge 59 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 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
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
46 changes: 44 additions & 2 deletions modules/javafx.base/src/test/java/test/util/ReflectionUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this annotation still needed (the build gives no warnings when it's removed)?

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
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
67 changes: 48 additions & 19 deletions modules/javafx.graphics/src/main/java/com/sun/glass/ui/View.java
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 All @@ -26,7 +26,7 @@

import com.sun.glass.events.MouseEvent;
import com.sun.glass.events.ViewEvent;

import com.sun.javafx.tk.HeaderAreaType;
import java.lang.annotation.Native;
import java.lang.ref.WeakReference;
import java.util.Map;
Expand Down Expand Up @@ -67,8 +67,9 @@ public boolean handleKeyEvent(View view, long time, int action,
int keyCode, char[] keyChars, int modifiers) {
return false;
}
public void handleMenuEvent(View view, int x, int y, int xAbs,
public boolean handleMenuEvent(View view, int x, int y, int xAbs,
int yAbs, boolean isKeyboardTrigger) {
return false;
}
public void handleMouseEvent(View view, long time, int type, int button,
int x, int y, int xAbs, int yAbs,
Expand Down Expand Up @@ -363,6 +364,18 @@ public void handleSwipeGestureEvent(View view, long time, int type,
int yAbs) {
}

/**
* Returns the header area type at the specified coordinates, or {@code null}
* if the specified coordinates do not intersect with a header area.
*
* @param x the X coordinate
* @param y the Y coordinate
* @return the header area type, or {@code null}
*/
public HeaderAreaType pickHeaderArea(double x, double y) {
return null;
}

public Accessible getSceneAccessible() {
return null;
}
Expand Down Expand Up @@ -527,7 +540,7 @@ public void setEventHandler(EventHandler eventHandler) {
this.eventHandler = eventHandler;
}

private boolean shouldHandleEvent() {
protected boolean shouldHandleEvent() {
// Don't send any more events if the application has shutdown
if (Application.GetApplication() == null) {
return false;
Expand All @@ -552,21 +565,27 @@ private boolean handleKeyEvent(long time, int action,
return false;
}

private void handleMouseEvent(long time, int type, int button, int x, int y,
int xAbs, int yAbs,
int modifiers, boolean isPopupTrigger,
boolean isSynthesized) {
protected void handleMouseEvent(long time, int type, int button, int x, int y,
int xAbs, int yAbs,
int modifiers, boolean isPopupTrigger,
boolean isSynthesized) {
if (shouldHandleEvent()) {
eventHandler.handleMouseEvent(this, time, type, button, x, y, xAbs,
yAbs, modifiers,
isPopupTrigger, isSynthesized);
}
}

private void handleMenuEvent(int x, int y, int xAbs, int yAbs, boolean isKeyboardTrigger) {
protected boolean handleNonClientMouseEvent(long time, int type, int button, int x, int y,
int xAbs, int yAbs, int modifiers, int clickCount) {
return false;
}

protected boolean handleMenuEvent(int x, int y, int xAbs, int yAbs, boolean isKeyboardTrigger) {
if (shouldHandleEvent()) {
this.eventHandler.handleMenuEvent(this, x, y, xAbs, yAbs, isKeyboardTrigger);
return this.eventHandler.handleMenuEvent(this, x, y, xAbs, yAbs, isKeyboardTrigger);
}
return false;
}

public void handleBeginTouchEvent(View view, long time, int modifiers,
Expand Down Expand Up @@ -911,15 +930,6 @@ protected void notifyMenu(int x, int y, int xAbs, int yAbs, boolean isKeyboardTr
protected void notifyMouse(int type, int button, int x, int y, int xAbs,
int yAbs, int modifiers, boolean isPopupTrigger,
boolean isSynthesized) {
// gznote: optimize - only call for undecorated Windows!
if (this.window != null) {
// handled by window (programmatical move/resize)
if (this.window.handleMouseEvent(type, button, x, y, xAbs, yAbs)) {
// The evnet has been processed by Glass
return;
}
}

long now = System.nanoTime();
if (type == MouseEvent.DOWN) {
View lastClickedView = View.lastClickedView == null ? null : View.lastClickedView.get();
Expand All @@ -943,6 +953,25 @@ protected void notifyMouse(int type, int button, int x, int y, int xAbs,
lastClickedTime = now;
}

// If this is an extended window, we give the non-client handler the first chance to handle the event.
// Note that a full-screen window has no non-client area, and thus the non-client event handler
// is not notified.
// Some implementations (like GTK) can fire synthesized events when they receive a mouse button
// event on the resize border. These events, even though happening on non-client regions, must
// not be processed by the non-client event handler. For example, if a mouse click happens on
// the resize border that straddles the window close button, we don't want the close button to
// act on this click, because we just started a resize-drag operation.
boolean handled = window != null
&& window.isExtendedWindow()
&& !isSynthesized
&& !inFullscreen
&& shouldHandleEvent()
&& handleNonClientMouseEvent(now, type, button, x, y, xAbs, yAbs, modifiers, clickCount);

if (handled) {
return;
}

handleMouseEvent(now, type, button, x, y, xAbs, yAbs,
modifiers, isPopupTrigger, isSynthesized);

Expand Down
Loading