Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
mstr2 committed Oct 19, 2024
1 parent 6ac2dd3 commit afe49dd
Show file tree
Hide file tree
Showing 59 changed files with 3,817 additions and 483 deletions.
4 changes: 2 additions & 2 deletions buildSrc/win.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,9 @@ WIN.glass.rcFlags = [
WIN.glass.ccFlags = [ccFlags].flatten()
WIN.glass.linker = linker
WIN.glass.linkFlags = (IS_STATIC_BUILD ? [linkFlags] : [linkFlags, "delayimp.lib", "gdi32.lib", "urlmon.lib", "Comdlg32.lib",
"winmm.lib", "imm32.lib", "shell32.lib", "Uiautomationcore.lib", "dwmapi.lib",
"winmm.lib", "imm32.lib", "shell32.lib", "Uiautomationcore.lib", "dwmapi.lib", "uxtheme.lib",
"/DELAYLOAD:user32.dll", "/DELAYLOAD:urlmon.dll", "/DELAYLOAD:winmm.dll", "/DELAYLOAD:shell32.dll",
"/DELAYLOAD:Uiautomationcore.dll", "/DELAYLOAD:dwmapi.dll"]).flatten()
"/DELAYLOAD:Uiautomationcore.dll", "/DELAYLOAD:dwmapi.dll", "/DELAYLOAD:uxtheme.dll"]).flatten()
WIN.glass.lib = "glass"

WIN.decora = [:]
Expand Down
41 changes: 41 additions & 0 deletions modules/javafx.base/src/test/java/test/util/ReflectionUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@
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.
Expand Down Expand Up @@ -61,4 +65,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, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2024, 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 @@ -24,6 +24,8 @@
*/
package com.sun.glass.events;

import com.sun.glass.ui.WindowControlsOverlay;
import javafx.stage.StageStyle;
import java.lang.annotation.Native;

public class MouseEvent {
Expand All @@ -49,4 +51,33 @@ public class MouseEvent {
* This identifier is required for internal purposes.
*/
@Native final static public int WHEEL = 228;

/**
* Non-client events are only natively produced on the Windows platform as a result of
* handling the {@code WM_NCHITTEST} message for an {@link StageStyle#EXTENDED} window.
* <p>
* They are never sent to applications, but are processed by {@link WindowControlsOverlay}.
*/
@Native final static public int NC_DOWN = 230;
@Native final static public int NC_UP = 231;
@Native final static public int NC_DRAG = 232;
@Native final static public int NC_MOVE = 233;
@Native final static public int NC_ENTER = 234;
@Native final static public int NC_EXIT = 235;

public static boolean isNonClientEvent(int event) {
return event >= NC_DOWN && event <= NC_EXIT;
}

public static int toNonClientEvent(int event) {
return switch (event) {
case DOWN -> NC_DOWN;
case UP -> NC_UP;
case DRAG -> NC_DRAG;
case MOVE -> NC_MOVE;
case ENTER -> NC_ENTER;
case EXIT -> NC_EXIT;
default -> event;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,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,43 @@
/*
* Copyright (c) 2024, 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.stage.StageStyle;

/**
* A non-client handler is used in some implementations of windows with the {@link StageStyle#EXTENDED} style.
* It can inspect a mouse event before it is sent to FX, and decide to consume it if it affects
* a non-client part of the window (for example, minimize/maximize/close buttons).
*/
public interface NonClientHandler {

/**
* Handles the event.
*
* @return {@code true} if the event was handled, {@code false} otherwise
*/
boolean handleMouseEvent(int type, int button, int x, int y, int xAbs, int yAbs, int clickCount);
}
34 changes: 25 additions & 9 deletions modules/javafx.graphics/src/main/java/com/sun/glass/ui/View.java
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,10 @@ public void handleSwipeGestureEvent(View view, long time, int type,
int yAbs) {
}

public boolean handleDragAreaHitTestEvent(double x, double y) {
return false;
}

public Accessible getSceneAccessible() {
return null;
}
Expand Down Expand Up @@ -395,6 +399,7 @@ protected void _finishInputMethodComposition(long ptr) {
*/
private volatile long ptr; // Native handle (NSView*, or internal structure pointer)
private Window window; // parent window
private NonClientHandler nonClientHandler;
private EventHandler eventHandler;

private int width = -1; // not set
Expand Down Expand Up @@ -494,6 +499,12 @@ void setWindow(Window window) {
this.window = window;
_setParent(this.ptr, window == null ? 0L : window.getNativeHandle());
this.isValid = this.ptr != 0 && window != null;

if (this.isValid && window.isExtendedWindow()) {
this.nonClientHandler = window.getNonClientHandler();
} else {
this.nonClientHandler = null;
}
}

// package private
Expand Down Expand Up @@ -913,15 +924,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 @@ -945,6 +947,20 @@ protected void notifyMouse(int type, int button, int x, int y, int xAbs,
lastClickedTime = now;
}

// If we have a non-client handler, we give it the first chance to handle the event.
// Note that a full-screen window has no non-client area, and thus the non-client handler
// is not notified.
if (!inFullscreen
&& nonClientHandler != null
&& nonClientHandler.handleMouseEvent(type, button, x, y, xAbs, yAbs, clickCount)) {
return;
}

// We never send non-client events to the application.
if (MouseEvent.isNonClientEvent(type)) {
return;
}

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

Expand Down
Loading

0 comments on commit afe49dd

Please sign in to comment.