Add support for eventSender.mouseScrollBy in WTR
authorweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 1 Oct 2011 00:16:48 +0000 (00:16 +0000)
committerweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 1 Oct 2011 00:16:48 +0000 (00:16 +0000)
https://bugs.webkit.org/show_bug.cgi?id=69189

Source/WebKit2:

Reviewed by Simon Fraser.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::handleWheelEvent):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::wheelEventSyncForTesting):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:
Add sync version of wheel event handling for use in testing.

Tools:

Add implementation of eventSender.mouseScrollBy for the mac.

Reviewed by Simon Fraser.

* WebKitTestRunner/EventSenderProxy.h:
* WebKitTestRunner/InjectedBundle/Bindings/EventSendingController.idl:
* WebKitTestRunner/InjectedBundle/EventSendingController.cpp:
(WTR::EventSendingController::keyDown):
(WTR::EventSendingController::mouseScrollBy):
* WebKitTestRunner/InjectedBundle/EventSendingController.h:
* WebKitTestRunner/TestController.cpp:
(WTR::TestController::didReceiveSynchronousMessageFromInjectedBundle):
* WebKitTestRunner/mac/EventSenderProxy.mm:
(WTR::EventSenderProxy::mouseScrollBy):

LayoutTests:

Reviewed by Simon Fraser.

* platform/mac-wk2/Skipped:
Removes tests that used eventSender.mouseScrollBy.

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

15 files changed:
LayoutTests/ChangeLog
LayoutTests/platform/mac-wk2/Skipped
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h
Source/WebKit2/WebProcess/WebPage/WebPage.messages.in
Tools/ChangeLog
Tools/WebKitTestRunner/EventSenderProxy.h
Tools/WebKitTestRunner/InjectedBundle/Bindings/EventSendingController.idl
Tools/WebKitTestRunner/InjectedBundle/EventSendingController.cpp
Tools/WebKitTestRunner/InjectedBundle/EventSendingController.h
Tools/WebKitTestRunner/TestController.cpp
Tools/WebKitTestRunner/mac/EventSenderProxy.mm
Tools/WebKitTestRunner/qt/EventSenderProxyQt.cpp

index a3c399f..f2e0aa9 100644 (file)
@@ -1,3 +1,13 @@
+2011-09-30  Sam Weinig  <sam@webkit.org>
+
+        Add support for eventSender.mouseScrollBy in WTR
+        https://bugs.webkit.org/show_bug.cgi?id=69189
+
+        Reviewed by Simon Fraser.
+
+        * platform/mac-wk2/Skipped:
+        Removes tests that used eventSender.mouseScrollBy.
+
 2011-09-30  Johnny Ding  <jnd@chromium.org>
 
         Support -webkit-tap-highlight-color in WebCore when enabling touch events support. 
index cd1ed0d..5f5bb3a 100644 (file)
@@ -147,14 +147,11 @@ fast/events/mouseup-from-button2.html
 fast/events/node-event-anchor-lock.html
 fast/events/ondragenter.html
 fast/events/open-window-from-another-frame.html
-fast/events/platform-wheelevent-in-scrolling-div.html
 fast/events/popup-blocking-click-in-iframe.html
 fast/events/popup-when-select-change.html
 fast/events/prevent-drag-to-navigate.html
-fast/events/remove-child-onscroll.html
 fast/events/right-click-focus.html
 fast/events/scroll-after-click-on-tab-index.html
-fast/events/scroll-in-scaled-page-with-overflow-hidden.html
 fast/events/selectstart-by-drag.html
 fast/events/selectstart-prevent-selection-on-right-click.html
 fast/events/standalone-image-drag-to-editable.html
index 695d502..a1631b5 100644 (file)
@@ -1,3 +1,18 @@
+2011-09-30  Sam Weinig  <sam@webkit.org>
+
+        Add support for eventSender.mouseScrollBy in WTR
+        https://bugs.webkit.org/show_bug.cgi?id=69189
+
+        Reviewed by Simon Fraser.
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::handleWheelEvent):
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::wheelEventSyncForTesting):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+        Add sync version of wheel event handling for use in testing.
+
 2011-09-30  Caio Marcelo de Oliveira Filho  <caio.oliveira@openbossa.org>
 
         [Qt] Add missing include for QMimeData
