REGRESSION: SVG does not support link dragging
authordbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Apr 2015 18:21:30 +0000 (18:21 +0000)
committerdbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Apr 2015 18:21:30 +0000 (18:21 +0000)
https://bugs.webkit.org/show_bug.cgi?id=141597

Reviewed by Darin Adler.

Source/WebCore:

Fixes an issue where a SVG hyperlink cannot be dragged. We should support
dragging an SVG A element just as we support dragging an HTML A element.

Test: fast/events/drag-and-drop-link.html

* page/DragController.cpp: Removed explicit include of header Element.h as it will
be ultimately included by HTMLAnchorElement.h, among other headers.
(WebCore::isDraggableLink): Added. Extracted code from HitTestResult::isLiveLink().
(WebCore::DragController::draggableElement): Call WebCore::isDraggableLink() to
determine whether a element is a hyperlink that can be dragged.
* page/DragController.h:
* page/EventHandler.cpp:
(WebCore::EventHandler::selectClosestWordOrLinkFromMouseEvent): Write code in terms of
 WebCore::isDraggableLink().
* rendering/HitTestResult.cpp:
(WebCore::HitTestResult::isLiveLink): Deleted.
* rendering/HitTestResult.h:

Source/WebKit/mac:

Write -[WebElementDictionary _isLiveLink] in terms of WebCore::isDraggableLink().

* Misc/WebElementDictionary.mm:
(-[WebElementDictionary _isLiveLink]):

LayoutTests:

Add a test to ensure we do not regress dragging of a HTML hyperlink or a SVG hyperlink.

* fast/events/drag-and-drop-link-expected.txt: Added.
* fast/events/drag-and-drop-link.html: Added.
* platform/efl/TestExpectations: Mark the test as "failure" since EFL does not support drag-and-drop.
* platform/gtk/TestExpectations: Mark the test as "failure" until we implement drag-and-drop support for
GTK+ as part of fixing <https://bugs.webkit.org/show_bug.cgi?id=42194>.
* platform/ios-simulator/TestExpectations: Skip the test since iOS does not implement
drag-and-drop support.
* platform/mac-wk2/TestExpectations: Skip the test until we implement drag-and-drop support in EventSender
for Mac as part of fixing <https://bugs.webkit.org/show_bug.cgi?id=42194>.

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

15 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/events/drag-and-drop-link-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/drag-and-drop-link.html [new file with mode: 0644]
LayoutTests/platform/efl/TestExpectations
LayoutTests/platform/gtk/TestExpectations
LayoutTests/platform/ios-simulator/TestExpectations
LayoutTests/platform/mac-wk2/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/page/DragController.cpp
Source/WebCore/page/DragController.h
Source/WebCore/page/EventHandler.cpp
Source/WebCore/rendering/HitTestResult.cpp
Source/WebCore/rendering/HitTestResult.h
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/Misc/WebElementDictionary.mm

index 03ea984..b28ca61 100644 (file)
@@ -1,3 +1,22 @@
+2015-04-17  Daniel Bates  <dabates@apple.com>
+
+        REGRESSION: SVG does not support link dragging
+        https://bugs.webkit.org/show_bug.cgi?id=141597
+
+        Reviewed by Darin Adler.
+
+        Add a test to ensure we do not regress dragging of a HTML hyperlink or a SVG hyperlink.
+
+        * fast/events/drag-and-drop-link-expected.txt: Added.
+        * fast/events/drag-and-drop-link.html: Added.
+        * platform/efl/TestExpectations: Mark the test as "failure" since EFL does not support drag-and-drop.
+        * platform/gtk/TestExpectations: Mark the test as "failure" until we implement drag-and-drop support for
+        GTK+ as part of fixing <https://bugs.webkit.org/show_bug.cgi?id=42194>.
+        * platform/ios-simulator/TestExpectations: Skip the test since iOS does not implement
+        drag-and-drop support.
+        * platform/mac-wk2/TestExpectations: Skip the test until we implement drag-and-drop support in EventSender
+        for Mac as part of fixing <https://bugs.webkit.org/show_bug.cgi?id=42194>.
+
 2015-04-17  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r182912 and r182920.
