[WK2] Unify macOS and iOS codepaths in the UI process when starting a drag
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 12 Jan 2018 18:49:11 +0000 (18:49 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 12 Jan 2018 18:49:11 +0000 (18:49 +0000)
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.

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

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm
Source/WebKit/UIProcess/Cocoa/WebViewImpl.h
Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm
Source/WebKit/UIProcess/PageClient.h
Source/WebKit/UIProcess/ios/PageClientImplIOS.h
Source/WebKit/UIProcess/ios/PageClientImplIOS.mm
Source/WebKit/UIProcess/mac/PageClientImplMac.h
Source/WebKit/UIProcess/mac/PageClientImplMac.mm
Source/WebKit/UIProcess/mac/WebPageProxyMac.mm

index 3d9beb5..56e454f 100644 (file)
@@ -1,3 +1,42 @@
+2018-01-12  Wenson Hsieh  <wenson_hsieh@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  <graouts@apple.com>
 
         Add support for the frames() timing function
index f053a81..0d6fc1c 100644 (file)
@@ -103,13 +103,15 @@ void WebPageProxy::createSandboxExtensionsIfNeeded(const Vector<String>& files,
     }
 }
 
-#if PLATFORM(IOS) && ENABLE(DRAG_SUPPORT)
+#if ENABLE(DRAG_SUPPORT)
 
 void WebPageProxy::startDrag(const DragItem& dragItem, const ShareableBitmap::Handle& dragImageHandle)
 {
     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 @@ void WebPageProxy::setDragCaretRect(const IntRect& dragCaretRect)
     m_pageClient.didChangeDataInteractionCaretRect(previousRect, dragCaretRect);
 }
 
-#endif // PLATFORM(IOS) && ENABLE(DRAG_SUPPORT)
+#endif // PLATFORM(IOS)
+
+#endif // ENABLE(DRAG_SUPPORT)
 
 }
index b093c92..b3780a7 100644 (file)
@@ -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 @@ OBJC_CLASS WebPlaybackControlsManager;
 @end
 
 namespace WebCore {
+struct DragItem;
 struct KeyPressCommand;
 }
 
@@ -413,7 +413,7 @@ public:
 
     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 *);
index 4d2518c..84b856e 100644 (file)
@@ -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 @@ void WebViewImpl::startWindowDrag()
     [[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 @@ void WebViewImpl::dragImageForView(NSView *view, NSImage *image, CGPoint clientP
     [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)
index 51e9c01..02fe24d 100644 (file)
@@ -172,7 +172,7 @@ public:
 #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 @@ public:
     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
index a89cbeb..f1483d2 100644 (file)
@@ -82,7 +82,6 @@ private:
     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;
index 0aa15ea..4596f51 100644 (file)
@@ -363,11 +363,6 @@ bool PageClientImpl::executeSavedCommandBySelector(const String&)
     return false;
 }
 
-void PageClientImpl::setDragImage(const IntPoint&, Ref<ShareableBitmap>&&, DragSourceAction)
-{
-    notImplemented();
-}
-
 void PageClientImpl::selectionDidChange()
 {
     [m_contentView _selectionChanged];
index bb3df12..7878c68 100644 (file)
@@ -37,6 +37,7 @@
 
 namespace WebCore {
 class AlternativeTextUIController;
+struct DragItem;
 struct PromisedBlobInfo;
 }
 
@@ -95,7 +96,7 @@ private:
     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;
index ca58cf1..f0ce181 100644 (file)
@@ -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 @@ void PageClientImpl::executeUndoRedo(WebPageProxy::UndoOrRedo undoOrRedo)
     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)
index 20f9b42..684ffaa 100644 (file)
@@ -266,13 +266,6 @@ void WebPageProxy::replaceSelectionWithPasteboardData(const Vector<String>& type
 #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)