Title: [215184] trunk
Revision
215184
Author
wenson_hs...@apple.com
Date
2017-04-10 10:07:44 -0700 (Mon, 10 Apr 2017)

Log Message

Data interaction on an image enclosed by an anchor should vend the anchor's URL
https://bugs.webkit.org/show_bug.cgi?id=170660
<rdar://problem/31043220>

Reviewed by Tim Horton.

Source/WebCore:

When writing an image embedded inside an anchor to the pasteboard, actually use the enclosing anchor's href if
it exists. Previously, we were simply dropping this argument on the floor.

Covered by 2 new DataInteractionTests: ImageInLinkToInput and ImageInLinkWithoutHREFToInput.

* editing/ios/EditorIOS.mm:
(WebCore::Editor::writeImageToPasteboard):

Tools:

Adds two new unit tests covering cases where data interaction is triggered from an image nested underneath an
anchor. In one of the tests, the link has an href, and in the other, its href is missing, in which case we
should fall back to the image URL instead. Also fixes a related unit test that was trying to check selection
rects, but should not be.

See WebCore ChangeLog for more details.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2Cocoa/image-in-link-and-input.html: Added.
* TestWebKitAPI/Tests/ios/DataInteractionTests.mm:
(TestWebKitAPI::TEST):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (215183 => 215184)


--- trunk/Source/WebCore/ChangeLog	2017-04-10 16:44:01 UTC (rev 215183)
+++ trunk/Source/WebCore/ChangeLog	2017-04-10 17:07:44 UTC (rev 215184)
@@ -1,3 +1,19 @@
+2017-04-10  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        Data interaction on an image enclosed by an anchor should vend the anchor's URL
+        https://bugs.webkit.org/show_bug.cgi?id=170660
+        <rdar://problem/31043220>
+
+        Reviewed by Tim Horton.
+
+        When writing an image embedded inside an anchor to the pasteboard, actually use the enclosing anchor's href if
+        it exists. Previously, we were simply dropping this argument on the floor.
+
+        Covered by 2 new DataInteractionTests: ImageInLinkToInput and ImageInLinkWithoutHREFToInput.
+
+        * editing/ios/EditorIOS.mm:
+        (WebCore::Editor::writeImageToPasteboard):
+
 2017-04-10  Jon Lee  <jon...@apple.com>
 
         Update localizable strings to "full screen" from "fullscreen"

Modified: trunk/Source/WebCore/editing/ios/EditorIOS.mm (215183 => 215184)


--- trunk/Source/WebCore/editing/ios/EditorIOS.mm	2017-04-10 16:44:01 UTC (rev 215183)
+++ trunk/Source/WebCore/editing/ios/EditorIOS.mm	2017-04-10 17:07:44 UTC (rev 215184)
@@ -197,7 +197,7 @@
     cachedImage = tentativeCachedImage;
 }
 
