[Qt][WK2] Add support for touch event testing to WebKitTestRunner
authorhausmann@webkit.org <hausmann@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 2 Nov 2011 09:57:22 +0000 (09:57 +0000)
committerhausmann@webkit.org <hausmann@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 2 Nov 2011 09:57:22 +0000 (09:57 +0000)
https://bugs.webkit.org/show_bug.cgi?id=71310

Reviewed by Kenneth Rohde Christiansen.

Source/WebKit2:

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::handleTouchEvent): Add support for m_shouldSendEventsSynchronously.
* UIProcess/qt/QtDesktopWebPageProxy.cpp:
(QtDesktopWebPageProxy::handleEvent): Handle plain touch events in the desktop page proxy by
forwarding them appropriately. We will receive them from WTR through ::event, but we won't
receive them from QQuickCanvas (i.e. the user) because that doesn't uses ::event but only
dedicated fooEvent() handlers, of which we don't re-implement the touch version.
(QtDesktopWebPageProxy::handleTouchEvent): Forward touch events to WebPageProxy.
* UIProcess/qt/QtDesktopWebPageProxy.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::touchEventSyncForTesting): Add support for synchronous touch event testing,
similar to the way it's done for mouse events.
* WebProcess/WebPage/WebPage.h: Ditto.
* WebProcess/WebPage/WebPage.messages.in: Ditto.

Tools:

* WebKitTestRunner/DerivedSources.pro: Build system foo to ensure the ENABLE_TOUCH_EVENTS
define works in EventSendingController.idl
* WebKitTestRunner/EventSenderProxy.h: Add declarations for Qt implementations of touch
handlers.
* WebKitTestRunner/InjectedBundle/Bindings/EventSendingController.idl: Add touch functions
required by tests.
* WebKitTestRunner/InjectedBundle/EventSendingController.cpp: Forward touch messages to the
ui process.
(WTR::EventSendingController::addTouchPoint):
(WTR::EventSendingController::updateTouchPoint):
(WTR::EventSendingController::setTouchModifier):
(WTR::EventSendingController::touchStart):
(WTR::EventSendingController::touchMove):
(WTR::EventSendingController::touchEnd):
(WTR::EventSendingController::clearTouchPoints):
(WTR::EventSendingController::releaseTouchPoint):
* WebKitTestRunner/InjectedBundle/EventSendingController.h:
* WebKitTestRunner/InjectedBundle/qt/InjectedBundle.pro: Include features.pri for feature
defines.
* WebKitTestRunner/TestController.cpp:
(WTR::TestController::didReceiveSynchronousMessageFromInjectedBundle): Forward incoming
touch messages to the EventSenderProxy.
* WebKitTestRunner/qt/EventSenderProxyQt.cpp: Implement touch test harness functions.
(WTR::EventSenderProxy::EventSenderProxy):
(WTR::EventSenderProxy::addTouchPoint):
(WTR::EventSenderProxy::updateTouchPoint):
(WTR::EventSenderProxy::setTouchModifier):
(WTR::EventSenderProxy::touchStart):
(WTR::EventSenderProxy::touchMove):
(WTR::EventSenderProxy::touchEnd):
(WTR::EventSenderProxy::clearTouchPoints):
(WTR::EventSenderProxy::releaseTouchPoint):
(WTR::EventSenderProxy::sendTouchEvent):
* WebKitTestRunner/qt/WebKitTestRunner.pro: Include features.pri for feature defines.

LayoutTests:

* platform/qt-wk2/Skipped: Unskip touch tests that are passing now.

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

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

index cb8311880c741310abba68fe88eac5905cb7f285..ecac50930c494a20b40dda0bdfbbff6d472471aa 100755 (executable)
@@ -1,3 +1,12 @@
+2011-11-02  Simon Hausmann  <simon.hausmann@nokia.com>
+
+        [Qt][WK2] Add support for touch event testing to WebKitTestRunner
+        https://bugs.webkit.org/show_bug.cgi?id=71310
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        * platform/qt-wk2/Skipped: Unskip touch tests that are passing now.
+
 2011-11-02  Philippe Normand  <pnormand@igalia.com>
 
         Unreviewed, GTK baselines for new tests.
