[iOS] Multiple links in Mail are dropped in a single line, and are difficult to tell...
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 5 May 2018 04:39:52 +0000 (04:39 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 5 May 2018 04:39:52 +0000 (04:39 +0000)
https://bugs.webkit.org/show_bug.cgi?id=185289
<rdar://problem/35756912>

Reviewed by Tim Horton and Darin Adler.

Source/WebCore:

When inserting multiple URLs as individual items in a single drop, we currently separate each item with a space
(see r217284). However, it still seems difficult to tell dropped links apart. This patch makes some slight
tweaks to WebContentReader::readURL so that it inserts line breaks before dropped URLs, if the dropped URL isn't
the first item to be inserted in the resulting document fragment.

Augments existing API tests in DataInteractionTests.

* editing/ios/WebContentReaderIOS.mm:

Additionally remove some extraneous header imports from this implementation file.

(WebCore::WebContentReader::readURL):

Tools:

Augment and rebaseline some iOS drag-and-drop API tests that handle dropping URLs as a part of multi-item drop
sessions.

* TestWebKitAPI/Tests/ios/DataInteractionTests.mm:
(TestWebKitAPI::TEST):

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

Source/WebCore/ChangeLog
Source/WebCore/editing/ios/WebContentReaderIOS.mm
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm

index 293ccf0..6438990 100644 (file)
@@ -1,3 +1,24 @@
+2018-05-04  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [iOS] Multiple links in Mail are dropped in a single line, and are difficult to tell apart
+        https://bugs.webkit.org/show_bug.cgi?id=185289
+        <rdar://problem/35756912>
+
+        Reviewed by Tim Horton and Darin Adler.
+
+        When inserting multiple URLs as individual items in a single drop, we currently separate each item with a space
+        (see r217284). However, it still seems difficult to tell dropped links apart. This patch makes some slight
+        tweaks to WebContentReader::readURL so that it inserts line breaks before dropped URLs, if the dropped URL isn't
+        the first item to be inserted in the resulting document fragment.
+
+        Augments existing API tests in DataInteractionTests.
+
+        * editing/ios/WebContentReaderIOS.mm:
+
+        Additionally remove some extraneous header imports from this implementation file.
+
+        (WebCore::WebContentReader::readURL):
+
 2018-05-02  Dean Jackson  <dino@apple.com>
 
         Use IOSurfaces for CoreImage operations where possible
index 9b310d5..8de5c15 100644 (file)
 
 #if PLATFORM(IOS)
 
-#import "ArchiveResource.h"
 #import "Document.h"
 #import "DocumentFragment.h"
-#import "DocumentLoader.h"
 #import "Editor.h"
 #import "EditorClient.h"
-#import "FragmentScriptingPermission.h"
-#import "FrameLoader.h"
-#import "FrameLoaderClient.h"
 #import "HTMLAnchorElement.h"
+#import "HTMLBRElement.h"
 #import "HTMLNames.h"
-#import "LegacyWebArchive.h"
-#import "MIMETypeRegistry.h"
 #import "Text.h"
-#import "UTIUtilities.h"
-#import "markup.h"
-#import <MobileCoreServices/MobileCoreServices.h>
-#import <wtf/unicode/CharacterNames.h>
 
 namespace WebCore {
 
@@ -63,15 +53,16 @@ bool WebContentReader::readURL(const URL& url, const String& title)
     if ([(NSURL *)url isFileURL])
         return false;
 
-    auto anchor = HTMLAnchorElement::create(*frame.document());
+    auto document = makeRef(*frame.document());
+    auto anchor = HTMLAnchorElement::create(document.get());
     anchor->setAttributeWithoutSynchronization(HTMLNames::hrefAttr, url.string());
 
     String linkText = title.length() ? title : String([[(NSURL *)url absoluteString] precomposedStringWithCanonicalMapping]);
-    anchor->appendChild(frame.document()->createTextNode(linkText));
+    anchor->appendChild(document->createTextNode(linkText));
 
-    auto newFragment = frame.document()->createDocumentFragment();
+    auto newFragment = document->createDocumentFragment();
     if (fragment)
-        newFragment->appendChild(Text::create(*frame.document(), { &space, 1 }));
+        newFragment->appendChild(HTMLBRElement::create(document.get()));
     newFragment->appendChild(anchor);
     addFragment(WTFMove(newFragment));
     return true;
index 5316f64..5a2e276 100644 (file)
@@ -1,3 +1,17 @@
+2018-05-04  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [iOS] Multiple links in Mail are dropped in a single line, and are difficult to tell apart
+        https://bugs.webkit.org/show_bug.cgi?id=185289
+        <rdar://problem/35756912>
+
+        Reviewed by Tim Horton and Darin Adler.
+
+        Augment and rebaseline some iOS drag-and-drop API tests that handle dropping URLs as a part of multi-item drop
+        sessions.
+
+        * TestWebKitAPI/Tests/ios/DataInteractionTests.mm:
+        (TestWebKitAPI::TEST):
+
 2018-05-04  Timothy Hatcher  <timothy@apple.com>
 
         Deprecate legacy WebView and friends
index 4a348c2..bf0d929 100644 (file)
@@ -856,11 +856,17 @@ TEST(DataInteractionTests, ExternalSourceMultipleURLsToContentEditable)
     [dataInteractionSimulator setExternalItemProviders:@[ firstItem.get(), secondItem.get(), thirdItem.get() ]];
     [dataInteractionSimulator runFrom:CGPointMake(300, 400) to:CGPointMake(100, 300)];
 
-    NSArray *separatedLinks = [[webView stringByEvaluatingJavaScript:@"editor.textContent"] componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
-    EXPECT_EQ(3UL, separatedLinks.count);
-    EXPECT_WK_STREQ("https://www.apple.com/iphone/", separatedLinks[0]);
-    EXPECT_WK_STREQ("https://www.apple.com/mac/", separatedLinks[1]);
-    EXPECT_WK_STREQ("https://webkit.org/", separatedLinks[2]);
+    NSArray *droppedURLs = [webView objectByEvaluatingJavaScript:@"Array.from(editor.querySelectorAll('a')).map(a => a.href)"];
+    EXPECT_EQ(3UL, droppedURLs.count);
+    EXPECT_WK_STREQ("https://www.apple.com/iphone/", droppedURLs[0]);
+    EXPECT_WK_STREQ("https://www.apple.com/mac/", droppedURLs[1]);
+    EXPECT_WK_STREQ("https://webkit.org/", droppedURLs[2]);
+
+    NSArray *linksSeparatedByLine = [[webView objectByEvaluatingJavaScript:@"editor.innerText"] componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
+    EXPECT_EQ(3UL, linksSeparatedByLine.count);
+    EXPECT_WK_STREQ("https://www.apple.com/iphone/", linksSeparatedByLine[0]);
+    EXPECT_WK_STREQ("https://www.apple.com/mac/", linksSeparatedByLine[1]);
+    EXPECT_WK_STREQ("https://webkit.org/", linksSeparatedByLine[2]);
 }
 
 TEST(DataInteractionTests, RespectsExternalSourceFidelityRankings)
@@ -1466,7 +1472,7 @@ TEST(DataInteractionTests, AdditionalLinkAndImageIntoContentEditable)
         @0.33: [NSValue valueWithCGPoint:CGPointMake(50, 150)],
         @0.66: [NSValue valueWithCGPoint:CGPointMake(50, 250)]
     }];
-    EXPECT_WK_STREQ("ABCD A link", [webView stringByEvaluatingJavaScript:@"editor.textContent"]);
+    EXPECT_WK_STREQ("ABCDA link", [webView stringByEvaluatingJavaScript:@"editor.textContent"]);
     EXPECT_TRUE([webView stringByEvaluatingJavaScript:@"!!editor.querySelector('img')"]);
     EXPECT_WK_STREQ("https://www.apple.com/", [webView stringByEvaluatingJavaScript:@"editor.querySelector('a').href"]);
 }