Title: [90475] trunk/Tools
Revision
90475
Author
[email protected]
Date
2011-07-06 11:41:45 -0700 (Wed, 06 Jul 2011)

Log Message

[Qt] [WK2] Add touch mocking to Qt's MiniBrowser
https://bugs.webkit.org/show_bug.cgi?id=63995

Reviewed by Andreas Kling.

The mouse events are intercepted through QCoreApplication::notify(),
and fake touch events are generated for mouse events when necessary.

If touch events are received from the platform, we assume the current
hardware has a touch screen and we stop generating fake events.

* MiniBrowser/qt/MiniBrowserApplication.cpp:
(isTouchEvent):
(isMouseEvent):
(MiniBrowserApplication::MiniBrowserApplication):
(MiniBrowserApplication::notify):
* MiniBrowser/qt/MiniBrowserApplication.h:

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (90474 => 90475)


--- trunk/Tools/ChangeLog	2011-07-06 18:31:37 UTC (rev 90474)
+++ trunk/Tools/ChangeLog	2011-07-06 18:41:45 UTC (rev 90475)
@@ -1,3 +1,23 @@
+2011-07-06  Benjamin Poulain  <[email protected]>
+
+        [Qt] [WK2] Add touch mocking to Qt's MiniBrowser
+        https://bugs.webkit.org/show_bug.cgi?id=63995
+
+        Reviewed by Andreas Kling.
+
+        The mouse events are intercepted through QCoreApplication::notify(),
+        and fake touch events are generated for mouse events when necessary.
+
+        If touch events are received from the platform, we assume the current
+        hardware has a touch screen and we stop generating fake events.
+
+        * MiniBrowser/qt/MiniBrowserApplication.cpp:
+        (isTouchEvent):
+        (isMouseEvent):
+        (MiniBrowserApplication::MiniBrowserApplication):
+        (MiniBrowserApplication::notify):
+        * MiniBrowser/qt/MiniBrowserApplication.h:
+
 2011-07-06  Xan Lopez  <[email protected]>
 
         Reviewed by Gustavo Noronha.

Modified: trunk/Tools/MiniBrowser/qt/MiniBrowserApplication.cpp (90474 => 90475)


--- trunk/Tools/MiniBrowser/qt/MiniBrowserApplication.cpp	2011-07-06 18:31:37 UTC (rev 90474)
+++ trunk/Tools/MiniBrowser/qt/MiniBrowserApplication.cpp	2011-07-06 18:41:45 UTC (rev 90475)
@@ -30,10 +30,42 @@
 
 #include "utils.h"
 #include <QRegExp>
+#include <QEvent>
+#include <QMouseEvent>
+#include <QTouchEvent>
 
+extern Q_GUI_EXPORT void qt_translateRawTouchEvent(QWidget*, QTouchEvent::DeviceType, const QList<QTouchEvent::TouchPoint>&);
+
+static inline bool isTouchEvent(const QEvent* event)
+{
+    switch (event->type()) {
+    case QEvent::TouchBegin:
+    case QEvent::TouchUpdate:
+    case QEvent::TouchEnd:
+        return true;
+    default:
+        return false;
+    }
+}
+
+static inline bool isMouseEvent(const QEvent* event)
+{
+    switch (event->type()) {
+    case QEvent::MouseButtonPress:
+    case QEvent::MouseMove:
+    case QEvent::MouseButtonRelease:
+    case QEvent::MouseButtonDblClick:
+        return true;
+    default:
+        return false;
+    }
+}
+
 MiniBrowserApplication::MiniBrowserApplication(int& argc, char** argv)
     : QApplication(argc, argv, QApplication::GuiServer)
     , m_windowOptions()
+    , m_spontaneousTouchEventReceived(false)
+    , m_sendingFakeTouchEvent(false)
     , m_isRobotized(false)
     , m_robotTimeoutSeconds(0)
     , m_robotExtraTimeSeconds(0)
@@ -45,6 +77,53 @@
     handleUserOptions();
 }
 
+bool MiniBrowserApplication::notify(QObject* target, QEvent* event)
+{
+    // We try to be smart, if we received real touch event, we are probably on a device
+    // with touch screen, and we should not have touch mocking.
+
+    if (!event->spontaneous() || m_sendingFakeTouchEvent || m_spontaneousTouchEventReceived)
+        return QApplication::notify(target, event);
+    if (isTouchEvent(event) && static_cast<QTouchEvent*>(event)->deviceType() == QTouchEvent::TouchScreen) {
+        m_spontaneousTouchEventReceived = true;
+        return QApplication::notify(target, event);
+    }
+    if (isMouseEvent(event)) {
+        const QMouseEvent* const mouseEvent = static_cast<QMouseEvent*>(event);
+        if (mouseEvent->button() != Qt::LeftButton && mouseEvent->buttons() != Qt::LeftButton)
+            return QApplication::notify(target, event);
+
+        QTouchEvent::TouchPoint touchPoint;
+        touchPoint.setScreenPos(mouseEvent->globalPos());
+        touchPoint.setPos(mouseEvent->pos());
+        touchPoint.setId(0);
+
+        switch (mouseEvent->type()) {
+        case QEvent::MouseButtonPress:
+        case QEvent::MouseButtonDblClick:
+            touchPoint.setState(Qt::TouchPointPressed);
+            break;
+        case QEvent::MouseMove:
+            touchPoint.setState(Qt::TouchPointMoved);
+            break;
+        case QEvent::MouseButtonRelease:
+            touchPoint.setState(Qt::TouchPointReleased);
+            break;
+        default:
+            Q_ASSERT(false);
+            break;
+        }
+
+        QList<QTouchEvent::TouchPoint> touchPoints;
+        touchPoints.append(touchPoint);
+        m_sendingFakeTouchEvent = true;
+        qt_translateRawTouchEvent(0, QTouchEvent::TouchScreen, touchPoints);
+        m_sendingFakeTouchEvent = false;
+    }
+
+    return QApplication::notify(target, event);
+}
+
 void MiniBrowserApplication::handleUserOptions()
 {
     QStringList args = arguments();

Modified: trunk/Tools/MiniBrowser/qt/MiniBrowserApplication.h (90474 => 90475)


--- trunk/Tools/MiniBrowser/qt/MiniBrowserApplication.h	2011-07-06 18:31:37 UTC (rev 90474)
+++ trunk/Tools/MiniBrowser/qt/MiniBrowserApplication.h	2011-07-06 18:41:45 UTC (rev 90475)
@@ -67,10 +67,14 @@
 
     WindowOptions m_windowOptions;
 
+    virtual bool notify(QObject*, QEvent*);
+
 private:
     void handleUserOptions();
 
 private:
+    bool m_spontaneousTouchEventReceived;
+    bool m_sendingFakeTouchEvent;
     bool m_isRobotized;
     int m_robotTimeoutSeconds;
     int m_robotExtraTimeSeconds;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to