Changeset 215724 in webkit


Ignore:
Timestamp:
Apr 25, 2017 12:00:59 AM (7 years ago)
Author:
Wenson Hsieh
Message:

Support reading NSURL titles from the pasteboard when performing data interaction
https://bugs.webkit.org/show_bug.cgi?id=171156
<rdar://problem/31356937>

Reviewed by Tim Horton.

Source/WebCore:

Support reading link titles from the pasteboard when performing data interaction. To do this, we refactor
Pasteboard::readURL to take in an additional String& title which is ultimately plumbed to the PlatformPasteboard
where it is set to the value of -[NSURL _title].

Test: DataInteractionTests.ExternalSourceTitledNSURL.

  • editing/FrameSelection.h:
  • editing/ios/EditorIOS.mm:

(WebCore::Editor::WebContentReader::readURL):

  • page/DragController.cpp:

(WebCore::DragController::performDragOperation):
(WebCore::DragController::concludeEditDrag):

Move calls to clearDragCaret() out of concludeEditDrag and into the call site, in performDragOperation after
attempting to concludeEditDrag. This is done so that if the WebEditorClient queries whether the drag caret is
in richly editable content for the purposes of generating a document fragment to insert, the answer will not
always be false as a drop is occurring.

  • platform/PasteboardStrategy.h:
  • platform/PlatformPasteboard.h:
  • platform/ios/PasteboardIOS.mm:

(WebCore::Pasteboard::respectsUTIFidelities):
(WebCore::Pasteboard::readString):

  • platform/ios/PlatformPasteboardIOS.mm:

(WebCore::PlatformPasteboard::readURL):

Source/WebKit/mac:

Add a new WK1 SPI property, -[WebFrame hasRichlyEditableDragCaret].

  • WebCoreSupport/WebPlatformStrategies.h:
  • WebCoreSupport/WebPlatformStrategies.mm:

(WebPlatformStrategies::readURLFromPasteboard):

  • WebView/WebFrame.mm:

(-[WebFrame hasRichlyEditableDragCaret]):

  • WebView/WebFramePrivate.h:

Source/WebKit2:

Adjust for interface changes in WebCore to support plumbing the title of an NSURL from the platform pasteboard
back to WebCore. Additionally, implement WebEditorClient::hasRichlyEditableSelection (which previously returned
false) to check whether the current selection is richly editable, or the drop caret is in richly editable content.
See WebCore ChangeLog for more details.

  • UIProcess/Cocoa/WebPasteboardProxyCocoa.mm:

(WebKit::WebPasteboardProxy::readURLFromPasteboard):

  • UIProcess/WebPasteboardProxy.h:
  • UIProcess/WebPasteboardProxy.messages.in:
  • WebProcess/WebCoreSupport/WebPlatformStrategies.cpp:

(WebKit::WebPlatformStrategies::readURLFromPasteboard):

  • WebProcess/WebCoreSupport/WebPlatformStrategies.h:
  • WebProcess/WebCoreSupport/ios/WebEditorClientIOS.mm:

(WebKit::WebEditorClient::hasRichlyEditableSelection):

  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::hasRichlyEditableSelection):

  • WebProcess/WebPage/WebPage.h:

Tools:

Adds a new unit test, DataInteractionTests.ExternalSourceTitledNSURL.

  • TestWebKitAPI/Tests/ios/DataInteractionTests.mm:

(TestWebKitAPI::TEST):

