[Mac] Set NSApplication current event while sending events directly to views
authorap@apple.com <ap@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 1 Oct 2013 22:45:17 +0000 (22:45 +0000)
committerap@apple.com <ap@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 1 Oct 2013 22:45:17 +0000 (22:45 +0000)
https://bugs.webkit.org/show_bug.cgi?id=122179

Reviewed by Darin Adler.

DumpRenderTree and WebKitTestRunner send events directly to WebHMTLView or WKView,
which doesn't update [NSApp currentEvent]. But there are many places in WebKit that
use the current event.

* DumpRenderTree/mac/EventSendingController.mm:
(-[EventSendingController mouseDown:withModifiers:]):
(-[EventSendingController mouseUp:withModifiers:]):
(-[EventSendingController mouseMoveToX:Y:]):
(-[EventSendingController mouseScrollByX:andY:continuously:]):
(-[EventSendingController contextClick]):
(-[EventSendingController keyDown:withModifiers:withLocation:]):
* WebKitTestRunner/mac/EventSenderProxy.mm:
(WTR::EventSenderProxy::mouseDown):
(WTR::EventSenderProxy::mouseUp):
(WTR::EventSenderProxy::mouseMoveTo):
(WTR::EventSenderProxy::keyDown):
(WTR::EventSenderProxy::mouseScrollBy):
Update the current event. We were already using the SPI in WebKit.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@156740 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/DumpRenderTree/mac/EventSendingController.mm
Tools/WebKitTestRunner/mac/EventSenderProxy.mm

index 3f00746..5dfabf2 100644 (file)
@@ -1,3 +1,29 @@
+2013-10-01  Alexey Proskuryakov  <ap@apple.com>
+
+        [Mac] Set NSApplication current event while sending events directly to views
+        https://bugs.webkit.org/show_bug.cgi?id=122179
+
+        Reviewed by Darin Adler.
+
+        DumpRenderTree and WebKitTestRunner send events directly to WebHMTLView or WKView,
+        which doesn't update [NSApp currentEvent]. But there are many places in WebKit that
+        use the current event.
+
+        * DumpRenderTree/mac/EventSendingController.mm:
+        (-[EventSendingController mouseDown:withModifiers:]):
+        (-[EventSendingController mouseUp:withModifiers:]):
+        (-[EventSendingController mouseMoveToX:Y:]):
+        (-[EventSendingController mouseScrollByX:andY:continuously:]):
+        (-[EventSendingController contextClick]):
+        (-[EventSendingController keyDown:withModifiers:withLocation:]):
+        * WebKitTestRunner/mac/EventSenderProxy.mm:
+        (WTR::EventSenderProxy::mouseDown):
+        (WTR::EventSenderProxy::mouseUp):
+        (WTR::EventSenderProxy::mouseMoveTo):
+        (WTR::EventSenderProxy::keyDown):
+        (WTR::EventSenderProxy::mouseScrollBy):
+        Update the current event. We were already using the SPI in WebKit.
+
 2013-10-01  Joseph Pecoraro  <pecoraro@apple.com>
 
         Buildbot Dashboard: Fix JSHint issue: 'perlTestResults' used out of scope.
index 05bfd36..2e70071 100644 (file)
 
 extern "C" void _NSNewKillRingSequence();
 
+@interface NSApplication (Details)
+- (void)_setCurrentEvent:(NSEvent *)event;
+@end
+
 enum MouseAction {
     MouseDown,
     MouseUp,
@@ -353,7 +357,9 @@ static int buildModifierFlags(const WebScriptObject* modifiers)
 
     NSView *subView = [[mainFrame webView] hitTest:[event locationInWindow]];
     if (subView) {
+        [NSApp _setCurrentEvent:event];
         [subView mouseDown:event];
+        [NSApp _setCurrentEvent:nil];
         if (buttonNumber == LeftMouseButton)
             leftMouseButtonDown = YES;
     }
@@ -422,7 +428,9 @@ static int buildModifierFlags(const WebScriptObject* modifiers)
     // instead of rolling our own algorithm for selecting an event target.
     targetView = targetView ? targetView : [[mainFrame frameView] documentView];
     assert(targetView);
+    [NSApp _setCurrentEvent:event];
     [targetView mouseUp:event];
+    [NSApp _setCurrentEvent:nil];
     if (buttonNumber == LeftMouseButton)
         leftMouseButtonDown = NO;
     lastClick = [event timestamp];
@@ -476,6 +484,7 @@ static int buildModifierFlags(const WebScriptObject* modifiers)
 
     NSView *subView = [[mainFrame webView] hitTest:[event locationInWindow]];
     if (subView) {
+        [NSApp _setCurrentEvent:event];
         if (leftMouseButtonDown) {
             if (draggingInfo) {
                 // Per NSDragging.h: draggingSources may not implement draggedImage:movedTo:
@@ -486,6 +495,7 @@ static int buildModifierFlags(const WebScriptObject* modifiers)
                 [subView mouseDragged:event];
         } else
             [subView mouseMoved:event];
+        [NSApp _setCurrentEvent:nil];
     }
 }
 
@@ -505,8 +515,11 @@ static int buildModifierFlags(const WebScriptObject* modifiers)
     CFRelease(cgScrollEvent);
 
     NSView *subView = [[mainFrame webView] hitTest:[scrollEvent locationInWindow]];
-    if (subView)
+    if (subView) {
+        [NSApp _setCurrentEvent:scrollEvent];
         [subView scrollWheel:scrollEvent];
+        [NSApp _setCurrentEvent:nil];
+    }
 }
 
 - (void)continuousMouseScrollByX:(int)x andY:(int)y
