7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
authoralexsch
Wed, 02 May 2012 17:54:18 +0400
changeset 12535 6d2ee83614e8
parent 12534 5fbdf283ed28
child 12536 3584064dc0ee
child 12639 c1634bcec0a8
7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side Reviewed-by: anthony, leonidr
jdk/src/macosx/classes/sun/lwawt/LWWindowPeer.java
jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java
jdk/src/macosx/native/sun/awt/AWTView.h
jdk/src/macosx/native/sun/awt/AWTView.m
jdk/src/macosx/native/sun/awt/AWTWindow.h
jdk/src/macosx/native/sun/awt/AWTWindow.m
jdk/test/java/awt/Mouse/EnterExitEvents/DragWindowOutOfFrameTest.java
jdk/test/java/awt/Mouse/EnterExitEvents/DragWindowTest.java
jdk/test/java/awt/Mouse/EnterExitEvents/ResizingFrameTest.java
jdk/test/java/awt/regtesthelpers/Util.java
--- a/jdk/src/macosx/classes/sun/lwawt/LWWindowPeer.java	Wed May 02 13:53:06 2012 +0400
+++ b/jdk/src/macosx/classes/sun/lwawt/LWWindowPeer.java	Wed May 02 17:54:18 2012 +0400
@@ -669,39 +669,42 @@
             }
         } else {
             if (targetPeer != lastMouseEventPeer) {
-                // 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,
+
+                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,
                                                  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,
+                                                 newp.x, newp.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/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java	Wed May 02 13:53:06 2012 +0400
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java	Wed May 02 17:54:18 2012 +0400
@@ -61,6 +61,7 @@
     private static native void nativeSetNSWindowMinimizedIcon(long nsWindowPtr, long nsImage);
     private static native void nativeSetNSWindowRepresentedFilename(long nsWindowPtr, String representedFilename);
     private static native void nativeSetNSWindowSecurityWarningPositioning(long nsWindowPtr, double x, double y, float biasX, float biasY);
+    private static native void nativeSynthesizeMouseEnteredExitedEvents(long nsWindowPtr);
 
     private static native int nativeGetScreenNSWindowIsOn_AppKitThread(long nsWindowPtr);
 
@@ -582,6 +583,8 @@
             }
         }
 
+        nativeSynthesizeMouseEnteredExitedEvents(nsWindowPtr);
+
         // 6. Configure stuff #2
         updateFocusabilityForAutoRequestFocus(true);
 
@@ -791,6 +794,8 @@
                 throw new RuntimeException("Unknown window state: " + windowState);
         }
 
+        nativeSynthesizeMouseEnteredExitedEvents(nsWindowPtr);
+
         // NOTE: the SWP.windowState field gets updated to the newWindowState
         //       value when the native notification comes to us
     }
--- a/jdk/src/macosx/native/sun/awt/AWTView.h	Wed May 02 13:53:06 2012 +0400
+++ b/jdk/src/macosx/native/sun/awt/AWTView.h	Wed May 02 17:54:18 2012 +0400
@@ -52,9 +52,12 @@
     BOOL fPAHNeedsToSelect;
 
     id cglLayer; // is a sublayer of view.layer
+
+    BOOL mouseIsOver;
 }
 
 @property (nonatomic, retain) id cglLayer;
+@property (nonatomic) BOOL mouseIsOver;
 
 - (id) initWithRect:(NSRect) rect platformView:(jobject)cPlatformView windowLayer:(CALayer*)windowLayer;
 - (void) deliverJavaMouseEvent: (NSEvent *) event;
--- a/jdk/src/macosx/native/sun/awt/AWTView.m	Wed May 02 13:53:06 2012 +0400
+++ b/jdk/src/macosx/native/sun/awt/AWTView.m	Wed May 02 17:54:18 2012 +0400
@@ -61,6 +61,7 @@
 @synthesize _dropTarget;
 @synthesize _dragSource;
 @synthesize cglLayer;
+@synthesize mouseIsOver;
 
 // Note: Must be called on main (AppKit) thread only
 - (id) initWithRect: (NSRect) rect
@@ -80,6 +81,8 @@
     fEnablePressAndHold = shouldUsePressAndHold();
     fInPressAndHold = NO;
     fPAHNeedsToSelect = NO;