-void Editor::writeImageToPasteboard(Pasteboard& pasteboard, Element& imageElement, const URL&, const String& title)
+void Editor::writeImageToPasteboard(Pasteboard& pasteboard, Element& imageElement, const URL& url, const String& title)
 {
     PasteboardImage pasteboardImage;
 
@@ -207,7 +207,7 @@
         return;
     ASSERT(cachedImage);
 
-    pasteboardImage.url.url = ""
+    pasteboardImage.url.url = "" ? imageElement.document().completeURL(stripLeadingAndTrailingHTMLSpaces(imageElement.imageSourceURL())) : url;
     pasteboardImage.url.title = title;
     pasteboardImage.resourceMIMEType = pasteboard.resourceMIMEType(cachedImage->response().mimeType());
     pasteboardImage.resourceData = cachedImage->resourceBuffer();

Modified: trunk/Tools/ChangeLog (215183 => 215184)


--- trunk/Tools/ChangeLog	2017-04-10 16:44:01 UTC (rev 215183)
+++ trunk/Tools/ChangeLog	2017-04-10 17:07:44 UTC (rev 215184)
@@ -1,3 +1,23 @@
+2017-04-10  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        Data interaction on an image enclosed by an anchor should vend the anchor's URL
+        https://bugs.webkit.org/show_bug.cgi?id=170660
+        <rdar://problem/31043220>
+
+        Reviewed by Tim Horton.
+
+        Adds two new unit tests covering cases where data interaction is triggered from an image nested underneath an
+        anchor. In one of the tests, the link has an href, and in the other, its href is missing, in which case we
+        should fall back to the image URL instead. Also fixes a related unit test that was trying to check selection
+        rects, but should not be.
+
+        See WebCore ChangeLog for more details.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit2Cocoa/image-in-link-and-input.html: Added.
+        * TestWebKitAPI/Tests/ios/DataInteractionTests.mm:
+        (TestWebKitAPI::TEST):
+
 2017-04-10  Carlos Garcia Campos  <cgar...@igalia.com>
 
         [GTK] Remove the GDK dependency from ImageDiff

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (215183 => 215184)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2017-04-10 16:44:01 UTC (rev 215183)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2017-04-10 17:07:44 UTC (rev 215184)
@@ -585,6 +585,7 @@
 		F4C2AB221DD6D95E00E06D5B /* enormous-video-with-sound.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4C2AB211DD6D94100E06D5B /* enormous-video-with-sound.html */; };
 		F4D4F3B61E4E2BCB00BB2767 /* DataInteractionSimulator.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4D4F3B41E4E2BCB00BB2767 /* DataInteractionSimulator.mm */; };
 		F4D4F3B91E4E36E400BB2767 /* DataInteractionTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4D4F3B71E4E36E400BB2767 /* DataInteractionTests.mm */; };
+		F4DEF6ED1E9B4DB60048EF61 /* image-in-link-and-input.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4DEF6EC1E9B4D950048EF61 /* image-in-link-and-input.html */; };
 		F4F137921D9B683E002BEC57 /* large-video-test-now-playing.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4F137911D9B6832002BEC57 /* large-video-test-now-playing.html */; };
 		F4F405BC1D4C0D1C007A9707 /* full-size-autoplaying-video-with-audio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4F405BA1D4C0CF8007A9707 /* full-size-autoplaying-video-with-audio.html */; };
 		F4F405BD1D4C0D1C007A9707 /* skinny-autoplaying-video-with-audio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4F405BB1D4C0CF8007A9707 /* skinny-autoplaying-video-with-audio.html */; };