index 85ee45ce028992997585e3402bad503cc7360125..35834040634df19785e03b600e37a6fc08f45880 100644 (file)
@@ -301,9 +301,6 @@ http/tests/websocket/tests/hixie76/bad-sub-protocol-non-ascii.html
 # EventSender.mouseMoveTo is not yet supported
 svg/dynamic-updates
 
-# eventSender.clearTouchPoints is unimplemented
-fast/events/touch
-
 # layoutTestController.ignoreDesktopNotificationPermissionRequests is unimplemented
 fast/notifications
 
index 9c9adf833c61fe289ec5cdb47083b1ac46e3d039..2b2aa0975f265f432ab3e44e0b20ae56e8167c88 100644 (file)
@@ -1,3 +1,25 @@
+2011-11-02  Simon Hausmann  <simon.hausmann@nokia.com>
+
+        [Qt][WK2] Add support for touch event testing to WebKitTestRunner
+        https://bugs.webkit.org/show_bug.cgi?id=71310
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::handleTouchEvent): Add support for m_shouldSendEventsSynchronously.
+        * UIProcess/qt/QtDesktopWebPageProxy.cpp:
+        (QtDesktopWebPageProxy::handleEvent): Handle plain touch events in the desktop page proxy by
+        forwarding them appropriately. We will receive them from WTR through ::event, but we won't
+        receive them from QQuickCanvas (i.e. the user) because that doesn't uses ::event but only
+        dedicated fooEvent() handlers, of which we don't re-implement the touch version.
+        (QtDesktopWebPageProxy::handleTouchEvent): Forward touch events to WebPageProxy.
+        * UIProcess/qt/QtDesktopWebPageProxy.h:
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::touchEventSyncForTesting): Add support for synchronous touch event testing,
+        similar to the way it's done for mouse events.
+        * WebProcess/WebPage/WebPage.h: Ditto.
+        * WebProcess/WebPage/WebPage.messages.in: Ditto.
+
 2011-11-02  Simon Hausmann  <simon.hausmann@nokia.com>
 
         [WK2] Remove unused/duplicated modifiers member from WebTouchEvent
index 3c6c323764360654c685ef48540104df7382bb3c..b403a4bf5b9b9c9a9ad00e80112c7024681fa1d1 100644 (file)
@@ -960,7 +960,12 @@ void WebPageProxy::handleTouchEvent(const NativeWebTouchEvent& event)
     if (m_needTouchEvents) {
         m_touchEventQueue.append(event);
         process()->responsivenessTimer()->start();
-        process()->send(Messages::WebPage::TouchEvent(event), m_pageID);
+        if (m_shouldSendEventsSynchronously) {
+            bool handled = false;
+            process()->sendSync(Messages::WebPage::TouchEventSyncForTesting(event), Messages::WebPage::TouchEventSyncForTesting::Reply(handled), m_pageID);
+            didReceiveEvent(event.type(), handled);
+        } else
+            process()->send(Messages::WebPage::TouchEvent(event), m_pageID);
     } else {
         if (m_touchEventQueue.isEmpty()) {
             bool isEventHandled = false;
index 388b602db987dfb59c94e0926cac63495a5c40c5..719f7bd8085571e3861431c5af349374349bfced 100644 (file)
@@ -116,6 +116,13 @@ bool QtDesktopWebPageProxy::handleEvent(QEvent* ev)
         return handleDragMoveEvent(reinterpret_cast<QDragMoveEvent*>(ev));
     case QEvent::Drop:
         return handleDropEvent(reinterpret_cast<QDropEvent*>(ev));
+    // Touch events only for WebKitTestRunner
+    case QEvent::TouchBegin:
+    case QEvent::TouchUpdate:
+    case QEvent::TouchEnd:
+        return handleTouchEvent(static_cast<QTouchEvent*>(ev));
+    default:
+        break;
     }
     return QtWebPageProxy::handleEvent(ev);
 }
@@ -238,6 +245,13 @@ bool QtDesktopWebPageProxy::handleDropEvent(QDropEvent* ev)
     return accepted;
 }
 