+    
+    mouseIsOver = NO;
 
     if (windowLayer != nil) {
         self.cglLayer = windowLayer;
@@ -299,6 +302,16 @@
  */
 
 -(void) deliverJavaMouseEvent: (NSEvent *) event {
+    
+    NSEventType type = [event type];    
+    
+    // check synthesized mouse entered/exited events
+    if ((type == NSMouseEntered && mouseIsOver) || (type == NSMouseExited && !mouseIsOver)) {
+        return;
+    }else if ((type == NSMouseEntered && !mouseIsOver) || (type == NSMouseExited && mouseIsOver)) {
+        mouseIsOver = !mouseIsOver;
+    }
+    
     [AWTToolkit eventCountPlusPlus];
 
     JNIEnv *env = [ThreadUtilities getJNIEnv];
@@ -306,7 +319,6 @@
     NSPoint eventLocation = [event locationInWindow];
     NSPoint localPoint = [self convertPoint: eventLocation fromView: nil];
     NSPoint absP = [NSEvent mouseLocation];
-    NSEventType type = [event type];
 
     // Convert global numbers between Cocoa's coordinate system and Java.
     // TODO: need consitent way for doing that both with global as well as with local coordinates.
--- a/jdk/src/macosx/native/sun/awt/AWTWindow.h	Wed May 02 13:53:06 2012 +0400
+++ b/jdk/src/macosx/native/sun/awt/AWTWindow.h	Wed May 02 17:54:18 2012 +0400
@@ -56,6 +56,7 @@
                   contentView:(NSView *)contentView;
 
 - (void) adjustGrowBoxWindow;
+- (BOOL) isTopmostWindowUnderMouse;
 @end
 
 #endif _AWTWINDOW_H
--- a/jdk/src/macosx/native/sun/awt/AWTWindow.m	Wed May 02 13:53:06 2012 +0400
+++ b/jdk/src/macosx/native/sun/awt/AWTWindow.m	Wed May 02 17:54:18 2012 +0400
@@ -170,6 +170,66 @@
     return self;
 }
 
+// checks that this window is under the mouse cursor and this point is not overlapped by others windows 
+- (BOOL) isTopmostWindowUnderMouse {
+    
+    int currentWinID = [self windowNumber]; 
+    
+    NSRect screenRect = [[NSScreen mainScreen] frame];    
+    NSPoint nsMouseLocation = [NSEvent mouseLocation];
+    CGPoint cgMouseLocation = CGPointMake(nsMouseLocation.x, screenRect.size.height - nsMouseLocation.y);    
+    
+    NSMutableArray *windows = (NSMutableArray *)CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID);
+    
+    
+    for (NSDictionary *window in windows) {
+        int layer = [[window objectForKey:(id)kCGWindowLayer] intValue];
+        if (layer == 0) {
+            int winID = [[window objectForKey:(id)kCGWindowNumber] intValue];            
+            CGRect rect;
+            CGRectMakeWithDictionaryRepresentation((CFDictionaryRef)[window objectForKey:(id)kCGWindowBounds], &rect);
+            if (CGRectContainsPoint(rect, cgMouseLocation)) {
+                return currentWinID == winID;
+            } else if (currentWinID == winID) {
+                return NO;
+            }
+        }
+    }
+    return NO;
+}
+
+- (void) synthesizeMouseEnteredExitedEvents {
+    
+    int eventType = 0;
+    BOOL isUnderMouse = [self isTopmostWindowUnderMouse];
+    BOOL mouseIsOver = [[self contentView] mouseIsOver];
+    
+    if (isUnderMouse && !mouseIsOver) {
+        eventType = NSMouseEntered;
+    } else if (!isUnderMouse && mouseIsOver) {
+        eventType = NSMouseExited;        
+    } else {
+        return;
+    }
+    
+    NSPoint screenLocation = [NSEvent mouseLocation];        
+    NSPoint windowLocation = [self convertScreenToBase: screenLocation];        
+    int modifierFlags = (eventType == NSMouseEntered) ? NSMouseEnteredMask : NSMouseExitedMask;
+    
+    NSEvent *mouseEvent = [NSEvent enterExitEventWithType: eventType
+                                                  location: windowLocation
+                                             modifierFlags: modifierFlags
+                                                 timestamp: 0
+                                              windowNumber: [self windowNumber]
+                                                   context: nil
+                                               eventNumber: 0
+                                            trackingNumber: 0
+                                                  userData: nil
+                            ];
+    
+    [[self contentView] deliverJavaMouseEvent: mouseEvent];
+}
+
 - (void) dealloc {
 AWT_ASSERT_APPKIT_THREAD;
 
@@ -669,6 +729,8 @@
         // ensure we repaint the whole window after the resize operation
         // (this will also re-enable screen updates, which were disabled above)
         // TODO: send PaintEvent
+        
+        [window synthesizeMouseEnteredExitedEvents];
     }];
 
 JNF_COCOA_EXIT(env);
