Title: [226899] trunk/Source/WebKit
Revision
226899
Author
wenson_hs...@apple.com
Date
2018-01-12 10:49:11 -0800 (Fri, 12 Jan 2018)

Log Message

[WK2] Unify macOS and iOS codepaths in the UI process when starting a drag
https://bugs.webkit.org/show_bug.cgi?id=181574

Reviewed by Tim Horton.

Rearrange some macOS drag start logic in the UI process so that it uses the same codepaths in WebPageProxy as
iOS. Namely, startDrag should just forward the DragItem and drag image handle along to the appropriate views on
each platform (WKContentView and WebViewImpl).

There should be no change in behavior.

* UIProcess/Cocoa/WebPageProxyCocoa.mm:

Both macOS and iOS now funnel through this method.

* UIProcess/Cocoa/WebViewImpl.h:
* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::startDrag):
(WebKit::WebViewImpl::dragImageForView): Deleted.

Rename dragImageForView to startDrag. Move the call to didStartDrag() here, and call dragCancelled() in the
case where we bailed from starting the drag (due to failing to create a drag image).

* UIProcess/PageClient.h:
* UIProcess/ios/PageClientImplIOS.h:
* UIProcess/ios/PageClientImplIOS.mm:
(WebKit::PageClientImpl::setDragImage): Deleted.

Rename setDragImage to startDrag.

* UIProcess/mac/PageClientImplMac.h:
* UIProcess/mac/PageClientImplMac.mm:
(WebKit::PageClientImpl::startDrag):
(WebKit::PageClientImpl::setDragImage): Deleted.
* UIProcess/mac/WebPageProxyMac.mm:
(WebKit::WebPageProxy::startDrag): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (226898 => 226899)


--- trunk/Source/WebKit/ChangeLog	2018-01-12 18:30:06 UTC (rev 226898)
+++ trunk/Source/WebKit/ChangeLog	2018-01-12 18:49:11 UTC (rev 226899)
@@ -1,3 +1,42 @@
+2018-01-12  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        [WK2] Unify macOS and iOS codepaths in the UI process when starting a drag
+        https://bugs.webkit.org/show_bug.cgi?id=181574
+
+        Reviewed by Tim Horton.
+
+        Rearrange some macOS drag start logic in the UI process so that it uses the same codepaths in WebPageProxy as
+        iOS. Namely, startDrag should just forward the DragItem and drag image handle along to the appropriate views on
+        each platform (WKContentView and WebViewImpl).
+
+        There should be no change in behavior.
+
+        * UIProcess/Cocoa/WebPageProxyCocoa.mm:
+
+        Both macOS and iOS now funnel through this method.
+
+        * UIProcess/Cocoa/WebViewImpl.h:
+        * UIProcess/Cocoa/WebViewImpl.mm:
+        (WebKit::WebViewImpl::startDrag):
+        (WebKit::WebViewImpl::dragImageForView): Deleted.
+
+        Rename dragImageForView to startDrag. Move the call to didStartDrag() here, and call dragCancelled() in the
+        case where we bailed from starting the drag (due to failing to create a drag image).
+
+        * UIProcess/PageClient.h:
+        * UIProcess/ios/PageClientImplIOS.h:
+        * UIProcess/ios/PageClientImplIOS.mm:
+        (WebKit::PageClientImpl::setDragImage): Deleted.
+
+        Rename setDragImage to startDrag.
+
+        * UIProcess/mac/PageClientImplMac.h:
+        * UIProcess/mac/PageClientImplMac.mm:
+        (WebKit::PageClientImpl::startDrag):
+        (WebKit::PageClientImpl::setDragImage): Deleted.
+        * UIProcess/mac/WebPageProxyMac.mm:
+        (WebKit::WebPageProxy::startDrag): Deleted.
+
 2018-01-12  Antoine Quint  <grao...@apple.com>
 
         Add support for the frames() timing function

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm (226898 => 226899)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm	2018-01-12 18:30:06 UTC (rev 226898)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm	2018-01-12 18:49:11 UTC (rev 226899)
@@ -103,7 +103,7 @@
     }
 }
 
