Title: [215849] trunk
Revision
215849
Author
[email protected]
Date
2017-04-26 18:03:14 -0700 (Wed, 26 Apr 2017)

Log Message

Should not drag x-apple-data-detectors links
https://bugs.webkit.org/show_bug.cgi?id=171352
<rdar://problem/31309081>

Reviewed by Beth Dakin.

Test: fast/events/do-not-drag-and-drop-data-detectors-link.html

These links are only meaningful in the context of the original document,
so they should not be draggable.

* editing/cocoa/DataDetection.h:
* editing/cocoa/DataDetection.mm:
(WebCore::DataDetection::dataDetectorURLProtocol):
(WebCore::DataDetection::isDataDetectorURL):
* page/DragController.cpp:
(WebCore::isDraggableLink):
Disallow dragging of <a href="" links.

* fast/events/do-not-drag-and-drop-data-detectors-link-expected.txt: Added.
* fast/events/do-not-drag-and-drop-data-detectors-link.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (215848 => 215849)


--- trunk/LayoutTests/ChangeLog	2017-04-27 01:01:57 UTC (rev 215848)
+++ trunk/LayoutTests/ChangeLog	2017-04-27 01:03:14 UTC (rev 215849)
@@ -1,5 +1,16 @@
 2017-04-26  Tim Horton  <[email protected]>
 
+        Should not drag x-apple-data-detectors links
+        https://bugs.webkit.org/show_bug.cgi?id=171352
+        <rdar://problem/31309081>
+
+        Reviewed by Beth Dakin.
+
+        * fast/events/do-not-drag-and-drop-data-detectors-link-expected.txt: Added.
+        * fast/events/do-not-drag-and-drop-data-detectors-link.html: Added.
+
+2017-04-26  Tim Horton  <[email protected]>
+
         Revert accidentally smushed commit.
 
         * TestExpectations:

Modified: trunk/LayoutTests/TestExpectations (215848 => 215849)


--- trunk/LayoutTests/TestExpectations	2017-04-27 01:01:57 UTC (rev 215848)
+++ trunk/LayoutTests/TestExpectations	2017-04-27 01:03:14 UTC (rev 215849)
@@ -106,6 +106,9 @@
 # FKA focus ring only make sense on Mac
 media/modern-media-controls/icon-button/icon-button-focus-state.html [ Skip ]
 
+# DataDetectors tests only make sense on Mac
+fast/events/do-not-drag-and-drop-data-detectors-link.html [ Skip ]
+
 #//////////////////////////////////////////////////////////////////////////////////////////
 # End platform-specific tests.
 #//////////////////////////////////////////////////////////////////////////////////////////

Added: trunk/LayoutTests/fast/events/do-not-drag-and-drop-data-detectors-link-expected.txt (0 => 215849)


--- trunk/LayoutTests/fast/events/do-not-drag-and-drop-data-detectors-link-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/events/do-not-drag-and-drop-data-detectors-link-expected.txt	2017-04-27 01:03:14 UTC (rev 215849)
@@ -0,0 +1,10 @@
+This test checks that drag-and-drop is blocked for Data Detectors links.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Trying to drag Data Detectors link (should fail)
+
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/events/do-not-drag-and-drop-data-detectors-link.html (0 => 215849)


--- trunk/LayoutTests/fast/events/do-not-drag-and-drop-data-detectors-link.html	                        (rev 0)
+++ trunk/LayoutTests/fast/events/do-not-drag-and-drop-data-detectors-link.html	2017-04-27 01:03:14 UTC (rev 215849)
@@ -0,0 +1,68 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script>
+var ddLink;
+var didDragStart = false;
+
+window.jsTestIsAsync = true;
+
+window._onload_ = function ()
+{
+    ddLink = document.getElementById("ddLink");
+
+    ddLink._ondragstart_ = dragStart;
+    document.body._onmouseup_ = mouseUp;
+
+    runTests();
+}
+
+function dragStart(e)
+{
+    didDragStart = true;
+    debug('<br><span class="fail">FAIL! Got dragStart().</span>');
+}
+
+function mouseUp(e)
+{
+    var testContainer = document.getElementById("test-container");
+    if (testContainer)
+        document.body.removeChild(testContainer);
+    if (!didDragStart)
+        debug('<br><span class="pass">TEST COMPLETE</span>');
+    finishJSTest();
+}
+
+function dragAndDrop(beginX, beginY, endX, endY)
+{
+    if (!window.eventSender)
+        return;
+    eventSender.mouseMoveTo(beginX, beginY);
+    eventSender.mouseDown();
+    eventSender.leapForward(100);
+    eventSender.mouseMoveTo(endX, endY);
+    eventSender.mouseUp();
+}
+
+function runTests()
+{
+    if (!window.testRunner)
+        return;
+
+    debug("<br>Trying to drag Data Detectors link (should fail)<br>");
+    dragAndDrop(ddLink.offsetLeft, ddLink.offsetTop + ddLink.offsetHeight / 2, 100, 100);
+}
+</script>
+</head>
+<body>
+<div id="description"></div>
+<div id="test-container">
+    <a href="" id="ddLink">Data Detectors Link</a>
+</div>
+<div id="console"></div>
+<script>
+description("This test checks that drag-and-drop is blocked for Data Detectors links.");
+</script>
+</body>
+</html>