index 88e1462..6c0447e 100644 (file)
@@ -869,7 +869,13 @@ void WebPageProxy::handleWheelEvent(const NativeWebWheelEvent& event)
     m_currentlyProcessedWheelEvents.append(event);
 
     process()->responsivenessTimer()->start();
-    process()->send(Messages::WebPage::WheelEvent(event), m_pageID);
+
+    if (m_shouldSendEventsSynchronously) {
+        bool handled = false;
+        process()->sendSync(Messages::WebPage::WheelEventSyncForTesting(event), Messages::WebPage::WheelEventSyncForTesting::Reply(handled), m_pageID);
+        didReceiveEvent(event.type(), handled);
+    } else
+        process()->send(Messages::WebPage::WheelEvent(event), m_pageID);
 }
 
 void WebPageProxy::handleKeyboardEvent(const NativeWebKeyboardEvent& event)
index d4c6fbe..e9265bd 100644 (file)
@@ -1133,6 +1133,20 @@ void WebPage::wheelEvent(const WebWheelEvent& wheelEvent)
     send(Messages::WebPageProxy::DidReceiveEvent(static_cast<uint32_t>(wheelEvent.type()), handled));
 }
 
+void WebPage::wheelEventSyncForTesting(const WebWheelEvent& wheelEvent, bool& handled)
+{
+    CurrentEvent currentEvent(wheelEvent);
+
+#if PLATFORM(MAC)
+    if (wheelEvent.momentumPhase() == WebWheelEvent::PhaseBegan || wheelEvent.phase() == WebWheelEvent::PhaseBegan)
+        m_drawingArea->disableDisplayThrottling();
+    else if (wheelEvent.momentumPhase() == WebWheelEvent::PhaseEnded || wheelEvent.phase() == WebWheelEvent::PhaseEnded)
+        m_drawingArea->enableDisplayThrottling();
+#endif
+
+    handled = handleWheelEvent(wheelEvent, m_page.get());
+}
+
 static bool handleKeyEvent(const WebKeyboardEvent& keyboardEvent, Page* page)
 {
     if (!page->mainFrame()->view())
index d50cde3..e5d0b99 100644 (file)
@@ -489,6 +489,7 @@ private:
     void mouseEvent(const WebMouseEvent&);
     void mouseEventSyncForTesting(const WebMouseEvent&, bool&);
     void wheelEvent(const WebWheelEvent&);
+    void wheelEventSyncForTesting(const WebWheelEvent&, bool&);
     void keyEvent(const WebKeyboardEvent&);
     void keyEventSyncForTesting(const WebKeyboardEvent&, bool&);
 #if ENABLE(GESTURE_EVENTS)
index c26f2e3..924f00d 100644 (file)
@@ -37,6 +37,7 @@ messages -> WebPage {
     MouseEvent(WebKit::WebMouseEvent event)
     MouseEventSyncForTesting(WebKit::WebMouseEvent event) -> (bool handled)
     WheelEvent(WebKit::WebWheelEvent event)
+    WheelEventSyncForTesting(WebKit::WebWheelEvent event) -> (bool handled)
 #if ENABLE(GESTURE_EVENTS)
     GestureEvent(WebKit::WebGestureEvent event)
 #endif
index 5102099..6a79e0f 100644 (file)
@@ -1,3 +1,23 @@
+2011-09-30  Sam Weinig  <sam@webkit.org>
+
+        Add support for eventSender.mouseScrollBy in WTR
+        https://bugs.webkit.org/show_bug.cgi?id=69189
+
+        Add implementation of eventSender.mouseScrollBy for the mac.
+
+        Reviewed by Simon Fraser.
+
+        * WebKitTestRunner/EventSenderProxy.h:
+        * WebKitTestRunner/InjectedBundle/Bindings/EventSendingController.idl:
+        * WebKitTestRunner/InjectedBundle/EventSendingController.cpp:
+        (WTR::EventSendingController::keyDown):
+        (WTR::EventSendingController::mouseScrollBy):
+        * WebKitTestRunner/InjectedBundle/EventSendingController.h:
+        * WebKitTestRunner/TestController.cpp:
+        (WTR::TestController::didReceiveSynchronousMessageFromInjectedBundle):
+        * WebKitTestRunner/mac/EventSenderProxy.mm:
+        (WTR::EventSenderProxy::mouseScrollBy):
+
 2011-09-30  Simon Fraser  <simon.fraser@apple.com>
 
         fast/forms/text-control-intrinsic-widths.html fails on Mac if Word/Office fonts are installed
index d4eb9c8..e550228 100644 (file)
@@ -38,6 +38,8 @@ public:
     void mouseDown(unsigned button, WKEventModifiers);
     void mouseUp(unsigned button, WKEventModifiers);
     void mouseMoveTo(double x, double y);
+    void mouseScrollBy(int x, int y);
+
     void leapForward(int milliseconds);
 
     void keyDown(WKStringRef key, WKEventModifiers, unsigned location);
index 3268278..66c4f71 100644 (file)
@@ -29,6 +29,8 @@ module WTR {
         void mouseDown(in long buttonNumber, in object modifierArray);
         void mouseUp(in long buttonNumber, in object modifierArray);
         void mouseMoveTo(in long x, in long y);
+        void mouseScrollBy(in long x, in long y);
+
         void leapForward(in long milliseconds);
 
         void keyDown(in DOMString key, in object modifierArray, in long location);
index 4d63513..41265eb 100644 (file)
@@ -217,6 +217,53 @@ void EventSendingController::leapForward(int milliseconds)
 #endif
 }
 
+void EventSendingController::keyDown(JSStringRef key, JSValueRef modifierArray, int location)
+{
+    WKBundlePageRef page = InjectedBundle::shared().page()->page();
+    WKBundleFrameRef frame = WKBundlePageGetMainFrame(page);
+    JSContextRef context = WKBundleFrameGetJavaScriptContext(frame);
+    WKEventModifiers modifiers = parseModifierArray(context, modifierArray);
+
+    WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
+    WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
+
+    WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
+    WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("KeyDown"));
+    WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
+
+    WKRetainPtr<WKStringRef> keyKey = adoptWK(WKStringCreateWithUTF8CString("Key"));
+    WKDictionaryAddItem(EventSenderMessageBody.get(), keyKey.get(), toWK(key).get());
+
+    WKRetainPtr<WKStringRef> modifiersKey = adoptWK(WKStringCreateWithUTF8CString("Modifiers"));
+    WKRetainPtr<WKUInt64Ref> modifiersRef = WKUInt64Create(modifiers);
+    WKDictionaryAddItem(EventSenderMessageBody.get(), modifiersKey.get(), modifiersRef.get());
+
+    WKRetainPtr<WKStringRef> locationKey = adoptWK(WKStringCreateWithUTF8CString("Location"));
+    WKRetainPtr<WKUInt64Ref> locationRef = WKUInt64Create(location);
+    WKDictionaryAddItem(EventSenderMessageBody.get(), locationKey.get(), locationRef.get());
+
+    WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
+}
+
+void EventSendingController::mouseScrollBy(int x, int y)
+{
+    WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
+    WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
+
+    WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
+    WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("MouseScrollBy"));
+    WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
+
+    WKRetainPtr<WKStringRef> xKey = adoptWK(WKStringCreateWithUTF8CString("X"));
+    WKRetainPtr<WKDoubleRef> xRef = WKDoubleCreate(x);
+    WKDictionaryAddItem(EventSenderMessageBody.get(), xKey.get(), xRef.get());
+
+    WKRetainPtr<WKStringRef> yKey = adoptWK(WKStringCreateWithUTF8CString("Y"));
+    WKRetainPtr<WKDoubleRef> yRef = WKDoubleCreate(y);
+    WKDictionaryAddItem(EventSenderMessageBody.get(), yKey.get(), yRef.get());
+
+    WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
+}
 
 #ifdef USE_WEBPROCESS_EVENT_SIMULATION
 void EventSendingController::updateClickCount(WKEventMouseButton button)
