Diff
Modified: trunk/Source/WebCore/ChangeLog (174867 => 174868)
--- trunk/Source/WebCore/ChangeLog 2014-10-19 07:01:55 UTC (rev 174867)
+++ trunk/Source/WebCore/ChangeLog 2014-10-19 07:33:19 UTC (rev 174868)
@@ -1,3 +1,18 @@
+2014-10-19 Carlos Garcia Campos <[email protected]>
+
+ [GTK] Move GtkDragAndDropHelper from Platform to WebKit2
+ https://bugs.webkit.org/show_bug.cgi?id=137422
+
+ Reviewed by Martin Robinson.
+
+ Remove ClipboardUtilitiesGtk and GtkDragAndDropHelper.
+
+ * PlatformGTK.cmake:
+ * platform/gtk/ClipboardUtilitiesGtk.cpp: Removed.
+ * platform/gtk/ClipboardUtilitiesGtk.h: Removed.
+ * platform/gtk/GtkDragAndDropHelper.cpp: Removed.
+ * platform/gtk/GtkDragAndDropHelper.h: Removed.
+
2014-10-19 Roger Fong <[email protected]>
Unreviewed. Style fix following r174855.
Modified: trunk/Source/WebCore/PlatformGTK.cmake (174867 => 174868)
--- trunk/Source/WebCore/PlatformGTK.cmake 2014-10-19 07:01:55 UTC (rev 174867)
+++ trunk/Source/WebCore/PlatformGTK.cmake 2014-10-19 07:33:19 UTC (rev 174868)
@@ -213,7 +213,6 @@
platform/graphics/gtk/ImageBufferGtk.cpp
platform/graphics/gtk/ImageGtk.cpp
- platform/gtk/ClipboardUtilitiesGtk.cpp
platform/gtk/ContextMenuGtk.cpp
platform/gtk/ContextMenuItemGtk.cpp
platform/gtk/CursorGtk.cpp
@@ -223,7 +222,6 @@
platform/gtk/DragImageGtk.cpp
platform/gtk/GRefPtrGtk.cpp
platform/gtk/GtkClickCounter.cpp
- platform/gtk/GtkDragAndDropHelper.cpp
platform/gtk/GtkInputMethodFilter.cpp
platform/gtk/GtkUtilities.cpp
platform/gtk/GtkVersioning.c
Deleted: trunk/Source/WebCore/platform/gtk/ClipboardUtilitiesGtk.cpp (174867 => 174868)
--- trunk/Source/WebCore/platform/gtk/ClipboardUtilitiesGtk.cpp 2014-10-19 07:01:55 UTC (rev 174867)
+++ trunk/Source/WebCore/platform/gtk/ClipboardUtilitiesGtk.cpp 2014-10-19 07:33:19 UTC (rev 174868)
@@ -1,75 +0,0 @@
-/*
- * Copyright (C) 2010, Igalia S.L.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include "config.h"
-#include "ClipboardUtilitiesGtk.h"
-
-namespace WebCore {
-
-GdkDragAction dragOperationToGdkDragActions(DragOperation coreAction)
-{
- GdkDragAction gdkAction = static_cast<GdkDragAction>(0);
- if (coreAction == DragOperationNone)
- return gdkAction;
-
- if (coreAction & DragOperationCopy)
- gdkAction = static_cast<GdkDragAction>(GDK_ACTION_COPY | gdkAction);
- if (coreAction & DragOperationMove)
- gdkAction = static_cast<GdkDragAction>(GDK_ACTION_MOVE | gdkAction);
- if (coreAction & DragOperationLink)
- gdkAction = static_cast<GdkDragAction>(GDK_ACTION_LINK | gdkAction);
- if (coreAction & DragOperationPrivate)
- gdkAction = static_cast<GdkDragAction>(GDK_ACTION_PRIVATE | gdkAction);
-
- return gdkAction;
-}
-
-GdkDragAction dragOperationToSingleGdkDragAction(DragOperation coreAction)
-{
- if (coreAction == DragOperationEvery || coreAction & DragOperationCopy)
- return GDK_ACTION_COPY;
- if (coreAction & DragOperationMove)
- return GDK_ACTION_MOVE;
- if (coreAction & DragOperationLink)
- return GDK_ACTION_LINK;
- if (coreAction & DragOperationPrivate)
- return GDK_ACTION_PRIVATE;
- return static_cast<GdkDragAction>(0);
-}
-
-DragOperation gdkDragActionToDragOperation(GdkDragAction gdkAction)
-{
- // We have no good way to detect DragOperationEvery other than
- // to use it when all applicable flags are on.
- if (gdkAction & GDK_ACTION_COPY && gdkAction & GDK_ACTION_MOVE
- && gdkAction & GDK_ACTION_LINK && gdkAction & GDK_ACTION_PRIVATE)
- return DragOperationEvery;
-
- unsigned int action = ""
- if (gdkAction & GDK_ACTION_COPY)
- action |= DragOperationCopy;
- if (gdkAction & GDK_ACTION_MOVE)
- action |= DragOperationMove;
- if (gdkAction & GDK_ACTION_LINK)
- action |= DragOperationLink;
- if (gdkAction & GDK_ACTION_PRIVATE)
- action |= DragOperationPrivate;
- return static_cast<DragOperation>(action);
-}
-
-}
Deleted: trunk/Source/WebCore/platform/gtk/ClipboardUtilitiesGtk.h (174867 => 174868)
--- trunk/Source/WebCore/platform/gtk/ClipboardUtilitiesGtk.h 2014-10-19 07:01:55 UTC (rev 174867)
+++ trunk/Source/WebCore/platform/gtk/ClipboardUtilitiesGtk.h 2014-10-19 07:33:19 UTC (rev 174868)
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2010, Igalia S.L.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef ClipboardUtilitiesGtk_h
-#define ClipboardUtilitiesGtk_h
-
-#include "DragActions.h"
-#include <gdk/gdk.h>
-
-namespace WebCore {
-
-GdkDragAction dragOperationToGdkDragActions(DragOperation);
-GdkDragAction dragOperationToSingleGdkDragAction(DragOperation);
-DragOperation gdkDragActionToDragOperation(GdkDragAction);
-
-}
-
-#endif // ClipboardUtilitiesGtk_h
Deleted: trunk/Source/WebCore/platform/gtk/GtkDragAndDropHelper.cpp (174867 => 174868)
--- trunk/Source/WebCore/platform/gtk/GtkDragAndDropHelper.cpp 2014-10-19 07:01:55 UTC (rev 174867)
+++ trunk/Source/WebCore/platform/gtk/GtkDragAndDropHelper.cpp 2014-10-19 07:33:19 UTC (rev 174868)
@@ -1,172 +0,0 @@
-/*
- * Copyright (C) 2011, Igalia S.L.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include "config.h"
-#include "GtkDragAndDropHelper.h"
-
-#if ENABLE(DRAG_SUPPORT)
-
-#include "ClipboardUtilitiesGtk.h"
-#include "DragData.h"
-#include "GtkUtilities.h"
-#include "GtkVersioning.h"
-#include "PasteboardHelper.h"
-#include <gtk/gtk.h>
-#include <wtf/gobject/GMainLoopSource.h>
-
-namespace WebCore {
-
-struct DroppingContext {
- DroppingContext(GdkDragContext* gdkContext, const IntPoint& position)
- : gdkContext(gdkContext)
- , dataObject(DataObjectGtk::create())
- , lastMotionPosition(position)
- , dropHappened(false)
- , exitedCallback(0)
- {
- }
-
- GdkDragContext* gdkContext;
- RefPtr<DataObjectGtk> dataObject;
- WebCore::IntPoint lastMotionPosition;
- int pendingDataRequests;
- bool dropHappened;
- DragExitedCallback exitedCallback;
-};
-
-GtkDragAndDropHelper::GtkDragAndDropHelper()
- : m_widget(nullptr)
-{
-}
-
-GtkDragAndDropHelper::~GtkDragAndDropHelper()
-{
-}
-
-bool GtkDragAndDropHelper::handleDragEnd(GdkDragContext* dragContext)
-{
- return m_draggingDataObjects.remove(dragContext);
-}
-
-void GtkDragAndDropHelper::handleGetDragData(GdkDragContext* context, GtkSelectionData* selectionData, guint info)
-{
- DataObjectGtk* dataObject = m_draggingDataObjects.get(context);
- if (!dataObject)
- return;
- PasteboardHelper::defaultPasteboardHelper()->fillSelectionData(selectionData, info, dataObject);
-}
-
-void GtkDragAndDropHelper::handleDragLeaveLater(DroppingContext* context)
-{
- auto iterator = m_droppingContexts.find(context->gdkContext);
- if (iterator == m_droppingContexts.end())
- return;
-
- // If the view doesn't know about the drag yet (there are still pending data)
- // requests, don't update it with information about the drag.
- if (context->pendingDataRequests)
- return;
-
- const IntPoint& position = context->lastMotionPosition;
- DragData dragData(context->dataObject.get(), position,
- convertWidgetPointToScreenPoint(m_widget, position),
- DragOperationNone);
- context->exitedCallback(m_widget, dragData, context->dropHappened);
-
- m_droppingContexts.remove(iterator);
-}
-
-void GtkDragAndDropHelper::handleDragLeave(GdkDragContext* gdkContext, DragExitedCallback exitedCallback)
-{
- DroppingContext* context = m_droppingContexts.get(gdkContext);
- if (!context)
- return;
-
- // During a drop GTK+ will fire a drag-leave signal right before firing
- // the drag-drop signal. We want the actions for drag-leave to happen after
- // those for drag-drop, so schedule them to happen asynchronously here.
- context->exitedCallback = exitedCallback;
- GMainLoopSource::scheduleAndDeleteOnDestroy("[WebKit] handleDragLeaveLater", std::function<void()>(std::bind(&GtkDragAndDropHelper::handleDragLeaveLater, this, context)));
-}
-
-static void queryNewDropContextData(DroppingContext* dropContext, GtkWidget* widget, guint time)
-{
- GdkDragContext* gdkContext = dropContext->gdkContext;
- Vector<GdkAtom> acceptableTargets(PasteboardHelper::defaultPasteboardHelper()->dropAtomsForContext(widget, gdkContext));
- dropContext->pendingDataRequests = acceptableTargets.size();
- for (size_t i = 0; i < acceptableTargets.size(); i++)
- gtk_drag_get_data(widget, gdkContext, acceptableTargets.at(i), time);
-}
-
-DataObjectGtk* GtkDragAndDropHelper::handleDragMotion(GdkDragContext* context, const IntPoint& position, unsigned time)
-{
- std::unique_ptr<DroppingContext>& droppingContext = m_droppingContexts.add(context, nullptr).iterator->value;
- if (!droppingContext) {
- droppingContext = std::make_unique<DroppingContext>(context, position);
- queryNewDropContextData(droppingContext.get(), m_widget, time);
- } else
- droppingContext->lastMotionPosition = position;
-
- // Don't send any drag information to WebCore until we've retrieved all
- // the data for this drag operation. Otherwise we'd have to block to wait
- // for the drag's data.
- if (droppingContext->pendingDataRequests > 0)
- return nullptr;
-
- return droppingContext->dataObject.get();
-}
-
-DataObjectGtk* GtkDragAndDropHelper::handleDragDataReceived(GdkDragContext* context, GtkSelectionData* selectionData, unsigned info, IntPoint& position)
-{
- DroppingContext* droppingContext = m_droppingContexts.get(context);
- if (!droppingContext)
- return nullptr;
-
- droppingContext->pendingDataRequests--;
- PasteboardHelper::defaultPasteboardHelper()->fillDataObjectFromDropData(selectionData, info, droppingContext->dataObject.get());
-
- if (droppingContext->pendingDataRequests)
- return nullptr;
-
- // The coordinates passed to drag-data-received signal are sometimes
- // inaccurate in DRT, so use the coordinates of the last motion event.
- position = droppingContext->lastMotionPosition;
-
- // If there are no more pending requests, start sending dragging data to WebCore.
- return droppingContext->dataObject.get();
-}
-
-DataObjectGtk* GtkDragAndDropHelper::handleDragDrop(GdkDragContext* context)
-{
- DroppingContext* droppingContext = m_droppingContexts.get(context);
- if (!droppingContext)
- return nullptr;
-
- droppingContext->dropHappened = true;
-
- return droppingContext->dataObject.get();
-}
-
-void GtkDragAndDropHelper::startedDrag(GdkDragContext* context, DataObjectGtk* dataObject)
-{
- m_draggingDataObjects.set(context, dataObject);
-}
-
-} // namespace WebCore
-
-#endif // ENABLE(DRAG_SUPPORT)
Deleted: trunk/Source/WebCore/platform/gtk/GtkDragAndDropHelper.h (174867 => 174868)
--- trunk/Source/WebCore/platform/gtk/GtkDragAndDropHelper.h 2014-10-19 07:01:55 UTC (rev 174867)
+++ trunk/Source/WebCore/platform/gtk/GtkDragAndDropHelper.h 2014-10-19 07:33:19 UTC (rev 174868)
@@ -1,64 +0,0 @@
-/*
- * Copyright (C) 2011, Igalia S.L.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef GtkDragAndDropHelper_h
-#define GtkDragAndDropHelper_h
-
-#if ENABLE(DRAG_SUPPORT)
-
-#include "DataObjectGtk.h"
-#include <wtf/FastMalloc.h>
-#include <wtf/Noncopyable.h>
-
-namespace WebCore {
-
-struct DroppingContext;
-class DragData;
-class IntPoint;
-
-typedef void (*DragExitedCallback)(GtkWidget*, DragData&, bool dropHappened);
-
-class GtkDragAndDropHelper {
- WTF_MAKE_NONCOPYABLE(GtkDragAndDropHelper);
- WTF_MAKE_FAST_ALLOCATED;
-
-public:
- GtkDragAndDropHelper();
- ~GtkDragAndDropHelper();
-
- void setWidget(GtkWidget* widget) { m_widget = widget; }
- bool handleDragEnd(GdkDragContext*);
- void handleGetDragData(GdkDragContext*, GtkSelectionData*, guint info);
- void handleDragLeave(GdkDragContext*, DragExitedCallback);
- void handleDragLeaveLater(DroppingContext*);
- DataObjectGtk* handleDragMotion(GdkDragContext*, const IntPoint&, unsigned time);
- DataObjectGtk* handleDragDataReceived(GdkDragContext*, GtkSelectionData*, unsigned info, IntPoint&);
- DataObjectGtk* handleDragDrop(GdkDragContext*);
- void startedDrag(GdkDragContext*, DataObjectGtk*);
-
-private:
- GtkWidget* m_widget;
- HashMap<GdkDragContext*, std::unique_ptr<DroppingContext>> m_droppingContexts;
- HashMap<GdkDragContext*, RefPtr<DataObjectGtk>> m_draggingDataObjects;
-};
-
-}
-
-#endif // ENABLE(DRAG_SUPPORT)
-
-#endif // DataObjectGtk_h
Modified: trunk/Source/WebKit2/ChangeLog (174867 => 174868)
--- trunk/Source/WebKit2/ChangeLog 2014-10-19 07:01:55 UTC (rev 174867)
+++ trunk/Source/WebKit2/ChangeLog 2014-10-19 07:33:19 UTC (rev 174868)
@@ -1,3 +1,48 @@
+2014-10-19 Carlos Garcia Campos <[email protected]>
+
+ [GTK] Move GtkDragAndDropHelper from Platform to WebKit2
+ https://bugs.webkit.org/show_bug.cgi?id=137422
+
+ Reviewed by Martin Robinson.
+
+ WebKitWebViewBase is currently the only user of
+ GtkDragAndDropHelper, that was added to share the code with
+ WebKit1. Move all the drag and drop logic to a new class
+ DragAndDropHandler.
+
+ * PlatformGTK.cmake: Add new files to compilation.
+ * UIProcess/API/gtk/PageClientImpl.cpp:
+ (WebKit::PageClientImpl::startDrag):
+ * UIProcess/API/gtk/WebKitWebViewBase.cpp:
+ (webkitWebViewBaseConstructed):
+ (webkitWebViewBaseDragDataGet):
+ (webkitWebViewBaseDragEnd):
+ (webkitWebViewBaseDragDataReceived):
+ (webkitWebViewBaseDragMotion):
+ (webkitWebViewBaseDragLeave):
+ (webkitWebViewBaseDragDrop):
+ (webkitWebViewBaseDragAndDropHandler):
+ (dragExitedCallback): Deleted.
+ (webkitWebViewBaseStartDrag): Deleted.
+ * UIProcess/API/gtk/WebKitWebViewBasePrivate.h:
+ * UIProcess/gtk/DragAndDropHandler.cpp: Added.
+ (WebKit::DragAndDropHandler::create):
+ (WebKit::DragAndDropHandler::DragAndDropHandler):
+ (WebKit::DragAndDropHandler::DroppingContext::DroppingContext):
+ (WebKit::dragOperationToGdkDragActions):
+ (WebKit::dragOperationToSingleGdkDragAction):
+ (WebKit::gdkDragActionToDragOperation):
+ (WebKit::DragAndDropHandler::startDrag):
+ (WebKit::DragAndDropHandler::fillDragData):
+ (WebKit::DragAndDropHandler::finishDrag):
+ (WebKit::DragAndDropHandler::dataObjectForDropData):
+ (WebKit::DragAndDropHandler::dragEntered):
+ (WebKit::DragAndDropHandler::requestDragData):
+ (WebKit::DragAndDropHandler::dragMotion):
+ (WebKit::DragAndDropHandler::dragLeave):
+ (WebKit::DragAndDropHandler::drop):
+ * UIProcess/gtk/DragAndDropHandler.h: Added.
+
2014-10-18 Dan Bernstein <[email protected]>
WorkQueue dispatches functions but isn’t a FunctionDispatcher
Modified: trunk/Source/WebKit2/PlatformGTK.cmake (174867 => 174868)
--- trunk/Source/WebKit2/PlatformGTK.cmake 2014-10-19 07:01:55 UTC (rev 174867)
+++ trunk/Source/WebKit2/PlatformGTK.cmake 2014-10-19 07:33:19 UTC (rev 174868)
@@ -251,6 +251,7 @@
UIProcess/cairo/BackingStoreCairo.cpp
+ UIProcess/gtk/DragAndDropHandler.cpp
UIProcess/gtk/ExperimentalFeatures.cpp
UIProcess/gtk/TextCheckerGtk.cpp
UIProcess/gtk/WebContextGtk.cpp
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/PageClientImpl.cpp (174867 => 174868)
--- trunk/Source/WebKit2/UIProcess/API/gtk/PageClientImpl.cpp 2014-10-19 07:01:55 UTC (rev 174867)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/PageClientImpl.cpp 2014-10-19 07:33:19 UTC (rev 174868)
@@ -271,7 +271,12 @@
#if ENABLE(DRAG_SUPPORT)
void PageClientImpl::startDrag(const WebCore::DragData& dragData, PassRefPtr<ShareableBitmap> dragImage)
{
- webkitWebViewBaseStartDrag(WEBKIT_WEB_VIEW_BASE(m_viewWidget), dragData, dragImage);
+ WebKitWebViewBase* webView = WEBKIT_WEB_VIEW_BASE(m_viewWidget);
+ webkitWebViewBaseDragAndDropHandler(webView).startDrag(dragData, dragImage);
+
+ // A drag starting should prevent a double-click from happening. This might
+ // happen if a drag is followed very quickly by another click (like in the WTR).
+ webkitWebViewBaseResetClickCounter(webView);
}
#endif
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp (174867 => 174868)
--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp 2014-10-19 07:01:55 UTC (rev 174867)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp 2014-10-19 07:33:19 UTC (rev 174868)
@@ -48,13 +48,8 @@
#include "WebUserContentControllerProxy.h"
#include "WebViewBaseInputMethodFilter.h"
#include <WebCore/CairoUtilities.h>
-#include <WebCore/ClipboardUtilitiesGtk.h>
-#include <WebCore/DataObjectGtk.h>
-#include <WebCore/DragData.h>
-#include <WebCore/DragIcon.h>
#include <WebCore/GUniquePtrGtk.h>
#include <WebCore/GtkClickCounter.h>
-#include <WebCore/GtkDragAndDropHelper.h>
#include <WebCore/GtkUtilities.h>
#include <WebCore/GtkVersioning.h>
#include <WebCore/NotImplemented.h>
@@ -101,10 +96,6 @@
GtkClickCounter clickCounter;
CString tooltipText;
IntRect tooltipArea;
-#if ENABLE(DRAG_SUPPORT)
- GtkDragAndDropHelper dragAndDropHelper;
-#endif
- DragIcon dragIcon;
#if !GTK_CHECK_VERSION(3, 13, 4)
IntSize resizerSize;
#endif
@@ -143,6 +134,10 @@
#if USE(TEXTURE_MAPPER_GL) && PLATFORM(X11)
OwnPtr<RedirectedXCompositeWindow> redirectedWindow;
#endif
+
+#if ENABLE(DRAG_SUPPORT)
+ std::unique_ptr<DragAndDropHandler> dragAndDropHandler;
+#endif
};
WEBKIT_DEFINE_TYPE(WebKitWebViewBase, webkit_web_view_base, GTK_TYPE_CONTAINER)
@@ -419,15 +414,12 @@
GtkWidget* viewWidget = GTK_WIDGET(object);
gtk_widget_set_can_focus(viewWidget, TRUE);
- gtk_drag_dest_set(viewWidget, static_cast<GtkDestDefaults>(0), 0, 0,
- static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK | GDK_ACTION_PRIVATE));
+ gtk_drag_dest_set(viewWidget, static_cast<GtkDestDefaults>(0), nullptr, 0,
+ static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK | GDK_ACTION_PRIVATE));
gtk_drag_dest_set_target_list(viewWidget, PasteboardHelper::defaultPasteboardHelper()->targetList());
WebKitWebViewBasePrivate* priv = WEBKIT_WEB_VIEW_BASE(object)->priv;
priv->pageClient = PageClientImpl::create(viewWidget);
-#if ENABLE(DRAG_SUPPORT)
- priv->dragAndDropHelper.setWidget(viewWidget);
-#endif
#if USE(TEXTURE_MAPPER_GL) && PLATFORM(X11)
GdkDisplay* display = gdk_display_manager_get_default_display(gdk_display_manager_get());
@@ -847,37 +839,21 @@
#if ENABLE(DRAG_SUPPORT)
static void webkitWebViewBaseDragDataGet(GtkWidget* widget, GdkDragContext* context, GtkSelectionData* selectionData, guint info, guint /* time */)
{
- WEBKIT_WEB_VIEW_BASE(widget)->priv->dragAndDropHelper.handleGetDragData(context, selectionData, info);
+ WebKitWebViewBasePrivate* priv = WEBKIT_WEB_VIEW_BASE(widget)->priv;
+ ASSERT(priv->dragAndDropHandler);
+ priv->dragAndDropHandler->fillDragData(context, selectionData, info);
}
static void webkitWebViewBaseDragEnd(GtkWidget* widget, GdkDragContext* context)
{
- WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget);
- if (!webViewBase->priv->dragAndDropHelper.handleDragEnd(context))
- return;
-
- GdkDevice* device = gdk_drag_context_get_device(context);
- int x = 0, y = 0;
- gdk_device_get_window_at_position(device, &x, &y);
- int xRoot = 0, yRoot = 0;
- gdk_device_get_position(device, 0, &xRoot, &yRoot);
- webViewBase->priv->pageProxy->dragEnded(IntPoint(x, y), IntPoint(xRoot, yRoot),
- gdkDragActionToDragOperation(gdk_drag_context_get_selected_action(context)));
+ WebKitWebViewBasePrivate* priv = WEBKIT_WEB_VIEW_BASE(widget)->priv;
+ ASSERT(priv->dragAndDropHandler);
+ priv->dragAndDropHandler->finishDrag(context);
}
static void webkitWebViewBaseDragDataReceived(GtkWidget* widget, GdkDragContext* context, gint /* x */, gint /* y */, GtkSelectionData* selectionData, guint info, guint time)
{
- WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget);
- IntPoint position;
- DataObjectGtk* dataObject = webViewBase->priv->dragAndDropHelper.handleDragDataReceived(context, selectionData, info, position);
- if (!dataObject)
- return;
-
- DragData dragData(dataObject, position, convertWidgetPointToScreenPoint(widget, position), gdkDragActionToDragOperation(gdk_drag_context_get_actions(context)));
- webViewBase->priv->pageProxy->resetCurrentDragInformation();
- webViewBase->priv->pageProxy->dragEntered(dragData);
- DragOperation operation = webViewBase->priv->pageProxy->currentDragOperation();
- gdk_drag_status(context, dragOperationToSingleGdkDragAction(operation), time);
+ webkitWebViewBaseDragAndDropHandler(WEBKIT_WEB_VIEW_BASE(widget)).dragEntered(context, selectionData, info, time);
}
#endif // ENABLE(DRAG_SUPPORT)
@@ -912,50 +888,22 @@
#if ENABLE(DRAG_SUPPORT)
static gboolean webkitWebViewBaseDragMotion(GtkWidget* widget, GdkDragContext* context, gint x, gint y, guint time)
{
- WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget);
- IntPoint position(x, y);
- DataObjectGtk* dataObject = webViewBase->priv->dragAndDropHelper.handleDragMotion(context, position, time);
- if (!dataObject)
- return TRUE;
-
- DragData dragData(dataObject, position, convertWidgetPointToScreenPoint(widget, position), gdkDragActionToDragOperation(gdk_drag_context_get_actions(context)));
- webViewBase->priv->pageProxy->dragUpdated(dragData);
- DragOperation operation = webViewBase->priv->pageProxy->currentDragOperation();
- gdk_drag_status(context, dragOperationToSingleGdkDragAction(operation), time);
+ webkitWebViewBaseDragAndDropHandler(WEBKIT_WEB_VIEW_BASE(widget)).dragMotion(context, IntPoint(x, y), time);
return TRUE;
}
-static void dragExitedCallback(GtkWidget* widget, DragData& dragData, bool dropHappened)
-{
- // Don't call dragExited if we have just received a drag-drop signal. This
- // happens in the case of a successful drop onto the view.
- if (dropHappened)
- return;
-
- WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget);
- webViewBase->priv->pageProxy->dragExited(dragData);
- webViewBase->priv->pageProxy->resetCurrentDragInformation();
-}
-
static void webkitWebViewBaseDragLeave(GtkWidget* widget, GdkDragContext* context, guint /* time */)
{
- WEBKIT_WEB_VIEW_BASE(widget)->priv->dragAndDropHelper.handleDragLeave(context, dragExitedCallback);
+ WebKitWebViewBasePrivate* priv = WEBKIT_WEB_VIEW_BASE(widget)->priv;
+ ASSERT(priv->dragAndDropHandler);
+ priv->dragAndDropHandler->dragLeave(context);
}
static gboolean webkitWebViewBaseDragDrop(GtkWidget* widget, GdkDragContext* context, gint x, gint y, guint time)
{
- WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget);
- DataObjectGtk* dataObject = webViewBase->priv->dragAndDropHelper.handleDragDrop(context);
- if (!dataObject)
- return FALSE;
-
- IntPoint position(x, y);
- DragData dragData(dataObject, position, convertWidgetPointToScreenPoint(widget, position), gdkDragActionToDragOperation(gdk_drag_context_get_actions(context)));
- SandboxExtension::Handle handle;
- SandboxExtension::HandleArray sandboxExtensionForUpload;
- webViewBase->priv->pageProxy->performDragOperation(dragData, String(), handle, sandboxExtensionForUpload);
- gtk_drag_finish(context, TRUE, FALSE, time);
- return TRUE;
+ WebKitWebViewBasePrivate* priv = WEBKIT_WEB_VIEW_BASE(widget)->priv;
+ ASSERT(priv->dragAndDropHandler);
+ return priv->dragAndDropHandler->drop(context, IntPoint(x, y), time);
}
#endif // ENABLE(DRAG_SUPPORT)
@@ -1115,31 +1063,12 @@
}
#if ENABLE(DRAG_SUPPORT)
-void webkitWebViewBaseStartDrag(WebKitWebViewBase* webViewBase, const DragData& dragData, PassRefPtr<ShareableBitmap> dragImage)
+DragAndDropHandler& webkitWebViewBaseDragAndDropHandler(WebKitWebViewBase* webViewBase)
{
WebKitWebViewBasePrivate* priv = webViewBase->priv;
-
- RefPtr<DataObjectGtk> dataObject = adoptRef(dragData.platformData());
- GRefPtr<GtkTargetList> targetList = adoptGRef(PasteboardHelper::defaultPasteboardHelper()->targetListForDataObject(dataObject.get()));
- GUniquePtr<GdkEvent> currentEvent(gtk_get_current_event());
- GdkDragContext* context = gtk_drag_begin(GTK_WIDGET(webViewBase),
- targetList.get(),
- dragOperationToGdkDragActions(dragData.draggingSourceOperationMask()),
- 1, /* button */
- currentEvent.get());
- priv->dragAndDropHelper.startedDrag(context, dataObject.get());
-
-
- // A drag starting should prevent a double-click from happening. This might
- // happen if a drag is followed very quickly by another click (like in the DRT).
- priv->clickCounter.reset();
-
- if (dragImage) {
- RefPtr<cairo_surface_t> image(dragImage->createCairoSurface());
- priv->dragIcon.setImage(image.get());
- priv->dragIcon.useForDrag(context);
- } else
- gtk_drag_set_icon_default(context);
+ if (!priv->dragAndDropHandler)
+ priv->dragAndDropHandler = DragAndDropHandler::create(*priv->pageProxy);
+ return *priv->dragAndDropHandler;
}
#endif // ENABLE(DRAG_SUPPORT)
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBasePrivate.h (174867 => 174868)
--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBasePrivate.h 2014-10-19 07:01:55 UTC (rev 174867)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBasePrivate.h 2014-10-19 07:33:19 UTC (rev 174868)
@@ -28,6 +28,7 @@
#ifndef WebKitWebViewBasePrivate_h
#define WebKitWebViewBasePrivate_h
+#include "DragAndDropHandler.h"
#include "WebContextMenuProxyGtk.h"
#include "WebInspectorProxy.h"
#include "WebKitPrivate.h"
@@ -41,7 +42,6 @@
void webkitWebViewBaseSetTooltipText(WebKitWebViewBase*, const char*);
void webkitWebViewBaseSetTooltipArea(WebKitWebViewBase*, const WebCore::IntRect&);
void webkitWebViewBaseForwardNextKeyEvent(WebKitWebViewBase*);
-void webkitWebViewBaseStartDrag(WebKitWebViewBase*, const WebCore::DragData&, PassRefPtr<WebKit::ShareableBitmap> dragImage);
void webkitWebViewBaseChildMoveResize(WebKitWebViewBase*, GtkWidget*, const WebCore::IntRect&);
void webkitWebViewBaseEnterFullScreen(WebKitWebViewBase*);
void webkitWebViewBaseExitFullScreen(WebKitWebViewBase*);
@@ -74,4 +74,8 @@
void webkitWebViewBaseAddWebInspector(WebKitWebViewBase*, GtkWidget* inspector, WebKit::AttachmentSide);
void webkitWebViewBaseResetClickCounter(WebKitWebViewBase*);
+#if ENABLE(DRAG_SUPPORT)
+WebKit::DragAndDropHandler& webkitWebViewBaseDragAndDropHandler(WebKitWebViewBase*);
+#endif
+
#endif // WebKitWebViewBasePrivate_h
Added: trunk/Source/WebKit2/UIProcess/gtk/DragAndDropHandler.cpp (0 => 174868)
--- trunk/Source/WebKit2/UIProcess/gtk/DragAndDropHandler.cpp (rev 0)
+++ trunk/Source/WebKit2/UIProcess/gtk/DragAndDropHandler.cpp 2014-10-19 07:33:19 UTC (rev 174868)
@@ -0,0 +1,274 @@
+/*
+ * Copyright (C) 2014 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "DragAndDropHandler.h"
+
+#if ENABLE(DRAG_SUPPORT)
+
+#include "WebPageProxy.h"
+#include <WebCore/DataObjectGtk.h>
+#include <WebCore/DragData.h>
+#include <WebCore/DragIcon.h>
+#include <WebCore/GRefPtrGtk.h>
+#include <WebCore/GtkUtilities.h>
+#include <WebCore/PasteboardHelper.h>
+#include <gtk/gtk.h>
+#include <wtf/gobject/GMainLoopSource.h>
+#include <wtf/gobject/GUniquePtr.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+std::unique_ptr<DragAndDropHandler> DragAndDropHandler::create(WebPageProxy& page)
+{
+ return std::unique_ptr<DragAndDropHandler>(new DragAndDropHandler(page));
+}
+
+DragAndDropHandler::DragAndDropHandler(WebPageProxy& page)
+ : m_page(page)
+{
+}
+
+DragAndDropHandler::DroppingContext::DroppingContext(GdkDragContext* gdkContext, const IntPoint& position)
+ : gdkContext(gdkContext)
+ , dataObject(DataObjectGtk::create())
+ , lastMotionPosition(position)
+ , dropHappened(false)
+{
+}
+
+static inline GdkDragAction dragOperationToGdkDragActions(DragOperation coreAction)
+{
+ GdkDragAction gdkAction = static_cast<GdkDragAction>(0);
+ if (coreAction == DragOperationNone)
+ return gdkAction;
+
+ if (coreAction & DragOperationCopy)
+ gdkAction = static_cast<GdkDragAction>(GDK_ACTION_COPY | gdkAction);
+ if (coreAction & DragOperationMove)
+ gdkAction = static_cast<GdkDragAction>(GDK_ACTION_MOVE | gdkAction);
+ if (coreAction & DragOperationLink)
+ gdkAction = static_cast<GdkDragAction>(GDK_ACTION_LINK | gdkAction);
+ if (coreAction & DragOperationPrivate)
+ gdkAction = static_cast<GdkDragAction>(GDK_ACTION_PRIVATE | gdkAction);
+
+ return gdkAction;
+}
+
+static inline GdkDragAction dragOperationToSingleGdkDragAction(DragOperation coreAction)
+{
+ if (coreAction == DragOperationEvery || coreAction & DragOperationCopy)
+ return GDK_ACTION_COPY;
+ if (coreAction & DragOperationMove)
+ return GDK_ACTION_MOVE;
+ if (coreAction & DragOperationLink)
+ return GDK_ACTION_LINK;
+ if (coreAction & DragOperationPrivate)
+ return GDK_ACTION_PRIVATE;
+ return static_cast<GdkDragAction>(0);
+}
+
+static inline DragOperation gdkDragActionToDragOperation(GdkDragAction gdkAction)
+{
+ // We have no good way to detect DragOperationEvery other than
+ // to use it when all applicable flags are on.
+ if (gdkAction & GDK_ACTION_COPY
+ && gdkAction & GDK_ACTION_MOVE
+ && gdkAction & GDK_ACTION_LINK
+ && gdkAction & GDK_ACTION_PRIVATE)
+ return DragOperationEvery;
+
+ unsigned action = ""
+ if (gdkAction & GDK_ACTION_COPY)
+ action |= DragOperationCopy;
+ if (gdkAction & GDK_ACTION_MOVE)
+ action |= DragOperationMove;
+ if (gdkAction & GDK_ACTION_LINK)
+ action |= DragOperationLink;
+ if (gdkAction & GDK_ACTION_PRIVATE)
+ action |= DragOperationPrivate;
+ return static_cast<DragOperation>(action);
+}
+
+void DragAndDropHandler::startDrag(const DragData& dragData, PassRefPtr<ShareableBitmap> dragImage)
+{
+ RefPtr<DataObjectGtk> dataObject = adoptRef(dragData.platformData());
+ GRefPtr<GtkTargetList> targetList = adoptGRef(PasteboardHelper::defaultPasteboardHelper()->targetListForDataObject(dataObject.get()));
+ GUniquePtr<GdkEvent> currentEvent(gtk_get_current_event());
+
+ GdkDragContext* context = gtk_drag_begin(m_page.viewWidget(), targetList.get(), dragOperationToGdkDragActions(dragData.draggingSourceOperationMask()),
+ GDK_BUTTON_PRIMARY, currentEvent.get());
+ m_draggingDataObjects.set(context, dataObject.get());
+
+ if (dragImage) {
+ RefPtr<cairo_surface_t> image(dragImage->createCairoSurface());
+ m_dragIcon.setImage(image.get());
+ m_dragIcon.useForDrag(context);
+ } else
+ gtk_drag_set_icon_default(context);
+}
+
+void DragAndDropHandler::fillDragData(GdkDragContext* context, GtkSelectionData* selectionData, unsigned info)
+{
+ if (DataObjectGtk* dataObject = m_draggingDataObjects.get(context))
+ PasteboardHelper::defaultPasteboardHelper()->fillSelectionData(selectionData, info, dataObject);
+}
+
+void DragAndDropHandler::finishDrag(GdkDragContext* context)
+{
+ if (!m_draggingDataObjects.remove(context))
+ return;
+
+ GdkDevice* device = gdk_drag_context_get_device(context);
+ int x = 0, y = 0;
+ gdk_device_get_window_at_position(device, &x, &y);
+ int xRoot = 0, yRoot = 0;
+ gdk_device_get_position(device, nullptr, &xRoot, &yRoot);
+ m_page.dragEnded(IntPoint(x, y), IntPoint(xRoot, yRoot), gdkDragActionToDragOperation(gdk_drag_context_get_selected_action(context)));
+}
+
+DataObjectGtk* DragAndDropHandler::dataObjectForDropData(GdkDragContext* context, GtkSelectionData* selectionData, unsigned info, IntPoint& position)
+{
+ DroppingContext* droppingContext = m_droppingContexts.get(context);
+ if (!droppingContext)
+ return nullptr;
+
+ droppingContext->pendingDataRequests--;
+ PasteboardHelper::defaultPasteboardHelper()->fillDataObjectFromDropData(selectionData, info, droppingContext->dataObject.get());
+ if (droppingContext->pendingDataRequests)
+ return nullptr;
+
+ // The coordinates passed to drag-data-received signal are sometimes
+ // inaccurate in WTR, so use the coordinates of the last motion event.
+ position = droppingContext->lastMotionPosition;
+
+ // If there are no more pending requests, start sending dragging data to WebCore.
+ return droppingContext->dataObject.get();
+}
+
+void DragAndDropHandler::dragEntered(GdkDragContext* context, GtkSelectionData* selectionData, unsigned info, unsigned time)
+{
+ IntPoint position;
+ DataObjectGtk* dataObject = dataObjectForDropData(context, selectionData, info, position);
+ if (!dataObject)
+ return;
+
+ DragData dragData(dataObject, position, convertWidgetPointToScreenPoint(m_page.viewWidget(), position), gdkDragActionToDragOperation(gdk_drag_context_get_actions(context)));
+ m_page.resetCurrentDragInformation();
+ m_page.dragEntered(dragData);
+ DragOperation operation = m_page.currentDragOperation();
+ gdk_drag_status(context, dragOperationToSingleGdkDragAction(operation), time);
+}
+
+DataObjectGtk* DragAndDropHandler::requestDragData(GdkDragContext* context, const IntPoint& position, unsigned time)
+{
+ std::unique_ptr<DroppingContext>& droppingContext = m_droppingContexts.add(context, nullptr).iterator->value;
+ if (!droppingContext) {
+ GtkWidget* widget = m_page.viewWidget();
+ droppingContext = std::make_unique<DroppingContext>(context, position);
+ Vector<GdkAtom> acceptableTargets(PasteboardHelper::defaultPasteboardHelper()->dropAtomsForContext(widget, droppingContext->gdkContext));
+ droppingContext->pendingDataRequests = acceptableTargets.size();
+ for (auto& target : acceptableTargets)
+ gtk_drag_get_data(widget, droppingContext->gdkContext, target, time);
+ } else
+ droppingContext->lastMotionPosition = position;
+
+ // Don't send any drag information to WebCore until we've retrieved all the data for this drag operation.
+ // Otherwise we'd have to block to wait for the drag's data.
+ if (droppingContext->pendingDataRequests > 0)
+ return nullptr;
+
+ return droppingContext->dataObject.get();
+}
+
+void DragAndDropHandler::dragMotion(GdkDragContext* context, const IntPoint& position, unsigned time)
+{
+ DataObjectGtk* dataObject = requestDragData(context, position, time);
+ if (!dataObject)
+ return;
+
+ DragData dragData(dataObject, position, convertWidgetPointToScreenPoint(m_page.viewWidget(), position), gdkDragActionToDragOperation(gdk_drag_context_get_actions(context)));
+ m_page.dragUpdated(dragData);
+ DragOperation operation = m_page.currentDragOperation();
+ gdk_drag_status(context, dragOperationToSingleGdkDragAction(operation), time);
+}
+
+void DragAndDropHandler::dragLeave(GdkDragContext* context)
+{
+ DroppingContext* droppingContext = m_droppingContexts.get(context);
+ if (!droppingContext)
+ return;
+
+ // During a drop GTK+ will fire a drag-leave signal right before firing
+ // the drag-drop signal. We want the actions for drag-leave to happen after
+ // those for drag-drop, so schedule them to happen asynchronously here.
+ GMainLoopSource::scheduleAndDeleteOnDestroy("[WebKit] handleDragLeaveLater", [this, droppingContext]() {
+ auto it = m_droppingContexts.find(droppingContext->gdkContext);
+ if (it == m_droppingContexts.end())
+ return;
+
+ // If the view doesn't know about the drag yet (there are still pending data requests),
+ // don't update it with information about the drag.
+ if (droppingContext->pendingDataRequests)
+ return;
+
+ if (!droppingContext->dropHappened) {
+ // Don't call dragExited if we have just received a drag-drop signal. This
+ // happens in the case of a successful drop onto the view.
+ const IntPoint& position = droppingContext->lastMotionPosition;
+ DragData dragData(droppingContext->dataObject.get(), position, convertWidgetPointToScreenPoint(m_page.viewWidget(), position), DragOperationNone);
+ m_page.dragExited(dragData);
+ m_page.resetCurrentDragInformation();
+ }
+
+ m_droppingContexts.remove(it);
+ });
+}
+
+bool DragAndDropHandler::drop(GdkDragContext* context, const IntPoint& position, unsigned time)
+{
+ DroppingContext* droppingContext = m_droppingContexts.get(context);
+ if (!droppingContext)
+ return false;
+
+ droppingContext->dropHappened = true;
+
+ DataObjectGtk* dataObject = droppingContext->dataObject.get();
+ if (!dataObject)
+ return false;
+
+ DragData dragData(dataObject, position, convertWidgetPointToScreenPoint(m_page.viewWidget(), position), gdkDragActionToDragOperation(gdk_drag_context_get_actions(context)));
+ SandboxExtension::Handle handle;
+ SandboxExtension::HandleArray sandboxExtensionForUpload;
+ m_page.performDragOperation(dragData, String(), handle, sandboxExtensionForUpload);
+ gtk_drag_finish(context, TRUE, FALSE, time);
+ return true;
+}
+
+} // namespace WebKit
+
+#endif // ENABLE(DRAG_SUPPORT)
Added: trunk/Source/WebKit2/UIProcess/gtk/DragAndDropHandler.h (0 => 174868)
--- trunk/Source/WebKit2/UIProcess/gtk/DragAndDropHandler.h (rev 0)
+++ trunk/Source/WebKit2/UIProcess/gtk/DragAndDropHandler.h 2014-10-19 07:33:19 UTC (rev 174868)
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2014 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef DragAndDropHandler_h
+#define DragAndDropHandler_h
+
+#if ENABLE(DRAG_SUPPORT)
+
+#include <WebCore/DataObjectGtk.h>
+#include <WebCore/DragIcon.h>
+#include <wtf/HashMap.h>
+#include <wtf/Noncopyable.h>
+
+typedef struct _GdkDragContext GdkDragContext;
+typedef struct _GtkSelectionData GtkSelectionData;
+
+namespace WebCore {
+class DragData;
+class IntPoint;
+}
+
+namespace WebKit {
+
+class ShareableBitmap;
+class WebPageProxy;
+
+class DragAndDropHandler {
+ WTF_MAKE_NONCOPYABLE(DragAndDropHandler);
+public:
+ static std::unique_ptr<DragAndDropHandler> create(WebPageProxy&);
+
+ void startDrag(const WebCore::DragData&, PassRefPtr<ShareableBitmap> dragImage);
+ void fillDragData(GdkDragContext*, GtkSelectionData*, unsigned info);
+ void finishDrag(GdkDragContext*);
+
+ void dragEntered(GdkDragContext*, GtkSelectionData*, unsigned info, unsigned time);
+ void dragMotion(GdkDragContext*, const WebCore::IntPoint& position, unsigned time);
+ void dragLeave(GdkDragContext*);
+ bool drop(GdkDragContext*, const WebCore::IntPoint& position, unsigned time);
+
+private:
+ struct DroppingContext {
+ DroppingContext(GdkDragContext*, const WebCore::IntPoint& position);
+
+ GdkDragContext* gdkContext;
+ RefPtr<WebCore::DataObjectGtk> dataObject;
+ WebCore::IntPoint lastMotionPosition;
+ unsigned pendingDataRequests;
+ bool dropHappened;
+ };
+
+ DragAndDropHandler(WebPageProxy&);
+
+ WebCore::DataObjectGtk* dataObjectForDropData(GdkDragContext*, GtkSelectionData*, unsigned info, WebCore::IntPoint& position);
+ WebCore::DataObjectGtk* requestDragData(GdkDragContext*, const WebCore::IntPoint& position, unsigned time);
+
+ WebPageProxy& m_page;
+ WebCore::DragIcon m_dragIcon;
+ HashMap<GdkDragContext*, std::unique_ptr<DroppingContext>> m_droppingContexts;
+ HashMap<GdkDragContext*, RefPtr<WebCore::DataObjectGtk>> m_draggingDataObjects;
+};
+
+} // namespace WebKit
+
+#endif // ENABLE(DRAG_SUPPORT)
+
+#endif // DragAndDropHandler_h