diff --git a/LayoutTests/fast/events/drag-and-drop-link-expected.txt b/LayoutTests/fast/events/drag-and-drop-link-expected.txt
new file mode 100644 (file)
index 0000000..aea23e4
--- /dev/null
@@ -0,0 +1,15 @@
+This test checks that drag-and-drop support works for a hyperlink.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Dragging HTML hyperlink
+
+PASS event.dataTransfer.getData("url") is "http://www.whatwg.org/html"
+
+Dragging SVG hyperlink
+
+PASS event.dataTransfer.getData("url") is "http://www.w3.org/TR/SVG11/"
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/events/drag-and-drop-link.html b/LayoutTests/fast/events/drag-and-drop-link.html
new file mode 100644 (file)
index 0000000..0a63024
--- /dev/null
@@ -0,0 +1,139 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<style>
+#drop-container > div {
+    height: 256px;
+    width: 256px;
+    color: gray;
+}
+#drop-instructions {
+    display: -webkit-box;
+    display: -moz-box;
+    display: -ms-flexbox;
+    -webkit-box-align: center;
+    -moz-box-align: center;
+    -ms-flex-align: center;
+    -webkit-box-pack: center;
+    -moz-box-pack: center;
+    -ms-flex-pack: center;
+    -webkit-user-select: none;
+    -moz-user-select: none;
+    -ms-user-select: none;
+    pointer-events: none;
+}
+#drop-target {
+    border: 1px dashed black;
+    margin-top: -256px; /* Paint on top of #drop-instructions. */
+}
+</style>
+<script>
+var dropTarget;
+var draggingElement;
+var event;
+
+var svgHyperlink;
+var htmlHyperlink;
+var numberOfTestsToRun;
+
+window.jsTestIsAsync = true;
+
+window.onload = function ()
+{
+    svgHyperlink = document.getElementById("svgHyperlink");
+    htmlHyperlink = document.getElementById("htmlHyperlink");
+
+    svgHyperlink.ondragstart = dragStart;
+    svgHyperlink.ondragend = dragEnd;
+    htmlHyperlink.ondragstart = dragStart;
+    htmlHyperlink.ondragend = dragEnd;
+
+    dropTarget = document.getElementById("drop-target");
+    dropTarget.ondrop = drop;
+
+    runTests();
+}
+
+function dragStart(e)
+{
+    event = e;
+    draggingElement = e.target;
+}
+
+function dragEnd(e)
+{
+    dropTarget.innerHTML = "";
+    draggingElement = null;
+}
+
+function drop(e)
+{
+    event = e;
+    var expectedHref = draggingElement instanceof SVGElement ? draggingElement.href.baseVal : draggingElement.href;
+    shouldBeEqualToString('event.dataTransfer.getData("url")', expectedHref);
+    if (window.testRunner && !--numberOfTestsToRun)
+        done();
+}
+
+function done()
+{
+    var testContainer = document.getElementById("test-container");
+    if (testContainer)
+        document.body.removeChild(testContainer);
+    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;
+
+    var endX = dropTarget.offsetLeft + 10;
+    var endY = dropTarget.offsetTop + dropTarget.offsetHeight / 2;
+
+    numberOfTestsToRun = 2;
+
+    debug("<br>Dragging HTML hyperlink<br>");
+    dragAndDrop(htmlHyperlink.offsetLeft, htmlHyperlink.offsetTop + htmlHyperlink.offsetHeight / 2, endX, endY);
+
+    debug("<br>Dragging SVG hyperlink<br>");
+    // Only the SVG root element has a CSS layout box. And Offset{Left, Top, Width, Height} only work for elements that have a CSS layout box
+    // per <http://www.w3.org/TR/cssom-view/#extensions-to-the-htmlelement-interface>.
+    dragAndDrop(svgHyperlink.ownerSVGElement.offsetLeft, svgHyperlink.ownerSVGElement.offsetTop + 10, endX, endY);
+}
+</script>
+</head>
+<body>
+<div id="description"></div>
+<div id="test-container">
+    <div id="drop-container">
+        <div id="drop-instructions">Drop a hyperlink on me.</div>
+        <div id="drop-target" contenteditable="true"></div>
+    </div>
+    <hr>
+    <p>Items that can be dragged to the drop target:</p>
+    <svg width="200" height="30">
+        <a xlink:href="http://www.w3.org/TR/SVG11/" id="svgHyperlink"><text x="0" y="20" style="text-decoration: underline">SVG hyperlink</text></a>
+    </svg>
+    <a href="http://www.whatwg.org/html" id="htmlHyperlink">HTML hyperlink</a>
+    <hr>
+</div>
+<div id="console"></div>
+<script>
+description("This test checks that drag-and-drop support works for a hyperlink.");
+</script>
+</body>
+</html>
index 1bd8499..56861a2 100644 (file)
@@ -343,6 +343,7 @@ webkit.org/b/86623 fast/events/drag-customData.html
 webkit.org/b/86623 fast/events/drag-dataTransferItemList.html
 webkit.org/b/86623 fast/events/drag-image-filename.html [ Timeout ]
 webkit.org/b/86623 fast/events/drag-in-frames.html [ Failure ]