-#if PLATFORM(IOS) && ENABLE(DRAG_SUPPORT)
+#if ENABLE(DRAG_SUPPORT)
 
 void WebPageProxy::startDrag(const DragItem& dragItem, const ShareableBitmap::Handle& dragImageHandle)
 {
@@ -110,6 +110,8 @@
     m_pageClient.startDrag(dragItem, dragImageHandle);
 }
 
+#if PLATFORM(IOS)
+
 void WebPageProxy::setPromisedDataForImage(const String&, const SharedMemory::Handle&, uint64_t, const String&, const String&, const String&, const String&, const String&, const SharedMemory::Handle&, uint64_t)
 {
     notImplemented();
@@ -125,6 +127,8 @@
     m_pageClient.didChangeDataInteractionCaretRect(previousRect, dragCaretRect);
 }
 
-#endif // PLATFORM(IOS) && ENABLE(DRAG_SUPPORT)
+#endif // PLATFORM(IOS)
 
+#endif // ENABLE(DRAG_SUPPORT)
+
 }

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h (226898 => 226899)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h	2018-01-12 18:30:06 UTC (rev 226898)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h	2018-01-12 18:49:11 UTC (rev 226899)
@@ -33,7 +33,6 @@
 #include "WeakObjCPtr.h"
 #include "WebPageProxy.h"
 #include "_WKOverlayScrollbarStyle.h"
-#include <WebCore/PromisedBlobInfo.h>
 #include <WebCore/TextIndicatorWindow.h>
 #include <WebCore/UserInterfaceLayoutDirection.h>
 #include <pal/spi/cocoa/AVKitSPI.h>
@@ -108,6 +107,7 @@
 @end
 
 namespace WebCore {
+struct DragItem;
 struct KeyPressCommand;
 }
 
@@ -413,7 +413,7 @@
 
     void startWindowDrag();
 
-    void dragImageForView(NSView *, NSImage *, CGPoint clientPoint, bool linkDrag);
+    void startDrag(const WebCore::DragItem&, const ShareableBitmap::Handle& image);
     void setFileAndURLTypes(NSString *filename, NSString *extension, NSString *title, NSString *url, NSString *visibleURL, NSPasteboard *);
     void setPromisedDataForImage(WebCore::Image*, NSString *filename, NSString *extension, NSString *title, NSString *url, NSString *visibleURL, WebCore::SharedBuffer* archiveBuffer, NSString *pasteboardName);
     void pasteboardChangedOwner(NSPasteboard *);

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm (226898 => 226899)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm	2018-01-12 18:30:06 UTC (rev 226898)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm	2018-01-12 18:49:11 UTC (rev 226899)
@@ -73,6 +73,7 @@
 #import <WebCore/ColorMac.h>
 #import <WebCore/DictionaryLookup.h>
 #import <WebCore/DragData.h>
+#import <WebCore/DragItem.h>
 #import <WebCore/Editor.h>
 #import <WebCore/KeypressCommand.h>
 #import <WebCore/LegacyNSPasteboardTypes.h>
@@ -3776,8 +3777,21 @@
     [[m_view window] performWindowDragWithEvent:m_lastMouseDownEvent.get()];
 }
 