+bool QtDesktopWebPageProxy::handleTouchEvent(QTouchEvent* event)
+{
+    m_webPageProxy->handleTouchEvent(NativeWebTouchEvent(event));
+    event->accept();
+    return true;
+}
+
 void QtDesktopWebPageProxy::timerEvent(QTimerEvent* ev)
 {
     int timerId = ev->timerId();
index 75d10c730bbbfb92ba0daf3cafd51aef6c2246c1..f739086a1c027b0228e55aed45e08cc66fbdf20a 100644 (file)
@@ -61,6 +61,7 @@ private:
     bool handleDragLeaveEvent(QDragLeaveEvent*);
     bool handleDragMoveEvent(QDragMoveEvent*);
     bool handleDropEvent(QDropEvent*);
+    bool handleTouchEvent(QTouchEvent*);
 
     QPoint m_tripleClick;
     QBasicTimer m_tripleClickTimer;
index c1ddd8df184ea44bead8f3bf1cf8339cc73ce494..5395ea373f05830508153d0ba48b3763b8955876 100644 (file)
@@ -1323,6 +1323,12 @@ void WebPage::touchEvent(const WebTouchEvent& touchEvent)
 
     send(Messages::WebPageProxy::DidReceiveEvent(static_cast<uint32_t>(touchEvent.type()), handled));
 }
+
+void WebPage::touchEventSyncForTesting(const WebTouchEvent& touchEvent, bool& handled)
+{
+    CurrentEvent currentEvent(touchEvent);
+    handled = handleTouchEvent(touchEvent, m_page.get());
+}
 #endif
 
 void WebPage::scroll(Page* page, ScrollDirection direction, ScrollGranularity granularity)
index 1b1896bef5e5f378340c606fe077d77048d4ed10..5a3bfaa5652e0d18742c096a3d5c0e7197bdfa91 100644 (file)
@@ -509,6 +509,7 @@ private:
 #endif
 #if ENABLE(TOUCH_EVENTS)
     void touchEvent(const WebTouchEvent&);
+    void touchEventSyncForTesting(const WebTouchEvent&, bool& handled);
 #endif
     void contextMenuHidden() { m_isShowingContextMenu = false; }
 
