changeset 12249:3d2dfed2b420 jdk8u131-b03

8173030: Temporary backout fix #8035568 from 8u131-b03 Summary: Backed out changeset 1e335cd9b0fb Reviewed-by: dmarkov
author asaha
date Wed, 18 Jan 2017 22:44:37 -0800
parents 06926fc104a2
children a2476ec26274
files src/macosx/classes/sun/lwawt/LWMouseInfoPeer.java src/macosx/classes/sun/lwawt/LWToolkit.java src/macosx/classes/sun/lwawt/LWWindowPeer.java src/macosx/classes/sun/lwawt/PlatformWindow.java src/macosx/classes/sun/lwawt/macosx/CPlatformEmbeddedFrame.java src/macosx/classes/sun/lwawt/macosx/CPlatformLWWindow.java src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java src/macosx/classes/sun/lwawt/macosx/CRobot.java src/macosx/classes/sun/lwawt/macosx/CViewPlatformEmbeddedFrame.java src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java src/macosx/native/sun/awt/AWTWindow.m src/macosx/native/sun/awt/CCursorManager.m src/macosx/native/sun/awt/CRobot.m test/java/awt/MouseInfo/GetPointerInfoTest.java test/java/awt/MouseInfo/MultiscreenPointerInfo.java
diffstat 15 files changed, 82 insertions(+), 224 deletions(-) [+]
line wrap: on
line diff
--- a/src/macosx/classes/sun/lwawt/LWMouseInfoPeer.java	Wed Jan 18 22:41:15 2017 -0800
+++ b/src/macosx/classes/sun/lwawt/LWMouseInfoPeer.java	Wed Jan 18 22:44:37 2017 -0800
@@ -51,12 +51,8 @@
             return false;
         }
 
-        LWWindowPeer windowPeer = (LWWindowPeer)AWTAccessor.getComponentAccessor().getPeer(w);
-        if (windowPeer == null) {
-            return false;
-        }
-
-        return LWToolkit.getLWToolkit().getPlatformWindowUnderMouse() == windowPeer.getPlatformWindow();
+        final Object windowPeer = AWTAccessor.getComponentAccessor().getPeer(w);
+        return LWWindowPeer.getWindowUnderCursor() == windowPeer;
     }
 
 }
--- a/src/macosx/classes/sun/lwawt/LWToolkit.java	Wed Jan 18 22:41:15 2017 -0800
+++ b/src/macosx/classes/sun/lwawt/LWToolkit.java	Wed Jan 18 22:44:37 2017 -0800
@@ -385,8 +385,6 @@
         return new LWMouseInfoPeer();
     }
 