@@ -538,7 +551,9 @@ static int buildModifierFlags(const WebScriptObject* modifiers)
     NSMutableArray *menuItemStrings = [NSMutableArray array];
     
     if (subView) {
+        [NSApp _setCurrentEvent:event];
         NSMenu* menu = [subView menuForEvent:event];
+        [NSApp _setCurrentEvent:nil];
 
         for (int i = 0; i < [menu numberOfItems]; ++i) {
             NSMenuItem* menuItem = [menu itemAtIndex:i];
@@ -774,7 +789,9 @@ static int buildModifierFlags(const WebScriptObject* modifiers)
                         isARepeat:NO
                         keyCode:keyCode];
 
+    [NSApp _setCurrentEvent:event];
     [[[[mainFrame webView] window] firstResponder] keyDown:event];
+    [NSApp _setCurrentEvent:nil];
 
     event = [NSEvent keyEventWithType:NSKeyUp
                         location:NSMakePoint(5, 5)
@@ -787,7 +804,9 @@ static int buildModifierFlags(const WebScriptObject* modifiers)
                         isARepeat:NO
                         keyCode:keyCode];
 
+    [NSApp _setCurrentEvent:event];
     [[[[mainFrame webView] window] firstResponder] keyUp:event];
+    [NSApp _setCurrentEvent:nil];
 }
 
 - (void)keyDownWrapper:(NSString *)character withModifiers:(WebScriptObject *)modifiers withLocation:(unsigned long)location
index 233d2f8..428b210 100644 (file)
 #import <WebKit2/WKString.h>
 #import <wtf/RetainPtr.h>
 
+@interface NSApplication (Details)
+- (void)_setCurrentEvent:(NSEvent *)event;
+@end
+
 namespace WTR {
 
 enum MouseAction {
@@ -159,7 +163,9 @@ void EventSenderProxy::mouseDown(unsigned buttonNumber, WKEventModifiers modifie
 
     NSView *targetView = [m_testController->mainWebView()->platformView() hitTest:[event locationInWindow]];
     if (targetView) {
+        [NSApp _setCurrentEvent:event];
         [targetView mouseDown:event];
+        [NSApp _setCurrentEvent:nil];
         if (buttonNumber == LeftMouseButton)
             m_leftMouseButtonDown = true;
     }
@@ -184,7 +190,9 @@ void EventSenderProxy::mouseUp(unsigned buttonNumber, WKEventModifiers modifiers
     // instead of rolling our own algorithm for selecting an event target.
     targetView = targetView ? targetView : m_testController->mainWebView()->platformView();
     ASSERT(targetView);
+    [NSApp _setCurrentEvent:event];
     [targetView mouseUp:event];
+    [NSApp _setCurrentEvent:nil];
     if (buttonNumber == LeftMouseButton)
         m_leftMouseButtonDown = false;
     m_clickTime = currentEventTime();
@@ -208,8 +216,11 @@ void EventSenderProxy::mouseMoveTo(double x, double y)
                                         pressure:0.0];
 
     NSView *targetView = [m_testController->mainWebView()->platformView() hitTest:[event locationInWindow]];
-    if (targetView)
+    if (targetView) {
+        [NSApp _setCurrentEvent:event];
         [targetView mouseMoved:event];
+        [NSApp _setCurrentEvent:nil];
+    }
 }
 
 void EventSenderProxy::leapForward(int milliseconds)
@@ -408,7 +419,9 @@ void EventSenderProxy::keyDown(WKStringRef key, WKEventModifiers modifiers, unsi
                         isARepeat:NO
                         keyCode:keyCode];
 
+    [NSApp _setCurrentEvent:event];
     [[m_testController->mainWebView()->platformWindow() firstResponder] keyDown:event];
+    [NSApp _setCurrentEvent:nil];
 
     event = [NSEvent keyEventWithType:NSKeyUp
                         location:NSMakePoint(5, 5)
@@ -421,7 +434,9 @@ void EventSenderProxy::keyDown(WKStringRef key, WKEventModifiers modifiers, unsi
                         isARepeat:NO
                         keyCode:keyCode];
 
+    [NSApp _setCurrentEvent:event];
     [[m_testController->mainWebView()->platformWindow() firstResponder] keyUp:event];
+    [NSApp _setCurrentEvent:nil];
 }
 
 void EventSenderProxy::mouseScrollBy(int x, int y)
@@ -433,8 +448,11 @@ void EventSenderProxy::mouseScrollBy(int x, int y)
     CGEventSetLocation(cgScrollEvent.get(), lastGlobalMousePosition);
 
     NSEvent *event = [NSEvent eventWithCGEvent:cgScrollEvent.get()];
-    if (NSView *targetView = [m_testController->mainWebView()->platformView() hitTest:[event locationInWindow]])
+    if (NSView *targetView = [m_testController->mainWebView()->platformView() hitTest:[event locationInWindow]]) {
+        [NSApp _setCurrentEvent:event];
         [targetView scrollWheel:event];
+        [NSApp _setCurrentEvent:nil];
+    }
 }
 
 void EventSenderProxy::continuousMouseScrollBy(int x, int y, bool paged)