@@ -659,6 +660,7 @@
 			dstPath = TestWebKitAPI.resources;
 			dstSubfolderSpec = 7;
 			files = (
+				F4DEF6ED1E9B4DB60048EF61 /* image-in-link-and-input.html in Copy Resources */,
 				1A9E52C913E65EF4006917F5 /* 18-characters.html in Copy Resources */,
 				379028B914FAC24C007E6B43 /* acceptsFirstMouse.html in Copy Resources */,
 				1C2B81871C8925A000A5529F /* Ahem.ttf in Copy Resources */,
@@ -1448,6 +1450,7 @@
 		F4D4F3B41E4E2BCB00BB2767 /* DataInteractionSimulator.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DataInteractionSimulator.mm; sourceTree = "<group>"; };
 		F4D4F3B51E4E2BCB00BB2767 /* DataInteractionSimulator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DataInteractionSimulator.h; sourceTree = "<group>"; };
 		F4D4F3B71E4E36E400BB2767 /* DataInteractionTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DataInteractionTests.mm; sourceTree = "<group>"; };
+		F4DEF6EC1E9B4D950048EF61 /* image-in-link-and-input.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "image-in-link-and-input.html"; sourceTree = "<group>"; };
 		F4F137911D9B6832002BEC57 /* large-video-test-now-playing.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "large-video-test-now-playing.html"; sourceTree = "<group>"; };
 		F4F405BA1D4C0CF8007A9707 /* full-size-autoplaying-video-with-audio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "full-size-autoplaying-video-with-audio.html"; sourceTree = "<group>"; };
 		F4F405BB1D4C0CF8007A9707 /* skinny-autoplaying-video-with-audio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "skinny-autoplaying-video-with-audio.html"; sourceTree = "<group>"; };
@@ -1830,6 +1833,7 @@
 				CD78E11B1DB7EA360014A2DE /* FullscreenDelegate.html */,
 				3FBD1B491D39D1DB00E6D6FA /* FullscreenLayoutConstraints.html */,
 				CDE195B21CFE0ADE0053D256 /* FullscreenTopContentInset.html */,
+				F4DEF6EC1E9B4D950048EF61 /* image-in-link-and-input.html */,
 				510477761D298E57009747EB /* IDBDeleteRecovery.html */,
 				5104776F1D298D85009747EB /* IDBDeleteRecovery.sqlite3 */,
 				510477701D298D85009747EB /* IDBDeleteRecovery.sqlite3-shm */,

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/image-in-link-and-input.html (0 => 215184)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/image-in-link-and-input.html	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/image-in-link-and-input.html	2017-04-10 17:07:44 UTC (rev 215184)
@@ -0,0 +1,30 @@
+<head>
+    <meta name="viewport" content="width=device-width, initial-scale=1">
+        <style>
+        body {
+            width: 100%;
+            height: 100%;
+            margin: 0;
+        }
+
+        img, a, #editor {
+            width: 100%;
+            height: 200px;
+            font-size: 200px;
+            white-space: nowrap;
+        }
+
+        a {
+            display: block;
+        }
+
+        #editor {
+            border: black 1px solid;
+        }
+        </style>
+</head>
+
+<body>
+    <div><a id="link" href="" src=""
+    <div><input id="editor"></input></div>
+</body>

Modified: trunk/Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm (215183 => 215184)


--- trunk/Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm	2017-04-10 16:44:01 UTC (rev 215183)
+++ trunk/Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm	2017-04-10 17:07:44 UTC (rev 215184)
@@ -106,11 +106,34 @@
     EXPECT_TRUE([observedEventNames containsObject:DataInteractionOverEventName]);
     EXPECT_TRUE([observedEventNames containsObject:DataInteractionPerformOperationEventName]);
 
-    NSArray *expectedSelectionRects = [NSArray arrayWithObjects:makeCGRectValue(6, 203, 188, 14), makeCGRectValue(6, 217, 188, 14), makeCGRectValue(6, 231, 66, 14), nil];
-    checkSelectionRectsWithLogging(expectedSelectionRects, [dataInteractionSimulator finalSelectionRects]);
     checkTypeIdentifierPrecedesOtherTypeIdentifier(dataInteractionSimulator.get(), (NSString *)kUTTypePNG, (NSString *)kUTTypeFileURL);
 }
 
+TEST(DataInteractionTests, ImageInLinkToInput)
+{
+    RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+    [webView synchronouslyLoadTestPageNamed:@"image-in-link-and-input"];
+
+    RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]);
+    [dataInteractionSimulator runFrom:CGPointMake(100, 50) to:CGPointMake(100, 300)];
+
+    EXPECT_WK_STREQ("https://www.apple.com/", [webView editorValue].UTF8String);
+    checkSelectionRectsWithLogging(@[ makeCGRectValue(101, 241, 2057, 232) ], [dataInteractionSimulator finalSelectionRects]);
+}
+
+TEST(DataInteractionTests, ImageInLinkWithoutHREFToInput)
+{
+    RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+    [webView synchronouslyLoadTestPageNamed:@"image-in-link-and-input"];
+    [webView stringByEvaluatingJavaScript:@"link.href = ''"];
+
+    RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]);
+    [dataInteractionSimulator runFrom:CGPointMake(100, 50) to:CGPointMake(100, 300)];
+
+    NSURL *imageURL = [NSURL fileURLWithPath:[webView editorValue]];
+    EXPECT_WK_STREQ("icon.png", imageURL.lastPathComponent);
+}
+
 TEST(DataInteractionTests, ContentEditableToContentEditable)
 {
     RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to