index 5ab719d8edfbe1b9e20fecc2790be14fa7467d8b..b0fed1ac09b6f52f307f37e25c3259998475a79b 100644 (file)
@@ -43,6 +43,7 @@ messages -> WebPage {
 #endif
 #if ENABLE(TOUCH_EVENTS)
     TouchEvent(WebKit::WebTouchEvent event)
+    TouchEventSyncForTesting(WebKit::WebTouchEvent event) -> (bool handled)
 #endif
 
     ContextMenuHidden()
index fcb822c3613489efcf3463422a1bdf10f1886553..860bfaf939a398e52466daba30c77205d26d0e74 100644 (file)
@@ -1,3 +1,45 @@
+2011-11-02  Simon Hausmann  <simon.hausmann@nokia.com>
+
+        [Qt][WK2] Add support for touch event testing to WebKitTestRunner
+        https://bugs.webkit.org/show_bug.cgi?id=71310
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        * WebKitTestRunner/DerivedSources.pro: Build system foo to ensure the ENABLE_TOUCH_EVENTS
+        define works in EventSendingController.idl
+        * WebKitTestRunner/EventSenderProxy.h: Add declarations for Qt implementations of touch
+        handlers.
+        * WebKitTestRunner/InjectedBundle/Bindings/EventSendingController.idl: Add touch functions
+        required by tests.
+        * WebKitTestRunner/InjectedBundle/EventSendingController.cpp: Forward touch messages to the
+        ui process.
+        (WTR::EventSendingController::addTouchPoint):
+        (WTR::EventSendingController::updateTouchPoint):
+        (WTR::EventSendingController::setTouchModifier):
+        (WTR::EventSendingController::touchStart):
+        (WTR::EventSendingController::touchMove):
+        (WTR::EventSendingController::touchEnd):
+        (WTR::EventSendingController::clearTouchPoints):
+        (WTR::EventSendingController::releaseTouchPoint):
+        * WebKitTestRunner/InjectedBundle/EventSendingController.h:
+        * WebKitTestRunner/InjectedBundle/qt/InjectedBundle.pro: Include features.pri for feature
+        defines.
+        * WebKitTestRunner/TestController.cpp:
+        (WTR::TestController::didReceiveSynchronousMessageFromInjectedBundle): Forward incoming
+        touch messages to the EventSenderProxy.
+        * WebKitTestRunner/qt/EventSenderProxyQt.cpp: Implement touch test harness functions.
+        (WTR::EventSenderProxy::EventSenderProxy):
+        (WTR::EventSenderProxy::addTouchPoint):
+        (WTR::EventSenderProxy::updateTouchPoint):
+        (WTR::EventSenderProxy::setTouchModifier):
+        (WTR::EventSenderProxy::touchStart):
+        (WTR::EventSenderProxy::touchMove):
+        (WTR::EventSenderProxy::touchEnd):
+        (WTR::EventSenderProxy::clearTouchPoints):
+        (WTR::EventSenderProxy::releaseTouchPoint):
+        (WTR::EventSenderProxy::sendTouchEvent):
+        * WebKitTestRunner/qt/WebKitTestRunner.pro: Include features.pri for feature defines.
+
 2011-11-01  Sam Weinig  <sam@webkit.org>
 
         resolve-ChangeLogs --help should be faster.
index eda239e8ec145d9bc46f32a11d2db4ae24ba102f..20c30db68a8cec54698aa4f20e16793d6c514a10 100644 (file)
@@ -37,6 +37,8 @@ defineTest(addExtraCompiler) {
 
 SRC_ROOT_DIR = $$replace(PWD, /Tools/WebKitTestRunner, "")
 
+include($$SRC_ROOT_DIR/Source/WebCore/features.pri) # for ENABLE_TOUCH_EVENTS
+
 # Make sure forwarded headers needed by this project are present
 fwheader_generator.commands = perl $${SRC_ROOT_DIR}/Source/WebKit2/Scripts/generate-forwarding-headers.pl $${SRC_ROOT_DIR}/Tools/WebKitTestRunner $${OUTPUT_DIR}/include qt
 fwheader_generator.depends  = $${SRC_ROOT_DIR}/Source/WebKit2/Scripts/generate-forwarding-headers.pl
@@ -47,7 +49,7 @@ QMAKE_EXTRA_TARGETS         += fwheader_generator
 idl.output = $${GENERATED_SOURCES_DIR}/JS${QMAKE_FILE_BASE}.cpp
 idl.input = IDL_BINDINGS
 idl.wkScript = $$PWD/../../Source/WebCore/bindings/scripts/generate-bindings.pl
-idl.commands = perl -I$$PWD/../../Source/WebCore/bindings/scripts -I$$PWD/InjectedBundle/Bindings $$idl.wkScript --defines \"\" --generator TestRunner --include $$PWD/InjectedBundle/Bindings --outputDir $$GENERATED_SOURCES_DIR --preprocessor \"$${QMAKE_MOC} -E\" ${QMAKE_FILE_NAME}
+idl.commands = perl -I$$PWD/../../Source/WebCore/bindings/scripts -I$$PWD/InjectedBundle/Bindings $$idl.wkScript --defines \"$${FEATURE_DEFINES_JAVASCRIPT}\" --generator TestRunner --include $$PWD/InjectedBundle/Bindings --outputDir $$GENERATED_SOURCES_DIR --preprocessor \"$${QMAKE_MOC} -E\" ${QMAKE_FILE_NAME}
 idl.depends = $$PWD/../../Source/WebCore/bindings/scripts/CodeGenerator.pm \
               $$PWD/InjectedBundle/Bindings/CodeGeneratorTestRunner.pm \
               $$PWD/../../Source/WebCore/bindings/scripts/IDLParser.pm \
index 22d9acb532388fa387dfa1f19d657f11e95149d1..cab093a537c179c420e6f2662e39aa882d4706bd 100644 (file)
@@ -48,6 +48,18 @@ public:
 
     void keyDown(WKStringRef key, WKEventModifiers, unsigned location);
 
+#if ENABLE(TOUCH_EVENTS)
+    // Touch events.
+    void addTouchPoint(int x, int y);
+    void updateTouchPoint(int index, int x, int y);
+    void setTouchModifier(WKEventModifiers, bool enable);
+    void touchStart();
+    void touchMove();
+    void touchEnd();
+    void clearTouchPoints();
+    void releaseTouchPoint(int index);
+#endif
+
 private:
     TestController* m_testController;
 
@@ -55,6 +67,9 @@ private:
     void updateClickCountForButton(int button);
 
 #if PLATFORM(QT)
+#if ENABLE(TOUCH_EVENTS)
+    void sendTouchEvent(QEvent::Type);
+#endif
     void sendOrQueueEvent(QEvent*);
     void replaySavedEvents();
 #endif
@@ -70,6 +85,12 @@ private:
     int eventNumber;
 #elif PLATFORM(QT)
     Qt::MouseButtons m_mouseButtons;
+
+#if ENABLE(TOUCH_EVENTS)
+    QList<QTouchEvent::TouchPoint> m_touchPoints;
+    Qt::KeyboardModifiers m_touchModifiers;
+    bool m_touchActive;
+#endif
 #endif
 };
 
index 66c4f71e9b86494b0053ed1ee1f6c01b1706304a..d6914fc135a7e54c5319676bd72d7524d89301d9 100644 (file)
@@ -41,6 +41,18 @@ module WTR {
         void zoomPageIn();
         void zoomPageOut();
         void scalePageBy(in double scale, in double x, in double y);
+
+#if defined(ENABLE_TOUCH_EVENTS) && ENABLE_TOUCH_EVENTS
+        // Touch events.
+        void addTouchPoint(in long x, in long y);
+        void updateTouchPoint(in long index, in long x, in long y);
+        void setTouchModifier(in DOMString modifier, in boolean enable);
+        void touchStart();
+        void touchMove();
+        void touchEnd();
+        void clearTouchPoints();
+        void releaseTouchPoint(in long index);
+#endif
     };
 
 }
