8191696: Better mouse positioning
authorserb
Wed, 03 Jan 2018 09:05:11 -0800
changeset 49782 7cbb8bd1fc29
parent 49781 21fa027e2e62
child 49783 977c6dd636bd
8191696: Better mouse positioning Reviewed-by: skoivu, rhalade, prr, aghaisas
src/java.desktop/unix/classes/sun/awt/X11/XMouseInfoPeer.java
src/java.desktop/windows/native/libawt/windows/MouseInfo.cpp
--- a/src/java.desktop/unix/classes/sun/awt/X11/XMouseInfoPeer.java	Tue Jan 02 09:23:01 2018 -0500
+++ b/src/java.desktop/unix/classes/sun/awt/X11/XMouseInfoPeer.java	Wed Jan 03 09:05:11 2018 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, 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
@@ -25,16 +25,16 @@
 
 package sun.awt.X11;
 
+import java.awt.GraphicsDevice;
+import java.awt.GraphicsEnvironment;
 import java.awt.Point;
 import java.awt.Window;
-import java.awt.GraphicsEnvironment;
-import java.awt.GraphicsDevice;
 import java.awt.peer.MouseInfoPeer;
+
+import sun.awt.AWTAccessor;
 import sun.awt.X11GraphicsDevice;
 
-import sun.awt.AWTAccessor;
-
-public class XMouseInfoPeer implements MouseInfoPeer {
+public final class XMouseInfoPeer implements MouseInfoPeer {
 
     /**
      * Package-private constructor to prevent instantiation.
@@ -85,13 +85,14 @@
 
     @SuppressWarnings("deprecation")
     public boolean isWindowUnderMouse(Window w) {
-
+        if (w == null) {
+            return false;
+        }
+        XWindow peer = AWTAccessor.getComponentAccessor().getPeer(w);
+        if (peer == null) {
+            return false;
+        }
         long display = XToolkit.getDisplay();
-
-        // java.awt.Component.findUnderMouseInWindow checks that
-        // the peer is non-null by checking that the component
-        // is showing.
-        XWindow peer = AWTAccessor.getComponentAccessor().getPeer(w);
         long contentWindow = peer.getContentWindow();
         long parent = XlibUtil.getParentWindow(contentWindow);
 
--- a/src/java.desktop/windows/native/libawt/windows/MouseInfo.cpp	Tue Jan 02 09:23:01 2018 -0500
+++ b/src/java.desktop/windows/native/libawt/windows/MouseInfo.cpp	Wed Jan 03 09:05:11 2018 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, 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
@@ -48,6 +48,7 @@
     }
 
     jobject winPeer = AwtObject::GetPeerForTarget(env, window);
+    CHECK_NULL_RETURN(winPeer, JNI_FALSE);
     PDATA pData;
     pData = JNI_GET_PDATA(winPeer);
     env->DeleteLocalRef(winPeer);