Title: [290728] trunk/Source
Revision
290728
Author
[email protected]
Date
2022-03-02 07:06:43 -0800 (Wed, 02 Mar 2022)

Log Message

[GTK] setDragImage ignores offset
https://bugs.webkit.org/show_bug.cgi?id=237292

Patch by Michael Catanzaro <[email protected]> on 2022-03-02
Reviewed by Carlos Garcia Campos.

Source/WebCore:

To fix this, I need DataTransfer to expose its dragLocation, which is the offset passed to
setDragImage.

* dom/DataTransfer.h:
(WebCore::DataTransfer::dragLocation const):

Source/WebKit:

Plumb the offset from the last place we have access to a DataTransfer object down to
DragSource, where it's ultimately used. This allows web content to properly position the
drag image under the mouse cursor.

* UIProcess/API/gtk/DragSource.h:
* UIProcess/API/gtk/DragSourceGtk3.cpp:
(WebKit::DragSource::begin):
* UIProcess/API/gtk/DragSourceGtk4.cpp:
(WebKit::DragSource::begin):
* UIProcess/API/gtk/PageClientImpl.cpp:
(WebKit::PageClientImpl::startDrag):
* UIProcess/API/gtk/PageClientImpl.h:
* UIProcess/API/gtk/WebKitWebViewBase.cpp:
(webkitWebViewBaseStartDrag):
* UIProcess/API/gtk/WebKitWebViewBasePrivate.h:
* UIProcess/PageClient.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::startDrag):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* WebProcess/WebCoreSupport/gtk/WebDragClientGtk.cpp:
(WebKit::WebDragClient::startDrag):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (290727 => 290728)


--- trunk/Source/WebCore/ChangeLog	2022-03-02 15:03:58 UTC (rev 290727)
+++ trunk/Source/WebCore/ChangeLog	2022-03-02 15:06:43 UTC (rev 290728)
@@ -1,3 +1,16 @@
+2022-03-02  Michael Catanzaro  <[email protected]>
+
+        [GTK] setDragImage ignores offset
+        https://bugs.webkit.org/show_bug.cgi?id=237292
+
+        Reviewed by Carlos Garcia Campos.
+
+        To fix this, I need DataTransfer to expose its dragLocation, which is the offset passed to
+        setDragImage.
+
+        * dom/DataTransfer.h:
+        (WebCore::DataTransfer::dragLocation const):
+
 2022-03-02  Alan Bujtas  <[email protected]>
 
         [RTL] Incorrect alt text position in right to left context

Modified: trunk/Source/WebCore/dom/DataTransfer.h (290727 => 290728)


--- trunk/Source/WebCore/dom/DataTransfer.h	2022-03-02 15:03:58 UTC (rev 290727)
+++ trunk/Source/WebCore/dom/DataTransfer.h	2022-03-02 15:06:43 UTC (rev 290728)
@@ -108,6 +108,8 @@
 
     void moveDragState(Ref<DataTransfer>&&);
     bool hasDragImage() const;
+
+    IntPoint dragLocation() const { return m_dragLocation; }
 #endif
 
     void didAddFileToItemList();

Modified: trunk/Source/WebKit/ChangeLog (290727 => 290728)


--- trunk/Source/WebKit/ChangeLog	2022-03-02 15:03:58 UTC (rev 290727)
+++ trunk/Source/WebKit/ChangeLog	2022-03-02 15:06:43 UTC (rev 290728)
@@ -1,3 +1,33 @@
+2022-03-02  Michael Catanzaro  <[email protected]>
+
+        [GTK] setDragImage ignores offset
+        https://bugs.webkit.org/show_bug.cgi?id=237292
+
+        Reviewed by Carlos Garcia Campos.
+
+        Plumb the offset from the last place we have access to a DataTransfer object down to
+        DragSource, where it's ultimately used. This allows web content to properly position the
+        drag image under the mouse cursor.
+
+        * UIProcess/API/gtk/DragSource.h:
+        * UIProcess/API/gtk/DragSourceGtk3.cpp:
+        (WebKit::DragSource::begin):
+        * UIProcess/API/gtk/DragSourceGtk4.cpp:
+        (WebKit::DragSource::begin):
+        * UIProcess/API/gtk/PageClientImpl.cpp:
+        (WebKit::PageClientImpl::startDrag):
+        * UIProcess/API/gtk/PageClientImpl.h:
+        * UIProcess/API/gtk/WebKitWebViewBase.cpp:
+        (webkitWebViewBaseStartDrag):
+        * UIProcess/API/gtk/WebKitWebViewBasePrivate.h:
+        * UIProcess/PageClient.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::startDrag):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+        * WebProcess/WebCoreSupport/gtk/WebDragClientGtk.cpp:
+        (WebKit::WebDragClient::startDrag):
+
 2022-03-02  Youenn Fablet  <[email protected]>
 
         Annotate LibWebRTC with thread safety macros