index 41265ebe867fb6d354281bbc2cfedbb693e634a9..d584d331aff7933f8f05cbce22c25e77ef893a08 100644 (file)
@@ -323,6 +323,146 @@ void EventSendingController::scalePageBy(double scale, double x, double y)
     WKBundlePageSetScaleAtOrigin(InjectedBundle::shared().page()->page(), scale, origin);
 }
 
+#if ENABLE(TOUCH_EVENTS)
+void EventSendingController::addTouchPoint(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("AddTouchPoint"));
+    WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
+
+    WKRetainPtr<WKStringRef> xKey = adoptWK(WKStringCreateWithUTF8CString("X"));
+    WKRetainPtr<WKUInt64Ref> xRef = WKUInt64Create(x);
+    WKDictionaryAddItem(EventSenderMessageBody.get(), xKey.get(), xRef.get());
+
+    WKRetainPtr<WKStringRef> yKey = adoptWK(WKStringCreateWithUTF8CString("Y"));
+    WKRetainPtr<WKUInt64Ref> yRef = WKUInt64Create(y);
+    WKDictionaryAddItem(EventSenderMessageBody.get(), yKey.get(), yRef.get());
+
+    WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
+}
+
+void EventSendingController::updateTouchPoint(int index, 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("UpdateTouchPoint"));
+    WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
+
+    WKRetainPtr<WKStringRef> indexKey = adoptWK(WKStringCreateWithUTF8CString("Index"));
+    WKRetainPtr<WKUInt64Ref> indexRef = WKUInt64Create(index);
+    WKDictionaryAddItem(EventSenderMessageBody.get(), indexKey.get(), indexRef.get());
+
+    WKRetainPtr<WKStringRef> xKey = adoptWK(WKStringCreateWithUTF8CString("X"));
+    WKRetainPtr<WKUInt64Ref> xRef = WKUInt64Create(x);
+    WKDictionaryAddItem(EventSenderMessageBody.get(), xKey.get(), xRef.get());
+
+    WKRetainPtr<WKStringRef> yKey = adoptWK(WKStringCreateWithUTF8CString("Y"));
+    WKRetainPtr<WKUInt64Ref> yRef = WKUInt64Create(y);
+    WKDictionaryAddItem(EventSenderMessageBody.get(), yKey.get(), yRef.get());
+
+    WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
+}
+
+void EventSendingController::setTouchModifier(const JSStringRef &modifier, bool enable)
+{
+    WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
+    WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
+
+    WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
+    WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("SetTouchModifier"));
+    WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
+
+    WKEventModifiers mod = 0;
+    if (JSStringIsEqualToUTF8CString(modifier, "ctrl"))
+        mod = kWKEventModifiersControlKey;
+    if (JSStringIsEqualToUTF8CString(modifier, "shift"))
+        mod = kWKEventModifiersShiftKey;
+    if (JSStringIsEqualToUTF8CString(modifier, "alt"))
+        mod = kWKEventModifiersAltKey;
+    if (JSStringIsEqualToUTF8CString(modifier, "meta"))
+        mod = kWKEventModifiersMetaKey;
+
+    WKRetainPtr<WKStringRef> modifierKey = adoptWK(WKStringCreateWithUTF8CString("Modifier"));
+    WKRetainPtr<WKUInt64Ref> modifierRef = WKUInt64Create(mod);
+    WKDictionaryAddItem(EventSenderMessageBody.get(), modifierKey.get(), modifierRef.get());
+
+    WKRetainPtr<WKStringRef> enableKey = adoptWK(WKStringCreateWithUTF8CString("Enable"));
+    WKRetainPtr<WKUInt64Ref> enableRef = WKUInt64Create(enable);
+    WKDictionaryAddItem(EventSenderMessageBody.get(), enableKey.get(), enableRef.get());
+
+    WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
+}
+
+void EventSendingController::touchStart()
+{
+    WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
+    WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
+
+    WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
+    WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("TouchStart"));
+    WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
+
+    WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
+}
+
+void EventSendingController::touchMove()
+{
+    WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
+    WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
+
+    WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
+    WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("TouchMove"));
+    WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
+
+    WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
+}
+
+void EventSendingController::touchEnd()
+{
+    WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
+    WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
+
+    WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
+    WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("TouchEnd"));
+    WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
+
+    WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
+}
+
+void EventSendingController::clearTouchPoints()
+{
+    WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
+    WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
+
+    WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
+    WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("ClearTouchPoints"));
+    WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
+
+    WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
+}
+
+void EventSendingController::releaseTouchPoint(int index)
+{
+    WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
+    WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
+
+    WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
+    WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("ReleaseTouchPoint"));
+    WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
+
+    WKRetainPtr<WKStringRef> indexKey = adoptWK(WKStringCreateWithUTF8CString("Index"));
+    WKRetainPtr<WKUInt64Ref> indexRef = WKUInt64Create(index);
+    WKDictionaryAddItem(EventSenderMessageBody.get(), indexKey.get(), indexRef.get());
+
+    WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
+}
+#endif
+
 // Object Creation
 
 void EventSendingController::makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception)
