Changeset 261570 in webkit


Ignore:
Timestamp:
May 12, 2020 12:27:48 PM (4 years ago)
Author:
Carlos Garcia Campos
Message:

[GTK] Rework drag and drop handling in preparation for GTK4
https://bugs.webkit.org/show_bug.cgi?id=211723

Reviewed by Adrian Perez de Castro.

Source/WebCore:

Remove PasteboardHelper that is no longer used and add conversion functions to GtkUtilities.

  • PlatformGTK.cmake:
  • SourcesGTK.txt:
  • platform/gtk/GtkUtilities.cpp:

(WebCore::gdkDragActionToDragOperation):
(WebCore::dragOperationToGdkDragActions):
(WebCore::dragOperationToSingleGdkDragAction):

  • platform/gtk/GtkUtilities.h:
  • platform/gtk/PasteboardHelper.cpp: Removed.
  • platform/gtk/PasteboardHelper.h: Removed.

Source/WebKit:

Split DragAndDropHelper class into DragSource and DropTarget classes. This separates the source and destination
parts making it easier to follow. This patch also adds PageClient::didPerformDragControllerAction() to notify
back the view when an operation is done to update the result.

  • SourcesGTK.txt:
  • UIProcess/API/gtk/DragSource.h: Added.
  • UIProcess/API/gtk/DragSourceGtk3.cpp: Added.

(WebKit::DragSource::DragSource):
(WebKit::DragSource::~DragSource):
(WebKit::DragSource::begin):

  • UIProcess/API/gtk/DropTarget.h: Added.
  • UIProcess/API/gtk/DropTargetGtk3.cpp: Added.

(WebKit::DropTarget::DropTarget):
(WebKit::DropTarget::~DropTarget):
(WebKit::DropTarget::accept):
(WebKit::DropTarget::enter):
(WebKit::DropTarget::update):
(WebKit::DropTarget::dataReceived):
(WebKit::DropTarget::didPerformAction):
(WebKit::DropTarget::leaveTimerFired):
(WebKit::DropTarget::leave):
(WebKit::DropTarget::drop):

  • UIProcess/API/gtk/PageClientImpl.cpp:

(WebKit::PageClientImpl::startDrag):
(WebKit::PageClientImpl::didPerformDragControllerAction):

  • UIProcess/API/gtk/PageClientImpl.h:
  • UIProcess/API/gtk/WebKitWebViewBase.cpp:

(webkitWebViewBaseConstructed):
(webkit_web_view_base_class_init):
(webkitWebViewBaseStartDrag):
(webkitWebViewBaseDidPerformDragControllerAction):

  • UIProcess/API/gtk/WebKitWebViewBasePrivate.h:
  • UIProcess/PageClient.h:

(WebKit::PageClient::didPerformDragControllerAction):

  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::didPerformDragControllerAction):

  • UIProcess/gtk/DragAndDropHandler.cpp: Removed.
  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::performDragControllerAction):

  • WebProcess/WebPage/gtk/WebPageGtk.cpp:
Location:
trunk/Source
Files:
6 added
3 deleted
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r261566 r261570  
     12020-05-12  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Rework drag and drop handling in preparation for GTK4
     4        https://bugs.webkit.org/show_bug.cgi?id=211723
     5
     6        Reviewed by Adrian Perez de Castro.
     7
     8        Remove PasteboardHelper that is no longer used and add conversion functions to GtkUtilities.
     9
     10        * PlatformGTK.cmake:
     11        * SourcesGTK.txt:
     12        * platform/gtk/GtkUtilities.cpp:
     13        (WebCore::gdkDragActionToDragOperation):
     14        (WebCore::dragOperationToGdkDragActions):
     15        (WebCore::dragOperationToSingleGdkDragAction):
     16        * platform/gtk/GtkUtilities.h:
     17        * platform/gtk/PasteboardHelper.cpp: Removed.
     18        * platform/gtk/PasteboardHelper.h: Removed.
     19
    1202020-05-12  Jacob Uphoff  <jacob_uphoff@apple.com>
    221
  • trunk/Source/WebCore/PlatformGTK.cmake

    r260132 r261570  
    6262    platform/gtk/GtkUtilities.h
    6363    platform/gtk/GtkVersioning.h
    64     platform/gtk/PasteboardHelper.h
    6564    platform/gtk/ScrollbarThemeGtk.h
    6665    platform/gtk/SelectionData.h
  • trunk/Source/WebCore/SourcesGTK.txt

    r261554 r261570  
    108108platform/gtk/LocalizedStringsGtk.cpp
    109109platform/gtk/PasteboardGtk.cpp
    110 platform/gtk/PasteboardHelper.cpp
    111110platform/gtk/PlatformKeyboardEventGtk.cpp
    112111platform/gtk/PlatformScreenGtk.cpp
  • trunk/Source/WebCore/platform/gtk/GtkUtilities.cpp

    r260508 r261570  
    103103}
    104104
     105DragOperation gdkDragActionToDragOperation(GdkDragAction gdkAction)
     106{
     107    // We have no good way to detect DragOperationEvery other than
     108    // to use it when all applicable flags are on.
     109    if (gdkAction & GDK_ACTION_COPY
     110        && gdkAction & GDK_ACTION_MOVE
     111        && gdkAction & GDK_ACTION_LINK)
     112        return DragOperationEvery;
     113
     114    unsigned action = DragOperationNone;
     115    if (gdkAction & GDK_ACTION_COPY)
     116        action |= DragOperationCopy;
     117    if (gdkAction & GDK_ACTION_MOVE)
     118        action |= DragOperationMove;
     119    if (gdkAction & GDK_ACTION_LINK)
     120        action |= DragOperationLink;
     121
     122    return static_cast<DragOperation>(action);
     123}
     124
     125GdkDragAction dragOperationToGdkDragActions(DragOperation coreAction)
     126{
     127    unsigned gdkAction = 0;
     128    if (coreAction == DragOperationNone)
     129        return static_cast<GdkDragAction>(gdkAction);
     130
     131    if (coreAction & DragOperationCopy)
     132        gdkAction |= GDK_ACTION_COPY;
     133    if (coreAction & DragOperationMove)
     134        gdkAction |= GDK_ACTION_MOVE;
     135    if (coreAction & DragOperationLink)
     136        gdkAction |= GDK_ACTION_LINK;
     137
     138    return static_cast<GdkDragAction>(gdkAction);
     139}
     140
     141GdkDragAction dragOperationToSingleGdkDragAction(DragOperation coreAction)
     142{
     143    if (coreAction == DragOperationEvery || coreAction & DragOperationCopy)
     144        return GDK_ACTION_COPY;
     145    if (coreAction & DragOperationMove)
     146        return GDK_ACTION_MOVE;
     147    if (coreAction & DragOperationLink)
     148        return GDK_ACTION_LINK;
     149    return static_cast<GdkDragAction>(0);
     150}
     151
    105152} // namespace WebCore
  • trunk/Source/WebCore/platform/gtk/GtkUtilities.h

    r261014 r261570  
    1919#pragma once
    2020
     21#include "DragActions.h"
    2122#include <gtk/gtk.h>
    2223#include <wtf/MonotonicTime.h>
     
    4849WEBCORE_EXPORT unsigned stateModifierForGdkButton(unsigned button);
    4950
     51WEBCORE_EXPORT DragOperation gdkDragActionToDragOperation(GdkDragAction);
     52WEBCORE_EXPORT GdkDragAction dragOperationToGdkDragActions(DragOperation);
     53WEBCORE_EXPORT GdkDragAction dragOperationToSingleGdkDragAction(DragOperation);
     54
    5055} // namespace WebCore
  • trunk/Source/WebKit/ChangeLog

    r261566 r261570  
     12020-05-12  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Rework drag and drop handling in preparation for GTK4
     4        https://bugs.webkit.org/show_bug.cgi?id=211723
     5
     6        Reviewed by Adrian Perez de Castro.
     7
     8        Split DragAndDropHelper class into DragSource and DropTarget classes. This separates the source and destination
     9        parts making it easier to follow. This patch also adds PageClient::didPerformDragControllerAction() to notify
     10        back the view when an operation is done to update the result.
     11
     12        * SourcesGTK.txt:
     13        * UIProcess/API/gtk/DragSource.h: Added.
     14        * UIProcess/API/gtk/DragSourceGtk3.cpp: Added.
     15        (WebKit::DragSource::DragSource):
     16        (WebKit::DragSource::~DragSource):
     17        (WebKit::DragSource::begin):
     18        * UIProcess/API/gtk/DropTarget.h: Added.
     19        * UIProcess/API/gtk/DropTargetGtk3.cpp: Added.
     20        (WebKit::DropTarget::DropTarget):
     21        (WebKit::DropTarget::~DropTarget):
     22        (WebKit::DropTarget::accept):
     23        (WebKit::DropTarget::enter):
     24        (WebKit::DropTarget::update):
     25        (WebKit::DropTarget::dataReceived):
     26        (WebKit::DropTarget::didPerformAction):
     27        (WebKit::DropTarget::leaveTimerFired):
     28        (WebKit::DropTarget::leave):
     29        (WebKit::DropTarget::drop):
     30        * UIProcess/API/gtk/PageClientImpl.cpp:
     31        (WebKit::PageClientImpl::startDrag):
     32        (WebKit::PageClientImpl::didPerformDragControllerAction):
     33        * UIProcess/API/gtk/PageClientImpl.h:
     34        * UIProcess/API/gtk/WebKitWebViewBase.cpp:
     35        (webkitWebViewBaseConstructed):
     36        (webkit_web_view_base_class_init):
     37        (webkitWebViewBaseStartDrag):
     38        (webkitWebViewBaseDidPerformDragControllerAction):
     39        * UIProcess/API/gtk/WebKitWebViewBasePrivate.h:
     40        * UIProcess/PageClient.h:
     41        (WebKit::PageClient::didPerformDragControllerAction):
     42        * UIProcess/WebPageProxy.cpp:
     43        (WebKit::WebPageProxy::didPerformDragControllerAction):
     44        * UIProcess/gtk/DragAndDropHandler.cpp: Removed.
     45        * WebProcess/WebPage/WebPage.cpp:
     46        (WebKit::WebPage::performDragControllerAction):
     47        * WebProcess/WebPage/gtk/WebPageGtk.cpp:
     48
    1492020-05-12  Jacob Uphoff  <jacob_uphoff@apple.com>
    250
  • trunk/Source/WebKit/SourcesGTK.txt

    r261554 r261570  
    195195UIProcess/API/glib/WebKitWindowProperties.cpp @no-unify
    196196
     197UIProcess/API/gtk/DragSourceGtk3.cpp @no-unify
     198UIProcess/API/gtk/DragSourceGtk4.cpp @no-unify
     199UIProcess/API/gtk/DropTargetGtk3.cpp @no-unify
     200UIProcess/API/gtk/DropTargetGtk4.cpp @no-unify
    197201UIProcess/API/gtk/InputMethodFilterGtk.cpp @no-unify
    198202UIProcess/API/gtk/PageClientImpl.cpp @no-unify
     
    257261UIProcess/gtk/ClipboardGtk3.cpp @no-unify
    258262UIProcess/gtk/ClipboardGtk4.cpp @no-unify
    259 UIProcess/gtk/DragAndDropHandler.cpp
    260263UIProcess/gtk/GestureController.cpp
    261264UIProcess/gtk/HardwareAccelerationManager.cpp
  • trunk/Source/WebKit/UIProcess/API/gtk/PageClientImpl.cpp

    r261048 r261570  
    331331void PageClientImpl::startDrag(Ref<SelectionData>&& selection, DragOperation dragOperation, RefPtr<ShareableBitmap>&& dragImage)
    332332{
    333 #if !USE(GTK4)
    334     WebKitWebViewBase* webView = WEBKIT_WEB_VIEW_BASE(m_viewWidget);
    335     webkitWebViewBaseDragAndDropHandler(webView).startDrag(WTFMove(selection), dragOperation, WTFMove(dragImage));
    336 
    337     // A drag starting should prevent a double-click from happening. This might
    338     // happen if a drag is followed very quickly by another click (like in the WTR).
    339     webkitWebViewBaseResetClickCounter(webView);
    340 #endif
     333    webkitWebViewBaseStartDrag(WEBKIT_WEB_VIEW_BASE(m_viewWidget), WTFMove(selection), dragOperation, WTFMove(dragImage));
     334}
     335
     336void PageClientImpl::didPerformDragControllerAction()
     337{
     338    webkitWebViewBaseDidPerformDragControllerAction(WEBKIT_WEB_VIEW_BASE(m_viewWidget));
    341339}
    342340#endif
  • trunk/Source/WebKit/UIProcess/API/gtk/PageClientImpl.h

    r255343 r261570  
    102102#if ENABLE(DRAG_SUPPORT)
    103103    void startDrag(Ref<WebCore::SelectionData>&&, WebCore::DragOperation, RefPtr<ShareableBitmap>&& dragImage) override;
     104    void didPerformDragControllerAction() override;
    104105#endif
    105106
  • trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp

    r261284 r261570  
    3232#include "APIPageConfiguration.h"
    3333#include "AcceleratedBackingStore.h"
     34#include "DragSource.h"
    3435#include "DrawingAreaProxyCoordinatedGraphics.h"
     36#include "DropTarget.h"
    3537#include "InputMethodFilter.h"
    3638#include "KeyBindingTranslator.h"
     
    5961#include <WebCore/GtkVersioning.h>
    6062#include <WebCore/NotImplemented.h>
    61 #include <WebCore/PasteboardHelper.h>
    6263#include <WebCore/PlatformDisplay.h>
    6364#include <WebCore/RefPtrCairo.h>
     
    220221    std::unique_ptr<AcceleratedBackingStore> acceleratedBackingStore;
    221222
    222 #if ENABLE(DRAG_SUPPORT) && !USE(GTK4)
    223     std::unique_ptr<DragAndDropHandler> dragAndDropHandler;
     223#if ENABLE(DRAG_SUPPORT)
     224    std::unique_ptr<DragSource> dragSource;
     225    std::unique_ptr<DropTarget> dropTarget;
    224226#endif
    225227
     
    15551557}
    15561558
    1557 #if ENABLE(DRAG_SUPPORT) && !USE(GTK4)
    1558 static void webkitWebViewBaseDragDataGet(GtkWidget* widget, GdkDragContext* context, GtkSelectionData* selectionData, guint info, guint /* time */)
    1559 {
    1560     WebKitWebViewBasePrivate* priv = WEBKIT_WEB_VIEW_BASE(widget)->priv;
    1561     ASSERT(priv->dragAndDropHandler);
    1562     priv->dragAndDropHandler->fillDragData(context, selectionData, info);
    1563 }
    1564 
    1565 static void webkitWebViewBaseDragEnd(GtkWidget* widget, GdkDragContext* context)
    1566 {
    1567     WebKitWebViewBasePrivate* priv = WEBKIT_WEB_VIEW_BASE(widget)->priv;
    1568     ASSERT(priv->dragAndDropHandler);
    1569     priv->dragAndDropHandler->finishDrag(context);
    1570 }
    1571 
    1572 static void webkitWebViewBaseDragDataReceived(GtkWidget* widget, GdkDragContext* context, gint /* x */, gint /* y */, GtkSelectionData* selectionData, guint info, guint time)
    1573 {
    1574     webkitWebViewBaseDragAndDropHandler(WEBKIT_WEB_VIEW_BASE(widget)).dragEntered(context, selectionData, info, time);
    1575 }
    1576 #endif // ENABLE(DRAG_SUPPORT)
    1577 
    15781559#if !USE(GTK4)
    15791560static gboolean webkitWebViewBaseEvent(GtkWidget* widget, GdkEvent* event)
     
    16011582    return priv->accessible.get();
    16021583}
    1603 
    1604 #if ENABLE(DRAG_SUPPORT) && !USE(GTK4)
    1605 static gboolean webkitWebViewBaseDragMotion(GtkWidget* widget, GdkDragContext* context, gint x, gint y, guint time)
    1606 {
    1607     webkitWebViewBaseDragAndDropHandler(WEBKIT_WEB_VIEW_BASE(widget)).dragMotion(context, IntPoint(x, y), time);
    1608     return TRUE;
    1609 }
    1610 
    1611 static void webkitWebViewBaseDragLeave(GtkWidget* widget, GdkDragContext* context, guint /* time */)
    1612 {
    1613     WebKitWebViewBasePrivate* priv = WEBKIT_WEB_VIEW_BASE(widget)->priv;
    1614     ASSERT(priv->dragAndDropHandler);
    1615     priv->dragAndDropHandler->dragLeave(context);
    1616 }
    1617 
    1618 static gboolean webkitWebViewBaseDragDrop(GtkWidget* widget, GdkDragContext* context, gint x, gint y, guint time)
    1619 {
    1620     WebKitWebViewBasePrivate* priv = WEBKIT_WEB_VIEW_BASE(widget)->priv;
    1621     ASSERT(priv->dragAndDropHandler);
    1622     return priv->dragAndDropHandler->drop(context, IntPoint(x, y), time);
    1623 }
    1624 #endif // ENABLE(DRAG_SUPPORT)
    16251584
    16261585#if !USE(GTK4)
     
    16741633    gtk_container_add(GTK_CONTAINER(viewWidget), priv->keyBindingTranslator.widget());
    16751634
    1676 #if !USE(GTK4)
    1677     gtk_drag_dest_set(viewWidget, static_cast<GtkDestDefaults>(0), nullptr, 0,
    1678         static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK | GDK_ACTION_PRIVATE));
    1679     gtk_drag_dest_set_target_list(viewWidget, PasteboardHelper::singleton().targetList());
     1635#if ENABLE(DRAG_SUPPORT)
     1636    priv->dropTarget = makeUnique<DropTarget>(viewWidget);
    16801637#endif
    16811638
     
    17481705#endif
    17491706    widgetClass->query_tooltip = webkitWebViewBaseQueryTooltip;
    1750 #if ENABLE(DRAG_SUPPORT) && !USE(GTK4)
    1751     widgetClass->drag_end = webkitWebViewBaseDragEnd;
    1752     widgetClass->drag_data_get = webkitWebViewBaseDragDataGet;
    1753     widgetClass->drag_motion = webkitWebViewBaseDragMotion;
    1754     widgetClass->drag_leave = webkitWebViewBaseDragLeave;
    1755     widgetClass->drag_drop = webkitWebViewBaseDragDrop;
    1756     widgetClass->drag_data_received = webkitWebViewBaseDragDataReceived;
    1757 #endif // ENABLE(DRAG_SUPPORT)
    17581707#if !USE(GTK4)
    17591708    widgetClass->event = webkitWebViewBaseEvent;
     
    18301779}
    18311780
    1832 #if ENABLE(DRAG_SUPPORT) && !USE(GTK4)
    1833 DragAndDropHandler& webkitWebViewBaseDragAndDropHandler(WebKitWebViewBase* webViewBase)
    1834 {
    1835     WebKitWebViewBasePrivate* priv = webViewBase->priv;
    1836     if (!priv->dragAndDropHandler)
    1837         priv->dragAndDropHandler = makeUnique<DragAndDropHandler>(*priv->pageProxy);
    1838     return *priv->dragAndDropHandler;
     1781#if ENABLE(DRAG_SUPPORT)
     1782void webkitWebViewBaseStartDrag(WebKitWebViewBase* webViewBase, Ref<SelectionData>&& selectionData, DragOperation dragOperation, RefPtr<ShareableBitmap>&& image)
     1783{
     1784    WebKitWebViewBasePrivate* priv = webViewBase->priv;
     1785    if (!priv->dragSource)
     1786        priv->dragSource = makeUnique<DragSource>(GTK_WIDGET(webViewBase));
     1787
     1788    priv->dragSource->begin(WTFMove(selectionData), dragOperation, WTFMove(image));
     1789
     1790#if !USE(GTK4)
     1791    // A drag starting should prevent a double-click from happening. This might
     1792    // happen if a drag is followed very quickly by another click (like in the WTR).
     1793    priv->clickCounter.reset();
     1794#endif
     1795}
     1796
     1797void webkitWebViewBaseDidPerformDragControllerAction(WebKitWebViewBase* webViewBase)
     1798{
     1799    webViewBase->priv->dropTarget->didPerformAction();
    18391800}
    18401801#endif // ENABLE(DRAG_SUPPORT)
  • trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBasePrivate.h

    r260889 r261570  
    3333#include "InputMethodState.h"
    3434#include "SameDocumentNavigationType.h"
     35#include "ShareableBitmap.h"
    3536#include "ViewGestureController.h"
    3637#include "ViewSnapshotStore.h"
     
    4041#include "WebKitWebViewBase.h"
    4142#include "WebPageProxy.h"
     43#include <WebCore/DragActions.h>
     44#include <WebCore/SelectionData.h>
    4245#include <wtf/Optional.h>
    4346
     
    7982void webkitWebViewBasePageClosed(WebKitWebViewBase*);
    8083
    81 #if ENABLE(DRAG_SUPPORT) && !USE(GTK4)
    82 WebKit::DragAndDropHandler& webkitWebViewBaseDragAndDropHandler(WebKitWebViewBase*);
     84#if ENABLE(DRAG_SUPPORT)
     85void webkitWebViewBaseStartDrag(WebKitWebViewBase*, Ref<WebCore::SelectionData>&&, WebCore::DragOperation, RefPtr<WebKit::ShareableBitmap>&&);
     86void webkitWebViewBaseDidPerformDragControllerAction(WebKitWebViewBase*);
    8387#endif
    8488
  • trunk/Source/WebKit/UIProcess/PageClient.h

    r261457 r261570  
    251251#endif
    252252    virtual void didPerformDragOperation(bool) { }
     253    virtual void didPerformDragControllerAction() { }
    253254#endif // ENABLE(DRAG_SUPPORT)
    254255
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r261506 r261570  
    24252425    m_currentDragCaretEditableElementRect = editableElementRect;
    24262426    setDragCaretRect(insertionRect);
     2427    pageClient().didPerformDragControllerAction();
    24272428}
    24282429
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp

    r261560 r261570  
    39443944    }
    39453945    case DragControllerAction::Updated: {
    3946         DragOperation resolvedDragOperation = m_page->dragController().dragEntered(dragData);
     3946        DragOperation resolvedDragOperation = m_page->dragController().dragUpdated(dragData);
    39473947        send(Messages::WebPageProxy::DidPerformDragControllerAction(resolvedDragOperation, m_page->dragController().dragHandlingMethod(), m_page->dragController().mouseIsOverFileInput(), m_page->dragController().numberOfItemsToBeAccepted(), { }, { }));
    39483948        return;
  • trunk/Source/WebKit/WebProcess/WebPage/gtk/WebPageGtk.cpp

    r257299 r261570  
    4343#include <WebCore/NotImplemented.h>
    4444#include <WebCore/Page.h>
    45 #include <WebCore/PasteboardHelper.h>
    4645#include <WebCore/PlatformKeyboardEvent.h>
    4746#include <WebCore/RenderTheme.h>
Note: See TracChangeset for help on using the changeset viewer.