-    protected abstract PlatformWindow getPlatformWindowUnderMouse();
-
     @Override
     public final PrintJob getPrintJob(Frame frame, String doctitle,
                                       Properties props) {
--- a/src/macosx/classes/sun/lwawt/LWWindowPeer.java	Wed Jan 18 22:41:15 2017 -0800
+++ b/src/macosx/classes/sun/lwawt/LWWindowPeer.java	Wed Jan 18 22:44:37 2017 -0800
@@ -749,10 +749,11 @@
                 lastMouseEventPeer = targetPeer;
             }
         } else {
-            PlatformWindow topmostPlatformWindow = LWToolkit.getLWToolkit().getPlatformWindowUnderMouse();
+            PlatformWindow topmostPlatforWindow =
+                    platformWindow.getTopmostPlatformWindowUnderMouse();
 
             LWWindowPeer topmostWindowPeer =
-                    topmostPlatformWindow != null ? topmostPlatformWindow.getPeer() : null;
+                    topmostPlatforWindow != null ? topmostPlatforWindow.getPeer() : null;
 
             // topmostWindowPeer == null condition is added for the backward
             // compatibility with applets. It can be removed when the
@@ -763,7 +764,8 @@
                         screenX, screenY, modifiers, clickCount, popupTrigger,
                         targetPeer);
             } else {
-                LWComponentPeer<?, ?> topmostTargetPeer = topmostWindowPeer.findPeerAt(r.x + x, r.y + y);
+                LWComponentPeer<?, ?> topmostTargetPeer =
+                        topmostWindowPeer != null ? topmostWindowPeer.findPeerAt(r.x + x, r.y + y) : null;
                 topmostWindowPeer.generateMouseEnterExitEventsForComponents(when, button, x, y,
                         screenX, screenY, modifiers, clickCount, popupTrigger,
                         topmostTargetPeer);
--- a/src/macosx/classes/sun/lwawt/PlatformWindow.java	Wed Jan 18 22:41:15 2017 -0800
+++ b/src/macosx/classes/sun/lwawt/PlatformWindow.java	Wed Jan 18 22:44:37 2017 -0800
@@ -107,6 +107,8 @@
 
     public void setAlwaysOnTop(boolean value);
 
+    public PlatformWindow getTopmostPlatformWindowUnderMouse();
+
     public void updateFocusableWindowState();
 
     public boolean rejectFocusRequest(CausedFocusEvent.Cause cause);
--- a/src/macosx/classes/sun/lwawt/macosx/CPlatformEmbeddedFrame.java	Wed Jan 18 22:41:15 2017 -0800
+++ b/src/macosx/classes/sun/lwawt/macosx/CPlatformEmbeddedFrame.java	Wed Jan 18 22:44:37 2017 -0800
@@ -129,6 +129,11 @@
     @Override
     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
     public void updateFocusableWindowState() {}
 
--- a/src/macosx/classes/sun/lwawt/macosx/CPlatformLWWindow.java	Wed Jan 18 22:41:15 2017 -0800
+++ b/src/macosx/classes/sun/lwawt/macosx/CPlatformLWWindow.java	Wed Jan 18 22:44:37 2017 -0800
@@ -157,6 +157,11 @@
     }
 
     @Override
+    public PlatformWindow getTopmostPlatformWindowUnderMouse(){
+        return null;
+    }
+
+    @Override
     public void setOpacity(float opacity) {
     }
 
--- a/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java	Wed Jan 18 22:41:15 2017 -0800
+++ b/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java	Wed Jan 18 22:44:37 2017 -0800
@@ -65,9 +65,9 @@
     private static native void nativeSetEnabled(long nsWindowPtr, boolean isEnabled);
     private static native void nativeSynthesizeMouseEnteredExitedEvents();
     private static native void nativeDispose(long nsWindowPtr);
+    private static native CPlatformWindow nativeGetTopmostPlatformWindowUnderMouse();
     private static native void nativeEnterFullScreenMode(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
     private static final PlatformLogger logger = PlatformLogger.getLogger("sun.lwawt.macosx.CPlatformWindow");
@@ -769,6 +769,10 @@
         setStyleBits(ALWAYS_ON_TOP, isAlwaysOnTop);
     }
 
+    public PlatformWindow getTopmostPlatformWindowUnderMouse(){
+        return CPlatformWindow.nativeGetTopmostPlatformWindowUnderMouse();
+    }
+
     @Override
     public void setOpacity(float opacity) {
         execute(ptr -> CWrapper.NSWindow.setAlphaValue(ptr, opacity));
--- a/src/macosx/classes/sun/lwawt/macosx/CRobot.java	Wed Jan 18 22:41:15 2017 -0800
+++ b/src/macosx/classes/sun/lwawt/macosx/CRobot.java	Wed Jan 18 22:44:37 2017 -0800
@@ -78,7 +78,7 @@
     @Override
     public void mousePress(int buttons) {
         mouseButtonsState |= buttons;
-        checkMousePos();
+
         mouseEvent(fDevice.getCGDisplayID(), mouseLastX, mouseLastY,
                    buttons, true, false);
     }
@@ -92,40 +92,11 @@
     @Override
     public void mouseRelease(int buttons) {
         mouseButtonsState &= ~buttons;
-        checkMousePos();
+
         mouseEvent(fDevice.getCGDisplayID(), mouseLastX, mouseLastY,
                    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
     public native void mouseWheel(int wheelAmt);
 
--- a/src/macosx/classes/sun/lwawt/macosx/CViewPlatformEmbeddedFrame.java	Wed Jan 18 22:41:15 2017 -0800
+++ b/src/macosx/classes/sun/lwawt/macosx/CViewPlatformEmbeddedFrame.java	Wed Jan 18 22:44:37 2017 -0800
@@ -144,6 +144,11 @@
     }
 
     @Override
+    public PlatformWindow getTopmostPlatformWindowUnderMouse() {
+        return null;
+    }
+
+    @Override
     public void updateFocusableWindowState() {
     }
 
--- a/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java	Wed Jan 18 22:41:15 2017 -0800
+++ b/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java	Wed Jan 18 22:44:37 2017 -0800
@@ -917,9 +917,4 @@
                 !path.endsWith("/") &&
                 !path.endsWith(".");
     }
-
-    @Override
-    protected PlatformWindow getPlatformWindowUnderMouse() {
-        return CPlatformWindow.nativeGetTopmostPlatformWindowUnderMouse();
-    }
 }