+webkit.org/b/86623 fast/events/drag-and-drop-link.html [ Failure ]
 webkit.org/b/86623 fast/events/drag-and-drop-link-into-focused-contenteditable.html [ Failure ]
 webkit.org/b/86623 fast/events/drag-parent-node.html [ Failure ]
 webkit.org/b/86623 fast/events/drag-selects-image.html
index 55afc04..f0b7537 100644 (file)
@@ -1410,6 +1410,7 @@ webkit.org/b/63706 fast/events/drag-and-drop-dataTransfer-types-nocrash.html [ F
 webkit.org/b/63706 fast/events/drag-and-drop-fire-drag-dragover.html [ Failure ]
 webkit.org/b/63706 fast/events/drag-and-drop.html [ Failure Timeout ]
 webkit.org/b/63706 fast/events/drag-and-drop-subframe-dataTransfer.html [ Failure Timeout ]
+webkit.org/b/42194 fast/events/drag-and-drop-link.html [ Failure ]
 webkit.org/b/63706 fast/events/drag-and-drop-link-into-focused-contenteditable.html [ Failure ]
 webkit.org/b/63706 fast/events/drag-parent-node.html [ Failure ]
 webkit.org/b/63706 fast/events/dropzone-001.html [ Failure Timeout ]
index cec8a60..7d191df 100644 (file)
@@ -157,6 +157,7 @@ fast/events/drag-display-none-element.html
 fast/events/drag-file-crash.html
 fast/events/drag-image-filename.html
 fast/events/drag-in-frames.html
+fast/events/drag-and-drop-link.html
 fast/events/drag-and-drop-link-into-focused-contenteditable.html
 fast/events/drag-outside-window.html
 fast/events/drag-parent-node.html
index 651fb67..a0d689a 100644 (file)
@@ -76,6 +76,7 @@ fast/events/crash-on-mutate-during-drop.html
 fast/events/drag-and-drop-dataTransfer-types-nocrash.html
 fast/events/drag-and-drop-fire-drag-dragover.html
 fast/events/drag-and-drop.html
+fast/events/drag-and-drop-link.html
 fast/events/drag-in-frames.html
 fast/events/drag-parent-node.html
 fast/events/dropzone-001.html
index 79def80..0e0f400 100644 (file)
@@ -1,3 +1,28 @@
+2015-04-17  Daniel Bates  <dabates@apple.com>
+
+        REGRESSION: SVG does not support link dragging
+        https://bugs.webkit.org/show_bug.cgi?id=141597
+
+        Reviewed by Darin Adler.
+
+        Fixes an issue where a SVG hyperlink cannot be dragged. We should support
+        dragging an SVG A element just as we support dragging an HTML A element.
+
+        Test: fast/events/drag-and-drop-link.html
+
+        * page/DragController.cpp: Removed explicit include of header Element.h as it will
+        be ultimately included by HTMLAnchorElement.h, among other headers.
+        (WebCore::isDraggableLink): Added. Extracted code from HitTestResult::isLiveLink().
+        (WebCore::DragController::draggableElement): Call WebCore::isDraggableLink() to
+        determine whether a element is a hyperlink that can be dragged.
+        * page/DragController.h:
+        * page/EventHandler.cpp:
+        (WebCore::EventHandler::selectClosestWordOrLinkFromMouseEvent): Write code in terms of
+         WebCore::isDraggableLink().
+        * rendering/HitTestResult.cpp:
+        (WebCore::HitTestResult::isLiveLink): Deleted.
+        * rendering/HitTestResult.h:
+
 2015-04-17  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r182912 and r182920.
index 95152b2..283641e 100644 (file)
 #include "config.h"
 #include "DragController.h"
 
-#if ENABLE(DRAG_SUPPORT)
+#include "HTMLAnchorElement.h"
+#include "SVGAElement.h"
 
+#if ENABLE(DRAG_SUPPORT)
 #include "CachedImage.h"
 #include "CachedResourceLoader.h"
 #include "DataTransfer.h"
@@ -40,7 +42,6 @@
 #include "DragState.h"
 #include "Editor.h"
 #include "EditorClient.h"
-#include "Element.h"
 #include "EventHandler.h"
 #include "ExceptionCodePlaceholder.h"
 #include "FloatRect.h"
@@ -48,7 +49,6 @@
 #include "FrameLoader.h"
 #include "FrameSelection.h"
 #include "FrameView.h"
-#include "HTMLAnchorElement.h"
 #include "HTMLAttachmentElement.h"
 #include "HTMLImageElement.h"
 #include "HTMLInputElement.h"
 #include "markup.h"
 #include <wtf/CurrentTime.h>
 #include <wtf/RefPtr.h>
+#endif
 
 namespace WebCore {
 
+bool isDraggableLink(const Element& element)
+{
+    if (is<HTMLAnchorElement>(element))
+        return downcast<HTMLAnchorElement>(element).isLiveLink();
+    if (is<SVGAElement>(element))
+        return element.isLink();
+    return false;
+}
+
+#if ENABLE(DRAG_SUPPORT)
+    
 static PlatformMouseEvent createMouseEvent(DragData& dragData)
 {
     int keyState = dragData.modifierKeyState();
@@ -652,9 +664,7 @@ Element* DragController::draggableElement(const Frame* sourceFrame, Element* sta
                 state.type = static_cast<DragSourceAction>(state.type | DragSourceActionImage);
                 return element;
             }
-            if ((m_dragSourceAction & DragSourceActionLink)
-                && is<HTMLAnchorElement>(*element)
-                && downcast<HTMLAnchorElement>(*element).isLiveLink()) {
+            if ((m_dragSourceAction & DragSourceActionLink) && isDraggableLink(*element)) {
                 state.type = static_cast<DragSourceAction>(state.type | DragSourceActionLink);
                 return element;
             }
@@ -988,6 +998,6 @@ void DragController::placeDragCaret(const IntPoint& windowPoint)
     m_page.dragCaretController().setCaretPosition(frame->visiblePositionForPoint(framePoint));
 }
 
-} // namespace WebCore
-
 #endif // ENABLE(DRAG_SUPPORT)
+
+} // namespace WebCore
index b3d23d1..fccad94 100644 (file)
@@ -140,6 +140,8 @@ namespace WebCore {
 #endif
     };
 
+    WEBCORE_EXPORT bool isDraggableLink(const Element&);
+
 }
 
 #endif