@@ -899,6 +961,27 @@
 
 /*
  * Class:     sun_lwawt_macosx_CPlatformWindow
+ * Method:    nativeSynthesizeMouseEnteredExitedEvents
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSynthesizeMouseEnteredExitedEvents
+(JNIEnv *env, jclass clazz, jlong windowPtr)
+{
+    JNF_COCOA_ENTER(env);
+    AWT_ASSERT_NOT_APPKIT_THREAD;
+    
+    AWTWindow *window = OBJC(windowPtr);
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        AWT_ASSERT_APPKIT_THREAD;
+        
+        [window synthesizeMouseEnteredExitedEvents];
+    }];
+    
+    JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CPlatformWindow
  * Method:    nativeGetScreenNSWindowIsOn_AppKitThread
  * Signature: (J)I
  */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/Mouse/EnterExitEvents/DragWindowOutOfFrameTest.java	Wed May 02 17:54:18 2012 +0400
@@ -0,0 +1,267 @@
+/*
+ * 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 should be generated during dragging the window
+ *     out of the frame and to the frame.
+ * @library ../../regtesthelpers
+ * @build Util
+ * @author alexandr.scherbatiy area=awt.event
+ * @run main DragWindowOutOfFrameTest
+ */
+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 DragWindowOutOfFrameTest {
+
+    private static volatile int dragWindowMouseEnteredCount = 0;
+    private static volatile int dragWindowMouseExitedCount = 0;
+    private static volatile int dragWindowMouseReleasedCount = 0;
+    private static volatile int buttonMouseEnteredCount = 0;
+    private static volatile int buttonMouseExitedCount = 0;
+    private static volatile int labelMouseEnteredCount = 0;
+    private static volatile int labelMouseExitedCount = 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 && dragWindowMouseExitedCount != 0) {
+            throw new RuntimeException(
+                    "Wrong number mouse Entered/Exited events on Drag Window!");
+        }
+
+        Point pointToDrag = Util.invokeOnEDT(new Callable<Point>() {
+
+            @Override
+            public Point call() throws Exception {
+                label.addMouseListener(new LabelMouseListener());
+                button.addMouseListener(new ButtonMouseListener());
+                return getCenterPoint(button);
+            }
+        });
+
+        robot.mouseMove(450, pointToClick.y);
+        toolkit.realSync();
+
+        if (labelMouseEnteredCount != 0 && labelMouseExitedCount != 1) {
+            throw new RuntimeException(
+                    "Wrong number Mouse Entered/Exited events on label!");
+        }
+
+        robot.mouseMove(450, pointToDrag.y);
+        toolkit.realSync();
+
+        if (labelMouseEnteredCount != 0 && labelMouseExitedCount != 1) {
+            throw new RuntimeException(
+                    "Wrong number Mouse Entered/Exited events on label!");
+        }
+
+        if (buttonMouseEnteredCount != 0 && buttonMouseExitedCount != 0) {
+            throw new RuntimeException(
+                    "Wrong number Mouse Entered/Exited events on button!");
+        }
+
+        robot.mouseMove(pointToDrag.y, pointToDrag.y);
+        toolkit.realSync();
+
+        if (buttonMouseEnteredCount != 1 && buttonMouseExitedCount != 0) {
+            throw new RuntimeException(
+                    "Wrong number Mouse Entered/Exited events 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.setLocation(100, 100);
+        frame.setSize(300, 200);
+        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+
+        label = new JLabel("Label");
+
+        DragWindowCreationMouseListener listener = new DragWindowCreationMouseListener(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 {
+
+        public MyDragWindow(Window parent, Point location) {
+            super(parent);
+            setSize(500, 300);
+            setVisible(true);
+            JPanel panel = new JPanel();
+            add(panel);
+            setLocation(location.x - 250, location.y - 150);
+            addMouseListener(new DragWindowMouseListener());
+        }
+
+        void dragTo(Point point) {
+            setLocation(point.x - 250, point.y - 150);
+        }
+    }
+
+    static class DragWindowCreationMouseListener extends MouseAdapter {
+
+        Point origin;
+        Window parent;
+
+        public DragWindowCreationMouseListener(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 mouseExited(MouseEvent e) {
+            dragWindowMouseExitedCount++;
+        }
+
+        @Override
+        public void mouseReleased(MouseEvent e) {
+            dragWindowMouseReleasedCount++;
+        }
+    }
+
+    static class LabelMouseListener extends MouseAdapter {
+
+        @Override
+        public void mouseEntered(MouseEvent e) {
+            labelMouseEnteredCount++;
+        }
+
+        @Override
+        public void mouseExited(MouseEvent e) {
+            labelMouseExitedCount++;
+        }
+    }
+
+    static class ButtonMouseListener extends MouseAdapter {
+
+        @Override
+        public void mouseEntered(MouseEvent e) {
+            buttonMouseEnteredCount++;
+        }
+
+        @Override
+        public void mouseExited(MouseEvent e) {
+            buttonMouseExitedCount++;
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/Mouse/EnterExitEvents/DragWindowTest.java	Wed May 02 17:54:18 2012 +0400
@@ -0,0 +1,219 @@
+/*
+ * 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++;
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/Mouse/EnterExitEvents/ResizingFrameTest.java	Wed May 02 17:54:18 2012 +0400
@@ -0,0 +1,232 @@
+/*
+ * 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 Programmatically resized  window does not receive mouse entered/exited events
+ * @author  alexandr.scherbatiy area=awt.event
+ * @run main ResizingFrameTest
+ */
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+import sun.awt.SunToolkit;
+
+public class ResizingFrameTest {
+
+    private static volatile int mouseEnteredCount = 0;
+    private static volatile int mouseExitedCount = 0;
+    private static JFrame frame;
+
+    public static void main(String[] args) throws Exception {
+
+        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
+        Robot robot = new Robot();
+        robot.setAutoDelay(50);
+        robot.mouseMove(100, 100);
+
+        // create a frame under the mouse cursor
+        SwingUtilities.invokeAndWait(new Runnable() {
+
+            @Override
+            public void run() {
+                createAndShowGUI();
+            }
+        });
+
+
+        toolkit.realSync();
+
+        if (mouseEnteredCount != 1 || mouseExitedCount != 0) {
+            throw new RuntimeException("No Mouse Entered/Exited events!");
+        }
+
+        // iconify frame
+        SwingUtilities.invokeAndWait(new Runnable() {
+
+            @Override
+            public void run() {
+                frame.setExtendedState(Frame.ICONIFIED);
+            }
+        });
+
+        toolkit.realSync();
+        robot.delay(200);
+
+        if (mouseEnteredCount != 1 || mouseExitedCount != 1) {
+            throw new RuntimeException("No Mouse Entered/Exited events!");
+        }
+
+        // deiconify frame
+        SwingUtilities.invokeAndWait(new Runnable() {
+
+            @Override
+            public void run() {
+                frame.setExtendedState(Frame.NORMAL);
+            }
+        });
+
+        toolkit.realSync();
+        robot.delay(200);
+
+        if (mouseEnteredCount != 2 || mouseExitedCount != 1) {
+            throw new RuntimeException("No Mouse Entered/Exited events!");
+        }
+
+        // move the mouse out of the frame
+        robot.mouseMove(500, 500);
+        toolkit.realSync();
+        robot.delay(200);
+
+        if (mouseEnteredCount != 2 || mouseExitedCount != 2) {
+            throw new RuntimeException("No Mouse Entered/Exited events!");
+        }
+
+        // maximize the frame
+        SwingUtilities.invokeAndWait(new Runnable() {
+
+            @Override
+            public void run() {
+                frame.setExtendedState(Frame.MAXIMIZED_BOTH);
+            }
+        });
+
+        toolkit.realSync();
+        robot.delay(200);
+
+        if (mouseEnteredCount != 3 || mouseExitedCount != 2) {
+            throw new RuntimeException("No Mouse Entered/Exited events!");
+        }
+
+
+        // demaximize the frame
+        SwingUtilities.invokeAndWait(new Runnable() {
+
+            @Override
+            public void run() {
+                frame.setExtendedState(Frame.NORMAL);
+            }
+        });
+
+        toolkit.realSync();
+        robot.delay(200);
+
+        if (mouseEnteredCount != 3 || mouseExitedCount != 3) {
+            throw new RuntimeException("No Mouse Entered/Exited events!");
+
+        }
+
+        // move the frame under the mouse
+        SwingUtilities.invokeAndWait(new Runnable() {
+
+            @Override
+            public void run() {
+                frame.setLocation(400, 400);
+            }
+        });
+
+        toolkit.realSync();
+        robot.delay(200);
+
+        if (mouseEnteredCount != 4 || mouseExitedCount != 3) {
+            throw new RuntimeException("No Mouse Entered/Exited events!");
+        }
+
+        // move the frame out of the mouse
+        SwingUtilities.invokeAndWait(new Runnable() {
+
+            @Override
+            public void run() {
+                frame.setLocation(100, 100);
+            }
+        });
+
+        toolkit.realSync();
+        robot.delay(400);
+
+        if (mouseEnteredCount != 4 || mouseExitedCount != 4) {
+            throw new RuntimeException("No Mouse Entered/Exited events!");
+        }
+
+        // enlarge the frame bounds
+        SwingUtilities.invokeAndWait(new Runnable() {
+
+            @Override
+            public void run() {
+                frame.setBounds(100, 100, 800, 800);
+            }
+        });
+
+        toolkit.realSync();
+        robot.delay(200);
+
+        if (mouseEnteredCount != 5 || mouseExitedCount != 4) {
+            throw new RuntimeException("No Mouse Entered/Exited events!");
+        }
+
+        // make the frame bounds smaller
+        SwingUtilities.invokeAndWait(new Runnable() {
+
+            @Override
+            public void run() {
+                frame.setBounds(100, 100, 200, 300);
+            }
+        });
+
+        toolkit.realSync();
+        robot.delay(400);
+
+
+        if (mouseEnteredCount != 5 || mouseExitedCount != 5) {
+            throw new RuntimeException("No Mouse Entered/Exited events!");
+        }
+    }
+
+    private static void createAndShowGUI() {
+
+        frame = new JFrame("Main Frame");
+        frame.setSize(300, 200);
+        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+
+        frame.addMouseListener(new MouseAdapter() {
+
+            @Override
+            public void mouseEntered(MouseEvent e) {
+                mouseEnteredCount++;
+            }
+
+            @Override
+            public void mouseExited(MouseEvent e) {
+                mouseExitedCount++;
+            }
+        });
+
+        frame.setVisible(true);
+    }
+}
\ No newline at end of file
--- a/jdk/test/java/awt/regtesthelpers/Util.java	Wed May 02 13:53:06 2012 +0400
+++ b/jdk/test/java/awt/regtesthelpers/Util.java	Wed May 02 17:54:18 2012 +0400
@@ -600,4 +600,34 @@
                                 time, printEvent);
 
     }
+
+
+    /**
+     * Invokes the <code>task</code> on the EDT thread.
+     *
+     * @return result of the <code>task</code>
+     */
+    public static <T> T invokeOnEDT(final java.util.concurrent.Callable<T> task) throws Exception {
+        final java.util.List<T> result = new java.util.ArrayList<T>(1);
+        final Exception[] exception = new Exception[1];
+
+        javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+
+            @Override
+            public void run() {
+                try {
+                    result.add(task.call());
+                } catch (Exception e) {
+                    exception[0] = e;
+                }
+            }
+        });
+
+        if (exception[0] != null) {
+            throw exception[0];
+        }
+
+        return result.get(0);
+    }
+
 }