@@ -283,32 +330,4 @@ void EventSendingController::makeWindowObject(JSContextRef context, JSObjectRef
     setProperty(context, windowObject, "eventSender", this, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, exception);
 }
 
-void EventSendingController::keyDown(JSStringRef key, JSValueRef modifierArray, int location)
-{
-    WKBundlePageRef page = InjectedBundle::shared().page()->page();
-    WKBundleFrameRef frame = WKBundlePageGetMainFrame(page);
-    JSContextRef context = WKBundleFrameGetJavaScriptContext(frame);
-    WKEventModifiers modifiers = parseModifierArray(context, modifierArray);
-
-    WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
-    WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
-
-    WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
-    WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("KeyDown"));
-    WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
-
-    WKRetainPtr<WKStringRef> keyKey = adoptWK(WKStringCreateWithUTF8CString("Key"));
-    WKDictionaryAddItem(EventSenderMessageBody.get(), keyKey.get(), toWK(key).get());
-
-    WKRetainPtr<WKStringRef> modifiersKey = adoptWK(WKStringCreateWithUTF8CString("Modifiers"));
-    WKRetainPtr<WKUInt64Ref> modifiersRef = WKUInt64Create(modifiers);
-    WKDictionaryAddItem(EventSenderMessageBody.get(), modifiersKey.get(), modifiersRef.get());
-
-    WKRetainPtr<WKStringRef> locationKey = adoptWK(WKStringCreateWithUTF8CString("Location"));
-    WKRetainPtr<WKUInt64Ref> locationRef = WKUInt64Create(location);
-    WKDictionaryAddItem(EventSenderMessageBody.get(), locationKey.get(), locationRef.get());
-
-    WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
-}
-
 } // namespace WTR
