提交 723b6a08 编写于 作者: D dmarkov

8035568: [macosx] Cursor management unification

Reviewed-by: anthony, serb
上级 6d59e14a
...@@ -51,8 +51,12 @@ public class LWMouseInfoPeer implements MouseInfoPeer { ...@@ -51,8 +51,12 @@ public class LWMouseInfoPeer implements MouseInfoPeer {
return false; return false;
} }
final Object windowPeer = AWTAccessor.getComponentAccessor().getPeer(w); LWWindowPeer windowPeer = (LWWindowPeer)AWTAccessor.getComponentAccessor().getPeer(w);
return LWWindowPeer.getWindowUnderCursor() == windowPeer; if (windowPeer == null) {
return false;
}
return LWToolkit.getLWToolkit().getPlatformWindowUnderMouse() == windowPeer.getPlatformWindow();
} }
} }
......
...@@ -385,6 +385,8 @@ public abstract class LWToolkit extends SunToolkit implements Runnable { ...@@ -385,6 +385,8 @@ public abstract class LWToolkit extends SunToolkit implements Runnable {
return new LWMouseInfoPeer(); return new LWMouseInfoPeer();
} }
protected abstract PlatformWindow getPlatformWindowUnderMouse();
@Override @Override
public final PrintJob getPrintJob(Frame frame, String doctitle, public final PrintJob getPrintJob(Frame frame, String doctitle,
Properties props) { Properties props) {
......
...@@ -749,11 +749,10 @@ public class LWWindowPeer ...@@ -749,11 +749,10 @@ public class LWWindowPeer
lastMouseEventPeer = targetPeer; lastMouseEventPeer = targetPeer;
} }
} else { } else {
PlatformWindow topmostPlatforWindow = PlatformWindow topmostPlatformWindow = LWToolkit.getLWToolkit().getPlatformWindowUnderMouse();
platformWindow.getTopmostPlatformWindowUnderMouse();
LWWindowPeer topmostWindowPeer = LWWindowPeer topmostWindowPeer =
topmostPlatforWindow != null ? topmostPlatforWindow.getPeer() : null; topmostPlatformWindow != null ? topmostPlatformWindow.getPeer() : null;
// topmostWindowPeer == null condition is added for the backward // topmostWindowPeer == null condition is added for the backward
// compatibility with applets. It can be removed when the // compatibility with applets. It can be removed when the
...@@ -764,8 +763,7 @@ public class LWWindowPeer ...@@ -764,8 +763,7 @@ public class LWWindowPeer
screenX, screenY, modifiers, clickCount, popupTrigger, screenX, screenY, modifiers, clickCount, popupTrigger,
targetPeer); targetPeer);
} else { } else {
LWComponentPeer<?, ?> topmostTargetPeer = LWComponentPeer<?, ?> topmostTargetPeer = topmostWindowPeer.findPeerAt(r.x + x, r.y + y);
topmostWindowPeer != null ? topmostWindowPeer.findPeerAt(r.x + x, r.y + y) : null;
topmostWindowPeer.generateMouseEnterExitEventsForComponents(when, button, x, y, topmostWindowPeer.generateMouseEnterExitEventsForComponents(when, button, x, y,
screenX, screenY, modifiers, clickCount, popupTrigger, screenX, screenY, modifiers, clickCount, popupTrigger,
topmostTargetPeer); topmostTargetPeer);
......
...@@ -107,8 +107,6 @@ public interface PlatformWindow { ...@@ -107,8 +107,6 @@ public interface PlatformWindow {
public void setAlwaysOnTop(boolean value); public void setAlwaysOnTop(boolean value);
public PlatformWindow getTopmostPlatformWindowUnderMouse();
public void updateFocusableWindowState(); public void updateFocusableWindowState();
public boolean rejectFocusRequest(CausedFocusEvent.Cause cause); public boolean rejectFocusRequest(CausedFocusEvent.Cause cause);
......
...@@ -129,11 +129,6 @@ public class CPlatformEmbeddedFrame implements PlatformWindow { ...@@ -129,11 +129,6 @@ public class CPlatformEmbeddedFrame implements PlatformWindow {
@Override @Override
public void setAlwaysOnTop(boolean value) {} public void setAlwaysOnTop(boolean value) {}
// This method should be properly implemented for applets.
// It returns null just as a stub.
@Override
public PlatformWindow getTopmostPlatformWindowUnderMouse() { return null; }
@Override @Override
public void updateFocusableWindowState() {} public void updateFocusableWindowState() {}
......
...@@ -156,11 +156,6 @@ public class CPlatformLWWindow extends CPlatformWindow { ...@@ -156,11 +156,6 @@ public class CPlatformLWWindow extends CPlatformWindow {
public void setAlwaysOnTop(boolean isAlwaysOnTop) { public void setAlwaysOnTop(boolean isAlwaysOnTop) {
} }
@Override
public PlatformWindow getTopmostPlatformWindowUnderMouse(){
return null;
}
@Override @Override
public void setOpacity(float opacity) { public void setOpacity(float opacity) {
} }
......
...@@ -65,9 +65,9 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -65,9 +65,9 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
private static native void nativeSetEnabled(long nsWindowPtr, boolean isEnabled); private static native void nativeSetEnabled(long nsWindowPtr, boolean isEnabled);
private static native void nativeSynthesizeMouseEnteredExitedEvents(); private static native void nativeSynthesizeMouseEnteredExitedEvents();
private static native void nativeDispose(long nsWindowPtr); private static native void nativeDispose(long nsWindowPtr);
private static native CPlatformWindow nativeGetTopmostPlatformWindowUnderMouse();
private static native void nativeEnterFullScreenMode(long nsWindowPtr); private static native void nativeEnterFullScreenMode(long nsWindowPtr);
private static native void nativeExitFullScreenMode(long nsWindowPtr); private static native void nativeExitFullScreenMode(long nsWindowPtr);
static native CPlatformWindow nativeGetTopmostPlatformWindowUnderMouse();
// Loger to report issues happened during execution but that do not affect functionality // Loger to report issues happened during execution but that do not affect functionality
private static final PlatformLogger logger = PlatformLogger.getLogger("sun.lwawt.macosx.CPlatformWindow"); private static final PlatformLogger logger = PlatformLogger.getLogger("sun.lwawt.macosx.CPlatformWindow");
...@@ -769,10 +769,6 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -769,10 +769,6 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
setStyleBits(ALWAYS_ON_TOP, isAlwaysOnTop); setStyleBits(ALWAYS_ON_TOP, isAlwaysOnTop);
} }
public PlatformWindow getTopmostPlatformWindowUnderMouse(){
return CPlatformWindow.nativeGetTopmostPlatformWindowUnderMouse();
}
@Override @Override
public void setOpacity(float opacity) { public void setOpacity(float opacity) {
execute(ptr -> CWrapper.NSWindow.setAlphaValue(ptr, opacity)); execute(ptr -> CWrapper.NSWindow.setAlphaValue(ptr, opacity));
......
...@@ -78,7 +78,7 @@ class CRobot implements RobotPeer { ...@@ -78,7 +78,7 @@ class CRobot implements RobotPeer {
@Override @Override
public void mousePress(int buttons) { public void mousePress(int buttons) {
mouseButtonsState |= buttons; mouseButtonsState |= buttons;
checkMousePos();
mouseEvent(fDevice.getCGDisplayID(), mouseLastX, mouseLastY, mouseEvent(fDevice.getCGDisplayID(), mouseLastX, mouseLastY,
buttons, true, false); buttons, true, false);
} }
...@@ -92,11 +92,40 @@ class CRobot implements RobotPeer { ...@@ -92,11 +92,40 @@ class CRobot implements RobotPeer {
@Override @Override
public void mouseRelease(int buttons) { public void mouseRelease(int buttons) {
mouseButtonsState &= ~buttons; mouseButtonsState &= ~buttons;
checkMousePos();
mouseEvent(fDevice.getCGDisplayID(), mouseLastX, mouseLastY, mouseEvent(fDevice.getCGDisplayID(), mouseLastX, mouseLastY,
buttons, false, false); buttons, false, false);
} }
/**
* Set unknown mouse location, if needed.
*/
private void checkMousePos() {
if (mouseLastX == MOUSE_LOCATION_UNKNOWN ||
mouseLastY == MOUSE_LOCATION_UNKNOWN) {
Rectangle deviceBounds = fDevice.getDefaultConfiguration().getBounds();
Point mousePos = CCursorManager.getInstance().getCursorPosition();
if (mousePos.x < deviceBounds.x) {
mousePos.x = deviceBounds.x;
}
else if (mousePos.x > deviceBounds.x + deviceBounds.width) {
mousePos.x = deviceBounds.x + deviceBounds.width;
}
if (mousePos.y < deviceBounds.y) {
mousePos.y = deviceBounds.y;
}
else if (mousePos.y > deviceBounds.y + deviceBounds.height) {
mousePos.y = deviceBounds.y + deviceBounds.height;
}
mouseLastX = mousePos.x;
mouseLastY = mousePos.y;
}
}
@Override @Override
public native void mouseWheel(int wheelAmt); public native void mouseWheel(int wheelAmt);
......
...@@ -143,11 +143,6 @@ public class CViewPlatformEmbeddedFrame implements PlatformWindow { ...@@ -143,11 +143,6 @@ public class CViewPlatformEmbeddedFrame implements PlatformWindow {
public void setAlwaysOnTop(boolean value) { public void setAlwaysOnTop(boolean value) {
} }
@Override
public PlatformWindow getTopmostPlatformWindowUnderMouse() {
return null;
}
@Override @Override
public void updateFocusableWindowState() { public void updateFocusableWindowState() {
} }
......
...@@ -917,4 +917,9 @@ public final class LWCToolkit extends LWToolkit { ...@@ -917,4 +917,9 @@ public final class LWCToolkit extends LWToolkit {
!path.endsWith("/") && !path.endsWith("/") &&
!path.endsWith("."); !path.endsWith(".");
} }
@Override
protected PlatformWindow getPlatformWindowUnderMouse() {
return CPlatformWindow.nativeGetTopmostPlatformWindowUnderMouse();
}
} }
...@@ -1255,15 +1255,16 @@ JNIEXPORT jobject ...@@ -1255,15 +1255,16 @@ JNIEXPORT jobject
JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeGetTopmostPlatformWindowUnderMouse JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeGetTopmostPlatformWindowUnderMouse
(JNIEnv *env, jclass clazz) (JNIEnv *env, jclass clazz)
{ {
jobject topmostWindowUnderMouse = nil; __block jobject topmostWindowUnderMouse = nil;
JNF_COCOA_ENTER(env); JNF_COCOA_ENTER(env);
AWT_ASSERT_APPKIT_THREAD;
AWTWindow *awtWindow = [AWTWindow getTopmostWindowUnderMouse]; [ThreadUtilities performOnMainThreadWaiting:YES block:^{
if (awtWindow != nil) { AWTWindow *awtWindow = [AWTWindow getTopmostWindowUnderMouse];
topmostWindowUnderMouse = [awtWindow.javaPlatformWindow jObject]; if (awtWindow != nil) {
} topmostWindowUnderMouse = [awtWindow.javaPlatformWindow jObject];
}
}];
JNF_COCOA_EXIT(env); JNF_COCOA_EXIT(env);
......
...@@ -118,13 +118,11 @@ Java_sun_lwawt_macosx_CCursorManager_nativeGetCursorPosition ...@@ -118,13 +118,11 @@ Java_sun_lwawt_macosx_CCursorManager_nativeGetCursorPosition
JNF_COCOA_ENTER(env); JNF_COCOA_ENTER(env);
__block NSPoint pt = NSZeroPoint; CGEventRef event = CGEventCreate(NULL);
CGPoint globalPos = CGEventGetLocation(event);
[ThreadUtilities performOnMainThreadWaiting:YES block:^(){ CFRelease(event);
pt = ConvertNSScreenPoint(env, [NSEvent mouseLocation]);
}]; jpt = NSToJavaPoint(env, globalPos);
jpt = NSToJavaPoint(env, pt);
JNF_COCOA_EXIT(env); JNF_COCOA_EXIT(env);
......
...@@ -146,47 +146,10 @@ Java_sun_lwawt_macosx_CRobot_mouseEvent ...@@ -146,47 +146,10 @@ Java_sun_lwawt_macosx_CRobot_mouseEvent
// This is the native method called when Robot mouse events occur. // This is the native method called when Robot mouse events occur.
// The CRobot tracks the mouse position, and which button was // The CRobot tracks the mouse position, and which button was
// pressed. If the mouse position is unknown it is obtained from // pressed. The peer also tracks the mouse button desired state,
// CGEvents. The peer also tracks the mouse button desired state,
// the appropriate key modifier state, and whether the mouse action // the appropriate key modifier state, and whether the mouse action
// is simply a mouse move with no mouse button state changes. // is simply a mouse move with no mouse button state changes.
CGError err = kCGErrorSuccess;
CGRect globalDeviceBounds = CGDisplayBounds(displayID);
// Set unknown mouse location, if needed.
if ((mouseLastX == sun_lwawt_macosx_CRobot_MOUSE_LOCATION_UNKNOWN) ||
(mouseLastY == sun_lwawt_macosx_CRobot_MOUSE_LOCATION_UNKNOWN))
{
CGEventRef event = CGEventCreate(NULL);
if (event == NULL) {
return;
}
CGPoint globalPos = CGEventGetLocation(event);
CFRelease(event);
// Normalize the coords within this display device, as
// per Robot rules.
if (globalPos.x < CGRectGetMinX(globalDeviceBounds)) {
globalPos.x = CGRectGetMinX(globalDeviceBounds);
}
else if (globalPos.x > CGRectGetMaxX(globalDeviceBounds)) {
globalPos.x = CGRectGetMaxX(globalDeviceBounds);
}
if (globalPos.y < CGRectGetMinY(globalDeviceBounds)) {
globalPos.y = CGRectGetMinY(globalDeviceBounds);
}
else if (globalPos.y > CGRectGetMaxY(globalDeviceBounds)) {
globalPos.y = CGRectGetMaxY(globalDeviceBounds);
}
mouseLastX = (jint)globalPos.x;
mouseLastY = (jint)globalPos.y;
}
// volatile, otherwise it warns that it might be clobbered by 'longjmp' // volatile, otherwise it warns that it might be clobbered by 'longjmp'
volatile CGPoint point; volatile CGPoint point;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册