Changeset 218837 in webkit


Ignore:
Timestamp:
Jun 27, 2017 12:11:34 PM (7 years ago)
Author:
Wenson Hsieh
Message:

Refactor drag start codepaths to plumb a DragItem to client layers
https://bugs.webkit.org/show_bug.cgi?id=173832
Work towards <rdar://problem/32236827>

Reviewed by Ryosuke Niwa and Tim Horton.

Source/WebCore:

Refactor drag start logic in WebCore to set up a DragItem and propagate it to WebDragClient. No change in behavior.

  • loader/EmptyClients.cpp:
  • page/DragClient.h:
  • page/DragController.cpp:

(WebCore::DragController::startDrag):
(WebCore::DragController::doImageDrag):
(WebCore::DragController::doSystemDrag):

Refactor to pass along a DragItem. Also, remove unused drag image anchor computation.

  • page/DragController.h:
  • platform/DragImage.h:
  • platform/DragItem.h:

Add additional information needed to begin a drag on iOS.

(WebCore::DragItem::encode):
(WebCore::DragItem::decode):

Add IPC serialization/deserialization support for DragItem.

  • platform/PasteboardWriterData.cpp:

(WebCore::PasteboardWriterData::isEmpty):

  • platform/PasteboardWriterData.h:

Source/WebKit/mac:

Refactor code used to start a drag in WebKit1 to plumb a single DragItem from DragController to the client layer
in WebDragClient that contains all the information needed to begin a drag. Also renames _setDataInteractionData:
to _startDrag: to match logic used to start a drag on other platforms.

No behavior change -- the same information should be propagated to AppKit and UIKit when beginning a drag, only
through the DragItem struct.

  • WebCoreSupport/WebDragClient.h:
  • WebCoreSupport/WebDragClient.mm:

(WebDragClient::startDrag):
(WebDragClient::dragSourceActionMaskForPoint):
(WebDragClient::willPerformDragSourceAction):
(WebDragClient::beginDrag):

  • WebView/WebView.mm:

(-[WebView _startDrag:]):
(-[WebView _setDataInteractionData:textIndicator:atClientPosition:anchorPoint:action:]): Deleted.

  • WebView/WebViewInternal.h:

Source/WebKit/win:

Adjust for changes to WebDragClient::startDrag by pulling information out of DragItem.

  • WebCoreSupport/WebDragClient.cpp:

(WebDragClient::startDrag):

  • WebCoreSupport/WebDragClient.h:

Source/WebKit2:

Add support for serializing a DragItem over IPC. This encodes and decodes all members of DragItem except for the
PasteboardWriterData and the DragImage's image. The DragItem is sent over to the UI process in
WebDragClient::startDrag via the WebPageProxy::startDrag IPC message (renamed from WebPageProxy::setDragImage)
which now takes a DragItem.

  • UIProcess/Cocoa/WebPageProxyCocoa.mm:

(WebKit::WebPageProxy::startDrag):
(WebKit::WebPageProxy::setDragImage): Deleted.

  • UIProcess/PageClient.h:
  • UIProcess/WebPageProxy.h:
  • UIProcess/WebPageProxy.messages.in:

Rename SetDragImage to StartDrag and refactor to receive only a DragItem and shareable bitmap handle.

  • UIProcess/ios/PageClientImplIOS.h:
  • UIProcess/ios/PageClientImplIOS.mm:

(WebKit::PageClientImpl::startDrag):
(WebKit::PageClientImpl::startDataInteractionWithImage): Deleted.

  • UIProcess/ios/WKContentViewInteraction.h:
  • UIProcess/ios/WKContentViewInteraction.mm:

(-[WKContentView _startDrag:item:]):
(-[WKContentView _startDataInteractionWithImage:withIndicatorData:atClientPosition:anchorPoint:action:]): Deleted.

Rename startDataInteractionWithImage to startDrag.

  • UIProcess/mac/WebPageProxyMac.mm:

(WebKit::WebPageProxy::startDrag):
(WebKit::WebPageProxy::setDragImage): Deleted.

  • WebProcess/WebCoreSupport/WebDragClient.cpp:

(WebKit::WebDragClient::startDrag):

  • WebProcess/WebCoreSupport/WebDragClient.h:
  • WebProcess/WebCoreSupport/gtk/WebDragClientGtk.cpp:

(WebKit::WebDragClient::startDrag):

  • WebProcess/WebCoreSupport/mac/WebDragClientMac.mm:

(WebKit::WebDragClient::startDrag):

