[Qt][WK2] Move event handling out of QtWebPageProxy
authorjesus@webkit.org <jesus@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 25 Nov 2011 12:48:49 +0000 (12:48 +0000)
committerjesus@webkit.org <jesus@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 25 Nov 2011 12:48:49 +0000 (12:48 +0000)
https://bugs.webkit.org/show_bug.cgi?id=73089

Reviewed by Kenneth Rohde Christiansen.

Move all logic related to event handling, gestures and the
interaction engine out of QtWebPageProxy, creating a separate
class called QtWebPageEventHandler. This handler will be created
by the QQuickWebViewPrivate and will be registered into QtWebPageProxy.
QQuickWebPage will now call handleEvent through this entity.

* Target.pri:
* UIProcess/API/qt/qquickwebpage.cpp:
(QQuickWebPage::event):
* UIProcess/API/qt/qquickwebview.cpp:
(QQuickWebViewPrivate::QQuickWebViewPrivate):
(QQuickWebViewPrivate::initializeDesktop):
(QQuickWebViewPrivate::initializeTouch):
* UIProcess/API/qt/qquickwebview_p_p.h:
* UIProcess/qt/QtTapGestureRecognizer.cpp:
(WebKit::QtTapGestureRecognizer::QtTapGestureRecognizer):
(WebKit::QtTapGestureRecognizer::recognize):
(WebKit::QtTapGestureRecognizer::tapTimeout):
* UIProcess/qt/QtTapGestureRecognizer.h:
* UIProcess/qt/QtWebPageEventHandler.cpp: Added.
(QtWebPageEventHandler::dragOperationToDropAction):
(QtWebPageEventHandler::dragOperationToDropActions):
(QtWebPageEventHandler::dropActionToDragOperation):
(QtWebPageEventHandler::QtWebPageEventHandler):
(QtWebPageEventHandler::~QtWebPageEventHandler):
(QtWebPageEventHandler::handleEvent):
(QtWebPageEventHandler::handleMouseMoveEvent):
(QtWebPageEventHandler::handleMousePressEvent):
(QtWebPageEventHandler::handleMouseReleaseEvent):
(QtWebPageEventHandler::handleMouseDoubleClickEvent):
(QtWebPageEventHandler::handleWheelEvent):
(QtWebPageEventHandler::handleHoverLeaveEvent):
(QtWebPageEventHandler::handleHoverMoveEvent):
(QtWebPageEventHandler::handleDragEnterEvent):
(QtWebPageEventHandler::handleDragLeaveEvent):
(QtWebPageEventHandler::handleDragMoveEvent):
(QtWebPageEventHandler::handleDropEvent):
(QtWebPageEventHandler::handleSingleTapEvent):
(QtWebPageEventHandler::handleDoubleTapEvent):
(QtWebPageEventHandler::timerEvent):
(QtWebPageEventHandler::handleKeyPressEvent):
(QtWebPageEventHandler::handleKeyReleaseEvent):
(QtWebPageEventHandler::handleFocusInEvent):
(QtWebPageEventHandler::handleFocusOutEvent):
(QtWebPageEventHandler::setViewportInteractionEngine):
(QtWebPageEventHandler::touchEvent):
(QtWebPageEventHandler::resetGestureRecognizers):
(QtWebPageEventHandler::doneWithTouchEvent):
(QtWebPageEventHandler::didFindZoomableArea):
* UIProcess/qt/QtWebPageEventHandler.h: Added.
* UIProcess/qt/QtWebPageProxy.cpp:
(QtWebPageProxy::QtWebPageProxy):
(QtWebPageProxy::init):
(QtWebPageProxy::didFindZoomableArea):
(QtWebPageProxy::processDidCrash):
(QtWebPageProxy::startDrag):
(QtWebPageProxy::doneWithTouchEvent):
* UIProcess/qt/QtWebPageProxy.h:
(QtWebPageProxy::eventHandler):

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

Source/WebKit2/ChangeLog
Source/WebKit2/Target.pri
Source/WebKit2/UIProcess/API/qt/qquickwebpage.cpp
Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp
Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h
Source/WebKit2/UIProcess/qt/QtTapGestureRecognizer.cpp
Source/WebKit2/UIProcess/qt/QtTapGestureRecognizer.h
Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.cpp [new file with mode: 0644]
Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.h [new file with mode: 0644]
Source/WebKit2/UIProcess/qt/QtWebPageProxy.cpp
Source/WebKit2/UIProcess/qt/QtWebPageProxy.h

index 7ce6a0e..fc98a38 100644 (file)
@@ -1,3 +1,70 @@
+2011-11-24  Jesus Sanchez-Palencia  <jesus.palencia@openbossa.org>
+
+        [Qt][WK2] Move event handling out of QtWebPageProxy
+        https://bugs.webkit.org/show_bug.cgi?id=73089
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        Move all logic related to event handling, gestures and the
+        interaction engine out of QtWebPageProxy, creating a separate
+        class called QtWebPageEventHandler. This handler will be created
+        by the QQuickWebViewPrivate and will be registered into QtWebPageProxy.
+        QQuickWebPage will now call handleEvent through this entity.
+
+        * Target.pri:
+        * UIProcess/API/qt/qquickwebpage.cpp:
+        (QQuickWebPage::event):
+        * UIProcess/API/qt/qquickwebview.cpp:
+        (QQuickWebViewPrivate::QQuickWebViewPrivate):
+        (QQuickWebViewPrivate::initializeDesktop):
+        (QQuickWebViewPrivate::initializeTouch):
+        * UIProcess/API/qt/qquickwebview_p_p.h:
+        * UIProcess/qt/QtTapGestureRecognizer.cpp:
+        (WebKit::QtTapGestureRecognizer::QtTapGestureRecognizer):
+        (WebKit::QtTapGestureRecognizer::recognize):
+        (WebKit::QtTapGestureRecognizer::tapTimeout):
+        * UIProcess/qt/QtTapGestureRecognizer.h:
+        * UIProcess/qt/QtWebPageEventHandler.cpp: Added.
+        (QtWebPageEventHandler::dragOperationToDropAction):
+        (QtWebPageEventHandler::dragOperationToDropActions):
+        (QtWebPageEventHandler::dropActionToDragOperation):
+        (QtWebPageEventHandler::QtWebPageEventHandler):
+        (QtWebPageEventHandler::~QtWebPageEventHandler):
+        (QtWebPageEventHandler::handleEvent):
+        (QtWebPageEventHandler::handleMouseMoveEvent):
+        (QtWebPageEventHandler::handleMousePressEvent):
+        (QtWebPageEventHandler::handleMouseReleaseEvent):
+        (QtWebPageEventHandler::handleMouseDoubleClickEvent):
+        (QtWebPageEventHandler::handleWheelEvent):
+        (QtWebPageEventHandler::handleHoverLeaveEvent):
+        (QtWebPageEventHandler::handleHoverMoveEvent):
+        (QtWebPageEventHandler::handleDragEnterEvent):
+        (QtWebPageEventHandler::handleDragLeaveEvent):
+        (QtWebPageEventHandler::handleDragMoveEvent):
+        (QtWebPageEventHandler::handleDropEvent):
+        (QtWebPageEventHandler::handleSingleTapEvent):
+        (QtWebPageEventHandler::handleDoubleTapEvent):
+        (QtWebPageEventHandler::timerEvent):
+        (QtWebPageEventHandler::handleKeyPressEvent):
+        (QtWebPageEventHandler::handleKeyReleaseEvent):
+        (QtWebPageEventHandler::handleFocusInEvent):
+        (QtWebPageEventHandler::handleFocusOutEvent):
+        (QtWebPageEventHandler::setViewportInteractionEngine):
+        (QtWebPageEventHandler::touchEvent):
+        (QtWebPageEventHandler::resetGestureRecognizers):
+        (QtWebPageEventHandler::doneWithTouchEvent):
+        (QtWebPageEventHandler::didFindZoomableArea):
+        * UIProcess/qt/QtWebPageEventHandler.h: Added.
+        * UIProcess/qt/QtWebPageProxy.cpp:
+        (QtWebPageProxy::QtWebPageProxy):
+        (QtWebPageProxy::init):
+        (QtWebPageProxy::didFindZoomableArea):
+        (QtWebPageProxy::processDidCrash):
+        (QtWebPageProxy::startDrag):
+        (QtWebPageProxy::doneWithTouchEvent):
+        * UIProcess/qt/QtWebPageProxy.h:
+        (QtWebPageProxy::eventHandler):
+
 2011-11-25  Simon Hausmann  <simon.hausmann@nokia.com>
 
         [Qt] Cleanup in QML tests.
index 0414888..b073b46 100644 (file)
@@ -314,6 +314,7 @@ HEADERS += \
     UIProcess/WebResourceLoadClient.h \
     UIProcess/WebUIClient.h \
     UIProcess/qt/ClientImpl.h \
+    UIProcess/qt/QtWebPageEventHandler.h \
     UIProcess/qt/QtGestureRecognizer.h \
     UIProcess/qt/QtPanGestureRecognizer.h \
     UIProcess/qt/QtPinchGestureRecognizer.h \
@@ -618,6 +619,7 @@ SOURCES += \
     UIProcess/WebUIClient.cpp \
     UIProcess/qt/ClientImpl.cpp \
     UIProcess/qt/LayerTreeHostProxyQt.cpp \
+    UIProcess/qt/QtWebPageEventHandler.cpp \
     UIProcess/qt/QtGestureRecognizer.cpp \
     UIProcess/qt/QtPanGestureRecognizer.cpp \
     UIProcess/qt/QtPinchGestureRecognizer.cpp \
index 02fc63d..e18e383 100644 (file)
@@ -21,6 +21,7 @@
 #include "config.h"
 #include "qquickwebpage_p.h"
 
+#include "QtWebPageEventHandler.h"
 #include "QtWebPageProxy.h"
 #include "TransformationMatrix.h"
 #include "qquickwebpage_p_p.h"