index 5a6fa1a96b7264b5539f8623d293100d2331db7d..56724cca06d94b845a6da59a4c5ac730f7573813 100644 (file)
@@ -62,6 +62,18 @@ public:
     void zoomPageOut();
     void scalePageBy(double scale, double x, double y);
 
+#if ENABLE(TOUCH_EVENTS)
+    // Touch events.
+    void addTouchPoint(int x, int y);
+    void updateTouchPoint(int index, int x, int y);
+    void setTouchModifier(const JSStringRef &modifier, bool enable);
+    void touchStart();
+    void touchMove();
+    void touchEnd();
+    void clearTouchPoints();
+    void releaseTouchPoint(int index);
+#endif
+
 private:
     EventSendingController();
 
index 616adc3921624e2e6d0494789d723e0fe180123e..9e601ce79a2d87cde2c388a112d5bf1d75e0451c 100644 (file)
@@ -52,6 +52,8 @@ prependJavaScriptCoreLib(../../../JavaScriptCore)
 include(../../../../Source/WebKit2/WebKit2.pri)
 prependWebKit2Lib(../../../WebKit2)
 
+include(../../../../Source/WebCore/features.pri) # For ENABLE_TOUCH_EVENTS
+
 INCLUDEPATH = \
     $$PWD \
     $$PWD/.. \