Location:
trunk/Source
Files:
31 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r218835 r218837  
     12017-06-27  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Refactor drag start codepaths to plumb a DragItem to client layers
     4        https://bugs.webkit.org/show_bug.cgi?id=173832
     5        Work towards <rdar://problem/32236827>
     6
     7        Reviewed by Ryosuke Niwa and Tim Horton.
     8
     9        Refactor drag start logic in WebCore to set up a DragItem and propagate it to WebDragClient. No change in behavior.
     10
     11        * loader/EmptyClients.cpp:
     12        * page/DragClient.h:
     13        * page/DragController.cpp:
     14        (WebCore::DragController::startDrag):
     15        (WebCore::DragController::doImageDrag):
     16        (WebCore::DragController::doSystemDrag):
     17
     18        Refactor to pass along a DragItem. Also, remove unused drag image anchor computation.
     19
     20        * page/DragController.h:
     21        * platform/DragImage.h:
     22        * platform/DragItem.h:
     23
     24        Add additional information needed to begin a drag on iOS.
     25
     26        (WebCore::DragItem::encode):
     27        (WebCore::DragItem::decode):
     28
     29        Add IPC serialization/deserialization support for DragItem.
     30
     31        * platform/PasteboardWriterData.cpp:
     32        (WebCore::PasteboardWriterData::isEmpty):
     33        * platform/PasteboardWriterData.h:
     34
    1352017-06-27  Frederic Wang  <fwang@igalia.com>
    236
  • trunk/Source/WebCore/loader/EmptyClients.cpp

    r218501 r218837  
    132132    void willPerformDragSourceAction(DragSourceAction, const IntPoint&, DataTransfer&) final { }
    133133    DragSourceAction dragSourceActionMaskForPoint(const IntPoint&) final { return DragSourceActionNone; }
    134     void startDrag(DragImage, const IntPoint&, const IntPoint&, const FloatPoint&, DataTransfer&, Frame&, DragSourceAction) final { }
     134    void startDrag(DragItem, DataTransfer&, Frame&) final { }
    135135    void dragControllerDestroyed() final { }
    136136};
  • trunk/Source/WebCore/page/DragClient.h

    r214403 r218837  
    5050    virtual DragSourceAction dragSourceActionMaskForPoint(const IntPoint& rootViewPoint) = 0;
    5151   
    52     virtual void startDrag(DragImage, const IntPoint& dragImageOrigin, const IntPoint& eventPos, const FloatPoint& dragImageAnchor, DataTransfer&, Frame&, DragSourceAction) = 0;
     52    virtual void startDrag(DragItem, DataTransfer&, Frame&) = 0;
    5353    virtual void dragEnded() { }
    5454
  • trunk/Source/WebCore/page/DragController.cpp

    r218611 r218837  
    4444#include "Editor.h"
    4545#include "EditorClient.h"
     46#include "ElementAncestorIterator.h"
    4647#include "EventHandler.h"
    4748#include "FloatRect.h"
     
    5354#include "HTMLImageElement.h"
    5455#include "HTMLInputElement.h"
     56#include "HTMLParserIdioms.h"
    5557#include "HTMLPlugInElement.h"
    5658#include "HitTestRequest.h"
     
    964966
    965967        if (mustUseLegacyDragClient) {
    966             doSystemDrag(WTFMove(dragImage), dragLoc, dragOrigin, dragImageBounds, dataTransfer, src, DragSourceActionSelection);
     968            doSystemDrag(WTFMove(dragImage), dragLoc, dragOrigin, src, state);
    967969            return true;
    968970        }
     
    997999
    9981000        if (!dragImage)
    999             doImageDrag(element, dragOrigin, hitTestResult.imageRect(), dataTransfer, src, m_dragOffset);
     1001            doImageDrag(element, dragOrigin, hitTestResult.imageRect(), src, m_dragOffset, state);
    10001002        else {
    10011003            // DHTML defined drag image
    1002             doSystemDrag(WTFMove(dragImage), dragLoc, dragOrigin, { }, dataTransfer, src, DragSourceActionImage);
     1004            doSystemDrag(WTFMove(dragImage), dragLoc, dragOrigin, src, state);
    10031005        }
    10041006
     
    10521054
    10531055        if (mustUseLegacyDragClient) {
    1054             doSystemDrag(WTFMove(dragImage), dragLoc, dragOrigin, { }, dataTransfer, src, DragSourceActionLink);
     1056            doSystemDrag(WTFMove(dragImage), dragLoc, dragOrigin, src, state);
    10551057            return true;
    10561058        }
     
    11031105            m_dragOffset = IntPoint(dragOrigin.x() - dragLoc.x(), dragOrigin.y() - dragLoc.y());
    11041106        }
    1105         doSystemDrag(WTFMove(dragImage), dragLoc, dragOrigin, { }, dataTransfer, src, DragSourceActionAttachment);
     1107        doSystemDrag(WTFMove(dragImage), dragLoc, dragOrigin, src, state);
    11061108        src.selection().setSelection(previousSelection);
    11071109        src.editor().setIgnoreSelectionChanges(false);
     
    11131115        ASSERT(m_dragSourceAction & DragSourceActionDHTML);
    11141116        m_client.willPerformDragSourceAction(DragSourceActionDHTML, dragOrigin, dataTransfer);
    1115         doSystemDrag(WTFMove(dragImage), dragLoc, dragOrigin, { }, dataTransfer, src, DragSourceActionDHTML);
     1117        doSystemDrag(WTFMove(dragImage), dragLoc, dragOrigin, src, state);
    11161118        return true;
    11171119    }
     
    11201122}
    11211123
    1122 void DragController::doImageDrag(Element& element, const IntPoint& dragOrigin, const IntRect& layoutRect, DataTransfer& dataTransfer, Frame& frame, IntPoint& dragImageOffset)
     1124void DragController::doImageDrag(Element& element, const IntPoint& dragOrigin, const IntRect& layoutRect, Frame& frame, IntPoint& dragImageOffset, const DragState& state)
    11231125{
    11241126    IntPoint mouseDownPoint = dragOrigin;
     
    11611163
    11621164    dragImageOffset = mouseDownPoint + scaledOrigin;
    1163     doSystemDrag(WTFMove(dragImage), dragImageOffset, dragOrigin, element.boundsInRootViewSpace(), dataTransfer, frame, DragSourceActionImage);
     1165    doSystemDrag(WTFMove(dragImage), dragImageOffset, dragOrigin, frame, state);
    11641166}
    11651167
     
    11881190}
    11891191
    1190 void DragController::doSystemDrag(DragImage image, const IntPoint& dragLoc, const IntPoint& eventPos, const IntRect& dragImageBounds, DataTransfer& dataTransfer, Frame& frame, DragSourceAction dragSourceAction)
    1191 {
    1192     FloatPoint dragImageAnchor = { 0.5, 0.5 };
    1193     if (dragSourceAction == DragSourceActionLink)
    1194         dragImageAnchor.setY(1);
    1195     else if (!dragImageBounds.isEmpty()) {
    1196         dragImageAnchor.setX((eventPos.x() - dragImageBounds.x()) / (float)dragImageBounds.width());
    1197         dragImageAnchor.setY((eventPos.y() - dragImageBounds.y()) / (float)dragImageBounds.height());
    1198     }
    1199 
     1192void DragController::doSystemDrag(DragImage image, const IntPoint& dragLoc, const IntPoint& eventPos, Frame& frame, const DragState& state)
     1193{
    12001194    m_didInitiateDrag = true;
    12011195    m_dragInitiator = frame.document();
     
    12031197    Ref<MainFrame> frameProtector(m_page.mainFrame());
    12041198    RefPtr<FrameView> viewProtector = frameProtector->view();
    1205     m_client.startDrag(WTFMove(image), viewProtector->rootViewToContents(frame.view()->contentsToRootView(dragLoc)), viewProtector->rootViewToContents(frame.view()->contentsToRootView(eventPos)), dragImageAnchor, dataTransfer, frameProtector.get(), dragSourceAction);
     1199
     1200    DragItem item;
     1201    item.image = WTFMove(image);
     1202    item.sourceAction = state.type;
     1203    item.eventPositionInContentCoordinates = viewProtector->rootViewToContents(frame.view()->contentsToRootView(eventPos));
     1204    item.dragLocationInContentCoordinates = viewProtector->rootViewToContents(frame.view()->contentsToRootView(dragLoc));
     1205    item.eventPositionInWindowCoordinates = frame.view()->contentsToWindow(item.eventPositionInContentCoordinates);
     1206    item.dragLocationInWindowCoordinates = frame.view()->contentsToWindow(item.dragLocationInContentCoordinates);
     1207    if (auto element = state.source) {
     1208        item.elementBounds = element->boundsInRootViewSpace();
     1209        RefPtr<Element> link;
     1210        if (element->isLink())
     1211            link = element;
     1212        else {
     1213            for (auto& currentElement : elementLineage(element.get())) {
     1214                if (currentElement.isLink()) {
     1215                    link = &currentElement;
     1216                    break;
     1217                }
     1218            }
     1219        }
     1220        if (link) {
     1221            auto titleAttribute = link->attributeWithoutSynchronization(HTMLNames::titleAttr);
     1222            item.title = titleAttribute.isEmpty() ? link->innerText() : titleAttribute.string();
     1223            item.url = frame.document()->completeURL(stripLeadingAndTrailingHTMLSpaces(link->getAttribute(HTMLNames::hrefAttr)));
     1224        }
     1225    }
     1226    m_client.startDrag(WTFMove(item), *state.dataTransfer, frameProtector.get());
    12061227    // DragClient::startDrag can cause our Page to dispear, deallocating |this|.
    12071228    if (!frameProtector->page())
  • trunk/Source/WebCore/page/DragController.h

    r218343 r218837  
    116116        bool shouldUseCachedImageForDragImage(const Image&) const;
    117117
    118         void doImageDrag(Element&, const IntPoint&, const IntRect&, DataTransfer&, Frame&, IntPoint&);
    119         void doSystemDrag(DragImage, const IntPoint&, const IntPoint&, const IntRect& dragImageBounds, DataTransfer&, Frame&, DragSourceAction);
     118        void doImageDrag(Element&, const IntPoint&, const IntRect&, Frame&, IntPoint&, const DragState&);
     119        void doSystemDrag(DragImage, const IntPoint&, const IntPoint&, Frame&, const DragState&);
    120120
    121121        void beginDrag(DragItem, Frame&, const IntPoint& mouseDownPoint, const IntPoint& mouseDraggedPoint, DataTransfer&, DragSourceAction);
  • trunk/Source/WebCore/platform/DragImage.h

    r217727 r218837  
    9898class DragImage final {
    9999public:
    100     DragImage();
     100    WEBCORE_EXPORT DragImage();
    101101    explicit DragImage(DragImageRef);
    102102    DragImage(DragImage&&);
    103     ~DragImage();
     103    WEBCORE_EXPORT ~DragImage();
    104104
    105105    DragImage& operator=(DragImage&&);
  • trunk/Source/WebCore/platform/DragItem.h

    r212663 r218837  
    2828#include "DragImage.h"
    2929#include "FloatPoint.h"
     30#include "IntPoint.h"
     31#include "IntRect.h"
    3032#include "PasteboardWriterData.h"
    3133
     
    3840    FloatPoint imageAnchorPoint;
    3941
     42    DragSourceAction sourceAction { DragSourceActionNone };
     43    IntPoint eventPositionInContentCoordinates;
     44    IntPoint dragLocationInContentCoordinates;
     45    IntPoint eventPositionInWindowCoordinates;
     46    IntPoint dragLocationInWindowCoordinates;
     47    String title;
     48    URL url;
     49    IntRect elementBounds;
     50
    4051    PasteboardWriterData data;
     52
     53    template<class Encoder> void encode(Encoder&) const;
     54    template<class Decoder> static bool decode(Decoder&, DragItem&);
    4155};
    4256
     57template<class Encoder>
     58void DragItem::encode(Encoder& encoder) const
     59{
     60    // FIXME(173815): We should encode and decode PasteboardWriterData and platform drag image data
     61    // here too, as part of moving off of the legacy dragging codepath.
     62    encoder.encodeEnum(sourceAction);
     63    encoder << imageAnchorPoint << eventPositionInContentCoordinates << dragLocationInContentCoordinates << eventPositionInWindowCoordinates << dragLocationInWindowCoordinates << title << url << elementBounds;
     64    bool hasIndicatorData = image.hasIndicatorData();
     65    encoder << hasIndicatorData;
     66    if (hasIndicatorData)
     67        encoder << image.indicatorData().value();
    4368}
     69
     70template<class Decoder>
     71bool DragItem::decode(Decoder& decoder, DragItem& result)
     72{
     73    if (!decoder.decodeEnum(result.sourceAction))
     74        return false;
     75    if (!decoder.decode(result.imageAnchorPoint))
     76        return false;
     77    if (!decoder.decode(result.eventPositionInContentCoordinates))
     78        return false;
     79    if (!decoder.decode(result.dragLocationInContentCoordinates))
     80        return false;
     81    if (!decoder.decode(result.eventPositionInWindowCoordinates))
     82        return false;
     83    if (!decoder.decode(result.dragLocationInWindowCoordinates))
     84        return false;
     85    if (!decoder.decode(result.title))
     86        return false;
     87    if (!decoder.decode(result.url))
     88        return false;
     89    if (!decoder.decode(result.elementBounds))
     90        return false;
     91    bool hasIndicatorData;
     92    if (!decoder.decode(hasIndicatorData))
     93        return false;
     94    if (hasIndicatorData) {
     95        TextIndicatorData indicatorData;
     96        if (!decoder.decode(indicatorData))
     97            return false;
     98        result.image.setIndicatorData(indicatorData);
     99    }
     100    return true;
     101}
     102
     103}
  • trunk/Source/WebCore/platform/PasteboardWriterData.cpp

    r213597 r218837  
    4949bool PasteboardWriterData::isEmpty() const
    5050{
    51     if (m_plainText)
    52         return false;
    53 
    54     if (m_url)
    55         return false;
    56 
    57     return true;
     51    return !m_plainText && !m_url && !m_webContent;
    5852}
    5953
  • trunk/Source/WebCore/platform/PasteboardWriterData.h

    r214865 r218837  
    3636class PasteboardWriterData final {
    3737public:
    38     PasteboardWriterData();
    39     ~PasteboardWriterData();
     38    WEBCORE_EXPORT PasteboardWriterData();
     39    WEBCORE_EXPORT ~PasteboardWriterData();
    4040
    4141    WEBCORE_EXPORT bool isEmpty() const;
  • trunk/Source/WebKit/mac/ChangeLog

    r218794 r218837  
     12017-06-27  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Refactor drag start codepaths to plumb a DragItem to client layers
     4        https://bugs.webkit.org/show_bug.cgi?id=173832
     5        Work towards <rdar://problem/32236827>
     6
     7        Reviewed by Ryosuke Niwa and Tim Horton.
     8
     9        Refactor code used to start a drag in WebKit1 to plumb a single DragItem from DragController to the client layer
     10        in WebDragClient that contains all the information needed to begin a drag. Also renames _setDataInteractionData:
     11        to _startDrag: to match logic used to start a drag on other platforms.
     12
     13        No behavior change -- the same information should be propagated to AppKit and UIKit when beginning a drag, only
     14        through the DragItem struct.
     15
     16        * WebCoreSupport/WebDragClient.h:
     17        * WebCoreSupport/WebDragClient.mm:
     18        (WebDragClient::startDrag):
     19        (WebDragClient::dragSourceActionMaskForPoint):
     20        (WebDragClient::willPerformDragSourceAction):
     21        (WebDragClient::beginDrag):
     22        * WebView/WebView.mm:
     23        (-[WebView _startDrag:]):
     24        (-[WebView _setDataInteractionData:textIndicator:atClientPosition:anchorPoint:action:]): Deleted.
     25        * WebView/WebViewInternal.h:
     26
    1272017-06-25  Konstantin Tokarev  <annulen@yandex.ru>
    228
  • trunk/Source/WebKit/mac/WebCoreSupport/WebDragClient.h

    r214403 r218837  
    4040    void dragControllerDestroyed() override;
    4141    WebCore::DragSourceAction dragSourceActionMaskForPoint(const WebCore::IntPoint& windowPoint) override;
    42     void startDrag(WebCore::DragImage, const WebCore::IntPoint& dragPos, const WebCore::IntPoint& eventPos, const WebCore::FloatPoint&, WebCore::DataTransfer&, WebCore::Frame&, WebCore::DragSourceAction) override;
     42    void startDrag(WebCore::DragItem, WebCore::DataTransfer&, WebCore::Frame&) override;
    4343
    4444    void beginDrag(WebCore::DragItem, WebCore::Frame&, const WebCore::IntPoint& mouseDownPosition, const WebCore::IntPoint& mouseDraggedPosition, WebCore::DataTransfer&, WebCore::DragSourceAction) override;
  • trunk/Source/WebKit/mac/WebCoreSupport/WebDragClient.mm

    r218433 r218837  
    5151#import <WebCore/EditorClient.h>
    5252#import <WebCore/EventHandler.h>
     53#import <WebCore/FloatPoint.h>
    5354#import <WebCore/FrameView.h>
    5455#import <WebCore/Image.h>
     
    101102}
    102103
    103 void WebDragClient::startDrag(DragImage dragImage, const IntPoint& at, const IntPoint& eventPos, const FloatPoint&, DataTransfer& dataTransfer, Frame& frame, DragSourceAction dragSourceAction)
    104 {
     104void WebDragClient::startDrag(DragItem dragItem, DataTransfer& dataTransfer, Frame& frame)
     105{
     106    auto& dragImage = dragItem.image;
     107    auto dragLocationInContentCoordinates = dragItem.dragLocationInContentCoordinates;
     108
    105109    RetainPtr<WebHTMLView> htmlView = (WebHTMLView*)[[kit(&frame) frameView] documentView];
    106110    if (![htmlView.get() isKindOfClass:[WebHTMLView class]])
    107111        return;
    108112   
    109     NSEvent *event = dragSourceAction == DragSourceActionLink ? frame.eventHandler().currentNSEvent() : [htmlView.get() _mouseDownEvent];
     113    NSEvent *event = dragItem.sourceAction == DragSourceActionLink ? frame.eventHandler().currentNSEvent() : [htmlView.get() _mouseDownEvent];
    110114    WebHTMLView* topHTMLView = getTopHTMLView(&frame);
    111115    RetainPtr<WebHTMLView> topViewProtector = topHTMLView;
     
    125129    if ([delegate respondsToSelector:selector]) {
    126130        @try {
    127             [delegate webView:m_webView dragImage:dragNSImage at:at offset:NSZeroSize event:event pasteboard:pasteboard source:sourceHTMLView slideBack:YES forView:topHTMLView];
     131            [delegate webView:m_webView dragImage:dragNSImage at:dragLocationInContentCoordinates offset:NSZeroSize event:event pasteboard:pasteboard source:sourceHTMLView slideBack:YES forView:topHTMLView];
    128132        } @catch (id exception) {
    129133            ReportDiscardedDelegateException(selector, exception);
     
    132136#pragma clang diagnostic push
    133137#pragma clang diagnostic ignored "-Wdeprecated-declarations"
    134         [topHTMLView dragImage:dragNSImage at:at offset:NSZeroSize event:event pasteboard:pasteboard source:sourceHTMLView slideBack:YES];
     138        [topHTMLView dragImage:dragNSImage at:dragLocationInContentCoordinates offset:NSZeroSize event:event pasteboard:pasteboard source:sourceHTMLView slideBack:YES];
    135139#pragma clang diagnostic pop
    136140}
     
    199203}
    200204
    201 void WebDragClient::startDrag(WebCore::DragImage, const IntPoint&, const IntPoint&, const FloatPoint&, DataTransfer&, Frame&, WebCore::DragSourceAction)
     205void WebDragClient::startDrag(WebCore::DragItem, DataTransfer&, Frame&)
    202206{
    203207}
     
    240244}
    241245
    242 void WebDragClient::startDrag(DragImage dragImage, const IntPoint& point, const IntPoint& eventLocation, const FloatPoint& dragImageAnchor, DataTransfer& dataTransfer, Frame& frame, DragSourceAction dragSourceAction)
    243 {
    244     [m_webView _setDataInteractionData:dragImage.get().get() textIndicator:dragImage.indicatorData() atClientPosition:eventLocation anchorPoint:dragImageAnchor action:dragSourceAction];
     246void WebDragClient::startDrag(DragItem dragItem, DataTransfer&, Frame&)
     247{
     248    [m_webView _startDrag:dragItem];
    245249}
    246250
  • trunk/Source/WebKit/mac/WebView/WebView.mm

    r218803 r218837  
    134134#import <WebCore/DragController.h>
    135135#import <WebCore/DragData.h>
     136#import <WebCore/DragItem.h>
    136137#import <WebCore/Editing.h>
    137138#import <WebCore/Editor.h>
     
    18301831}
    18311832
    1832 - (void)_setDataInteractionData:(CGImageRef)image textIndicator:(std::optional<TextIndicatorData>)indicatorData atClientPosition:(CGPoint)clientPosition anchorPoint:(CGPoint)anchorPoint action:(uint64_t)action
    1833 {
     1833- (void)_startDrag:(const DragItem&)dragItem
     1834{
     1835    auto& dragImage = dragItem.image;
     1836    auto image = dragImage.get().get();
     1837    auto indicatorData = dragImage.indicatorData();
     1838
    18341839    if (indicatorData)
    18351840        _private->textIndicatorData = adoptNS([[WebUITextIndicatorData alloc] initWithImage:image textIndicatorData:indicatorData.value() scale:_private->page->deviceScaleFactor()]);
  • trunk/Source/WebKit/mac/WebView/WebViewInternal.h

    r217884 r218837  
    6464}
    6565
     66#if PLATFORM(IOS) && ENABLE(DRAG_SUPPORT)
     67namespace WebCore {
     68struct DragItem;
     69}
     70#endif
     71
    6672class WebMediaPlaybackTargetPicker;
    6773class WebSelectionServiceController;
     
    262268
    263269#if ENABLE(DATA_INTERACTION) && defined(__cplusplus)
    264 - (void)_setDataInteractionData:(CGImageRef)image textIndicator:(std::optional<WebCore::TextIndicatorData>)textIndicator atClientPosition:(CGPoint)clientPosition anchorPoint:(CGPoint)anchorPoint action:(uint64_t)action;
     270- (void)_startDrag:(const WebCore::DragItem&)dragItem;
    265271- (void)_didConcludeEditDataInteraction;
    266272#endif
  • trunk/Source/WebKit/win/ChangeLog

    r218794 r218837  
     12017-06-27  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Refactor drag start codepaths to plumb a DragItem to client layers
     4        https://bugs.webkit.org/show_bug.cgi?id=173832
     5        Work towards <rdar://problem/32236827>
     6
     7        Reviewed by Ryosuke Niwa and Tim Horton.
     8
     9        Adjust for changes to WebDragClient::startDrag by pulling information out of DragItem.
     10
     11        * WebCoreSupport/WebDragClient.cpp:
     12        (WebDragClient::startDrag):
     13        * WebCoreSupport/WebDragClient.h:
     14
    1152017-06-25  Konstantin Tokarev  <annulen@yandex.ru>
    216
  • trunk/Source/WebKit/win/WebCoreSupport/WebDragClient.cpp

    r214403 r218837  
    3232#include <WebCore/DragController.h>
    3333#include <WebCore/DragData.h>
     34#include <WebCore/DragItem.h>
    3435#include <WebCore/EventHandler.h>
    3536#include <WebCore/FrameView.h>
     
    99100}
    100101
    101 void WebDragClient::startDrag(DragImage image, const IntPoint& imageOrigin, const IntPoint& dragPoint, const FloatPoint&, DataTransfer& dataTransfer, Frame& frame, DragSourceAction dragSourceAction)
     102void WebDragClient::startDrag(DragItem item, DataTransfer& dataTransfer, Frame& frame)
    102103{
    103104    //FIXME: Allow UIDelegate to override behaviour <rdar://problem/5015953>
    104105
    105106    //We liberally protect everything, to protect against a load occurring mid-drag
     107    auto& image = item.image;
     108    auto imageOrigin = item.dragLocationInContentCoordinates;
     109    auto dragPoint = item.eventPositionInContentCoordinates;
     110
    106111    RefPtr<Frame> frameProtector = &frame;
    107112    COMPtr<IDragSourceHelper> helper;
     
    126131                sdi.ptOffset.x = dragPoint.x() - imageOrigin.x();
    127132                sdi.ptOffset.y = dragPoint.y() - imageOrigin.y();
    128                 if (dragSourceAction == DragSourceActionLink)
     133                if (item.sourceAction == DragSourceActionLink)
    129134                    sdi.ptOffset.y = b.bmHeight - sdi.ptOffset.y;
    130135
  • trunk/Source/WebKit/win/WebCoreSupport/WebDragClient.h

    r214403 r218837  
    3939    virtual void willPerformDragDestinationAction(WebCore::DragDestinationAction, const WebCore::DragData&);
    4040    virtual void willPerformDragSourceAction(WebCore::DragSourceAction, const WebCore::IntPoint&, WebCore::DataTransfer&);
    41     virtual void startDrag(WebCore::DragImage, const WebCore::IntPoint&, const WebCore::IntPoint&, const WebCore::FloatPoint&, WebCore::DataTransfer&, WebCore::Frame&, WebCore::DragSourceAction);
     41    virtual void startDrag(WebCore::DragItem, WebCore::DataTransfer&, WebCore::Frame&);
    4242
    4343private:
  • trunk/Source/WebKit2/ChangeLog

    r218834 r218837  
     12017-06-27  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Refactor drag start codepaths to plumb a DragItem to client layers
     4        https://bugs.webkit.org/show_bug.cgi?id=173832
     5        Work towards <rdar://problem/32236827>
     6
     7        Reviewed by Ryosuke Niwa and Tim Horton.
     8
     9        Add support for serializing a DragItem over IPC. This encodes and decodes all members of DragItem except for the
     10        PasteboardWriterData and the DragImage's image. The DragItem is sent over to the UI process in
     11        WebDragClient::startDrag via the WebPageProxy::startDrag IPC message (renamed from WebPageProxy::setDragImage)
     12        which now takes a DragItem.
     13
     14        * UIProcess/Cocoa/WebPageProxyCocoa.mm:
     15        (WebKit::WebPageProxy::startDrag):
     16        (WebKit::WebPageProxy::setDragImage): Deleted.
     17        * UIProcess/PageClient.h:
     18        * UIProcess/WebPageProxy.h:
     19        * UIProcess/WebPageProxy.messages.in:
     20
     21        Rename SetDragImage to StartDrag and refactor to receive only a DragItem and shareable bitmap handle.
     22
     23        * UIProcess/ios/PageClientImplIOS.h:
     24        * UIProcess/ios/PageClientImplIOS.mm:
     25        (WebKit::PageClientImpl::startDrag):
     26        (WebKit::PageClientImpl::startDataInteractionWithImage): Deleted.
     27        * UIProcess/ios/WKContentViewInteraction.h:
     28        * UIProcess/ios/WKContentViewInteraction.mm:
     29        (-[WKContentView _startDrag:item:]):
     30        (-[WKContentView _startDataInteractionWithImage:withIndicatorData:atClientPosition:anchorPoint:action:]): Deleted.
     31
     32        Rename startDataInteractionWithImage to startDrag.
     33
     34        * UIProcess/mac/WebPageProxyMac.mm:
     35        (WebKit::WebPageProxy::startDrag):
     36        (WebKit::WebPageProxy::setDragImage): Deleted.
     37        * WebProcess/WebCoreSupport/WebDragClient.cpp:
     38        (WebKit::WebDragClient::startDrag):
     39        * WebProcess/WebCoreSupport/WebDragClient.h:
     40        * WebProcess/WebCoreSupport/gtk/WebDragClientGtk.cpp:
     41        (WebKit::WebDragClient::startDrag):
     42        * WebProcess/WebCoreSupport/mac/WebDragClientMac.mm:
     43        (WebKit::WebDragClient::startDrag):
     44
    1452017-06-27  Wenson Hsieh  <wenson_hsieh@apple.com>
    246
  • trunk/Source/WebKit2/UIProcess/Cocoa/WebPageProxyCocoa.mm

    r218433 r218837  
    3232#import "PageClient.h"
    3333#import "WebProcessProxy.h"
     34#import <WebCore/DragItem.h>
    3435#import <WebCore/NotImplemented.h>
    3536#import <WebCore/SearchPopupMenuCocoa.h>
     
    105106#if PLATFORM(IOS) && ENABLE(DRAG_SUPPORT)
    106107
    107 void WebPageProxy::setDragImage(const IntPoint& clientPosition, const ShareableBitmap::Handle& dragImageHandle, std::optional<TextIndicatorData> textIndicator, const FloatPoint& dragImageAnchor, uint64_t action)
     108void WebPageProxy::startDrag(const DragItem& dragItem, const ShareableBitmap::Handle& dragImageHandle)
    108109{
    109     m_pageClient.startDataInteractionWithImage(clientPosition, dragImageHandle, textIndicator, dragImageAnchor, action);
     110    m_pageClient.startDrag(dragItem, dragImageHandle);
    110111}
    111112
  • trunk/Source/WebKit2/UIProcess/PageClient.h

    r218740 r218837  
    5757}
    5858
     59#if ENABLE(DRAG_SUPPORT)
     60namespace WebCore {
     61struct DragItem;
     62}
     63#endif
     64
    5965namespace WebKit {
    6066
     
    374380    virtual void didPerformDataInteractionControllerOperation(bool handled) = 0;
    375381    virtual void didHandleStartDataInteractionRequest(bool started) = 0;
    376     virtual void startDataInteractionWithImage(const WebCore::IntPoint& clientPosition, const ShareableBitmap::Handle& image, std::optional<WebCore::TextIndicatorData>, const WebCore::FloatPoint& anchorPoint, uint64_t action) = 0;
     382    virtual void startDrag(const WebCore::DragItem&, const ShareableBitmap::Handle& image) = 0;
    377383    virtual void didConcludeEditDataInteraction(std::optional<WebCore::TextIndicatorData>) = 0;
    378384    virtual void didChangeDataInteractionCaretRect(const WebCore::IntRect& previousCaretRect, const WebCore::IntRect& caretRect) = 0;
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.h

    r218750 r218837  
    833833    void setDragCaretRect(const WebCore::IntRect&);
    834834#if PLATFORM(COCOA)
    835     void setDragImage(const WebCore::IntPoint& clientPosition, const ShareableBitmap::Handle& dragImageHandle, std::optional<WebCore::TextIndicatorData>, const WebCore::FloatPoint& dragImageAnchor, uint64_t action);
     835    void startDrag(const WebCore::DragItem&, const ShareableBitmap::Handle& dragImageHandle);
    836836    void setPromisedDataForImage(const String& pasteboardName, const SharedMemory::Handle& imageHandle, uint64_t imageSize, const String& filename, const String& extension,
    837837                         const String& title, const String& url, const String& visibleURL, const SharedMemory::Handle& archiveHandle, uint64_t archiveSize);
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in

    r218750 r218837  
    303303#endif
    304304#if PLATFORM(COCOA) && ENABLE(DRAG_SUPPORT)
    305     SetDragImage(WebCore::IntPoint clientPosition, WebKit::ShareableBitmap::Handle dragImage, std::optional<WebCore::TextIndicatorData> textIndicator, WebCore::FloatPoint dragImageAnchor, uint64_t action)
     305    StartDrag(struct WebCore::DragItem dragItem, WebKit::ShareableBitmap::Handle dragImage)
    306306    SetPromisedDataForImage(String pasteboardName, WebKit::SharedMemory::Handle imageHandle, uint64_t imageSize, String filename, String extension, String title, String url, String visibleURL, WebKit::SharedMemory::Handle archiveHandle, uint64_t archiveSize)
    307307#if ENABLE(ATTACHMENT_ELEMENT)
  • trunk/Source/WebKit2/UIProcess/ios/PageClientImplIOS.h

    r218457 r218837  
    209209    void didPerformDataInteractionControllerOperation(bool handled) override;
    210210    void didHandleStartDataInteractionRequest(bool started) override;
    211     void startDataInteractionWithImage(const WebCore::IntPoint& clientPosition, const ShareableBitmap::Handle& image, std::optional<WebCore::TextIndicatorData>, const WebCore::FloatPoint& anchorPoint, uint64_t action) override;
     211    void startDrag(const WebCore::DragItem&, const ShareableBitmap::Handle& image) override;
    212212    void didConcludeEditDataInteraction(std::optional<WebCore::TextIndicatorData>) override;
    213213    void didChangeDataInteractionCaretRect(const WebCore::IntRect& previousCaretRect, const WebCore::IntRect& caretRect) override;
  • trunk/Source/WebKit2/UIProcess/ios/PageClientImplIOS.mm

    r218457 r218837  
    787787}
    788788
    789 void PageClientImpl::startDataInteractionWithImage(const IntPoint& clientPosition, const ShareableBitmap::Handle& image, std::optional<WebCore::TextIndicatorData> indicatorData, const FloatPoint& anchorPoint, uint64_t action)
    790 {
    791     [m_contentView _startDataInteractionWithImage:ShareableBitmap::create(image)->makeCGImageCopy() withIndicatorData:indicatorData atClientPosition:CGPointMake(clientPosition.x(), clientPosition.y()) anchorPoint:anchorPoint action:action];
     789void PageClientImpl::startDrag(const DragItem& item, const ShareableBitmap::Handle& image)
     790{
     791    [m_contentView _startDrag:ShareableBitmap::create(image)->makeCGImageCopy() item:item];
    792792}
    793793
  • trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.h

    r218606 r218837  
    5757class TextStream;
    5858}
     59
     60#if ENABLE(DRAG_SUPPORT)
     61namespace WebCore {
     62struct DragItem;
     63}
     64#endif
    5965
    6066namespace WebKit {
     
    330336- (void)_didPerformDataInteractionControllerOperation:(BOOL)handled;
    331337- (void)_didHandleStartDataInteractionRequest:(BOOL)started;
    332 - (void)_startDataInteractionWithImage:(RetainPtr<CGImageRef>)image withIndicatorData:(std::optional<WebCore::TextIndicatorData>)indicatorData atClientPosition:(CGPoint)clientPosition anchorPoint:(CGPoint)anchorPoint action:(uint64_t)action;
     338- (void)_startDrag:(RetainPtr<CGImageRef>)image item:(const WebCore::DragItem&)item;
    333339- (void)_didConcludeEditDataInteraction:(std::optional<WebCore::TextIndicatorData>)data;
    334340- (void)_didChangeDataInteractionCaretRect:(CGRect)previousRect currentRect:(CGRect)rect;
  • trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm

    r218834 r218837  
    102102#import <UIKit/_UITextDragCaretView.h>
    103103#import <WebCore/DragData.h>
     104#import <WebCore/DragItem.h>
    104105#import <WebCore/PlatformPasteboard.h>
    105106#import <WebCore/WebItemProviderPasteboard.h>
     
    42214222}
    42224223
    4223 - (void)_startDataInteractionWithImage:(RetainPtr<CGImageRef>)image withIndicatorData:(std::optional<TextIndicatorData>)indicatorData atClientPosition:(CGPoint)clientPosition anchorPoint:(CGPoint)anchorPoint action:(uint64_t)action
    4224 {
    4225     ASSERT(action != DragSourceActionNone);
     4224- (void)_startDrag:(RetainPtr<CGImageRef>)image item:(const DragItem&)item
     4225{
     4226    ASSERT(item.sourceAction != DragSourceActionNone);
     4227
    42264228    _dataInteractionState.image = adoptNS([[UIImage alloc] initWithCGImage:image.get() scale:_page->deviceScaleFactor() orientation:UIImageOrientationUp]);
    4227     _dataInteractionState.indicatorData = indicatorData;
    4228     _dataInteractionState.sourceAction = static_cast<DragSourceAction>(action);
     4229    _dataInteractionState.indicatorData = item.image.indicatorData();
     4230    _dataInteractionState.sourceAction = static_cast<DragSourceAction>(item.sourceAction);
    42294231}
    42304232
  • trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm

    r218457 r218837  
    4949#import <WebCore/DictationAlternative.h>
    5050#import <WebCore/DictionaryLookup.h>
     51#import <WebCore/DragItem.h>
    5152#import <WebCore/GraphicsLayer.h>
    5253#import <WebCore/NSApplicationSPI.h>
     
    270271
    271272#if ENABLE(DRAG_SUPPORT)
    272 void WebPageProxy::setDragImage(const WebCore::IntPoint& clientPosition, const ShareableBitmap::Handle& dragImageHandle, std::optional<TextIndicatorData>, const FloatPoint&, uint64_t action)
     273void WebPageProxy::startDrag(const DragItem& dragItem, const ShareableBitmap::Handle& dragImageHandle)
    273274{
    274275    if (auto dragImage = ShareableBitmap::create(dragImageHandle))
    275         m_pageClient.setDragImage(clientPosition, dragImage.releaseNonNull(), static_cast<DragSourceAction>(action));
     276        m_pageClient.setDragImage(dragItem.dragLocationInWindowCoordinates, dragImage.releaseNonNull(), static_cast<DragSourceAction>(dragItem.sourceAction));
    276277
    277278    didStartDrag();
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebDragClient.cpp

    r214403 r218837  
    5353
    5454#if !PLATFORM(COCOA) && !PLATFORM(GTK)
    55 void WebDragClient::startDrag(DragImage, const IntPoint&, const IntPoint&, const FloatPoint&, DataTransfer&, Frame&, DragSourceAction)
     55void WebDragClient::startDrag(DragItem, DataTransfer&, Frame&)
    5656{
    5757}
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebDragClient.h

    r214403 r218837  
    4747    WebCore::DragSourceAction dragSourceActionMaskForPoint(const WebCore::IntPoint& windowPoint) override;
    4848
    49     void startDrag(WebCore::DragImage, const WebCore::IntPoint& dragImageOrigin, const WebCore::IntPoint& eventPos, const WebCore::FloatPoint& dragImageAnchor, WebCore::DataTransfer&, WebCore::Frame&, WebCore::DragSourceAction) override;
     49    void startDrag(WebCore::DragItem, WebCore::DataTransfer&, WebCore::Frame&) override;
    5050    void didConcludeEditDrag() override;
    5151
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/gtk/WebDragClientGtk.cpp

    r213627 r218837  
    6161}
    6262
    63 void WebDragClient::startDrag(DragImage dragImage, const IntPoint& clientPosition, const IntPoint& globalPosition, const FloatPoint&, DataTransfer& dataTransfer, Frame&, DragSourceAction)
     63void WebDragClient::startDrag(DragItem item, DataTransfer& dataTransfer, Frame&)
    6464{
     65    auto& dragImage = item.image;
    6566    RefPtr<ShareableBitmap> bitmap = convertCairoSurfaceToShareableBitmap(dragImage.get().get());
    6667    ShareableBitmap::Handle handle;
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebDragClientMac.mm

    r218433 r218837  
    9393}
    9494
    95 void WebDragClient::startDrag(DragImage image, const IntPoint& point, const IntPoint&, const FloatPoint&, DataTransfer&, Frame& frame, DragSourceAction dragSourceAction)
    96 {
     95void WebDragClient::startDrag(DragItem dragItem, DataTransfer&, Frame& frame)
     96{
     97    auto& image = dragItem.image;
    9798    IntSize bitmapSize([image.get() size]);
    9899    RefPtr<ShareableBitmap> bitmap = convertImageToBitmap(image.get().get(), bitmapSize, frame);
     
    102103
    103104    m_page->willStartDrag();
    104 
    105     // FIXME: Seems this message should be named StartDrag, not SetDragImage.
    106     m_page->send(Messages::WebPageProxy::SetDragImage(frame.view()->contentsToWindow(point), handle, std::nullopt, { }, dragSourceAction));
     105    m_page->send(Messages::WebPageProxy::StartDrag(dragItem, handle));
    107106}
    108107
     
    208207}
    209208
    210 void WebDragClient::startDrag(DragImage image, const IntPoint& point, const IntPoint& eventLocation, const FloatPoint& dragImageAnchor, DataTransfer& dataTransfer, Frame& frame, DragSourceAction dragSourceAction)
    211 {
     209void WebDragClient::startDrag(DragItem dragItem, DataTransfer& dataTransfer, Frame& frame)
     210{
     211    auto& image = dragItem.image;
     212
    212213    IntSize bitmapSize(CGImageGetWidth(image.get().get()), CGImageGetHeight(image.get().get()));
    213214    auto bitmap = convertCGImageToBitmap(image.get().get(), bitmapSize, frame);
     
    217218
    218219    m_page->willStartDrag();
    219     m_page->send(Messages::WebPageProxy::SetDragImage(frame.view()->contentsToWindow(point), handle, image.indicatorData(), dragImageAnchor, dragSourceAction));
     220    m_page->send(Messages::WebPageProxy::StartDrag(dragItem, handle));
    220221}
    221222
Note: See TracChangeset for help on using the changeset viewer.