Commit 9ea7a8f3 authored by ap@apple.com's avatar ap@apple.com
Browse files

[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.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@156740 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 9a81e307
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> 2013-10-01 Joseph Pecoraro <pecoraro@apple.com>
Buildbot Dashboard: Fix JSHint issue: 'perlTestResults' used out of scope. Buildbot Dashboard: Fix JSHint issue: 'perlTestResults' used out of scope.
......
...@@ -43,6 +43,10 @@ ...@@ -43,6 +43,10 @@
extern "C" void _NSNewKillRingSequence(); extern "C" void _NSNewKillRingSequence();
@interface NSApplication (Details)
- (void)_setCurrentEvent:(NSEvent *)event;
@end
enum MouseAction { enum MouseAction {
MouseDown, MouseDown,
MouseUp, MouseUp,
...@@ -353,7 +357,9 @@ static int buildModifierFlags(const WebScriptObject* modifiers) ...@@ -353,7 +357,9 @@ static int buildModifierFlags(const WebScriptObject* modifiers)
NSView *subView = [[mainFrame webView] hitTest:[event locationInWindow]]; NSView *subView = [[mainFrame webView] hitTest:[event locationInWindow]];
if (subView) { if (subView) {
[NSApp _setCurrentEvent:event];
[subView mouseDown:event]; [subView mouseDown:event];
[NSApp _setCurrentEvent:nil];
if (buttonNumber == LeftMouseButton) if (buttonNumber == LeftMouseButton)
leftMouseButtonDown = YES; leftMouseButtonDown = YES;
} }
...@@ -422,7 +428,9 @@ static int buildModifierFlags(const WebScriptObject* modifiers) ...@@ -422,7 +428,9 @@ static int buildModifierFlags(const WebScriptObject* modifiers)
// instead of rolling our own algorithm for selecting an event target. // instead of rolling our own algorithm for selecting an event target.
targetView = targetView ? targetView : [[mainFrame frameView] documentView]; targetView = targetView ? targetView : [[mainFrame frameView] documentView];
assert(targetView); assert(targetView);
[NSApp _setCurrentEvent:event];
[targetView mouseUp:event]; [targetView mouseUp:event];
[NSApp _setCurrentEvent:nil];
if (buttonNumber == LeftMouseButton) if (buttonNumber == LeftMouseButton)
leftMouseButtonDown = NO; leftMouseButtonDown = NO;
lastClick = [event timestamp]; lastClick = [event timestamp];
...@@ -476,6 +484,7 @@ static int buildModifierFlags(const WebScriptObject* modifiers) ...@@ -476,6 +484,7 @@ static int buildModifierFlags(const WebScriptObject* modifiers)
NSView *subView = [[mainFrame webView] hitTest:[event locationInWindow]]; NSView *subView = [[mainFrame webView] hitTest:[event locationInWindow]];
if (subView) { if (subView) {
[NSApp _setCurrentEvent:event];
if (leftMouseButtonDown) { if (leftMouseButtonDown) {
if (draggingInfo) { if (draggingInfo) {
// Per NSDragging.h: draggingSources may not implement draggedImage:movedTo: // Per NSDragging.h: draggingSources may not implement draggedImage:movedTo:
...@@ -486,6 +495,7 @@ static int buildModifierFlags(const WebScriptObject* modifiers) ...@@ -486,6 +495,7 @@ static int buildModifierFlags(const WebScriptObject* modifiers)
[subView mouseDragged:event]; [subView mouseDragged:event];
} else } else
[subView mouseMoved:event]; [subView mouseMoved:event];
[NSApp _setCurrentEvent:nil];
} }
} }
...@@ -505,8 +515,11 @@ static int buildModifierFlags(const WebScriptObject* modifiers) ...@@ -505,8 +515,11 @@ static int buildModifierFlags(const WebScriptObject* modifiers)
CFRelease(cgScrollEvent); CFRelease(cgScrollEvent);
NSView *subView = [[mainFrame webView] hitTest:[scrollEvent locationInWindow]]; NSView *subView = [[mainFrame webView] hitTest:[scrollEvent locationInWindow]];
if (subView) if (subView) {
[NSApp _setCurrentEvent:scrollEvent];
[subView scrollWheel:scrollEvent]; [subView scrollWheel:scrollEvent];
[NSApp _setCurrentEvent:nil];
}
} }
- (void)continuousMouseScrollByX:(int)x andY:(int)y - (void)continuousMouseScrollByX:(int)x andY:(int)y
...@@ -538,7 +551,9 @@ static int buildModifierFlags(const WebScriptObject* modifiers) ...@@ -538,7 +551,9 @@ static int buildModifierFlags(const WebScriptObject* modifiers)
NSMutableArray *menuItemStrings = [NSMutableArray array]; NSMutableArray *menuItemStrings = [NSMutableArray array];
if (subView) { if (subView) {
[NSApp _setCurrentEvent:event];
NSMenu* menu = [subView menuForEvent:event]; NSMenu* menu = [subView menuForEvent:event];
[NSApp _setCurrentEvent:nil];
for (int i = 0; i < [menu numberOfItems]; ++i) { for (int i = 0; i < [menu numberOfItems]; ++i) {
NSMenuItem* menuItem = [menu itemAtIndex:i]; NSMenuItem* menuItem = [menu itemAtIndex:i];
...@@ -774,7 +789,9 @@ static int buildModifierFlags(const WebScriptObject* modifiers) ...@@ -774,7 +789,9 @@ static int buildModifierFlags(const WebScriptObject* modifiers)
isARepeat:NO isARepeat:NO
keyCode:keyCode]; keyCode:keyCode];
[NSApp _setCurrentEvent:event];
[[[[mainFrame webView] window] firstResponder] keyDown:event]; [[[[mainFrame webView] window] firstResponder] keyDown:event];
[NSApp _setCurrentEvent:nil];
event = [NSEvent keyEventWithType:NSKeyUp event = [NSEvent keyEventWithType:NSKeyUp
location:NSMakePoint(5, 5) location:NSMakePoint(5, 5)
...@@ -787,7 +804,9 @@ static int buildModifierFlags(const WebScriptObject* modifiers) ...@@ -787,7 +804,9 @@ static int buildModifierFlags(const WebScriptObject* modifiers)
isARepeat:NO isARepeat:NO
keyCode:keyCode]; keyCode:keyCode];
[NSApp _setCurrentEvent:event];
[[[[mainFrame webView] window] firstResponder] keyUp:event]; [[[[mainFrame webView] window] firstResponder] keyUp:event];
[NSApp _setCurrentEvent:nil];
} }
- (void)keyDownWrapper:(NSString *)character withModifiers:(WebScriptObject *)modifiers withLocation:(unsigned long)location - (void)keyDownWrapper:(NSString *)character withModifiers:(WebScriptObject *)modifiers withLocation:(unsigned long)location
......
...@@ -34,6 +34,10 @@ ...@@ -34,6 +34,10 @@
#import <WebKit2/WKString.h> #import <WebKit2/WKString.h>
#import <wtf/RetainPtr.h> #import <wtf/RetainPtr.h>
@interface NSApplication (Details)
- (void)_setCurrentEvent:(NSEvent *)event;
@end
namespace WTR { namespace WTR {
enum MouseAction { enum MouseAction {
...@@ -159,7 +163,9 @@ void EventSenderProxy::mouseDown(unsigned buttonNumber, WKEventModifiers modifie ...@@ -159,7 +163,9 @@ void EventSenderProxy::mouseDown(unsigned buttonNumber, WKEventModifiers modifie
NSView *targetView = [m_testController->mainWebView()->platformView() hitTest:[event locationInWindow]]; NSView *targetView = [m_testController->mainWebView()->platformView() hitTest:[event locationInWindow]];
if (targetView) { if (targetView) {
[NSApp _setCurrentEvent:event];
[targetView mouseDown:event]; [targetView mouseDown:event];
[NSApp _setCurrentEvent:nil];
if (buttonNumber == LeftMouseButton) if (buttonNumber == LeftMouseButton)
m_leftMouseButtonDown = true; m_leftMouseButtonDown = true;
} }
...@@ -184,7 +190,9 @@ void EventSenderProxy::mouseUp(unsigned buttonNumber, WKEventModifiers modifiers ...@@ -184,7 +190,9 @@ void EventSenderProxy::mouseUp(unsigned buttonNumber, WKEventModifiers modifiers
// instead of rolling our own algorithm for selecting an event target. // instead of rolling our own algorithm for selecting an event target.
targetView = targetView ? targetView : m_testController->mainWebView()->platformView(); targetView = targetView ? targetView : m_testController->mainWebView()->platformView();
ASSERT(targetView); ASSERT(targetView);
[NSApp _setCurrentEvent:event];
[targetView mouseUp:event]; [targetView mouseUp:event];
[NSApp _setCurrentEvent:nil];
if (buttonNumber == LeftMouseButton) if (buttonNumber == LeftMouseButton)
m_leftMouseButtonDown = false; m_leftMouseButtonDown = false;
m_clickTime = currentEventTime(); m_clickTime = currentEventTime();
...@@ -208,8 +216,11 @@ void EventSenderProxy::mouseMoveTo(double x, double y) ...@@ -208,8 +216,11 @@ void EventSenderProxy::mouseMoveTo(double x, double y)
pressure:0.0]; pressure:0.0];
NSView *targetView = [m_testController->mainWebView()->platformView() hitTest:[event locationInWindow]]; NSView *targetView = [m_testController->mainWebView()->platformView() hitTest:[event locationInWindow]];
if (targetView) if (targetView) {
[NSApp _setCurrentEvent:event];
[targetView mouseMoved:event]; [targetView mouseMoved:event];
[NSApp _setCurrentEvent:nil];
}
} }
void EventSenderProxy::leapForward(int milliseconds) void EventSenderProxy::leapForward(int milliseconds)
...@@ -408,7 +419,9 @@ void EventSenderProxy::keyDown(WKStringRef key, WKEventModifiers modifiers, unsi ...@@ -408,7 +419,9 @@ void EventSenderProxy::keyDown(WKStringRef key, WKEventModifiers modifiers, unsi
isARepeat:NO isARepeat:NO
keyCode:keyCode]; keyCode:keyCode];
[NSApp _setCurrentEvent:event];
[[m_testController->mainWebView()->platformWindow() firstResponder] keyDown:event]; [[m_testController->mainWebView()->platformWindow() firstResponder] keyDown:event];
[NSApp _setCurrentEvent:nil];
event = [NSEvent keyEventWithType:NSKeyUp event = [NSEvent keyEventWithType:NSKeyUp
location:NSMakePoint(5, 5) location:NSMakePoint(5, 5)
...@@ -421,7 +434,9 @@ void EventSenderProxy::keyDown(WKStringRef key, WKEventModifiers modifiers, unsi ...@@ -421,7 +434,9 @@ void EventSenderProxy::keyDown(WKStringRef key, WKEventModifiers modifiers, unsi
isARepeat:NO isARepeat:NO
keyCode:keyCode]; keyCode:keyCode];
[NSApp _setCurrentEvent:event];
[[m_testController->mainWebView()->platformWindow() firstResponder] keyUp:event]; [[m_testController->mainWebView()->platformWindow() firstResponder] keyUp:event];
[NSApp _setCurrentEvent:nil];
} }
void EventSenderProxy::mouseScrollBy(int x, int y) void EventSenderProxy::mouseScrollBy(int x, int y)
...@@ -433,8 +448,11 @@ void EventSenderProxy::mouseScrollBy(int x, int y) ...@@ -433,8 +448,11 @@ void EventSenderProxy::mouseScrollBy(int x, int y)
CGEventSetLocation(cgScrollEvent.get(), lastGlobalMousePosition); CGEventSetLocation(cgScrollEvent.get(), lastGlobalMousePosition);
NSEvent *event = [NSEvent eventWithCGEvent:cgScrollEvent.get()]; 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]; [targetView scrollWheel:event];
[NSApp _setCurrentEvent:nil];
}
} }
void EventSenderProxy::continuousMouseScrollBy(int x, int y, bool paged) void EventSenderProxy::continuousMouseScrollBy(int x, int y, bool paged)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment