[Qt][WK2] Move startDrag implementation to QtWebPageEventHandler
authorjesus@webkit.org <jesus@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 12 Dec 2011 14:54:34 +0000 (14:54 +0000)
committerjesus@webkit.org <jesus@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 12 Dec 2011 14:54:34 +0000 (14:54 +0000)
https://bugs.webkit.org/show_bug.cgi?id=73145

Reviewed by Simon Hausmann.

Move QtWebPageProxy::startDrag to QtWebPageEventHandler::startDrag
and call it straight from QtPageClient.

* UIProcess/API/qt/qquickwebview.cpp:
(QQuickWebViewPrivate::QQuickWebViewPrivate):
* UIProcess/qt/QtWebPageEventHandler.cpp:
(dragOperationToDropAction):
(dragOperationToDropActions):
(dropActionToDragOperation):
Now these functions are static inline and not part of QtWebPageEventHandler
anymore.

(QtWebPageEventHandler::QtWebPageEventHandler):
(QtWebPageEventHandler::startDrag):
* UIProcess/qt/QtWebPageEventHandler.h:
* UIProcess/qt/QtWebPageProxy.cpp:
(QtWebPageProxy::startDrag): removed.

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp
Source/WebKit2/UIProcess/qt/QtPageClient.cpp
Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.cpp
Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.h
Source/WebKit2/UIProcess/qt/QtWebPageProxy.cpp
Source/WebKit2/UIProcess/qt/QtWebPageProxy.h

index 5e9dfdd..4711bce 100644 (file)
@@ -1,3 +1,28 @@
+2011-12-09  Jesus Sanchez-Palencia  <jesus.palencia@openbossa.org>
+
+        [Qt][WK2] Move startDrag implementation to QtWebPageEventHandler
+        https://bugs.webkit.org/show_bug.cgi?id=73145
+
+        Reviewed by Simon Hausmann.
+
+        Move QtWebPageProxy::startDrag to QtWebPageEventHandler::startDrag
+        and call it straight from QtPageClient.
+
+        * UIProcess/API/qt/qquickwebview.cpp:
+        (QQuickWebViewPrivate::QQuickWebViewPrivate):
+        * UIProcess/qt/QtWebPageEventHandler.cpp:
+        (dragOperationToDropAction):
+        (dragOperationToDropActions):
+        (dropActionToDragOperation):
+        Now these functions are static inline and not part of QtWebPageEventHandler
+        anymore.
+
+        (QtWebPageEventHandler::QtWebPageEventHandler):
+        (QtWebPageEventHandler::startDrag):
+        * UIProcess/qt/QtWebPageEventHandler.h:
+        * UIProcess/qt/QtWebPageProxy.cpp:
+        (QtWebPageProxy::startDrag): removed.
+
 2011-12-12  Caio Marcelo de Oliveira Filho  <caio.oliveira@openbossa.org>
 
         [Qt] [WK2] Support customizing popup menus with QML
index a2fa93b..44d0911 100644 (file)
@@ -61,7 +61,7 @@ QQuickWebViewPrivate::QQuickWebViewPrivate(QQuickWebView* viewport, WKContextRef
     pageLoadClient.reset(new QtWebPageLoadClient(pageProxy->pageRef(), q_ptr));
     pagePolicyClient.reset(new QtWebPagePolicyClient(pageProxy->pageRef(), q_ptr));
     pageUIClient.reset(new QtWebPageUIClient(pageProxy->pageRef(), q_ptr));
-    eventHandler.reset(new QtWebPageEventHandler(pageProxy->pageRef()));
+    eventHandler.reset(new QtWebPageEventHandler(pageProxy->pageRef(), q_ptr));
 
     // Any page setting should preferrable be set before creating the page, so set them here:
     setUseTraditionalDesktopBehaviour(false);
index e6faf06..e7ba890 100644 (file)
@@ -82,7 +82,7 @@ void QtPageClient::didChangeViewportProperties(const WebCore::ViewportArguments&
 
 void QtPageClient::startDrag(const WebCore::DragData& dragData, PassRefPtr<ShareableBitmap> dragImage)
 {
-    m_qtWebPageProxy->startDrag(dragData, dragImage);
+    m_eventHandler->startDrag(dragData, dragImage);
 }
 
 void QtPageClient::handleDownloadRequest(DownloadProxy* download)
index 677ee7d..a00a359 100644 (file)
@@ -21,6 +21,7 @@
 #include "config.h"
 #include "QtWebPageEventHandler.h"
 
+#include "qquickwebview_p.h"
 #include "NativeWebKeyboardEvent.h"
 #include "NativeWebMouseEvent.h"
 #include "NativeWebWheelEvent.h"
@@ -28,6 +29,8 @@
 #include <QDrag>
 #include <QGraphicsSceneMouseEvent>
 #include <QGuiApplication>
+#include <QMimeData>
+#include <QtQuick/QQuickCanvas>
 #include <QStyleHints>
 #include <QTouchEvent>
 #include <WebCore/DragData.h>
@@ -35,7 +38,7 @@
 using namespace WebKit;
 using namespace WebCore;
 
-Qt::DropAction QtWebPageEventHandler::dragOperationToDropAction(unsigned dragOperation)
+static inline Qt::DropAction dragOperationToDropAction(unsigned dragOperation)
 {
     Qt::DropAction result = Qt::IgnoreAction;
     if (dragOperation & DragOperationCopy)
@@ -49,7 +52,7 @@ Qt::DropAction QtWebPageEventHandler::dragOperationToDropAction(unsigned dragOpe
     return result;
 }
 
-Qt::DropActions QtWebPageEventHandler::dragOperationToDropActions(unsigned dragOperations)
+static inline Qt::DropActions dragOperationToDropActions(unsigned dragOperations)
 {
     Qt::DropActions result = Qt::IgnoreAction;
     if (dragOperations & DragOperationCopy)
@@ -63,7 +66,7 @@ Qt::DropActions QtWebPageEventHandler::dragOperationToDropActions(unsigned dragO
     return result;
 }
 
-WebCore::DragOperation QtWebPageEventHandler::dropActionToDragOperation(Qt::DropActions actions)
+static inline WebCore::DragOperation dropActionToDragOperation(Qt::DropActions actions)
 {
     unsigned result = 0;
     if (actions & Qt::CopyAction)
@@ -77,12 +80,13 @@ WebCore::DragOperation QtWebPageEventHandler::dropActionToDragOperation(Qt::Drop
     return (DragOperation)result;
 }
 
-QtWebPageEventHandler::QtWebPageEventHandler(WKPageRef pageRef, WebKit::QtViewportInteractionEngine* viewportInteractionEngine)
+QtWebPageEventHandler::QtWebPageEventHandler(WKPageRef pageRef, QQuickWebView* qmlWebView, WebKit::QtViewportInteractionEngine* viewportInteractionEngine)
     : m_webPageProxy(toImpl(pageRef))
     , m_interactionEngine(viewportInteractionEngine)
     , m_panGestureRecognizer(this)
     , m_pinchGestureRecognizer(this)
     , m_tapGestureRecognizer(this)
+    , m_webView(qmlWebView)
     , m_previousClickButton(Qt::NoButton)
     , m_clickCount(0)
 {
@@ -394,4 +398,32 @@ void QtWebPageEventHandler::focusEditableArea(const IntRect& caret, const IntRec
     m_interactionEngine->focusEditableArea(QRectF(caret), QRectF(area));
 }
 
+void QtWebPageEventHandler::startDrag(const WebCore::DragData& dragData, PassRefPtr<ShareableBitmap> dragImage)
+{
+    QImage dragQImage;
+    if (dragImage)
+        dragQImage = dragImage->createQImage();
+    else if (dragData.platformData() && dragData.platformData()->hasImage())
+        dragQImage = qvariant_cast<QImage>(dragData.platformData()->imageData());
+
+    DragOperation dragOperationMask = dragData.draggingSourceOperationMask();
+    QMimeData* mimeData = const_cast<QMimeData*>(dragData.platformData());
+    Qt::DropActions supportedDropActions = dragOperationToDropActions(dragOperationMask);
+
+    QPoint clientPosition;
+    QPoint globalPosition;
+    Qt::DropAction actualDropAction = Qt::IgnoreAction;
+
+    if (QWindow* window = m_webView->canvas()) {
+        QDrag* drag = new QDrag(window);
+        drag->setPixmap(QPixmap::fromImage(dragQImage));
+        drag->setMimeData(mimeData);
+        actualDropAction = drag->exec(supportedDropActions);
+        globalPosition = QCursor::pos();
+        clientPosition = window->mapFromGlobal(globalPosition);
+    }
+
+    m_webPageProxy->dragEnded(clientPosition, globalPosition, dropActionToDragOperation(actualDropAction));
+}
+
 #include "moc_QtWebPageEventHandler.cpp"
index 19373d2..b51cdf8 100644 (file)
 #include <QTouchEvent>
 #include <WKPage.h>
 
+class QQuickWebView;
+
 using namespace WebKit;
 
 class QtWebPageEventHandler : public QObject {
     Q_OBJECT
 
 public:
-    QtWebPageEventHandler(WKPageRef, WebKit::QtViewportInteractionEngine* = 0);
+    QtWebPageEventHandler(WKPageRef, QQuickWebView*, 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*);
@@ -58,12 +56,15 @@ public:
 
     QtViewportInteractionEngine* interactionEngine() { return m_interactionEngine; }
 
+    void startDrag(const WebCore::DragData&, PassRefPtr<ShareableBitmap> dragImage);
+
 protected:
     WebPageProxy* m_webPageProxy;
     QtViewportInteractionEngine* m_interactionEngine;
     QtPanGestureRecognizer m_panGestureRecognizer;
     QtPinchGestureRecognizer m_pinchGestureRecognizer;
     QtTapGestureRecognizer m_tapGestureRecognizer;
+    QQuickWebView* m_webView;
 
 private:
     bool handleKeyPressEvent(QKeyEvent*);
index a6fd7b3..5bf3f85 100644 (file)
@@ -363,35 +363,6 @@ QWKHistory* QtWebPageProxy::history() const
     return m_history;
 }
 
-void QtWebPageProxy::startDrag(const WebCore::DragData& dragData, PassRefPtr<ShareableBitmap> dragImage)
-{
-    QImage dragQImage;
-    if (dragImage)
-        dragQImage = dragImage->createQImage();
-    else if (dragData.platformData() && dragData.platformData()->hasImage())
-        dragQImage = qvariant_cast<QImage>(dragData.platformData()->imageData());
-
-
-    DragOperation dragOperationMask = dragData.draggingSourceOperationMask();
-    QMimeData* mimeData = const_cast<QMimeData*>(dragData.platformData());
-    Qt::DropActions supportedDropActions = QtWebPageEventHandler::dragOperationToDropActions(dragOperationMask);
-
-    QPoint clientPosition;
-    QPoint globalPosition;
-    Qt::DropAction actualDropAction = Qt::IgnoreAction;
-
-    if (QWindow* window = m_qmlWebView->canvas()) {
-        QDrag* drag = new QDrag(window);
-        drag->setPixmap(QPixmap::fromImage(dragQImage));
-        drag->setMimeData(mimeData);
-        actualDropAction = drag->exec(supportedDropActions);
-        globalPosition = QCursor::pos();
-        clientPosition = window->mapFromGlobal(globalPosition);
-    }
-
-    m_webPageProxy->dragEnded(clientPosition, globalPosition, QtWebPageEventHandler::dropActionToDragOperation(actualDropAction));
-}
-
 void QtWebPageProxy::handleDownloadRequest(DownloadProxy* download)
 {
     // This function is responsible for hooking up a DownloadProxy to our API layer
index ed487aa..b0b5dba 100644 (file)
@@ -85,7 +85,6 @@ public:
     void didChangeContentsSize(const WebCore::IntSize&);
     void didChangeViewportProperties(const WebCore::ViewportArguments&);
 
-    void startDrag(const WebCore::DragData&, PassRefPtr<ShareableBitmap> dragImage);
     void registerEditCommand(PassRefPtr<WebKit::WebEditCommandProxy>, WebKit::WebPageProxy::UndoOrRedo);
     void clearAllEditCommands();
     bool canUndoRedo(WebPageProxy::UndoOrRedo);