Modified: trunk/LayoutTests/platform/mac/TestExpectations (215848 => 215849)


--- trunk/LayoutTests/platform/mac/TestExpectations	2017-04-27 01:01:57 UTC (rev 215848)
+++ trunk/LayoutTests/platform/mac/TestExpectations	2017-04-27 01:03:14 UTC (rev 215849)
@@ -29,6 +29,8 @@
 
 media/modern-media-controls/icon-button/icon-button-focus-state.html [ Pass ]
 
+fast/events/do-not-drag-and-drop-data-detectors-link.html [ Pass ]
+
 #//////////////////////////////////////////////////////////////////////////////////////////
 # End platform-specific directories.
 #//////////////////////////////////////////////////////////////////////////////////////////

Modified: trunk/Source/WebCore/ChangeLog (215848 => 215849)


--- trunk/Source/WebCore/ChangeLog	2017-04-27 01:01:57 UTC (rev 215848)
+++ trunk/Source/WebCore/ChangeLog	2017-04-27 01:03:14 UTC (rev 215849)
@@ -1,5 +1,26 @@
 2017-04-26  Tim Horton  <[email protected]>
 
+        Should not drag x-apple-data-detectors links
+        https://bugs.webkit.org/show_bug.cgi?id=171352
+        <rdar://problem/31309081>
+
+        Reviewed by Beth Dakin.
+
+        Test: fast/events/do-not-drag-and-drop-data-detectors-link.html
+
+        These links are only meaningful in the context of the original document,
+        so they should not be draggable.
+
+        * editing/cocoa/DataDetection.h:
+        * editing/cocoa/DataDetection.mm:
+        (WebCore::DataDetection::dataDetectorURLProtocol):
+        (WebCore::DataDetection::isDataDetectorURL):
+        * page/DragController.cpp:
+        (WebCore::isDraggableLink):
+        Disallow dragging of <a href="" links.
+
+2017-04-26  Tim Horton  <[email protected]>
+
         Revert accidentally smushed commit.
 
         * editing/cocoa/DataDetection.h:

Modified: trunk/Source/WebCore/editing/cocoa/DataDetection.h (215848 => 215849)


--- trunk/Source/WebCore/editing/cocoa/DataDetection.h	2017-04-27 01:01:57 UTC (rev 215848)
+++ trunk/Source/WebCore/editing/cocoa/DataDetection.h	2017-04-27 01:03:14 UTC (rev 215849)
@@ -39,6 +39,7 @@
 class FloatRect;
 class HitTestResult;
 class Range;
+class URL;
 
 enum DataDetectorTypes {
     DataDetectorTypeNone = 0,
@@ -64,6 +65,9 @@
     WEBCORE_EXPORT static bool shouldCancelDefaultAction(Element&);
     WEBCORE_EXPORT static bool requiresExtendedContext(Element&);
 #endif
+
+    static const String& dataDetectorURLProtocol();
+    static bool isDataDetectorURL(const URL&);
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/editing/cocoa/DataDetection.mm (215848 => 215849)


--- trunk/Source/WebCore/editing/cocoa/DataDetection.mm	2017-04-27 01:01:57 UTC (rev 215848)
+++ trunk/Source/WebCore/editing/cocoa/DataDetection.mm	2017-04-27 01:03:14 UTC (rev 215849)
@@ -659,4 +659,16 @@
     return nil;
 }
 #endif
+
+const String& DataDetection::dataDetectorURLProtocol()
+{
+    static NeverDestroyed<String> protocol(ASCIILiteral("x-apple-data-detectors"));
+    return protocol;
+}
+
+bool DataDetection::isDataDetectorURL(const URL& url)
+{
+    return url.protocolIs(dataDetectorURLProtocol());
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/page/DragController.cpp (215848 => 215849)


--- trunk/Source/WebCore/page/DragController.cpp	2017-04-27 01:01:57 UTC (rev 215848)
+++ trunk/Source/WebCore/page/DragController.cpp	2017-04-27 01:03:14 UTC (rev 215849)
@@ -88,12 +88,24 @@
 #include <wtf/RefPtr.h>
 #endif
 
+#if PLATFORM(COCOA)
+#include "DataDetection.h"
+#endif
+
 namespace WebCore {
 
 bool isDraggableLink(const Element& element)
 {
-    if (is<HTMLAnchorElement>(element))
-        return downcast<HTMLAnchorElement>(element).isLiveLink();
+    if (is<HTMLAnchorElement>(element)) {
+        auto& anchorElement = downcast<HTMLAnchorElement>(element);
+        if (!anchorElement.isLiveLink())
+            return false;
+#if PLATFORM(COCOA)
+        return !DataDetection::isDataDetectorURL(anchorElement.href());
+#else
+        return true;
+#endif
+    }
     if (is<SVGAElement>(element))
         return element.isLink();
     return false;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to