index befea0dada2014a255eefae8120fc5da578bdb3c..c1f83963023c44fdaf5efe34d3bde0266cd98cd6 100644 (file)
@@ -619,6 +619,77 @@ WKRetainPtr<WKTypeRef> TestController::didReceiveSynchronousMessageFromInjectedB
             return 0;
         }
 #endif
+
+#if ENABLE(TOUCH_EVENTS)
+        if (WKStringIsEqualToUTF8CString(subMessageName, "AddTouchPoint")) {
+            WKRetainPtr<WKStringRef> xKey = adoptWK(WKStringCreateWithUTF8CString("X"));
+            int x = static_cast<int>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, xKey.get()))));
+
+            WKRetainPtr<WKStringRef> yKey = adoptWK(WKStringCreateWithUTF8CString("Y"));
+            int y = static_cast<int>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, yKey.get()))));
+
+            m_eventSenderProxy->addTouchPoint(x, y);
+            return 0;
+        }
+
+        if (WKStringIsEqualToUTF8CString(subMessageName, "UpdateTouchPoint")) {
+            WKRetainPtr<WKStringRef> indexKey = adoptWK(WKStringCreateWithUTF8CString("Index"));
+            int index = static_cast<int>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, indexKey.get()))));
+
+            WKRetainPtr<WKStringRef> xKey = adoptWK(WKStringCreateWithUTF8CString("X"));
+            int x = static_cast<int>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, xKey.get()))));
+
+            WKRetainPtr<WKStringRef> yKey = adoptWK(WKStringCreateWithUTF8CString("Y"));
+            int y = static_cast<int>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, yKey.get()))));
+
+            m_eventSenderProxy->updateTouchPoint(index, x, y);
+            return 0;
+        }
+
+        if (WKStringIsEqualToUTF8CString(subMessageName, "SetTouchModifier")) {
+            WKRetainPtr<WKStringRef> modifierKey = adoptWK(WKStringCreateWithUTF8CString("Modifier"));
+            WKEventModifiers modifier = static_cast<WKEventModifiers>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, modifierKey.get()))));
+
+            WKRetainPtr<WKStringRef> enableKey = adoptWK(WKStringCreateWithUTF8CString("Enable"));
+            bool enable = static_cast<bool>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, enableKey.get()))));
+
+            m_eventSenderProxy->setTouchModifier(modifier, enable);
+            return 0;
+        }
+
+        if (WKStringIsEqualToUTF8CString(subMessageName, "TouchStart")) {
+            WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), true);
+            m_eventSenderProxy->touchStart();
+            WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), false);
+            return 0;
+        }
+
+        if (WKStringIsEqualToUTF8CString(subMessageName, "TouchMove")) {
+            WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), true);
+            m_eventSenderProxy->touchMove();
+            WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), false);
+            return 0;
+        }
+
+        if (WKStringIsEqualToUTF8CString(subMessageName, "TouchEnd")) {
+            WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), true);
+            m_eventSenderProxy->touchEnd();
+            WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), false);
+            return 0;
+        }
+
+        if (WKStringIsEqualToUTF8CString(subMessageName, "ClearTouchPoints")) {
+            m_eventSenderProxy->clearTouchPoints();
+            return 0;
+        }
+
+        if (WKStringIsEqualToUTF8CString(subMessageName, "ReleaseTouchPoint")) {
+            WKRetainPtr<WKStringRef> indexKey = adoptWK(WKStringCreateWithUTF8CString("Index"));
+            int index = static_cast<int>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, indexKey.get()))));
+            m_eventSenderProxy->releaseTouchPoint(index);
+            return 0;
+        }
+#endif
         ASSERT_NOT_REACHED();
     }
 #endif
index a1aeb057e6b2474d6762d5db9e1be22f245051a5..c5856162aad92c5c091e123166745e28186b15a1 100644 (file)
@@ -62,6 +62,9 @@ EventSenderProxy::EventSenderProxy(TestController* testController)
     , m_clickPosition()
     , m_clickButton(kWKEventMouseButtonNoButton)
     , m_mouseButtons(0)