-void WebViewImpl::dragImageForView(NSView *view, NSImage *image, CGPoint clientPoint, bool)
+void WebViewImpl::startDrag(const WebCore::DragItem& item, const ShareableBitmap::Handle& dragImageHandle)
 {
+    auto dragImageAsBitmap = ShareableBitmap::create(dragImageHandle);
+    if (!dragImageAsBitmap) {
+        m_page->dragCancelled();
+        return;
+    }
+
+    auto dragCGImage = dragImageAsBitmap->makeCGImage();
+    auto dragNSImage = adoptNS([[NSImage alloc] initWithCGImage:dragCGImage.get() size:dragImageAsBitmap->size()]);
+
+    WebCore::IntSize size([dragNSImage size]);
+    size.scale(1.0 / m_page->deviceScaleFactor());
+    [dragNSImage setSize:size];
+
     // The call below could release the view.
     auto protector = m_view.get();
 #pragma clang diagnostic push
@@ -3787,14 +3801,9 @@
     [pasteboard setString:@"" forType:PasteboardTypes::WebDummyPboardType];
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
-    [view dragImage:image
-                 at:NSPointFromCGPoint(clientPoint)
-             offset:NSZeroSize
-              event:m_lastMouseDownEvent.get()
-         pasteboard:pasteboard
-             source:m_view.getAutoreleased()
-          slideBack:YES];
+    [m_view dragImage:dragNSImage.get() at:NSPointFromCGPoint(item.dragLocationInWindowCoordinates) offset:NSZeroSize event:m_lastMouseDownEvent.get() pasteboard:pasteboard source:m_view.getAutoreleased() slideBack:YES];
 #pragma clang diagnostic pop
+    m_page->didStartDrag();
 }
 
 static bool matchesExtensionOrEquivalent(const String& filename, const String& extension)

Modified: trunk/Source/WebKit/UIProcess/PageClient.h (226898 => 226899)


--- trunk/Source/WebKit/UIProcess/PageClient.h	2018-01-12 18:30:06 UTC (rev 226898)
+++ trunk/Source/WebKit/UIProcess/PageClient.h	2018-01-12 18:49:11 UTC (rev 226899)
@@ -172,7 +172,7 @@
 #if PLATFORM(COCOA)
     virtual void accessibilityWebProcessTokenReceived(const IPC::DataReference&) = 0;
     virtual bool executeSavedCommandBySelector(const String& selector) = 0;
-    virtual void setDragImage(const WebCore::IntPoint& clientPosition, Ref<ShareableBitmap>&& dragImage, WebCore::DragSourceAction) = 0;
+    virtual void startDrag(const WebCore::DragItem&, const ShareableBitmap::Handle& image) = 0;
     virtual void updateSecureInputState() = 0;
     virtual void resetSecureInputState() = 0;
     virtual void notifyInputContextAboutDiscardedComposition() = 0;
@@ -375,7 +375,6 @@
     virtual void didPerformDataInteractionControllerOperation(bool handled) = 0;
     virtual void didHandleStartDataInteractionRequest(bool started) = 0;
     virtual void didHandleAdditionalDragItemsRequest(bool added) = 0;
-    virtual void startDrag(const WebCore::DragItem&, const ShareableBitmap::Handle& image) = 0;
     virtual void didConcludeEditDataInteraction(std::optional<WebCore::TextIndicatorData>) = 0;
     virtual void didChangeDataInteractionCaretRect(const WebCore::IntRect& previousCaretRect, const WebCore::IntRect& caretRect) = 0;
 #endif

Modified: trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.h (226898 => 226899)


--- trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.h	2018-01-12 18:30:06 UTC (rev 226898)
+++ trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.h	2018-01-12 18:49:11 UTC (rev 226899)
@@ -82,7 +82,6 @@
     void executeUndoRedo(WebPageProxy::UndoOrRedo) override;
     void accessibilityWebProcessTokenReceived(const IPC::DataReference&) override;
     bool executeSavedCommandBySelector(const String& selector) override;
-    void setDragImage(const WebCore::IntPoint& clientPosition, Ref<ShareableBitmap>&& dragImage, WebCore::DragSourceAction) override;
     void updateSecureInputState() override;
     void resetSecureInputState() override;
     void notifyInputContextAboutDiscardedComposition() override;

Modified: trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm (226898 => 226899)


--- trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm	2018-01-12 18:30:06 UTC (rev 226898)
+++ trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm	2018-01-12 18:49:11 UTC (rev 226899)
@@ -363,11 +363,6 @@
     return false;
 }
 