Modified: trunk/Source/WebKit/UIProcess/API/gtk/DragSource.h (290727 => 290728)


--- trunk/Source/WebKit/UIProcess/API/gtk/DragSource.h	2022-03-02 15:03:58 UTC (rev 290727)
+++ trunk/Source/WebKit/UIProcess/API/gtk/DragSource.h	2022-03-02 15:06:43 UTC (rev 290728)
@@ -52,7 +52,7 @@
     explicit DragSource(GtkWidget*);
     ~DragSource();
 
-    void begin(WebCore::SelectionData&&, OptionSet<WebCore::DragOperation>, RefPtr<ShareableBitmap>&&);
+    void begin(WebCore::SelectionData&&, OptionSet<WebCore::DragOperation>, RefPtr<ShareableBitmap>&&, WebCore::IntPoint&& imageHotspot);
 
 private:
     GtkWidget* m_webView { nullptr };

Modified: trunk/Source/WebKit/UIProcess/API/gtk/DragSourceGtk3.cpp (290727 => 290728)


--- trunk/Source/WebKit/UIProcess/API/gtk/DragSourceGtk3.cpp	2022-03-02 15:03:58 UTC (rev 290727)
+++ trunk/Source/WebKit/UIProcess/API/gtk/DragSourceGtk3.cpp	2022-03-02 15:06:43 UTC (rev 290728)
@@ -112,7 +112,7 @@
     g_signal_handlers_disconnect_by_data(m_webView, this);
 }
 