@@ -146,7 +147,7 @@ void QQuickWebPage::geometryChanged(const QRectF& newGeometry, const QRectF& old
 
 bool QQuickWebPage::event(QEvent* ev)
 {
-    if (d->pageProxy->handleEvent(ev))
+    if (d->pageProxy->eventHandler()->handleEvent(ev))
         return true;
     if (ev->type() == QEvent::InputMethod)
         return false; // This is necessary to avoid an endless loop in connection with QQuickItem::event().
index dd0c8e2..647459c 100644 (file)
@@ -51,11 +51,13 @@ QQuickWebViewPrivate::QQuickWebViewPrivate(QQuickWebView* viewport, WKContextRef
     pageView.reset(new QQuickWebPage(viewport));
 
     QQuickWebPagePrivate* const pageViewPrivate = pageView.data()->d;
-    setPageProxy(new QtWebPageProxy(pageView.data(), q_ptr, /* interactionEngine */ 0, contextRef, pageGroupRef));
+    setPageProxy(new QtWebPageProxy(pageView.data(), q_ptr, contextRef, pageGroupRef));
     pageViewPrivate->setPageProxy(pageProxy.data());
 
+    eventHandler.reset(new QtWebPageEventHandler(pageProxy->pageRef()));
+
     QWebPreferencesPrivate::get(pageProxy->preferences())->setAttribute(QWebPreferencesPrivate::AcceleratedCompositingEnabled, true);
-    pageProxy->init();
+    pageProxy->init(eventHandler.data());
 
     pageLoadClient.reset(new QtWebPageLoadClient(pageProxy->pageRef(), q_ptr));
     pagePolicyClient.reset(new QtWebPagePolicyClient(pageProxy->pageRef(), q_ptr));
@@ -87,14 +89,14 @@ void QQuickWebViewPrivate::initializeDesktop(QQuickWebView* viewport)
         QObject::disconnect(interactionEngine.data(), SIGNAL(viewportTrajectoryVectorChanged(const QPointF&)), viewport, SLOT(_q_viewportTrajectoryVectorChanged(const QPointF&)));
     }
     interactionEngine.reset(0);
-    pageProxy->setViewportInteractionEngine(0);
+    eventHandler->setViewportInteractionEngine(0);
     enableMouseEvents();
 }
 
 void QQuickWebViewPrivate::initializeTouch(QQuickWebView* viewport)
 {
     interactionEngine.reset(new QtViewportInteractionEngine(viewport, pageView.data()));
-    pageProxy->setViewportInteractionEngine(interactionEngine.data());
+    eventHandler->setViewportInteractionEngine(interactionEngine.data());
     disableMouseEvents();
     QObject::connect(interactionEngine.data(), SIGNAL(viewportUpdateRequested()), viewport, SLOT(_q_viewportUpdated()));
     QObject::connect(interactionEngine.data(), SIGNAL(viewportTrajectoryVectorChanged(const QPointF&)), viewport, SLOT(_q_viewportTrajectoryVectorChanged(const QPointF&)));
index fc8c2ca..c70d327 100644 (file)
@@ -21,6 +21,7 @@
 #ifndef qquickwebview_p_p_h
 #define qquickwebview_p_p_h
 
+#include "QtWebPageEventHandler.h"
 #include "QtViewportInteractionEngine.h"
 #include "QtWebPageLoadClient.h"
 #include "QtWebPagePolicyClient.h"
@@ -108,6 +109,8 @@ private:
 
     void setViewInAttachedProperties(QObject*);
 
+    QScopedPointer<QtWebPageEventHandler> eventHandler;
+
     QScopedPointer<QtWebPageLoadClient> pageLoadClient;
     QScopedPointer<QtWebPagePolicyClient> pagePolicyClient;
     QScopedPointer<QtWebPageUIClient> pageUIClient;
index 849b34d..12a305e 100644 (file)
 #include "config.h"
 #include "QtTapGestureRecognizer.h"
 
-#include "QtWebPageProxy.h"
+#include "QtWebPageEventHandler.h"
 #include "QtViewportInteractionEngine.h"
 #include <QLineF>
 #include <QTouchEvent>
 
 namespace WebKit {
 
-QtTapGestureRecognizer::QtTapGestureRecognizer(QtViewportInteractionEngine* interactionEngine, QtWebPageProxy* page)
+QtTapGestureRecognizer::QtTapGestureRecognizer(QtViewportInteractionEngine* interactionEngine, QtWebPageEventHandler* eventHandler)
     : QtGestureRecognizer(interactionEngine)
-    , m_webPageProxy(page)
+    , m_eventHandler(eventHandler)
     , m_tapState(NoTap)
 {
     reset();
@@ -100,8 +100,8 @@ bool QtTapGestureRecognizer::recognize(const QTouchEvent* event, qint64 eventTim
                 const QTouchEvent::TouchPoint& touchPoint = event->touchPoints().first();
                 QPointF startPosition = touchPoint.startScreenPos();
                 QPointF endPosition = touchPoint.screenPos();
-                if (QLineF(endPosition, startPosition).length() < maxDoubleTapDistance && m_webPageProxy)
-                    m_webPageProxy->handleDoubleTapEvent(touchPoint);
+                if (QLineF(endPosition, startPosition).length() < maxDoubleTapDistance && m_eventHandler)
+                    m_eventHandler->handleDoubleTapEvent(touchPoint);
                 break;
             }
         case SingleTapStarted:
@@ -125,7 +125,7 @@ bool QtTapGestureRecognizer::recognize(const QTouchEvent* event, qint64 eventTim
 void QtTapGestureRecognizer::tapTimeout()
 {
     m_doubleTapTimer.stop();
-    m_webPageProxy->handleSingleTapEvent(m_touchBeginEventForTap->touchPoints().at(0));
+    m_eventHandler->handleSingleTapEvent(m_touchBeginEventForTap->touchPoints().at(0));
     m_touchBeginEventForTap.clear();
 }
 
index b6abebe..4390fd3 100644 (file)
@@ -43,13 +43,13 @@ const qreal maxDoubleTapDistance = 120;
 const int tapAndHoldTime = 800;
 const int doubleClickInterval = 400;
 
-class QtWebPageProxy;
+class QtWebPageEventHandler;
 
 namespace WebKit {
 
 class QtTapGestureRecognizer : public QObject, private QtGestureRecognizer {
 public:
-    QtTapGestureRecognizer(QtViewportInteractionEngine*, QtWebPageProxy*);
+    QtTapGestureRecognizer(QtViewportInteractionEngine*, QtWebPageEventHandler*);
     void setViewportInteractionEngine(QtViewportInteractionEngine*);
     bool recognize(const QTouchEvent*, qint64 eventTimestampMillis);
     void reset();
@@ -60,7 +60,7 @@ protected:
     void tapAndHoldTimeout();
 
 private:
-    QtWebPageProxy* m_webPageProxy;
+    QtWebPageEventHandler* m_eventHandler;
     QBasicTimer m_doubleTapTimer;
     QBasicTimer m_tapAndHoldTimer;
     OwnPtr<QTouchEvent> m_touchBeginEventForTap;
diff --git a/Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.cpp b/Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.cpp
new file mode 100644 (file)
index 0000000..97f747e
--- /dev/null
@@ -0,0 +1,389 @@
+/*
+ * Copyright (C) 2010, 2011 Nokia Corporation and/or its subsidiary(-ies)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+#include "QtWebPageEventHandler.h"
+
+#include "NativeWebKeyboardEvent.h"
+#include "NativeWebMouseEvent.h"
+#include "NativeWebWheelEvent.h"
+#include "QtViewportInteractionEngine.h"
+#include <QDrag>
+#include <QGraphicsSceneMouseEvent>
+#include <QGuiApplication>
+#include <QStyleHints>
+#include <QTouchEvent>
+#include <WebCore/DragData.h>
+
+using namespace WebKit;
+using namespace WebCore;
+
+Qt::DropAction QtWebPageEventHandler::dragOperationToDropAction(unsigned dragOperation)
+{
+    Qt::DropAction result = Qt::IgnoreAction;
+    if (dragOperation & DragOperationCopy)
+        result = Qt::CopyAction;
+    else if (dragOperation & DragOperationMove)
+        result = Qt::MoveAction;
+    else if (dragOperation & DragOperationGeneric)
+        result = Qt::MoveAction;
+    else if (dragOperation & DragOperationLink)
+        result = Qt::LinkAction;
+    return result;
+}
+
+Qt::DropActions QtWebPageEventHandler::dragOperationToDropActions(unsigned dragOperations)
+{
+    Qt::DropActions result = Qt::IgnoreAction;
+    if (dragOperations & DragOperationCopy)
+        result |= Qt::CopyAction;
+    if (dragOperations & DragOperationMove)
+        result |= Qt::MoveAction;
+    if (dragOperations & DragOperationGeneric)
+        result |= Qt::MoveAction;
+    if (dragOperations & DragOperationLink)
+        result |= Qt::LinkAction;
+    return result;
+}
+
+WebCore::DragOperation QtWebPageEventHandler::dropActionToDragOperation(Qt::DropActions actions)
+{
+    unsigned result = 0;
+    if (actions & Qt::CopyAction)
+        result |= DragOperationCopy;
+    if (actions & Qt::MoveAction)
+        result |= (DragOperationMove | DragOperationGeneric);
+    if (actions & Qt::LinkAction)
+        result |= DragOperationLink;
+    if (result == (DragOperationCopy | DragOperationMove | DragOperationGeneric | DragOperationLink))
+        result = DragOperationEvery;
+    return (DragOperation)result;
+}
+
+QtWebPageEventHandler::QtWebPageEventHandler(WKPageRef pageRef, WebKit::QtViewportInteractionEngine* viewportInteractionEngine)
+    : m_webPageProxy(toImpl(pageRef))
+    , m_interactionEngine(viewportInteractionEngine)
+    , m_panGestureRecognizer(viewportInteractionEngine)
+    , m_pinchGestureRecognizer(viewportInteractionEngine)
+    , m_tapGestureRecognizer(viewportInteractionEngine, this)
+{
+}
+
+QtWebPageEventHandler::~QtWebPageEventHandler()
+{
+}
+
+bool QtWebPageEventHandler::handleEvent(QEvent* ev)
+{
+    switch (ev->type()) {
+    case QEvent::MouseMove:
+        return handleMouseMoveEvent(reinterpret_cast<QMouseEvent*>(ev));
+    case QEvent::MouseButtonPress:
+        return handleMousePressEvent(reinterpret_cast<QMouseEvent*>(ev));
+    case QEvent::MouseButtonRelease:
+        return handleMouseReleaseEvent(reinterpret_cast<QMouseEvent*>(ev));
+    case QEvent::MouseButtonDblClick:
+        return handleMouseDoubleClickEvent(reinterpret_cast<QMouseEvent*>(ev));
+    case QEvent::Wheel:
+        return handleWheelEvent(reinterpret_cast<QWheelEvent*>(ev));
+    case QEvent::HoverLeave:
+        return handleHoverLeaveEvent(reinterpret_cast<QHoverEvent*>(ev));
+    case QEvent::HoverEnter: // Fall-through, for WebKit the distinction doesn't matter.
+    case QEvent::HoverMove:
+        return handleHoverMoveEvent(reinterpret_cast<QHoverEvent*>(ev));
+    case QEvent::DragEnter:
+        return handleDragEnterEvent(reinterpret_cast<QDragEnterEvent*>(ev));
+    case QEvent::DragLeave:
+        return handleDragLeaveEvent(reinterpret_cast<QDragLeaveEvent*>(ev));
+    case QEvent::DragMove:
+        return handleDragMoveEvent(reinterpret_cast<QDragMoveEvent*>(ev));
+    case QEvent::Drop:
+        return handleDropEvent(reinterpret_cast<QDropEvent*>(ev));
+    case QEvent::KeyPress:
+        return handleKeyPressEvent(reinterpret_cast<QKeyEvent*>(ev));
+    case QEvent::KeyRelease:
+        return handleKeyReleaseEvent(reinterpret_cast<QKeyEvent*>(ev));
+    case QEvent::FocusIn:
+        return handleFocusInEvent(reinterpret_cast<QFocusEvent*>(ev));
+    case QEvent::FocusOut:
+        return handleFocusOutEvent(reinterpret_cast<QFocusEvent*>(ev));
+    case QEvent::TouchBegin:
+    case QEvent::TouchEnd:
+    case QEvent::TouchUpdate:
+        touchEvent(static_cast<QTouchEvent*>(ev));
+        return true;
+    }
+
+    // FIXME: Move all common event handling here.
+    return false;
+}
+
+bool QtWebPageEventHandler::handleMouseMoveEvent(QMouseEvent* ev)
+{
+    // For some reason mouse press results in mouse hover (which is
+    // converted to mouse move for WebKit). We ignore these hover
+    // events by comparing lastPos with newPos.
+    // NOTE: lastPos from the event always comes empty, so we work
+    // around that here.
+    static QPointF lastPos = QPointF();
+    if (lastPos == ev->pos())
+        return ev->isAccepted();
+    lastPos = ev->pos();
+
+    m_webPageProxy->handleMouseEvent(NativeWebMouseEvent(ev, /*eventClickCount*/ 0));
+
+    return ev->isAccepted();
+}
+
+bool QtWebPageEventHandler::handleMousePressEvent(QMouseEvent* ev)
+{
+    if (m_tripleClickTimer.isActive() && (ev->pos() - m_tripleClick).manhattanLength() < qApp->styleHints()->startDragDistance()) {
+        m_webPageProxy->handleMouseEvent(NativeWebMouseEvent(ev, /*eventClickCount*/ 3));
+        return ev->isAccepted();
+    }
+
+    m_webPageProxy->handleMouseEvent(NativeWebMouseEvent(ev, /*eventClickCount*/ 1));
+    return ev->isAccepted();
+}
+
+bool QtWebPageEventHandler::handleMouseReleaseEvent(QMouseEvent* ev)
+{
+    m_webPageProxy->handleMouseEvent(NativeWebMouseEvent(ev, /*eventClickCount*/ 0));
+    return ev->isAccepted();
+}
+
+bool QtWebPageEventHandler::handleMouseDoubleClickEvent(QMouseEvent* ev)
+{
+    m_webPageProxy->handleMouseEvent(NativeWebMouseEvent(ev, /*eventClickCount*/ 2));
+
+    m_tripleClickTimer.start(qApp->styleHints()->mouseDoubleClickInterval(), this);
+    m_tripleClick = ev->localPos().toPoint();
+    return ev->isAccepted();
+}
+
+bool QtWebPageEventHandler::handleWheelEvent(QWheelEvent* ev)
+{
+    m_webPageProxy->handleWheelEvent(NativeWebWheelEvent(ev));
+    // FIXME: Handle whether the page used the wheel event or not.
+    if (m_interactionEngine)
+        m_interactionEngine->wheelEvent(ev);
+    return ev->isAccepted();
+}
+
+bool QtWebPageEventHandler::handleHoverLeaveEvent(QHoverEvent* ev)
+{
+    // To get the correct behavior of mouseout, we need to turn the Leave event of our webview into a mouse move
+    // to a very far region.
+    QHoverEvent fakeEvent(QEvent::HoverMove, QPoint(INT_MIN, INT_MIN), ev->oldPos());
+    return handleHoverMoveEvent(&fakeEvent);
+}
+
+bool QtWebPageEventHandler::handleHoverMoveEvent(QHoverEvent* ev)
+{
+    QMouseEvent me(QEvent::MouseMove, ev->pos(), Qt::NoButton, Qt::NoButton, Qt::NoModifier);
+    me.setAccepted(ev->isAccepted());
+
+    return handleMouseMoveEvent(&me);
+}
+
+bool QtWebPageEventHandler::handleDragEnterEvent(QDragEnterEvent* ev)
+{
+    m_webPageProxy->resetDragOperation();
+    // FIXME: Should not use QCursor::pos()
+    DragData dragData(ev->mimeData(), ev->pos(), QCursor::pos(), dropActionToDragOperation(ev->possibleActions()));
+    m_webPageProxy->dragEntered(&dragData);
+    ev->acceptProposedAction();
+    return true;
+}
+
+bool QtWebPageEventHandler::handleDragLeaveEvent(QDragLeaveEvent* ev)
+{
+    bool accepted = ev->isAccepted();
+
+    // FIXME: Should not use QCursor::pos()
+    DragData dragData(0, IntPoint(), QCursor::pos(), DragOperationNone);
+    m_webPageProxy->dragExited(&dragData);
+    m_webPageProxy->resetDragOperation();
+
+    ev->setAccepted(accepted);
+    return accepted;
+}
+
+bool QtWebPageEventHandler::handleDragMoveEvent(QDragMoveEvent* ev)
+{
+    bool accepted = ev->isAccepted();
+
+    // FIXME: Should not use QCursor::pos()
+    DragData dragData(ev->mimeData(), ev->pos(), QCursor::pos(), dropActionToDragOperation(ev->possibleActions()));
+    m_webPageProxy->dragUpdated(&dragData);
+    ev->setDropAction(dragOperationToDropAction(m_webPageProxy->dragSession().operation));
+    if (m_webPageProxy->dragSession().operation != DragOperationNone)
+        ev->accept();
+
+    ev->setAccepted(accepted);
+    return accepted;
+}
+
+bool QtWebPageEventHandler::handleDropEvent(QDropEvent* ev)
+{
+    bool accepted = ev->isAccepted();
+
+    // FIXME: Should not use QCursor::pos()
+    DragData dragData(ev->mimeData(), ev->pos(), QCursor::pos(), dropActionToDragOperation(ev->possibleActions()));
+    SandboxExtension::Handle handle;
+    m_webPageProxy->performDrag(&dragData, String(), handle);
+    ev->setDropAction(dragOperationToDropAction(m_webPageProxy->dragSession().operation));
+    ev->accept();
+
+    ev->setAccepted(accepted);
+    return accepted;
+}
+
+void QtWebPageEventHandler::handleSingleTapEvent(const QTouchEvent::TouchPoint& point)
+{
+    WebGestureEvent gesture(WebEvent::GestureSingleTap, point.pos().toPoint(), point.screenPos().toPoint(), WebEvent::Modifiers(0), 0);
+    m_webPageProxy->handleGestureEvent(gesture);
+}
+
+void QtWebPageEventHandler::handleDoubleTapEvent(const QTouchEvent::TouchPoint& point)
+{
+    m_webPageProxy->findZoomableAreaForPoint(point.pos().toPoint());
+}
+
+void QtWebPageEventHandler::timerEvent(QTimerEvent* ev)
+{
+    int timerId = ev->timerId();
+    if (timerId == m_tripleClickTimer.timerId())
+        m_tripleClickTimer.stop();
+    else
+        QObject::timerEvent(ev);
+}
+
+bool QtWebPageEventHandler::handleKeyPressEvent(QKeyEvent* ev)
+{
+    m_webPageProxy->handleKeyboardEvent(NativeWebKeyboardEvent(ev));
+    return true;
+}
+
+bool QtWebPageEventHandler::handleKeyReleaseEvent(QKeyEvent* ev)
+{
+    m_webPageProxy->handleKeyboardEvent(NativeWebKeyboardEvent(ev));
+    return true;
+}
+
+bool QtWebPageEventHandler::handleFocusInEvent(QFocusEvent*)
+{
+    m_webPageProxy->viewStateDidChange(WebPageProxy::ViewIsFocused | WebPageProxy::ViewWindowIsActive);
+    return true;
+}
+
+bool QtWebPageEventHandler::handleFocusOutEvent(QFocusEvent*)
+{
+    m_webPageProxy->viewStateDidChange(WebPageProxy::ViewIsFocused | WebPageProxy::ViewWindowIsActive);
+    return true;
+}
+
+void QtWebPageEventHandler::setViewportInteractionEngine(QtViewportInteractionEngine* engine)
+{
+    m_interactionEngine = engine;
+    m_panGestureRecognizer.setViewportInteractionEngine(engine);
+    m_pinchGestureRecognizer.setViewportInteractionEngine(engine);
+    m_tapGestureRecognizer.setViewportInteractionEngine(engine);
+}
+
+void QtWebPageEventHandler::touchEvent(QTouchEvent* event)
+{
+#if ENABLE(TOUCH_EVENTS)
+    m_webPageProxy->handleTouchEvent(NativeWebTouchEvent(event));
+    event->accept();
+#else
+    ASSERT_NOT_REACHED();
+    ev->ignore();
+#endif
+}
+
+void QtWebPageEventHandler::resetGestureRecognizers()
+{
+    m_panGestureRecognizer.reset();
+    m_pinchGestureRecognizer.reset();
+    m_tapGestureRecognizer.reset();
+}
+
+void QtWebPageEventHandler::doneWithTouchEvent(const NativeWebTouchEvent& event, bool wasEventHandled)
+{
+    if (!m_interactionEngine)
+        return;
+
+    if (wasEventHandled || event.type() == WebEvent::TouchCancel) {
+        resetGestureRecognizers();
+        return;
+    }
+
+    const QTouchEvent* ev = event.nativeEvent();
+
+    switch (ev->type()) {
+    case QEvent::TouchBegin:
+        ASSERT(!m_interactionEngine->panGestureActive());
+        ASSERT(!m_interactionEngine->pinchGestureActive());
+
+        // The interaction engine might still be animating kinetic scrolling or a scale animation
+        // such as double-tap to zoom or the bounce back effect. A touch stops the kinetic scrolling
+        // where as it does not stop the scale animation.
+        if (m_interactionEngine->scrollAnimationActive())
+            m_interactionEngine->interruptScrollAnimation();
+        break;
+    case QEvent::TouchUpdate:
+        // The scale animation can only be interrupted by a pinch gesture, which will then take over.
+        if (m_interactionEngine->scaleAnimationActive() && m_pinchGestureRecognizer.isRecognized())
+            m_interactionEngine->interruptScaleAnimation();
+        break;
+    default:
+        break;
+    }
+
+    // If the scale animation is active we don't pass the event to the recognizers. In the future
+    // we would want to queue the event here and repost then when the animation ends.
+    if (m_interactionEngine->scaleAnimationActive())
+        return;
+
+    // Convert the event timestamp from second to millisecond.
+    qint64 eventTimestampMillis = static_cast<qint64>(event.timestamp() * 1000);
+    m_panGestureRecognizer.recognize(ev, eventTimestampMillis);
+    m_pinchGestureRecognizer.recognize(ev);
+
+    if (m_panGestureRecognizer.isRecognized() || m_pinchGestureRecognizer.isRecognized())
+        m_tapGestureRecognizer.reset();
+    else {
+        const QTouchEvent* ev = event.nativeEvent();
+        m_tapGestureRecognizer.recognize(ev, eventTimestampMillis);
+    }
+}
+
+void QtWebPageEventHandler::didFindZoomableArea(const IntPoint& target, const IntRect& area)
+{
+    if (!m_interactionEngine)
+        return;
+
+    // FIXME: As the find method might not respond immediately during load etc,
+    // we should ignore all but the latest request.
+    m_interactionEngine->zoomToAreaGestureEnded(QPointF(target), QRectF(area));
+}
+
+#include "moc_QtWebPageEventHandler.cpp"
diff --git a/Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.h b/Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.h
new file mode 100644 (file)
index 0000000..0a58ff7
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2010, 2011 Nokia Corporation and/or its subsidiary(-ies)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef QtWebPageEventHandler_h
+#define QtWebPageEventHandler_h
+
+#include "QtPanGestureRecognizer.h"
+#include "QtPinchGestureRecognizer.h"
+#include "QtTapGestureRecognizer.h"
+#include "WebPageProxy.h"
+#include <QBasicTimer>
+#include <QKeyEvent>
+#include <QTouchEvent>
+#include <WKPage.h>
+
+using namespace WebKit;
+
+class QtWebPageEventHandler : public QObject {
+    Q_OBJECT
+
+public:
+    QtWebPageEventHandler(WKPageRef, WebKit::QtViewportInteractionEngine* = 0);
+    ~QtWebPageEventHandler();
+
+    static Qt::DropAction dragOperationToDropAction(unsigned dragOperation);
+    static Qt::DropActions dragOperationToDropActions(unsigned dragOperations);
+    static WebCore::DragOperation dropActionToDragOperation(Qt::DropActions);
+
+    bool handleEvent(QEvent*);
+
+    void setViewportInteractionEngine(QtViewportInteractionEngine*);
+
+    void handleSingleTapEvent(const QTouchEvent::TouchPoint&);
+    void handleDoubleTapEvent(const QTouchEvent::TouchPoint&);
+
+    void didFindZoomableArea(const WebCore::IntPoint& target, const WebCore::IntRect& area);
+    void doneWithTouchEvent(const NativeWebTouchEvent&, bool wasEventHandled);
+    void resetGestureRecognizers();
+
+protected:
+    WebPageProxy* m_webPageProxy;
+    QtViewportInteractionEngine* m_interactionEngine;
+    QtPanGestureRecognizer m_panGestureRecognizer;
+    QtPinchGestureRecognizer m_pinchGestureRecognizer;
+    QtTapGestureRecognizer m_tapGestureRecognizer;
+
+private:
+    bool handleKeyPressEvent(QKeyEvent*);
+    bool handleKeyReleaseEvent(QKeyEvent*);
+    bool handleFocusInEvent(QFocusEvent*);
+    bool handleFocusOutEvent(QFocusEvent*);
+    bool handleMouseMoveEvent(QMouseEvent*);
+    bool handleMousePressEvent(QMouseEvent*);
+    bool handleMouseReleaseEvent(QMouseEvent*);
+    bool handleMouseDoubleClickEvent(QMouseEvent*);
+    bool handleWheelEvent(QWheelEvent*);
+    bool handleHoverLeaveEvent(QHoverEvent*);
+    bool handleHoverMoveEvent(QHoverEvent*);
+    bool handleDragEnterEvent(QDragEnterEvent*);
+    bool handleDragLeaveEvent(QDragLeaveEvent*);
+    bool handleDragMoveEvent(QDragMoveEvent*);
+    bool handleDropEvent(QDropEvent*);
+
+    void timerEvent(QTimerEvent*);
+
+    void touchEvent(QTouchEvent*);
+
+    QPoint m_tripleClick;
+    QBasicTimer m_tripleClickTimer;
+};
+
+#endif /* QtWebPageEventHandler_h */
index 4f9fb6a..0a106d1 100644 (file)
 #include "FindIndicator.h"
 #include "LocalizedStrings.h"
 #include "MutableArray.h"
-#include "NativeWebKeyboardEvent.h"
-#include "NativeWebMouseEvent.h"
-#include "NativeWebWheelEvent.h"
 #include "NotImplemented.h"
-#include "QtViewportInteractionEngine.h"
+#include "QtWebPageEventHandler.h"
 #include "QtWebUndoCommand.h"
 #include "WebBackForwardList.h"
 #include "WebContext.h"
 #include "WebContextMenuProxyQt.h"
 #include "WebEditCommandProxy.h"
-#include "WebEventFactoryQt.h"
 #include "WebPopupMenuProxyQtDesktop.h"
 #include "WKStringQt.h"
 #include "WKURLQt.h"
 #include <QDrag>
 #include <QGuiApplication>
-#include <QGraphicsSceneMouseEvent>
 #include <QJSEngine>
 #include <QMimeData>
 #include <QStyleHints>
-#include <QTouchEvent>
 #include <QUndoStack>
 #include <QtDebug>
 #include <WebCore/Cursor.h>
 #include <WebCore/DragData.h>
 #include <WebCore/FloatRect.h>
-#include <WebCore/NotImplemented.h>
 #include <WebCore/Region.h>
 #include <WebKit2/WKFrame.h>
 #include <WebKit2/WKPageGroup.h>
@@ -90,55 +83,9 @@ PassRefPtr<WebContext> QtWebPageProxy::defaultWKContext()
     return s_defaultContext;
 }
 
-static inline Qt::DropAction dragOperationToDropAction(unsigned dragOperation)
-{
-    Qt::DropAction result = Qt::IgnoreAction;
-    if (dragOperation & DragOperationCopy)
-        result = Qt::CopyAction;
-    else if (dragOperation & DragOperationMove)
-        result = Qt::MoveAction;
-    else if (dragOperation & DragOperationGeneric)
-        result = Qt::MoveAction;
-    else if (dragOperation & DragOperationLink)
-        result = Qt::LinkAction;
-    return result;
-}
-
-static inline Qt::DropActions dragOperationToDropActions(unsigned dragOperations)
-{
-    Qt::DropActions result = Qt::IgnoreAction;
-    if (dragOperations & DragOperationCopy)
-        result |= Qt::CopyAction;
-    if (dragOperations & DragOperationMove)
-        result |= Qt::MoveAction;
-    if (dragOperations & DragOperationGeneric)
-        result |= Qt::MoveAction;
-    if (dragOperations & DragOperationLink)
-        result |= Qt::LinkAction;
-    return result;
-}
-
-WebCore::DragOperation dropActionToDragOperation(Qt::DropActions actions)
-{
-    unsigned result = 0;
-    if (actions & Qt::CopyAction)
-        result |= DragOperationCopy;
-    if (actions & Qt::MoveAction)
-        result |= (DragOperationMove | DragOperationGeneric);
-    if (actions & Qt::LinkAction)
-        result |= DragOperationLink;
-    if (result == (DragOperationCopy | DragOperationMove | DragOperationGeneric | DragOperationLink))
-        result = DragOperationEvery;
-    return (DragOperation)result;
-}
-
-QtWebPageProxy::QtWebPageProxy(QQuickWebPage* qmlWebPage, QQuickWebView* qmlWebView, QtViewportInteractionEngine* viewportInteractionEngine, WKContextRef contextRef, WKPageGroupRef pageGroupRef)
+QtWebPageProxy::QtWebPageProxy(QQuickWebPage* qmlWebPage, QQuickWebView* qmlWebView, WKContextRef contextRef, WKPageGroupRef pageGroupRef)
     : m_qmlWebPage(qmlWebPage)
     , m_qmlWebView(qmlWebView)
-    , m_interactionEngine(viewportInteractionEngine)
-    , m_panGestureRecognizer(viewportInteractionEngine)
-    , m_pinchGestureRecognizer(viewportInteractionEngine)
-    , m_tapGestureRecognizer(viewportInteractionEngine, this)
     , m_context(contextRef ? toImpl(contextRef) : defaultWKContext())
     , m_undoStack(adoptPtr(new QUndoStack(this)))
     , m_navigatorQtObjectEnabled(false)
@@ -149,8 +96,9 @@ QtWebPageProxy::QtWebPageProxy(QQuickWebPage* qmlWebPage, QQuickWebView* qmlWebV
         s_defaultPageProxyCount++;
 }
 
-void QtWebPageProxy::init()
+void QtWebPageProxy::init(QtWebPageEventHandler* eventHandler)
 {
+    m_eventHandler = eventHandler;
     m_webPageProxy->initializeWebPage();
 }
 
@@ -169,183 +117,6 @@ QtWebPageProxy::~QtWebPageProxy()
     delete m_history;
 }
 
-bool QtWebPageProxy::handleEvent(QEvent* ev)
-{
-    switch (ev->type()) {
-    case QEvent::MouseMove:
-        return handleMouseMoveEvent(reinterpret_cast<QMouseEvent*>(ev));
-    case QEvent::MouseButtonPress:
-        return handleMousePressEvent(reinterpret_cast<QMouseEvent*>(ev));
-    case QEvent::MouseButtonRelease:
-        return handleMouseReleaseEvent(reinterpret_cast<QMouseEvent*>(ev));
-    case QEvent::MouseButtonDblClick:
-        return handleMouseDoubleClickEvent(reinterpret_cast<QMouseEvent*>(ev));
-    case QEvent::Wheel:
-        return handleWheelEvent(reinterpret_cast<QWheelEvent*>(ev));
-    case QEvent::HoverLeave:
-        return handleHoverLeaveEvent(reinterpret_cast<QHoverEvent*>(ev));
-    case QEvent::HoverEnter: // Fall-through, for WebKit the distinction doesn't matter.
-    case QEvent::HoverMove:
-        return handleHoverMoveEvent(reinterpret_cast<QHoverEvent*>(ev));
-    case QEvent::DragEnter:
-        return handleDragEnterEvent(reinterpret_cast<QDragEnterEvent*>(ev));
-    case QEvent::DragLeave:
-        return handleDragLeaveEvent(reinterpret_cast<QDragLeaveEvent*>(ev));
-    case QEvent::DragMove:
-        return handleDragMoveEvent(reinterpret_cast<QDragMoveEvent*>(ev));
-    case QEvent::Drop:
-        return handleDropEvent(reinterpret_cast<QDropEvent*>(ev));
-    case QEvent::KeyPress:
-        return handleKeyPressEvent(reinterpret_cast<QKeyEvent*>(ev));
-    case QEvent::KeyRelease:
-        return handleKeyReleaseEvent(reinterpret_cast<QKeyEvent*>(ev));
-    case QEvent::FocusIn:
-        return handleFocusInEvent(reinterpret_cast<QFocusEvent*>(ev));
-    case QEvent::FocusOut:
-        return handleFocusOutEvent(reinterpret_cast<QFocusEvent*>(ev));
-    case QEvent::TouchBegin:
-    case QEvent::TouchEnd:
-    case QEvent::TouchUpdate:
-        touchEvent(static_cast<QTouchEvent*>(ev));
-        return true;
-    }
-
-    // FIXME: Move all common event handling here.
-    return false;
-}
-
-bool QtWebPageProxy::handleMouseMoveEvent(QMouseEvent* ev)
-{
-    // For some reason mouse press results in mouse hover (which is
-    // converted to mouse move for WebKit). We ignore these hover
-    // events by comparing lastPos with newPos.
-    // NOTE: lastPos from the event always comes empty, so we work
-    // around that here.
-    static QPointF lastPos = QPointF();
-    if (lastPos == ev->pos())
-        return ev->isAccepted();
-    lastPos = ev->pos();
-
-    m_webPageProxy->handleMouseEvent(NativeWebMouseEvent(ev, /*eventClickCount=*/0));
-
-    return ev->isAccepted();
-}
-
-bool QtWebPageProxy::handleMousePressEvent(QMouseEvent* ev)
-{
-    if (m_tripleClickTimer.isActive() && (ev->pos() - m_tripleClick).manhattanLength() < qApp->styleHints()->startDragDistance()) {
-        m_webPageProxy->handleMouseEvent(NativeWebMouseEvent(ev, /*eventClickCount=*/3));
-        return ev->isAccepted();
-    }
-
-    m_webPageProxy->handleMouseEvent(NativeWebMouseEvent(ev, /*eventClickCount=*/1));
-    return ev->isAccepted();
-}
-
-bool QtWebPageProxy::handleMouseReleaseEvent(QMouseEvent* ev)
-{
-    m_webPageProxy->handleMouseEvent(NativeWebMouseEvent(ev, /*eventClickCount=*/0));
-    return ev->isAccepted();
-}
-
-bool QtWebPageProxy::handleMouseDoubleClickEvent(QMouseEvent* ev)
-{
-    m_webPageProxy->handleMouseEvent(NativeWebMouseEvent(ev, /*eventClickCount=*/2));
-
-    m_tripleClickTimer.start(qApp->styleHints()->mouseDoubleClickInterval(), this);
-    m_tripleClick = ev->localPos().toPoint();
-    return ev->isAccepted();
-}
-
-bool QtWebPageProxy::handleWheelEvent(QWheelEvent* ev)
-{
-    m_webPageProxy->handleWheelEvent(NativeWebWheelEvent(ev));
-    // FIXME: Handle whether the page used the wheel event or not.
-    if (m_interactionEngine)
-        m_interactionEngine->wheelEvent(ev);
-    return ev->isAccepted();
-}
-
-bool QtWebPageProxy::handleHoverLeaveEvent(QHoverEvent* ev)
-{
-    // To get the correct behavior of mouseout, we need to turn the Leave event of our webview into a mouse move
-    // to a very far region.
-    QHoverEvent fakeEvent(QEvent::HoverMove, QPoint(INT_MIN, INT_MIN), ev->oldPos());
-    return handleHoverMoveEvent(&fakeEvent);
-}
-
-bool QtWebPageProxy::handleHoverMoveEvent(QHoverEvent* ev)
-{
-    QMouseEvent me(QEvent::MouseMove, ev->pos(), Qt::NoButton, Qt::NoButton, Qt::NoModifier);
-    me.setAccepted(ev->isAccepted());
-
-    return handleMouseMoveEvent(&me);
-}
-
-bool QtWebPageProxy::handleDragEnterEvent(QDragEnterEvent* ev)
-{
-    m_webPageProxy->resetDragOperation();
-    // FIXME: Should not use QCursor::pos()
-    DragData dragData(ev->mimeData(), ev->pos(), QCursor::pos(), dropActionToDragOperation(ev->possibleActions()));
-    m_webPageProxy->dragEntered(&dragData);
-    ev->acceptProposedAction();
-    return true;
-}
-
-bool QtWebPageProxy::handleDragLeaveEvent(QDragLeaveEvent* ev)
-{
-    bool accepted = ev->isAccepted();
-
-    // FIXME: Should not use QCursor::pos()
-    DragData dragData(0, IntPoint(), QCursor::pos(), DragOperationNone);
-    m_webPageProxy->dragExited(&dragData);
-    m_webPageProxy->resetDragOperation();
-
-    ev->setAccepted(accepted);
-    return accepted;
-}
-
-bool QtWebPageProxy::handleDragMoveEvent(QDragMoveEvent* ev)
-{
-    bool accepted = ev->isAccepted();
-
-    // FIXME: Should not use QCursor::pos()
-    DragData dragData(ev->mimeData(), ev->pos(), QCursor::pos(), dropActionToDragOperation(ev->possibleActions()));
-    m_webPageProxy->dragUpdated(&dragData);
-    ev->setDropAction(dragOperationToDropAction(m_webPageProxy->dragSession().operation));
-    if (m_webPageProxy->dragSession().operation != DragOperationNone)
-        ev->accept();
-
-    ev->setAccepted(accepted);
-    return accepted;
-}
-
-bool QtWebPageProxy::handleDropEvent(QDropEvent* ev)
-{
-    bool accepted = ev->isAccepted();
-
-    // FIXME: Should not use QCursor::pos()
-    DragData dragData(ev->mimeData(), ev->pos(), QCursor::pos(), dropActionToDragOperation(ev->possibleActions()));
-    SandboxExtension::Handle handle;
-    m_webPageProxy->performDrag(&dragData, String(), handle);
-    ev->setDropAction(dragOperationToDropAction(m_webPageProxy->dragSession().operation));
-    ev->accept();
-
-    ev->setAccepted(accepted);
-    return accepted;
-}
-
-void QtWebPageProxy::handleSingleTapEvent(const QTouchEvent::TouchPoint& point)
-{
-    WebGestureEvent gesture(WebEvent::GestureSingleTap, point.pos().toPoint(), point.screenPos().toPoint(), WebEvent::Modifiers(0), 0);
-    m_webPageProxy->handleGestureEvent(gesture);
-}
-
-void QtWebPageProxy::handleDoubleTapEvent(const QTouchEvent::TouchPoint& point)
-{
-    m_webPageProxy->findZoomableAreaForPoint(point.pos().toPoint());
-}
-
 void QtWebPageProxy::showContextMenu(QSharedPointer<QMenu> menu)
 {
     // Remove the active menu in case this function is called twice.
@@ -378,39 +149,6 @@ void QtWebPageProxy::hideContextMenu()
         activeMenu->hide();
 }
 
-void QtWebPageProxy::timerEvent(QTimerEvent* ev)
-{
-    int timerId = ev->timerId();
-    if (timerId == m_tripleClickTimer.timerId())
-        m_tripleClickTimer.stop();
-    else
-        QObject::timerEvent(ev);
-}
-
-bool QtWebPageProxy::handleKeyPressEvent(QKeyEvent* ev)
-{
-    m_webPageProxy->handleKeyboardEvent(NativeWebKeyboardEvent(ev));
-    return true;
-}
-
-bool QtWebPageProxy::handleKeyReleaseEvent(QKeyEvent* ev)
-{
-    m_webPageProxy->handleKeyboardEvent(NativeWebKeyboardEvent(ev));
-    return true;
-}
-
-bool QtWebPageProxy::handleFocusInEvent(QFocusEvent*)
-{
-    m_webPageProxy->viewStateDidChange(WebPageProxy::ViewIsFocused | WebPageProxy::ViewWindowIsActive);
-    return true;
-}
-
-bool QtWebPageProxy::handleFocusOutEvent(QFocusEvent*)
-{
-    m_webPageProxy->viewStateDidChange(WebPageProxy::ViewIsFocused | WebPageProxy::ViewWindowIsActive);
-    return true;
-}
-
 void QtWebPageProxy::setCursor(const WebCore::Cursor& cursor)
 {
     // FIXME: This is a temporary fix until we get cursor support in QML items.
@@ -586,12 +324,8 @@ WKPageRef QtWebPageProxy::pageRef() const
 
 void QtWebPageProxy::didFindZoomableArea(const IntPoint& target, const IntRect& area)
 {
-    if (!m_interactionEngine)
-        return;
-
-    // FIXME: As the find method might not respond immediately during load etc,
-    // we should ignore all but the latest request.
-    m_interactionEngine->zoomToAreaGestureEnded(QPointF(target), QRectF(area));
+    ASSERT(m_eventHandler);
+    m_eventHandler->didFindZoomableArea(target, area);
 }
 
 void QtWebPageProxy::didReceiveMessageFromNavigatorQtObject(const String& message)
@@ -661,9 +395,9 @@ void QtWebPageProxy::didRelaunchProcess()
 void QtWebPageProxy::processDidCrash()
 {
     updateNavigationState();
-    m_panGestureRecognizer.reset();
-    m_pinchGestureRecognizer.reset();
-    m_tapGestureRecognizer.reset();
+
+    ASSERT(m_eventHandler);
+    m_eventHandler->resetGestureRecognizers();
 
     WebCore::KURL url(WebCore::ParsedURLString, m_webPageProxy->urlAtProcessExit());
     qWarning("WARNING: The web process experienced a crash on '%s'.", qPrintable(QUrl(url).toString(QUrl::RemoveUserInfo)));
@@ -701,14 +435,6 @@ void QtWebPageProxy::setNavigatorQtObjectEnabled(bool enabled)
     m_context->postMessageToInjectedBundle(messageName, body.get());
 }
 
-void QtWebPageProxy::setViewportInteractionEngine(QtViewportInteractionEngine* engine)
-{
-    m_interactionEngine = engine;
-    m_panGestureRecognizer.setViewportInteractionEngine(engine);
-    m_pinchGestureRecognizer.setViewportInteractionEngine(engine);
-    m_tapGestureRecognizer.setViewportInteractionEngine(engine);
-}
-
 void QtWebPageProxy::postMessageToNavigatorQtObject(const QString& message)
 {
     static String messageName("MessageToNavigatorQtObject");
@@ -796,7 +522,7 @@ void QtWebPageProxy::startDrag(const WebCore::DragData& dragData, PassRefPtr<Sha
 
     DragOperation dragOperationMask = dragData.draggingSourceOperationMask();
     QMimeData* mimeData = const_cast<QMimeData*>(dragData.platformData());
-    Qt::DropActions supportedDropActions = dragOperationToDropActions(dragOperationMask);
+    Qt::DropActions supportedDropActions = QtWebPageEventHandler::dragOperationToDropActions(dragOperationMask);
 
     QPoint clientPosition;
     QPoint globalPosition;
@@ -811,7 +537,7 @@ void QtWebPageProxy::startDrag(const WebCore::DragData& dragData, PassRefPtr<Sha
         clientPosition = window->mapFromGlobal(globalPosition);
     }
 
-    m_webPageProxy->dragEnded(clientPosition, globalPosition, dropActionToDragOperation(actualDropAction));
+    m_webPageProxy->dragEnded(clientPosition, globalPosition, QtWebPageEventHandler::dropActionToDragOperation(actualDropAction));
 }
 
 void QtWebPageProxy::handleDownloadRequest(DownloadProxy* download)
@@ -852,54 +578,8 @@ void QtWebPageProxy::renderToCurrentGLContext(const TransformationMatrix& transf
 #if ENABLE(TOUCH_EVENTS)
 void QtWebPageProxy::doneWithTouchEvent(const NativeWebTouchEvent& event, bool wasEventHandled)
 {
-    if (!m_interactionEngine)
-        return;
-
-    if (wasEventHandled || event.type() == WebEvent::TouchCancel) {
-        m_panGestureRecognizer.reset();
-        m_pinchGestureRecognizer.reset();
-        m_tapGestureRecognizer.reset();
-        return;
-    }
-
-    const QTouchEvent* ev = event.nativeEvent();
-
-    switch (ev->type()) {
-    case QEvent::TouchBegin:
-        ASSERT(!m_interactionEngine->panGestureActive());
-        ASSERT(!m_interactionEngine->pinchGestureActive());
-
-        // The interaction engine might still be animating kinetic scrolling or a scale animation
-        // such as double-tap to zoom or the bounce back effect. A touch stops the kinetic scrolling
-        // where as it does not stop the scale animation.
-        if (m_interactionEngine->scrollAnimationActive())
-            m_interactionEngine->interruptScrollAnimation();
-        break;
-    case QEvent::TouchUpdate:
-        // The scale animation can only be interrupted by a pinch gesture, which will then take over.
-        if (m_interactionEngine->scaleAnimationActive() && m_pinchGestureRecognizer.isRecognized())
-            m_interactionEngine->interruptScaleAnimation();
-        break;
-    default:
-        break;
-    }
-
-    // If the scale animation is active we don't pass the event to the recognizers. In the future
-    // we would want to queue the event here and repost then when the animation ends.
-    if (m_interactionEngine->scaleAnimationActive())
-        return;
-
-    // Convert the event timestamp from second to millisecond.
-    qint64 eventTimestampMillis = static_cast<qint64>(event.timestamp() * 1000);
-    m_panGestureRecognizer.recognize(ev, eventTimestampMillis);
-    m_pinchGestureRecognizer.recognize(ev);
-
-    if (m_panGestureRecognizer.isRecognized() || m_pinchGestureRecognizer.isRecognized())
-        m_tapGestureRecognizer.reset();
-    else {
-        const QTouchEvent* ev = event.nativeEvent();
-        m_tapGestureRecognizer.recognize(ev, eventTimestampMillis);
-    }
+    ASSERT(m_eventHandler);
+    m_eventHandler->doneWithTouchEvent(event, wasEventHandled);
 }
 #endif
 
@@ -923,20 +603,4 @@ void QtWebPageProxy::setVisibleContentRectTrajectoryVector(const QPointF& trajec
     m_webPageProxy->drawingArea()->setVisibleContentRectTrajectoryVector(trajectoryVector);
 }
 
-void QtWebPageProxy::touchEvent(QTouchEvent* event)
-{
-#if ENABLE(TOUCH_EVENTS)
-    m_webPageProxy->handleTouchEvent(NativeWebTouchEvent(event));
-    event->accept();
-#else
-    ASSERT_NOT_REACHED();
-    ev->ignore();
-#endif
-}
-
-void QtWebPageProxy::findZoomableAreaForPoint(const QPoint& point)
-{
-    m_webPageProxy->findZoomableAreaForPoint(point);
-}
-
 #include "moc_QtWebPageProxy.cpp"
index b04ee0e..9275b57 100644 (file)
 #include "LayerTreeContext.h"
 #include "PageClient.h"
 #include "QtDownloadManager.h"
-#include "QtPanGestureRecognizer.h"
-#include "QtPinchGestureRecognizer.h"
-#include "QtTapGestureRecognizer.h"
 #include "ShareableBitmap.h"
 #include "ViewportArguments.h"
 #include "WebContext.h"
 #include "WebPageProxy.h"
 #include <wtf/RefPtr.h>
-#include <QBasicTimer>
 #include <QGraphicsView>
-#include <QKeyEvent>
-#include <QTouchEvent>
 #include <QMenu>
 #include <QSharedPointer>
 
@@ -44,6 +38,7 @@ QT_BEGIN_NAMESPACE
 class QUndoStack;
 QT_END_NAMESPACE
 
+class QtWebPageEventHandler;
 class QtWebError;
 class QWebPreferences;
 class QWKHistory;
@@ -52,8 +47,6 @@ class QQuickWebView;
 
 using namespace WebKit;
 
-WebCore::DragOperation dropActionToDragOperation(Qt::DropActions actions);
-
 // FIXME: needs focus in/out, window activation, support through viewStateDidChange().
 class QtWebPageProxy : public QObject, WebKit::PageClient {
     Q_OBJECT
@@ -73,13 +66,11 @@ public:
         WebActionCount
     };
 
-    QtWebPageProxy(QQuickWebPage*, QQuickWebView*, WebKit::QtViewportInteractionEngine* = 0, WKContextRef = 0, WKPageGroupRef = 0);
+    QtWebPageProxy(QQuickWebPage*, QQuickWebView*, WKContextRef = 0, WKPageGroupRef = 0);
     ~QtWebPageProxy();
 
     virtual PassOwnPtr<DrawingAreaProxy> createDrawingAreaProxy();
 
-    virtual bool handleEvent(QEvent*);
-
     // PageClient
     virtual void setViewNeedsDisplay(const WebCore::IntRect&);
     virtual void displayView();
@@ -166,8 +157,6 @@ public:
     void setNavigatorQtObjectEnabled(bool);
     bool navigatorQtObjectEnabled() const { return m_navigatorQtObjectEnabled; }
 
-    void setViewportInteractionEngine(QtViewportInteractionEngine*);
-
     void postMessageToNavigatorQtObject(const QString&);
 
     qreal textZoomFactor() const;
@@ -178,7 +167,6 @@ public:
 
     void setVisibleContentRectAndScale(const QRectF&, float);
     void setVisibleContentRectTrajectoryVector(const QPointF&);
-    void findZoomableAreaForPoint(const QPoint&);
     void renderToCurrentGLContext(const WebCore::TransformationMatrix&, float);
 
     QWKHistory* history() const;
@@ -189,14 +177,13 @@ public:
     }
 
     void handleDownloadRequest(DownloadProxy*);
-    void init();
-
-    void handleSingleTapEvent(const QTouchEvent::TouchPoint&);
-    void handleDoubleTapEvent(const QTouchEvent::TouchPoint&);
+    void init(QtWebPageEventHandler*);
 
     void showContextMenu(QSharedPointer<QMenu>);
     void hideContextMenu();
 
+    QtWebPageEventHandler* eventHandler() { return m_eventHandler; }
+
 public Q_SLOTS:
     void didReceiveDownloadResponse(QWebDownloadItem* downloadItem);
 
@@ -208,36 +195,12 @@ protected:
     QQuickWebPage* m_qmlWebPage;
     QQuickWebView* m_qmlWebView;
     RefPtr<WebKit::WebPageProxy> m_webPageProxy;
-    QtViewportInteractionEngine* m_interactionEngine;
-    QtPanGestureRecognizer m_panGestureRecognizer;
-    QtPinchGestureRecognizer m_pinchGestureRecognizer;
-    QtTapGestureRecognizer m_tapGestureRecognizer;
 
 private:
-    bool handleKeyPressEvent(QKeyEvent*);
-    bool handleKeyReleaseEvent(QKeyEvent*);
-    bool handleFocusInEvent(QFocusEvent*);
-    bool handleFocusOutEvent(QFocusEvent*);
-    bool handleMouseMoveEvent(QMouseEvent*);
-    bool handleMousePressEvent(QMouseEvent*);
-    bool handleMouseReleaseEvent(QMouseEvent*);
-    bool handleMouseDoubleClickEvent(QMouseEvent*);
-    bool handleWheelEvent(QWheelEvent*);
-    bool handleHoverLeaveEvent(QHoverEvent*);
-    bool handleHoverMoveEvent(QHoverEvent*);
-    bool handleDragEnterEvent(QDragEnterEvent*);
-    bool handleDragLeaveEvent(QDragLeaveEvent*);
-    bool handleDragMoveEvent(QDragMoveEvent*);
-    bool handleDropEvent(QDropEvent*);
-
-    virtual void timerEvent(QTimerEvent*);
-
 #if ENABLE(TOUCH_EVENTS)
     virtual void doneWithTouchEvent(const NativeWebTouchEvent&, bool wasEventHandled);
 #endif
 
-    void touchEvent(QTouchEvent*);
-
     static PassRefPtr<WebContext> defaultWKContext();
     static RefPtr<WebContext> s_defaultContext;
     static RefPtr<QtDownloadManager> s_downloadManager;
@@ -251,10 +214,9 @@ private:
     OwnPtr<QUndoStack> m_undoStack;
 
     bool m_navigatorQtObjectEnabled;
-    QPoint m_tripleClick;
-    QBasicTimer m_tripleClickTimer;
 
     QSharedPointer<QMenu> activeMenu;
+    QtWebPageEventHandler* m_eventHandler;
 };
 
 #endif /* QtWebPageProxy_h */