Location:
trunk
Files:
24 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r215722 r215724  
     12017-04-25  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Support reading NSURL titles from the pasteboard when performing data interaction
     4        https://bugs.webkit.org/show_bug.cgi?id=171156
     5        <rdar://problem/31356937>
     6
     7        Reviewed by Tim Horton.
     8
     9        Support reading link titles from the pasteboard when performing data interaction. To do this, we refactor
     10        Pasteboard::readURL to take in an additional String& title which is ultimately plumbed to the PlatformPasteboard
     11        where it is set to the value of -[NSURL _title].
     12
     13        Test: DataInteractionTests.ExternalSourceTitledNSURL.
     14
     15        * editing/FrameSelection.h:
     16        * editing/ios/EditorIOS.mm:
     17        (WebCore::Editor::WebContentReader::readURL):
     18        * page/DragController.cpp:
     19        (WebCore::DragController::performDragOperation):
     20        (WebCore::DragController::concludeEditDrag):
     21
     22        Move calls to clearDragCaret() out of concludeEditDrag and into the call site, in performDragOperation after
     23        attempting to concludeEditDrag. This is done so that if the WebEditorClient queries whether the drag caret is
     24        in richly editable content for the purposes of generating a document fragment to insert, the answer will not
     25        always be false as a drop is occurring.
     26
     27        * platform/PasteboardStrategy.h:
     28        * platform/PlatformPasteboard.h:
     29        * platform/ios/PasteboardIOS.mm:
     30        (WebCore::Pasteboard::respectsUTIFidelities):
     31        (WebCore::Pasteboard::readString):
     32        * platform/ios/PlatformPasteboardIOS.mm:
     33        (WebCore::PlatformPasteboard::readURL):
     34
    1352017-04-24  Andy VanWagoner  <thetalecrafter@gmail.com>
    236
  • trunk/Source/WebCore/editing/FrameSelection.h

    r212484 r215724  
    9898
    9999    bool isContentEditable() const { return m_position.rootEditableElement(); }
    100     bool isContentRichlyEditable() const;
     100    WEBCORE_EXPORT bool isContentRichlyEditable() const;
    101101
    102102    bool hasCaret() const { return m_position.isNotNull(); }
  • trunk/Source/WebCore/editing/ios/EditorIOS.mm

    r215686 r215724  
    321321}
    322322
    323 bool Editor::WebContentReader::readURL(const URL& url, const String&)
     323bool Editor::WebContentReader::readURL(const URL& url, const String& title)
    324324{
    325325    if (url.isEmpty())
     
    349349        auto anchor = HTMLAnchorElement::create(*frame.document());
    350350        anchor->setAttributeWithoutSynchronization(HTMLNames::hrefAttr, url.string());
    351         anchor->appendChild(frame.document()->createTextNode([[(NSURL *)url absoluteString] precomposedStringWithCanonicalMapping]));
     351
     352        String linkText = title.length() ? title : String([[(NSURL *)url absoluteString] precomposedStringWithCanonicalMapping]);
     353        anchor->appendChild(frame.document()->createTextNode(linkText));
    352354
    353355        auto newFragment = frame.document()->createDocumentFragment();
  • trunk/Source/WebCore/page/DragController.cpp

    r215669 r215724  
    250250        m_client.didConcludeEditDrag();
    251251        m_documentUnderMouse = nullptr;
     252        clearDragCaret();
    252253        return true;
    253254    }
    254255
    255256    m_documentUnderMouse = nullptr;
     257    clearDragCaret();
    256258
    257259    if (operationForLoad(dragData) == DragOperationNone)
     
    509511    }
    510512
    511     if (!m_page.dragController().canProcessDrag(dragData)) {
    512         clearDragCaret();
    513         return false;
    514     }
     513    if (!m_page.dragController().canProcessDrag(dragData))
     514        return false;
    515515
    516516    VisibleSelection dragCaret = m_page.dragCaretController().caretPosition();
    517     clearDragCaret();
    518517    RefPtr<Range> range = dragCaret.toNormalizedRange();
    519518    RefPtr<Element> rootEditableElement = innerFrame->selection().selection().rootEditableElement();
  • trunk/Source/WebCore/platform/PasteboardStrategy.h

    r215714 r215724  
    5151    virtual String readStringFromPasteboard(int index, const String& pasteboardType, const String& pasteboardName) = 0;
    5252    virtual RefPtr<SharedBuffer> readBufferFromPasteboard(int index, const String& pasteboardType, const String& pasteboardName) = 0;
    53     virtual URL readURLFromPasteboard(int index, const String& pasteboardType, const String& pasteboardName) = 0;
     53    virtual URL readURLFromPasteboard(int index, const String& pasteboardType, const String& pasteboardName, String& title) = 0;
    5454    virtual void getFilenamesForDataInteraction(Vector<String>& filenames, const String& pasteboardName) = 0;
    5555    virtual void getTypesByFidelityForItemAtIndex(Vector<String>& types, uint64_t index, const String& pasteboardName) = 0;
  • trunk/Source/WebCore/platform/PlatformPasteboard.h

    r215714 r215724  
    8484    WEBCORE_EXPORT RefPtr<SharedBuffer> readBuffer(int index, const String& pasteboardType);
    8585    WEBCORE_EXPORT String readString(int index, const String& pasteboardType);
    86     WEBCORE_EXPORT URL readURL(int index, const String& pasteboardType);
     86    WEBCORE_EXPORT URL readURL(int index, const String& pasteboardType, String& title);
    8787    WEBCORE_EXPORT int count();
    8888    WEBCORE_EXPORT int numberOfFiles();
  • trunk/Source/WebCore/platform/ios/PasteboardIOS.mm

    r215714 r215724  
    194194
    195195    if ([type isEqualToString:(NSString *)kUTTypeURL]) {
    196         URL url = strategy.readURLFromPasteboard(itemIndex, kUTTypeURL, pasteboardName);
    197         return !url.isNull() && reader.readURL(url, String());
     196        String title;
     197        URL url = strategy.readURLFromPasteboard(itemIndex, kUTTypeURL, pasteboardName, title);
     198        return !url.isNull() && reader.readURL(url, title);
    198199    }
    199200
     
    329330
    330331    if ([cocoaType isEqualToString:(NSString *)kUTTypeURL]) {
    331         URL url = strategy.readURLFromPasteboard(0, kUTTypeURL, m_pasteboardName);
     332        String title;
     333        URL url = strategy.readURLFromPasteboard(0, kUTTypeURL, m_pasteboardName, title);
    332334        if (!url.isNull())
    333335            cocoaValue = [(NSURL *)url absoluteString];
  • trunk/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm

    r215714 r215724  
    390390}
    391391
    392 URL PlatformPasteboard::readURL(int index, const String& type)
     392URL PlatformPasteboard::readURL(int index, const String& type, String& title)
    393393{
    394394    NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:index];
     
    404404        return URL();
    405405
     406#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000
     407    if ([value respondsToSelector:@selector(_title)])
     408        title = [value _title];
     409#else
     410    UNUSED_PARAM(title);
     411#endif
     412
    406413    return (NSURL *)value;
    407414}
  • trunk/Source/WebKit/mac/ChangeLog

    r215722 r215724  
     12017-04-25  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Support reading NSURL titles from the pasteboard when performing data interaction
     4        https://bugs.webkit.org/show_bug.cgi?id=171156
     5        <rdar://problem/31356937>
     6
     7        Reviewed by Tim Horton.
     8
     9        Add a new WK1 SPI property, -[WebFrame hasRichlyEditableDragCaret].
     10
     11        * WebCoreSupport/WebPlatformStrategies.h:
     12        * WebCoreSupport/WebPlatformStrategies.mm:
     13        (WebPlatformStrategies::readURLFromPasteboard):
     14        * WebView/WebFrame.mm:
     15        (-[WebFrame hasRichlyEditableDragCaret]):
     16        * WebView/WebFramePrivate.h:
     17
    1182017-04-24  Andy VanWagoner  <thetalecrafter@gmail.com>
    219
  • trunk/Source/WebKit/mac/WebCoreSupport/WebPlatformStrategies.h

    r215714 r215724  
    6666    String readStringFromPasteboard(int index, const String& pasteboardType, const String& pasteboardName) override;
    6767    RefPtr<WebCore::SharedBuffer> readBufferFromPasteboard(int index, const String& pasteboardType, const String& pasteboardName) override;
    68     WebCore::URL readURLFromPasteboard(int index, const String& pasteboardType, const String& pasteboardName) override;
     68    WebCore::URL readURLFromPasteboard(int index, const String& pasteboardType, const String& pasteboardName, String& title) override;
    6969    void getFilenamesForDataInteraction(Vector<String>& filenames, const String& pasteboardName) override;
    7070    void getTypesByFidelityForItemAtIndex(Vector<String>& types, uint64_t index, const String& pasteboardName) override;
  • trunk/Source/WebKit/mac/WebCoreSupport/WebPlatformStrategies.mm

    r215714 r215724  
    222222}
    223223
    224 WebCore::URL WebPlatformStrategies::readURLFromPasteboard(int index, const String& type, const String& pasteboardName)
    225 {
    226     return PlatformPasteboard(pasteboardName).readURL(index, type);
     224WebCore::URL WebPlatformStrategies::readURLFromPasteboard(int index, const String& type, const String& pasteboardName, String& title)
     225{
     226    return PlatformPasteboard(pasteboardName).readURL(index, type, title);
    227227}
    228228
  • trunk/Source/WebKit/mac/WebView/WebFrame.mm

    r215686 r215724  
    22172217}
    22182218
     2219- (BOOL)hasRichlyEditableDragCaret
     2220{
     2221    if (auto* page = core(self)->page())
     2222        return page->dragCaretController().isContentRichlyEditable();
     2223    return NO;
     2224}
     2225
    22192226// Used by pagination code called from AppKit when a standalone web page is printed.
    22202227- (NSArray *)_computePageRectsWithPrintScaleFactor:(float)printScaleFactor pageSize:(NSSize)pageSize
  • trunk/Source/WebKit/mac/WebView/WebFramePrivate.h

    r211021 r215724  
    278278- (NSArray *)_computePageRectsWithPrintScaleFactor:(float)printWidthScaleFactor pageSize:(NSSize)pageSize;
    279279
     280// Drag and drop support.
     281@property (nonatomic, readonly) BOOL hasRichlyEditableDragCaret;
     282
    280283#if TARGET_OS_IPHONE
    281284- (DOMDocumentFragment *)_documentFragmentForText:(NSString *)text;
  • trunk/Source/WebKit2/ChangeLog

    r215714 r215724  
     12017-04-25  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Support reading NSURL titles from the pasteboard when performing data interaction
     4        https://bugs.webkit.org/show_bug.cgi?id=171156
     5        <rdar://problem/31356937>
     6
     7        Reviewed by Tim Horton.
     8
     9        Adjust for interface changes in WebCore to support plumbing the title of an NSURL from the platform pasteboard
     10        back to WebCore. Additionally, implement WebEditorClient::hasRichlyEditableSelection (which previously returned
     11        false) to check whether the current selection is richly editable, or the drop caret is in richly editable content.
     12        See WebCore ChangeLog for more details.
     13
     14        * UIProcess/Cocoa/WebPasteboardProxyCocoa.mm:
     15        (WebKit::WebPasteboardProxy::readURLFromPasteboard):
     16        * UIProcess/WebPasteboardProxy.h:
     17        * UIProcess/WebPasteboardProxy.messages.in:
     18        * WebProcess/WebCoreSupport/WebPlatformStrategies.cpp:
     19        (WebKit::WebPlatformStrategies::readURLFromPasteboard):
     20        * WebProcess/WebCoreSupport/WebPlatformStrategies.h:
     21        * WebProcess/WebCoreSupport/ios/WebEditorClientIOS.mm:
     22        (WebKit::WebEditorClient::hasRichlyEditableSelection):
     23        * WebProcess/WebPage/WebPage.cpp:
     24        (WebKit::WebPage::hasRichlyEditableSelection):
     25        * WebProcess/WebPage/WebPage.h:
     26
    1272017-04-24  Wenson Hsieh  <wenson_hsieh@apple.com>
    228
  • trunk/Source/WebKit2/UIProcess/Cocoa/WebPasteboardProxyCocoa.mm

    r215714 r215724  
    171171}
    172172
    173 void WebPasteboardProxy::readURLFromPasteboard(uint64_t index, const String& pasteboardType, const String& pasteboardName, String& url)
    174 {
    175     url = PlatformPasteboard(pasteboardName).readURL(index, pasteboardType);
     173void WebPasteboardProxy::readURLFromPasteboard(uint64_t index, const String& pasteboardType, const String& pasteboardName, String& url, String& title)
     174{
     175    url = PlatformPasteboard(pasteboardName).readURL(index, pasteboardType, title);
    176176}
    177177
  • trunk/Source/WebKit2/UIProcess/WebPasteboardProxy.h

    r215714 r215724  
    7676    void writeStringToPasteboard(const String& pasteboardType, const String&, const String& pasteboardName);
    7777    void readStringFromPasteboard(uint64_t index, const String& pasteboardType, const String& pasteboardName, WTF::String&);
    78     void readURLFromPasteboard(uint64_t index, const String& pasteboardType, const String& pasteboardName, String&);
     78    void readURLFromPasteboard(uint64_t index, const String& pasteboardType, const String& pasteboardName, String& url, String& title);
    7979    void readBufferFromPasteboard(uint64_t index, const String& pasteboardType, const String& pasteboardName, SharedMemory::Handle&, uint64_t& size);
    8080    void getPasteboardItemsCount(const String& pasteboardName, uint64_t& itemsCount);
  • trunk/Source/WebKit2/UIProcess/WebPasteboardProxy.messages.in

    r215714 r215724  
    2828    WriteStringToPasteboard(String pasteboardType, String text, String pasteboardName)
    2929    ReadStringFromPasteboard(uint64_t index, String pasteboardType, String pasteboardName) -> (String string)
    30     ReadURLFromPasteboard(uint64_t index, String pasteboardType, String pasteboardName) -> (String string)
     30    ReadURLFromPasteboard(uint64_t index, String pasteboardType, String pasteboardName) -> (String url, String title)
    3131    ReadBufferFromPasteboard(uint64_t index, String pasteboardType, String pasteboardName) -> (WebKit::SharedMemory::Handle handle, uint64_t size)
    3232    GetPasteboardItemsCount(String pasteboardName) -> (uint64_t itemsCount)
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp

    r215714 r215724  
    336336}
    337337
    338 WebCore::URL WebPlatformStrategies::readURLFromPasteboard(int index, const String& pasteboardType, const String& pasteboardName)
     338WebCore::URL WebPlatformStrategies::readURLFromPasteboard(int index, const String& pasteboardType, const String& pasteboardName, String& title)
    339339{
    340340    String urlString;
    341     WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::ReadURLFromPasteboard(index, pasteboardType, pasteboardName), Messages::WebPasteboardProxy::ReadURLFromPasteboard::Reply(urlString), 0);
     341    WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::ReadURLFromPasteboard(index, pasteboardType, pasteboardName), Messages::WebPasteboardProxy::ReadURLFromPasteboard::Reply(urlString, title), 0);
    342342    return URL(ParsedURLString, urlString);
    343343}
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.h

    r215714 r215724  
    6767    String readStringFromPasteboard(int index, const String& pasteboardType, const String& pasteboardName) override;
    6868    RefPtr<WebCore::SharedBuffer> readBufferFromPasteboard(int index, const String& pasteboardType, const String& pasteboardName) override;
    69     WebCore::URL readURLFromPasteboard(int index, const String& pasteboardType, const String& pasteboardName) override;
     69    WebCore::URL readURLFromPasteboard(int index, const String& pasteboardType, const String& pasteboardName, String& title) override;
    7070    void getFilenamesForDataInteraction(Vector<String>& filenames, const String& pasteboardName) override;
    7171    void getTypesByFidelityForItemAtIndex(Vector<String>& types, uint64_t index, const String& pasteboardName) override;
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/ios/WebEditorClientIOS.mm

    r204717 r215724  
    102102bool WebEditorClient::hasRichlyEditableSelection()
    103103{
    104     notImplemented();
    105     return false;
     104    return m_page->hasRichlyEditableSelection();
    106105}
    107106
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp

    r215653 r215724  
    38703870#endif
    38713871
     3872bool WebPage::hasRichlyEditableSelection() const
     3873{
     3874    auto& frame = m_page->focusController().focusedOrMainFrame();
     3875    if (m_page->dragCaretController().isContentRichlyEditable())
     3876        return true;
     3877
     3878    return frame.selection().selection().isContentRichlyEditable();
     3879}
     3880
    38723881void WebPage::changeSpellingToWord(const String& word)
    38733882{
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h

    r215255 r215724  
    600600    void setForceAlwaysUserScalable(bool);
    601601#endif
     602    bool hasRichlyEditableSelection() const;
    602603
    603604    void setLayerTreeStateIsFrozen(bool);
  • trunk/Tools/ChangeLog

    r215714 r215724  
     12017-04-25  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Support reading NSURL titles from the pasteboard when performing data interaction
     4        https://bugs.webkit.org/show_bug.cgi?id=171156
     5        <rdar://problem/31356937>
     6
     7        Reviewed by Tim Horton.
     8
     9        Adds a new unit test, DataInteractionTests.ExternalSourceTitledNSURL.
     10
     11        * TestWebKitAPI/Tests/ios/DataInteractionTests.mm:
     12        (TestWebKitAPI::TEST):
     13
    1142017-04-24  Wenson Hsieh  <wenson_hsieh@apple.com>
    215
  • trunk/Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm

    r215714 r215724  
    535535}
    536536
     537TEST(DataInteractionTests, ExternalSourceTitledNSURL)
     538{
     539    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
     540    [webView synchronouslyLoadTestPageNamed:@"autofocus-contenteditable"];
     541    [webView stringByEvaluatingJavaScript:@"getSelection().removeAllRanges()"];
     542
     543    NSURL *titledURL = [NSURL URLWithString:@"https://www.apple.com"];
     544    titledURL._title = @"Apple";
     545    auto simulatedItemProvider = adoptNS([[UIItemProvider alloc] init]);
     546    [simulatedItemProvider registerObject:titledURL visibility:NSItemProviderRepresentationVisibilityAll];
     547
     548    auto dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]);
     549    [dataInteractionSimulator setExternalItemProviders:@[ simulatedItemProvider.get() ]];
     550    [dataInteractionSimulator runFrom:CGPointMake(300, 400) to:CGPointMake(100, 300)];
     551
     552    EXPECT_WK_STREQ("Apple", [webView stringByEvaluatingJavaScript:@"editor.querySelector('a').textContent"]);
     553    EXPECT_WK_STREQ("https://www.apple.com/", [webView stringByEvaluatingJavaScript:@"editor.querySelector('a').href"]);
     554}
     555
    537556TEST(DataInteractionTests, OverrideDataInteractionOperation)
    538557{
Note: See TracChangeset for help on using the changeset viewer.