changeset 5278:a7aac7f4a4c4

7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag. Reviewed-by: anthony, serb
author alexsch
date Mon, 03 Sep 2012 16:31:53 +0400
parents 770fc16ac677
children 941233de8e72
files src/macosx/classes/sun/lwawt/LWWindowPeer.java test/java/awt/Mouse/EnterExitEvents/DragWindowTest.java
diffstat 2 files changed, 28 insertions(+), 250 deletions(-) [+]
line wrap: on
line diff
--- a/src/macosx/classes/sun/lwawt/LWWindowPeer.java	Fri Aug 31 13:42:47 2012 +0100
+++ b/src/macosx/classes/sun/lwawt/LWWindowPeer.java	Mon Sep 03 16:31:53 2012 +0400
@@ -751,42 +751,39 @@
             }
         } else {
             if (targetPeer != lastMouseEventPeer) {
-
-                if (id != MouseEvent.MOUSE_DRAGGED || lastMouseEventPeer == null) {
-                    // lastMouseEventPeer may be null if mouse was out of Java windows
-                    if (lastMouseEventPeer != null && lastMouseEventPeer.isEnabled()) {
-                        // Sometimes, MOUSE_EXITED is not sent by delegate (or is sent a bit
-                        // later), in which case lastWindowPeer is another window
-                        if (lastWindowPeer != this) {
-                            Point oldp = lastMouseEventPeer.windowToLocal(x, y, lastWindowPeer);
-                            // Additionally translate from this to lastWindowPeer coordinates
-                            Rectangle lr = lastWindowPeer.getBounds();
-                            oldp.x += r.x - lr.x;
-                            oldp.y += r.y - lr.y;
-                            postEvent(new MouseEvent(lastMouseEventPeer.getTarget(),
-                                                     MouseEvent.MOUSE_EXITED,
-                                                     when, modifiers,
-                                                     oldp.x, oldp.y, screenX, screenY,
-                                                     clickCount, popupTrigger, button));
-                        } else {
-                            Point oldp = lastMouseEventPeer.windowToLocal(x, y, this);
-                            postEvent(new MouseEvent(lastMouseEventPeer.getTarget(),
-                                                     MouseEvent.MOUSE_EXITED,
-                                                     when, modifiers,
-                                                     oldp.x, oldp.y, screenX, screenY,
-                                                     clickCount, popupTrigger, button));
-                        }
-                    }
-                    if (targetPeer != null && targetPeer.isEnabled() && id != MouseEvent.MOUSE_ENTERED) {
-                        Point newp = targetPeer.windowToLocal(x, y, curWindowPeer);
-                        postEvent(new MouseEvent(targetPeer.getTarget(),
-                                                 MouseEvent.MOUSE_ENTERED,
+                // lastMouseEventPeer may be null if mouse was out of Java windows
+                if (lastMouseEventPeer != null && lastMouseEventPeer.isEnabled()) {
+                    // Sometimes, MOUSE_EXITED is not sent by delegate (or is sent a bit
+                    // later), in which case lastWindowPeer is another window
+                    if (lastWindowPeer != this) {
+                        Point oldp = lastMouseEventPeer.windowToLocal(x, y, lastWindowPeer);
+                        // Additionally translate from this to lastWindowPeer coordinates
+                        Rectangle lr = lastWindowPeer.getBounds();
+                        oldp.x += r.x - lr.x;
+                        oldp.y += r.y - lr.y;
+                        postEvent(new MouseEvent(lastMouseEventPeer.getTarget(),
+                                                 MouseEvent.MOUSE_EXITED,
                                                  when, modifiers,
-                                                 newp.x, newp.y, screenX, screenY,
+                                                 oldp.x, oldp.y, screenX, screenY,
+                                                 clickCount, popupTrigger, button));
+                    } else {
+                        Point oldp = lastMouseEventPeer.windowToLocal(x, y, this);
+                        postEvent(new MouseEvent(lastMouseEventPeer.getTarget(),
+                                                 MouseEvent.MOUSE_EXITED,
+                                                 when, modifiers,
+                                                 oldp.x, oldp.y, screenX, screenY,
                                                  clickCount, popupTrigger, button));
                     }
                 }
                 lastMouseEventPeer = targetPeer;
+                if (targetPeer != null && targetPeer.isEnabled() && id != MouseEvent.MOUSE_ENTERED) {
+                    Point newp = targetPeer.windowToLocal(x, y, curWindowPeer);
+                    postEvent(new MouseEvent(targetPeer.getTarget(),
+                                             MouseEvent.MOUSE_ENTERED,
+                                             when, modifiers,
+                                             newp.x, newp.y, screenX, screenY,
+                                             clickCount, popupTrigger, button));
+                }
             }
             // TODO: fill "bdata" member of AWTEvent
 
--- a/test/java/awt/Mouse/EnterExitEvents/DragWindowTest.java	Fri Aug 31 13:42:47 2012 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,219 +0,0 @@
-/*
- * Copyright (c) 2005, 2006, 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
- * @bug 7154048
- * @summary Window created under a mouse does not receive mouse enter event.
- *     Mouse Entered/Exited events are wrongly generated during dragging the window
- *     from one component to another
- * @library ../../regtesthelpers
- * @build Util
- * @author alexandr.scherbatiy area=awt.event
- * @run main DragWindowTest
- */
-
-import java.awt.*;
-import java.awt.event.*;
-import javax.swing.*;
-
-import java.util.concurrent.*;
-import sun.awt.SunToolkit;
-
-import test.java.awt.regtesthelpers.Util;
-
-public class DragWindowTest {
-
-    private static volatile int dragWindowMouseEnteredCount = 0;
-    private static volatile int dragWindowMouseReleasedCount = 0;
-    private static volatile int buttonMouseEnteredCount = 0;
-    private static volatile int labelMouseReleasedCount = 0;
-    private static MyDragWindow dragWindow;
-    private static JLabel label;
-    private static JButton button;
-
-    public static void main(String[] args) throws Exception {
-
-        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
-        Robot robot = new Robot();
-        robot.setAutoDelay(50);
-
-        SwingUtilities.invokeAndWait(new Runnable() {
-
-            @Override
-            public void run() {
-                createAndShowGUI();
-            }
-        });
-
-        toolkit.realSync();
-
-        Point pointToClick = Util.invokeOnEDT(new Callable<Point>() {
-
-            @Override
-            public Point call() throws Exception {
-                return getCenterPoint(label);
-            }
-        });
-
-
-        robot.mouseMove(pointToClick.x, pointToClick.y);
-        robot.mousePress(InputEvent.BUTTON1_MASK);
-        toolkit.realSync();
-
-        if (dragWindowMouseEnteredCount != 1) {
-            throw new RuntimeException("No MouseEntered event on Drag Window!");
-        }
-
-        Point pointToDrag = Util.invokeOnEDT(new Callable<Point>() {
-
-            @Override
-            public Point call() throws Exception {
-                button.addMouseListener(new ButtonMouseListener());
-                return getCenterPoint(button);
-            }
-        });
-
-        robot.mouseMove(pointToDrag.x, pointToDrag.y);
-        toolkit.realSync();
-
-        if (buttonMouseEnteredCount != 0) {
-            throw new RuntimeException("Extra MouseEntered event on button!");
-        }
-
-        robot.mouseRelease(InputEvent.BUTTON1_MASK);
-        toolkit.realSync();
-
-        if (labelMouseReleasedCount != 1) {
-            throw new RuntimeException("No MouseReleased event on label!");
-        }
-
-    }
-
-    private static Point getCenterPoint(Component comp) {
-        Point p = comp.getLocationOnScreen();
-        Rectangle rect = comp.getBounds();
-        return new Point(p.x + rect.width / 2, p.y + rect.height / 2);
-    }
-
-    private static void createAndShowGUI() {
-
-        JFrame frame = new JFrame("Main Frame");
-        frame.setSize(300, 200);
-        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-
-        label = new JLabel("Label");
-
-        LabelMouseListener listener = new LabelMouseListener(frame);
-        label.addMouseListener(listener);
-        label.addMouseMotionListener(listener);
-
-        button = new JButton("Button");
-        Panel panel = new Panel(new BorderLayout());
-
-        panel.add(label, BorderLayout.NORTH);
-        panel.add(button, BorderLayout.CENTER);
-
-        frame.getContentPane().add(panel);
-        frame.setVisible(true);
-
-    }
-
-    private static Point getAbsoluteLocation(MouseEvent e) {
-        return new Point(e.getXOnScreen(), e.getYOnScreen());
-    }
-
-    static class MyDragWindow extends Window {
-
-        static int d = 30;
-
-        public MyDragWindow(Window parent, Point location) {
-            super(parent);
-            setSize(150, 150);
-            setVisible(true);
-            JPanel panel = new JPanel();
-            add(panel);
-            setLocation(location.x - d, location.y - d);
-            addMouseListener(new DragWindowMouseListener());
-        }
-
-        void dragTo(Point point) {
-            setLocation(point.x - d, point.y - d);
-        }
-    }
-
-    static class LabelMouseListener extends MouseAdapter {
-
-        Point origin;
-        Window parent;
-
-        public LabelMouseListener(Window parent) {
-            this.parent = parent;
-        }
-
-        @Override
-        public void mousePressed(MouseEvent e) {
-            if (dragWindow == null) {
-                dragWindow = new MyDragWindow(parent, getAbsoluteLocation(e));
-            } else {
-                dragWindow.setVisible(true);
-                dragWindow.dragTo(getAbsoluteLocation(e));
-            }
-        }
-
-        @Override
-        public void mouseReleased(MouseEvent e) {
-            labelMouseReleasedCount++;
-            if (dragWindow != null) {
-                dragWindow.setVisible(false);
-            }
-        }
-
-        public void mouseDragged(MouseEvent e) {
-            if (dragWindow != null) {
-                dragWindow.dragTo(getAbsoluteLocation(e));
-            }
-        }
-    }
-
-    static class DragWindowMouseListener extends MouseAdapter {
-
-        @Override
-        public void mouseEntered(MouseEvent e) {
-            dragWindowMouseEnteredCount++;
-        }
-
-        @Override
-        public void mouseReleased(MouseEvent e) {
-            dragWindowMouseReleasedCount++;
-        }
-    }
-
-    static class ButtonMouseListener extends MouseAdapter {
-
-        @Override
-        public void mouseEntered(MouseEvent e) {
-            buttonMouseEnteredCount++;
-        }
-    }
-}