-void PageClientImpl::setDragImage(const IntPoint&, Ref<ShareableBitmap>&&, DragSourceAction)
-{
-    notImplemented();
-}
-
 void PageClientImpl::selectionDidChange()
 {
     [m_contentView _selectionChanged];

Modified: trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.h (226898 => 226899)


--- trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.h	2018-01-12 18:30:06 UTC (rev 226898)
+++ trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.h	2018-01-12 18:49:11 UTC (rev 226899)
@@ -37,6 +37,7 @@
 
 namespace WebCore {
 class AlternativeTextUIController;
+struct DragItem;
 struct PromisedBlobInfo;
 }
 
@@ -95,7 +96,7 @@
     bool canUndoRedo(WebPageProxy::UndoOrRedo) override;
     void executeUndoRedo(WebPageProxy::UndoOrRedo) override;
     bool executeSavedCommandBySelector(const String& selector) override;
-    void setDragImage(const WebCore::IntPoint& clientPosition, Ref<ShareableBitmap>&& dragImage, WebCore::DragSourceAction) override;
+    void startDrag(const WebCore::DragItem&, const ShareableBitmap::Handle& image) override;
     void setPromisedDataForImage(const String& pasteboardName, Ref<WebCore::SharedBuffer>&& imageBuffer, const String& filename, const String& extension, const String& title,
         const String& url, const String& visibleUrl, RefPtr<WebCore::SharedBuffer>&& archiveBuffer) override;
     void updateSecureInputState() override;

Modified: trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.mm (226898 => 226899)


--- trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.mm	2018-01-12 18:30:06 UTC (rev 226898)
+++ trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.mm	2018-01-12 18:49:11 UTC (rev 226899)
@@ -59,6 +59,7 @@
 #import <WebCore/BitmapImage.h>
 #import <WebCore/Cursor.h>
 #import <WebCore/DictionaryLookup.h>
+#import <WebCore/DragItem.h>
 #import <WebCore/FloatRect.h>
 #import <WebCore/GraphicsContext.h>
 #import <WebCore/Image.h>
@@ -347,15 +348,9 @@
     return (undoOrRedo == WebPageProxy::Undo) ? [[m_view undoManager] undo] : [[m_view undoManager] redo];
 }
 
-void PageClientImpl::setDragImage(const IntPoint& clientPosition, Ref<ShareableBitmap>&& dragImage, DragSourceAction action)
+void PageClientImpl::startDrag(const WebCore::DragItem& item, const ShareableBitmap::Handle& image)
 {
-    RetainPtr<CGImageRef> dragCGImage = dragImage->makeCGImage();
-    RetainPtr<NSImage> dragNSImage = adoptNS([[NSImage alloc] initWithCGImage:dragCGImage.get() size:dragImage->size()]);
-    IntSize size([dragNSImage size]);
-    size.scale(1.0 / m_impl->page().deviceScaleFactor());
-    [dragNSImage setSize:size];
-
-    m_impl->dragImageForView(m_view, dragNSImage.get(), clientPosition, action == DragSourceActionLink);
+    m_impl->startDrag(item, image);
 }
 
 void PageClientImpl::setPromisedDataForImage(const String& pasteboardName, Ref<SharedBuffer>&& imageBuffer, const String& filename, const String& extension, const String& title, const String& url, const String& visibleURL, RefPtr<SharedBuffer>&& archiveBuffer)

Modified: trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm (226898 => 226899)


--- trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm	2018-01-12 18:30:06 UTC (rev 226898)
+++ trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm	2018-01-12 18:49:11 UTC (rev 226899)
@@ -266,14 +266,7 @@
 #endif
 
 #if ENABLE(DRAG_SUPPORT)
-void WebPageProxy::startDrag(const DragItem& dragItem, const ShareableBitmap::Handle& dragImageHandle)
-{
-    if (auto dragImage = ShareableBitmap::create(dragImageHandle))
-        m_pageClient.setDragImage(dragItem.dragLocationInWindowCoordinates, dragImage.releaseNonNull(), static_cast<DragSourceAction>(dragItem.sourceAction));
 
-    didStartDrag();
-}
-
 void WebPageProxy::setPromisedDataForImage(const String& pasteboardName, const SharedMemory::Handle& imageHandle, uint64_t imageSize, const String& filename, const String& extension,
                                    const String& title, const String& url, const String& visibleURL, const SharedMemory::Handle& archiveHandle, uint64_t archiveSize)
 {
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to