--- a/src/macosx/native/sun/awt/AWTWindow.m	Wed Jan 18 22:41:15 2017 -0800
+++ b/src/macosx/native/sun/awt/AWTWindow.m	Wed Jan 18 22:44:37 2017 -0800
@@ -1255,16 +1255,15 @@
 JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeGetTopmostPlatformWindowUnderMouse
 (JNIEnv *env, jclass clazz)
 {
-    __block jobject topmostWindowUnderMouse = nil;
+    jobject topmostWindowUnderMouse = nil;
 
     JNF_COCOA_ENTER(env);
+    AWT_ASSERT_APPKIT_THREAD;
 
-    [ThreadUtilities performOnMainThreadWaiting:YES block:^{
-        AWTWindow *awtWindow = [AWTWindow getTopmostWindowUnderMouse];
-        if (awtWindow != nil) {
-            topmostWindowUnderMouse = [awtWindow.javaPlatformWindow jObject];
-        }
-    }];
+    AWTWindow *awtWindow = [AWTWindow getTopmostWindowUnderMouse];
+    if (awtWindow != nil) {
+        topmostWindowUnderMouse = [awtWindow.javaPlatformWindow jObject];
+    }
 
     JNF_COCOA_EXIT(env);
 
--- a/src/macosx/native/sun/awt/CCursorManager.m	Wed Jan 18 22:41:15 2017 -0800
+++ b/src/macosx/native/sun/awt/CCursorManager.m	Wed Jan 18 22:44:37 2017 -0800
@@ -118,11 +118,13 @@
 
 JNF_COCOA_ENTER(env);
 
-    CGEventRef event = CGEventCreate(NULL);
-    CGPoint globalPos = CGEventGetLocation(event);
-    CFRelease(event);
-
-    jpt = NSToJavaPoint(env, globalPos);
+    __block NSPoint pt = NSZeroPoint;
+    
+    [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
+            pt = ConvertNSScreenPoint(env, [NSEvent mouseLocation]);
+    }];
+    
+    jpt = NSToJavaPoint(env, pt);
 
 JNF_COCOA_EXIT(env);
 
--- a/src/macosx/native/sun/awt/CRobot.m	Wed Jan 18 22:41:15 2017 -0800
+++ b/src/macosx/native/sun/awt/CRobot.m	Wed Jan 18 22:44:37 2017 -0800
@@ -146,10 +146,47 @@
 
     // This is the native method called when Robot mouse events occur.
     // The CRobot tracks the mouse position, and which button was
-    // pressed. The peer also tracks the mouse button desired state,
+    // pressed. If the mouse position is unknown it is obtained from
+    // CGEvents. The peer also tracks the mouse button desired state,
     // the appropriate key modifier state, and whether the mouse action
     // 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 CGPoint point;
 