-void DragSource::begin(SelectionData&& selectionData, OptionSet<DragOperation> operationMask, RefPtr<ShareableBitmap>&& image)
+void DragSource::begin(SelectionData&& selectionData, OptionSet<DragOperation> operationMask, RefPtr<ShareableBitmap>&& image, IntPoint&& imageHotspot)
 {
     if (m_drag) {
         gtk_drag_cancel(m_drag.get());
@@ -140,8 +140,7 @@
     m_drag = gtk_drag_begin_with_coordinates(m_webView, list.get(), dragOperationToGdkDragActions(operationMask), GDK_BUTTON_PRIMARY, nullptr, -1, -1);
     if (image) {
         RefPtr<cairo_surface_t> imageSurface(image->createCairoSurface());
-        // Use the center of the drag image as hotspot.
-        cairo_surface_set_device_offset(imageSurface.get(), -cairo_image_surface_get_width(imageSurface.get()) / 2, -cairo_image_surface_get_height(imageSurface.get()) / 2);
+        cairo_surface_set_device_offset(imageSurface.get(), -imageHotspot.x(), -imageHotspot.y());
         gtk_drag_set_icon_surface(m_drag.get(), imageSurface.get());
     } else
         gtk_drag_set_icon_default(m_drag.get());

Modified: trunk/Source/WebKit/UIProcess/API/gtk/DragSourceGtk4.cpp (290727 => 290728)


--- trunk/Source/WebKit/UIProcess/API/gtk/DragSourceGtk4.cpp	2022-03-02 15:03:58 UTC (rev 290727)
+++ trunk/Source/WebKit/UIProcess/API/gtk/DragSourceGtk4.cpp	2022-03-02 15:06:43 UTC (rev 290728)
@@ -45,7 +45,7 @@
 {
 }
 
-void DragSource::begin(SelectionData&& selectionData, OptionSet<DragOperation> operationMask, RefPtr<ShareableBitmap>&& image)
+void DragSource::begin(SelectionData&& selectionData, OptionSet<DragOperation> operationMask, RefPtr<ShareableBitmap>&& image, IntPoint&& imageHotspot)
 {
     if (m_drag) {
         gdk_drag_drop_done(m_drag.get(), FALSE);
@@ -129,7 +129,7 @@
     RefPtr<Image> iconImage = image ? image->createImage() : nullptr;
     if (iconImage) {
         if (GRefPtr<GdkTexture> texture = adoptGRef(iconImage->gdkTexture())) {
-            gdk_drag_set_hotspot(m_drag.get(), -gdk_texture_get_width(texture.get()) / 2, -gdk_texture_get_height(texture.get()) / 2);
+            gdk_drag_set_hotspot(m_drag.get(), -imageHotspot.x(), -imageHotspot.y());
             auto* picture = gtk_picture_new_for_paintable(GDK_PAINTABLE(texture.get()));
             gtk_drag_icon_set_child(GTK_DRAG_ICON(dragIcon), picture);
             return;

Modified: trunk/Source/WebKit/UIProcess/API/gtk/PageClientImpl.cpp (290727 => 290728)


--- trunk/Source/WebKit/UIProcess/API/gtk/PageClientImpl.cpp	2022-03-02 15:03:58 UTC (rev 290727)
+++ trunk/Source/WebKit/UIProcess/API/gtk/PageClientImpl.cpp	2022-03-02 15:06:43 UTC (rev 290728)
@@ -344,9 +344,9 @@
 }
 
 #if ENABLE(DRAG_SUPPORT)
-void PageClientImpl::startDrag(SelectionData&& selection, OptionSet<DragOperation> dragOperationMask, RefPtr<ShareableBitmap>&& dragImage)
+void PageClientImpl::startDrag(SelectionData&& selection, OptionSet<DragOperation> dragOperationMask, RefPtr<ShareableBitmap>&& dragImage, IntPoint&& dragImageHotspot)
 {
-    webkitWebViewBaseStartDrag(WEBKIT_WEB_VIEW_BASE(m_viewWidget), WTFMove(selection), dragOperationMask, WTFMove(dragImage));
+    webkitWebViewBaseStartDrag(WEBKIT_WEB_VIEW_BASE(m_viewWidget), WTFMove(selection), dragOperationMask, WTFMove(dragImage), WTFMove(dragImageHotspot));
 }
 
 void PageClientImpl::didPerformDragControllerAction()

Modified: trunk/Source/WebKit/UIProcess/API/gtk/PageClientImpl.h (290727 => 290728)


--- trunk/Source/WebKit/UIProcess/API/gtk/PageClientImpl.h	2022-03-02 15:03:58 UTC (rev 290727)
+++ trunk/Source/WebKit/UIProcess/API/gtk/PageClientImpl.h	2022-03-02 15:06:43 UTC (rev 290728)
@@ -105,7 +105,7 @@
     void selectionDidChange() override;
     RefPtr<ViewSnapshot> takeViewSnapshot(std::optional<WebCore::IntRect>&&) override;
 #if ENABLE(DRAG_SUPPORT)
-    void startDrag(WebCore::SelectionData&&, OptionSet<WebCore::DragOperation>, RefPtr<ShareableBitmap>&& dragImage) override;
+    void startDrag(WebCore::SelectionData&&, OptionSet<WebCore::DragOperation>, RefPtr<ShareableBitmap>&& dragImage, WebCore::IntPoint&& dragImageHotspot) override;
     void didPerformDragControllerAction() override;
 #endif
 

Modified: trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp (290727 => 290728)


--- trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp	2022-03-02 15:03:58 UTC (rev 290727)
+++ trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp	2022-03-02 15:06:43 UTC (rev 290728)
@@ -2308,13 +2308,13 @@
 }
 
 #if ENABLE(DRAG_SUPPORT)
-void webkitWebViewBaseStartDrag(WebKitWebViewBase* webViewBase, SelectionData&& selectionData, OptionSet<DragOperation> dragOperationMask, RefPtr<ShareableBitmap>&& image)
+void webkitWebViewBaseStartDrag(WebKitWebViewBase* webViewBase, SelectionData&& selectionData, OptionSet<DragOperation> dragOperationMask, RefPtr<ShareableBitmap>&& image, IntPoint&& dragImageHotspot)
 {
     WebKitWebViewBasePrivate* priv = webViewBase->priv;
     if (!priv->dragSource)
         priv->dragSource = makeUnique<DragSource>(GTK_WIDGET(webViewBase));
 
-    priv->dragSource->begin(WTFMove(selectionData), dragOperationMask, WTFMove(image));
+    priv->dragSource->begin(WTFMove(selectionData), dragOperationMask, WTFMove(image), WTFMove(dragImageHotspot));
 
 #if !USE(GTK4)
     // A drag starting should prevent a double-click from happening. This might

Modified: trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBasePrivate.h (290727 => 290728)


--- trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBasePrivate.h	2022-03-02 15:03:58 UTC (rev 290727)
+++ trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBasePrivate.h	2022-03-02 15:06:43 UTC (rev 290728)
@@ -85,7 +85,7 @@
 void webkitWebViewBasePageClosed(WebKitWebViewBase*);
 
 #if ENABLE(DRAG_SUPPORT)
-void webkitWebViewBaseStartDrag(WebKitWebViewBase*, WebCore::SelectionData&&, OptionSet<WebCore::DragOperation>, RefPtr<WebKit::ShareableBitmap>&&);
+void webkitWebViewBaseStartDrag(WebKitWebViewBase*, WebCore::SelectionData&&, OptionSet<WebCore::DragOperation>, RefPtr<WebKit::ShareableBitmap>&&, WebCore::IntPoint&& dragImageHotspot);
 void webkitWebViewBaseDidPerformDragControllerAction(WebKitWebViewBase*);
 #endif
 

Modified: trunk/Source/WebKit/UIProcess/PageClient.h (290727 => 290728)


--- trunk/Source/WebKit/UIProcess/PageClient.h	2022-03-02 15:03:58 UTC (rev 290727)
+++ trunk/Source/WebKit/UIProcess/PageClient.h	2022-03-02 15:06:43 UTC (rev 290728)
@@ -289,7 +289,7 @@
     
 #if ENABLE(DRAG_SUPPORT)
 #if PLATFORM(GTK)
-    virtual void startDrag(WebCore::SelectionData&&, OptionSet<WebCore::DragOperation>, RefPtr<ShareableBitmap>&& dragImage) = 0;
+    virtual void startDrag(WebCore::SelectionData&&, OptionSet<WebCore::DragOperation>, RefPtr<ShareableBitmap>&& dragImage, WebCore::IntPoint&& dragImageHotspot) = 0;
 #else
     virtual void startDrag(const WebCore::DragItem&, const ShareableBitmap::Handle&) { }
 #endif

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (290727 => 290728)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2022-03-02 15:03:58 UTC (rev 290727)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2022-03-02 15:06:43 UTC (rev 290728)
@@ -2729,10 +2729,10 @@
 }
 
 #if PLATFORM(GTK)
-void WebPageProxy::startDrag(SelectionData&& selectionData, OptionSet<WebCore::DragOperation> dragOperationMask, const ShareableBitmap::Handle& dragImageHandle)
+void WebPageProxy::startDrag(SelectionData&& selectionData, OptionSet<WebCore::DragOperation> dragOperationMask, const ShareableBitmap::Handle& dragImageHandle, IntPoint&& dragImageHotspot)
 {
     RefPtr<ShareableBitmap> dragImage = !dragImageHandle.isNull() ? ShareableBitmap::create(dragImageHandle) : nullptr;
-    pageClient().startDrag(WTFMove(selectionData), dragOperationMask, WTFMove(dragImage));
+    pageClient().startDrag(WTFMove(selectionData), dragOperationMask, WTFMove(dragImage), WTFMove(dragImageHotspot));
 
     didStartDrag();
 }

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (290727 => 290728)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2022-03-02 15:03:58 UTC (rev 290727)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2022-03-02 15:06:43 UTC (rev 290728)
@@ -1289,7 +1289,7 @@
         const String& title, const String& url, const String& visibleURL, const SharedMemory::IPCHandle& archiveHandle, const String& originIdentifier);
 #endif
 #if PLATFORM(GTK)
-    void startDrag(WebCore::SelectionData&&, OptionSet<WebCore::DragOperation>, const ShareableBitmap::Handle& dragImage);
+    void startDrag(WebCore::SelectionData&&, OptionSet<WebCore::DragOperation>, const ShareableBitmap::Handle& dragImage, WebCore::IntPoint&& dragImageHotspot);
 #endif
 #endif
 

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in (290727 => 290728)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in	2022-03-02 15:03:58 UTC (rev 290727)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in	2022-03-02 15:06:43 UTC (rev 290728)
@@ -303,7 +303,7 @@
     SetPromisedDataForImage(String pasteboardName, WebKit::SharedMemory::IPCHandle imageHandle, String filename, String extension, String title, String url, String visibleURL, WebKit::SharedMemory::IPCHandle archiveHandle, String originIdentifier)
 #endif
 #if PLATFORM(GTK) && ENABLE(DRAG_SUPPORT)
-    StartDrag(WebCore::SelectionData selectionData, OptionSet<WebCore::DragOperation> dragOperationMask, WebKit::ShareableBitmap::Handle dragImage)
+    StartDrag(WebCore::SelectionData selectionData, OptionSet<WebCore::DragOperation> dragOperationMask, WebKit::ShareableBitmap::Handle dragImage, WebCore::IntPoint dragImageHotspot)
 #endif
 
 #if ENABLE(DRAG_SUPPORT)

Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/gtk/WebDragClientGtk.cpp (290727 => 290728)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/gtk/WebDragClientGtk.cpp	2022-03-02 15:03:58 UTC (rev 290727)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/gtk/WebDragClientGtk.cpp	2022-03-02 15:06:43 UTC (rev 290728)
@@ -74,7 +74,7 @@
 
     m_page->willStartDrag();
 
-    m_page->send(Messages::WebPageProxy::StartDrag(dataTransfer.pasteboard().selectionData(), dataTransfer.sourceOperationMask(), handle));
+    m_page->send(Messages::WebPageProxy::StartDrag(dataTransfer.pasteboard().selectionData(), dataTransfer.sourceOperationMask(), handle, dataTransfer.dragLocation()));
 }
 
 }; // namespace WebKit.
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to