index 1f42a91..2e829b7 100644 (file)
@@ -598,17 +598,17 @@ void EventHandler::selectClosestWordFromMouseEvent(const MouseEventWithHitTestRe
 
 void EventHandler::selectClosestWordOrLinkFromMouseEvent(const MouseEventWithHitTestResults& result)
 {
-    if (!result.hitTestResult().isLiveLink())
+    Element* urlElement = result.hitTestResult().URLElement();
+    if (!urlElement || !isDraggableLink(*urlElement))
         return selectClosestWordFromMouseEvent(result);
 
     Node* targetNode = result.targetNode();
 
     if (targetNode && targetNode->renderer() && m_mouseDownMayStartSelect) {
         VisibleSelection newSelection;
-        Element* URLElement = result.hitTestResult().URLElement();
         VisiblePosition pos(targetNode->renderer()->positionForPoint(result.localPoint(), nullptr));
-        if (pos.isNotNull() && pos.deepEquivalent().deprecatedNode()->isDescendantOf(URLElement))
-            newSelection = VisibleSelection::selectionFromContentsOfNode(URLElement);
+        if (pos.isNotNull() && pos.deepEquivalent().deprecatedNode()->isDescendantOf(urlElement))
+            newSelection = VisibleSelection::selectionFromContentsOfNode(urlElement);
 
         updateSelectionForMouseDownDispatchingSelectStart(targetNode, expandSelectionToRespectSelectOnMouseDown(*targetNode, newSelection), WordGranularity);
     }
index a8da180..14449b6 100644 (file)
@@ -608,20 +608,6 @@ URL HitTestResult::absoluteLinkURL() const
     return URL();
 }
 
-bool HitTestResult::isLiveLink() const
-{
-    if (!m_innerURLElement)
-        return false;
-
-    if (is<HTMLAnchorElement>(*m_innerURLElement))
-        return downcast<HTMLAnchorElement>(*m_innerURLElement).isLiveLink();
-
-    if (is<SVGAElement>(*m_innerURLElement))
-        return m_innerURLElement->isLink();
-
-    return false;
-}
-
 bool HitTestResult::isOverLink() const
 {
     return m_innerURLElement && m_innerURLElement->isLink();
index ab1aec7..e855074 100644 (file)
@@ -111,7 +111,6 @@ public:
     WEBCORE_EXPORT URL absoluteAttachmentURL() const;
 #endif
     WEBCORE_EXPORT String textContent() const;
-    WEBCORE_EXPORT bool isLiveLink() const;
     bool isOverLink() const;
     WEBCORE_EXPORT bool isContentEditable() const;
     void toggleMediaControlsDisplay() const;
index 1542107..a130596 100644 (file)
@@ -1,3 +1,15 @@
+2015-04-17  Daniel Bates  <dabates@apple.com>
+
+        REGRESSION: SVG does not support link dragging
+        https://bugs.webkit.org/show_bug.cgi?id=141597
+
+        Reviewed by Darin Adler.
+
+        Write -[WebElementDictionary _isLiveLink] in terms of WebCore::isDraggableLink().
+
+        * Misc/WebElementDictionary.mm:
+        (-[WebElementDictionary _isLiveLink]):
+
 2015-04-16  Sam Weinig  <sam@webkit.org>
 
         Expose JavaScriptMarkupEnabled preference for WebKit1
index 7fe79aa..f9694c2 100644 (file)
@@ -36,6 +36,7 @@
 #import "WebTypesInternal.h"
 #import "WebView.h"
 #import "WebViewPrivate.h"
+#import <WebCore/DragController.h>
 #import <WebCore/Frame.h>
 #import <WebCore/HitTestResult.h>
 #import <WebCore/Image.h>
@@ -265,7 +266,8 @@ static NSString* NSStringOrNil(String coreString)
 
 - (NSNumber *)_isLiveLink
 {
-    return [NSNumber numberWithBool:_result->isLiveLink()];
+    Element* urlElement = _result->URLElement();
+    return [NSNumber numberWithBool:(urlElement && isDraggableLink(*urlElement))];
 }
 
 - (NSNumber *)_isContentEditable