--- a/test/java/awt/MouseInfo/GetPointerInfoTest.java	Wed Jan 18 22:41:15 2017 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,73 +0,0 @@
-/*
- * Copyright (c) 2014, 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.
- *
- * 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.
- */
-
-/*
-  @test
-  @summary unit test for getPointerInfo() from MouseInfo class
-  @author dav@sparc.spb.su: area=
-  @bug 4009555
-  @run main GetPointerInfoTest
-*/
-
-import java.awt.*;
-
-/**
- * Simply check the result on non-null and results are correct.
- */
-public class GetPointerInfoTest {
-    private static final String successStage = "Test stage completed.Passed.";
-
-    public static void main(String[] args) throws Exception {
-        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
-        GraphicsDevice[] gds = ge.getScreenDevices();
-        int gdslen = gds.length;
-        System.out.println("There are " + gdslen + " Graphics Devices");
-        if (gdslen == 0) {
-            System.out.println("Nothing to be done.");
-            return;
-        }
-        Robot robot = new Robot(gds[0]);
-        robot.setAutoDelay(0);
-        robot.setAutoWaitForIdle(true);
-        robot.delay(10);
-        robot.waitForIdle();
-        Point p = new Point(101, 99);
-        robot.mouseMove(p.x, p.y);
-
-        PointerInfo pi = MouseInfo.getPointerInfo();
-        if (pi == null) {
-            throw new RuntimeException("Test failed. getPointerInfo() returned null value.");
-        } else {
-            System.out.println(successStage);
-        }
-        Point piLocation = pi.getLocation();
-
-        if (piLocation.x != p.x || piLocation.y != p.y) {
-            throw new RuntimeException("Test failed.getPointerInfo() returned incorrect result.");
-        } else {
-            System.out.println(successStage);
-        }
-
-        System.out.println("Test PASSED.");
-    }
-}
--- a/test/java/awt/MouseInfo/MultiscreenPointerInfo.java	Wed Jan 18 22:41:15 2017 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,90 +0,0 @@
-/*
- * Copyright (c) 2014, 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.
- *
- * 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.
- */
-
-/*
-  @test
-  @summary unit test for getPointerInfo() from MouseInfo class
-  @author prs@sparc.spb.su: area=
-  @bug 4009555
-  @run main MultiscreenPointerInfo
-*/
-
-import java.awt.*;
-
-/**
- * Simply check the result on non-null and results are correct.
- */
-public class MultiscreenPointerInfo
-{
-    private static final String successStage = "Test stage completed.Passed.";
-
-    public static void main(String[] args) throws Exception {
-        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
-        GraphicsDevice[] gds = ge.getScreenDevices();
-        int gdslen = gds.length;
-        System.out.println("There are " + gdslen + " Graphics Devices");
-        if (gdslen < 2) {
-            System.out.println("Nothing to be done. PASSED automatically.");
-            return;
-        }
-        Rectangle rx = gds[1].getDefaultConfiguration().getBounds();
-        Robot robot;
-
-        if (rx.x == 0 && rx.y == 0) {
-            // Assuming independent graphics devices
-            robot = new Robot(gds[1]);
-        } else {
-            // Means we have a virtual device
-            robot = new Robot(gds[0]);
-        }
-        robot.setAutoDelay(0);
-        robot.setAutoWaitForIdle(true);
-        robot.delay(10);
-        robot.waitForIdle();
-        Point p = new Point(rx.x + 101, rx.y + 99);
-        robot.mouseMove(p.x, p.y);
-        PointerInfo pi = MouseInfo.getPointerInfo();
-        if (pi == null) {
-            throw new RuntimeException("Test failed. getPointerInfo() returned null value.");
-        } else {
-            System.out.println(successStage);
-        }
-
-        Point piLocation = pi.getLocation();
-
-        if (piLocation.x != p.x || piLocation.y != p.y) {
-            throw new RuntimeException("Test failed.getPointerInfo() returned incorrect location.");
-        } else {
-            System.out.println(successStage);
-        }
-
-        GraphicsDevice dev = pi.getDevice();
-
-        if (dev != gds[1]) {
-            throw new RuntimeException("Test failed.getPointerInfo() returned incorrect device.");
-        } else {
-            System.out.println(successStage);
-        }
-        System.out.println("Test PASSED.");
-    }
-}