+#if ENABLE(TOUCH_EVENTS)
+    , m_touchActive(false)
+#endif
 {
     memset(eventQueue, 0, sizeof(eventQueue));
     endOfQueue = 0;
@@ -305,6 +308,94 @@ void EventSenderProxy::leapForward(int ms)
     eventQueue[endOfQueue].m_delay = ms;
 }
 
+#if ENABLE(TOUCH_EVENTS)
+void EventSenderProxy::addTouchPoint(int x, int y)
+{
+    const int id = m_touchPoints.isEmpty() ? 0 : m_touchPoints.last().id() + 1;
+    const QPointF pos(x, y);
+    QTouchEvent::TouchPoint point(id);
+    point.setPos(pos);
+    point.setStartPos(pos);
+    point.setState(Qt::TouchPointPressed);
+    m_touchPoints.append(point);
+}
+
+void EventSenderProxy::updateTouchPoint(int index, int x, int y)
+{
+    ASSERT(index >= 0 && index < m_touchPoints.count());
+    QTouchEvent::TouchPoint &p = m_touchPoints[index];
+    p.setPos(QPointF(x, y));
+    p.setState(Qt::TouchPointMoved);
+}
+
+void EventSenderProxy::setTouchModifier(WKEventModifiers modifier, bool enable)
+{
+    Qt::KeyboardModifiers mod = getModifiers(modifier);
+
+    if (enable)
+        m_touchModifiers |= mod;
+    else
+        m_touchModifiers &= ~mod;
+}
+
+void EventSenderProxy::touchStart()
+{
+    if (!m_touchActive) {
+        sendTouchEvent(QEvent::TouchBegin);
+        m_touchActive = true;
+    } else
+        sendTouchEvent(QEvent::TouchUpdate);
+}
+
+void EventSenderProxy::touchMove()
+{
+    sendTouchEvent(QEvent::TouchUpdate);
+}
+
+void EventSenderProxy::touchEnd()
+{
+    for (int i = 0; i < m_touchPoints.count(); ++i) {
+        if (m_touchPoints[i].state() != Qt::TouchPointReleased) {
+            sendTouchEvent(QEvent::TouchUpdate);
+            return;
+        }
+    }
+    sendTouchEvent(QEvent::TouchEnd);
+    m_touchActive = false;
+}
+
+void EventSenderProxy::clearTouchPoints()
+{
+    m_touchPoints.clear();
+    m_touchModifiers = Qt::KeyboardModifiers();
+    m_touchActive = false;
+}
+
+void EventSenderProxy::releaseTouchPoint(int index)
+{
+    if (index < 0 || index >= m_touchPoints.count())
+        return;
+
+    m_touchPoints[index].setState(Qt::TouchPointReleased);
+}
+
+void EventSenderProxy::sendTouchEvent(QEvent::Type type)
+{
+    QTouchEvent event(type, QTouchEvent::TouchScreen, m_touchModifiers);
+    event.setTouchPoints(m_touchPoints);
+    m_testController->mainWebView()->sendEvent(&event);
+    QList<QTouchEvent::TouchPoint>::Iterator it = m_touchPoints.begin();
+    while (it != m_touchPoints.end()) {
+        if (it->state() == Qt::TouchPointReleased)
+            it = m_touchPoints.erase(it);
+        else {
+            it->setState(Qt::TouchPointStationary);
+            ++it;
+        }
+    }
+}
+#endif
+
 void EventSenderProxy::sendOrQueueEvent(QEvent* event)
 {
     if (endOfQueue == startOfQueue && !eventQueue[endOfQueue].m_delay) {
index 6fadceb148f2e2f092cf62b42222a874d420456c..4b69b7a6cc804e94acfb13f599f0a52910861e32 100644 (file)
@@ -8,6 +8,8 @@ GENERATED_SOURCES_DIR = ../generated
 
 include(../../../Source/WebKit.pri)
 
+include(../../../../Source/WebCore/features.pri) # For ENABLE_TOUCH_EVENTS
+
 DEFINES += USE_SYSTEM_MALLOC=1
 DEFINES -= QT_ASCII_CAST_WARNINGS