index 0be315c..5a6fa1a 100644 (file)
@@ -50,6 +50,7 @@ public:
     void mouseDown(int button, JSValueRef modifierArray);
     void mouseUp(int button, JSValueRef modifierArray);
     void mouseMoveTo(int x, int y);
+    void mouseScrollBy(int x, int y);
     void leapForward(int milliseconds);
 
     void keyDown(JSStringRef key, JSValueRef modifierArray, int location);
index 132397d..771c762 100644 (file)
@@ -574,6 +574,20 @@ WKRetainPtr<WKTypeRef> TestController::didReceiveSynchronousMessageFromInjectedB
             return 0;
         }
 
+        if (WKStringIsEqualToUTF8CString(subMessageName, "MouseScrollBy")) {
+            WKRetainPtr<WKStringRef> xKey = adoptWK(WKStringCreateWithUTF8CString("X"));
+            double x = WKDoubleGetValue(static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, xKey.get())));
+
+            WKRetainPtr<WKStringRef> yKey = adoptWK(WKStringCreateWithUTF8CString("Y"));
+            double y = WKDoubleGetValue(static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, yKey.get())));
+
+            // Forward to WebProcess
+            WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), true);
+            m_eventSenderProxy->mouseScrollBy(x, y);
+            WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), false);
+            return 0;
+        }
+
         if (WKStringIsEqualToUTF8CString(subMessageName, "LeapForward")) {
             WKRetainPtr<WKStringRef> timeKey = adoptWK(WKStringCreateWithUTF8CString("TimeInMilliseconds"));
             unsigned time = static_cast<unsigned>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, timeKey.get()))));
index 9a18dbb..7139550 100644 (file)
 #import "config.h"
 #import "EventSenderProxy.h"
 
-#import "StringFunctions.h"
 #import "PlatformWebView.h"
+#import "StringFunctions.h"
 #import "TestController.h"
+#import <JavaScriptCore/RetainPtr.h>
 #import <WebKit2/WKString.h>
 
 namespace WTR {
@@ -351,4 +352,21 @@ void EventSenderProxy::keyDown(WKStringRef key, WKEventModifiers modifiers, unsi
     [[m_testController->mainWebView()->platformWindow() firstResponder] keyUp:event];
 }
 
+void EventSenderProxy::mouseScrollBy(int x, int y)
+{
+    RetainPtr<CGEventRef> cgScrollEvent(AdoptCF, CGEventCreateScrollWheelEvent(0, kCGScrollEventUnitLine, 2, y, x));
+
+    // CGEvent locations are in global display coordinates.
+    CGPoint lastGlobalMousePosition = {
+        m_position.x,
+        [[NSScreen mainScreen] frame].size.height - m_position.y
+    };
+    CGEventSetLocation(cgScrollEvent.get(), lastGlobalMousePosition);
+
+    NSEvent *event = [NSEvent eventWithCGEvent:cgScrollEvent.get()];
+    NSView *targetView = [m_testController->mainWebView()->platformView() hitTest:[event locationInWindow]];
+    if (targetView)
+        [targetView scrollWheel:event];
+}
+
 } // namespace WTR
index f897b61..a1aeb05 100644 (file)
@@ -295,6 +295,11 @@ void EventSenderProxy::mouseMoveTo(double x, double y)
     sendOrQueueEvent(event);
 }
 
+void EventSenderProxy::mouseScrollBy(int, int)
+{
+    // FIXME: Implement this.
+}
+
 void EventSenderProxy::leapForward(int ms)
 {
     eventQueue[endOfQueue].m_delay = ms;