Title: [97878] trunk
Revision
97878
Author
[email protected]
Date
2011-10-19 14:38:03 -0700 (Wed, 19 Oct 2011)

Log Message

Don't always select images during an image drag.
https://bugs.webkit.org/show_bug.cgi?id=62998

Reviewed by Tony Chang.

Source/WebCore:

Only select an image being dragged if it is contenteditable.

Test: fast/events/drag-selects-image.html

* dom/Node.cpp:
(WebCore::Node::isContentRichlyEditable):
* dom/Node.h:
* page/DragController.cpp:
(WebCore::prepareClipboardForImageDrag):

LayoutTests:

* fast/events/drag-selects-image-expected.txt: Added.
* fast/events/drag-selects-image.html: Added.
* platform/chromium-win/editing/pasteboard/drag-image-to-contenteditable-in-iframe-expected.txt:
* platform/chromium-win/editing/selection/drag-to-contenteditable-iframe-expected.txt:
* platform/chromium/test_expectations.txt:
* platform/mac/editing/pasteboard/drag-image-to-contenteditable-in-iframe-expected.txt:
* platform/mac/editing/selection/drag-to-contenteditable-iframe-expected.txt:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (97877 => 97878)


--- trunk/LayoutTests/ChangeLog	2011-10-19 21:28:36 UTC (rev 97877)
+++ trunk/LayoutTests/ChangeLog	2011-10-19 21:38:03 UTC (rev 97878)
@@ -1,3 +1,18 @@
+2011-10-19  Daniel Cheng  <[email protected]>
+
+        Don't always select images during an image drag.
+        https://bugs.webkit.org/show_bug.cgi?id=62998
+
+        Reviewed by Tony Chang.
+
+        * fast/events/drag-selects-image-expected.txt: Added.
+        * fast/events/drag-selects-image.html: Added.
+        * platform/chromium-win/editing/pasteboard/drag-image-to-contenteditable-in-iframe-expected.txt:
+        * platform/chromium-win/editing/selection/drag-to-contenteditable-iframe-expected.txt:
+        * platform/chromium/test_expectations.txt:
+        * platform/mac/editing/pasteboard/drag-image-to-contenteditable-in-iframe-expected.txt:
+        * platform/mac/editing/selection/drag-to-contenteditable-iframe-expected.txt:
+
 2011-10-19  Chang Shu  <[email protected]>
 
         [Qt] Disable fullscreen api on Qt by default

Added: trunk/LayoutTests/fast/events/drag-selects-image-expected.txt (0 => 97878)


--- trunk/LayoutTests/fast/events/drag-selects-image-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/events/drag-selects-image-expected.txt	2011-10-19 21:38:03 UTC (rev 97878)
@@ -0,0 +1,16 @@
+Non-editable area
+
+
+Editable area
+
+
+This tests that images are properly left selected or unselected when an image drag is started. Only the image in the editable area should be selected when an image drag is started.
+
+Starting test...
+0 range(s) selected
+Dragging image in non-editable area...
+0 range(s) selected
+Dragging image in editable area...
+1 range(s) selected
+imageTwo is selected
+
Property changes on: trunk/LayoutTests/fast/events/drag-selects-image-expected.txt
___________________________________________________________________

Added: svn:eol-style

Added: trunk/LayoutTests/fast/events/drag-selects-image.html (0 => 97878)


--- trunk/LayoutTests/fast/events/drag-selects-image.html	                        (rev 0)
+++ trunk/LayoutTests/fast/events/drag-selects-image.html	2011-10-19 21:38:03 UTC (rev 97878)
@@ -0,0 +1,53 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script>
+    function log(str)
+    {
+        var result = document.getElementById('result');
+        result.appendChild(document.createTextNode(str));
+        result.appendChild(document.createElement('br'));
+    }
+    function dragNowhere(element)
+    {
+        eventSender.mouseMoveTo(element.offsetLeft + element.offsetWidth / 2,
+                                element.offsetTop + element.offsetHeight / 2);
+        eventSender.mouseDown();
+        eventSender.leapForward(100);
+        eventSender.mouseMoveTo(element.offsetLeft + 1, element.offsetHeight + 1);
+        eventSender.mouseUp();
+    }
+    window._onload_ = function()
+    {
+        if (!window.layoutTestController)
+            return;
+        layoutTestController.dumpAsText();
+
+        log('Starting test...');
+        log(window.getSelection().rangeCount + ' range(s) selected');
+        log('Dragging image in non-editable area...');
+        dragNowhere(document.getElementById('imageOne'));
+        log(window.getSelection().rangeCount + ' range(s) selected');
+        log('Dragging image in editable area...');
+        dragNowhere(document.getElementById('imageTwo'));
+        log(window.getSelection().rangeCount + ' range(s) selected');
+        if (window.getSelection().rangeCount && window.getSelection().containsNode(document.getElementById('imageTwo')))
+          log('imageTwo is selected');
+    }
+</script>
+</head>
+<body>
+<div>
+<h3>Non-editable area</h3>
+<img id="imageOne" src=""
+</div>
+<div contenteditable="true">
+<h3>Editable area</h3>
+<img id="imageTwo" src=""
+</div>
+<p>This tests that images are properly left selected or unselected when an image drag is started.
+Only the image in the editable area should be selected when an image drag is started.
+<div id="result">
+</div>
+</body>
+</html>
Property changes on: trunk/LayoutTests/fast/events/drag-selects-image.html
___________________________________________________________________

Added: svn:eol-style

Modified: trunk/LayoutTests/platform/chromium/test_expectations.txt (97877 => 97878)


--- trunk/LayoutTests/platform/chromium/test_expectations.txt	2011-10-19 21:28:36 UTC (rev 97877)
+++ trunk/LayoutTests/platform/chromium/test_expectations.txt	2011-10-19 21:38:03 UTC (rev 97878)
@@ -3876,3 +3876,7 @@
 BUGWK70383 LEOPARD CPU-CG : editing/pasteboard/4944770-1.html = IMAGE
 
 BUGWK70386 SNOWLEOPARD DEBUG : storage/domstorage/events/documentURI.html = PASS CRASH
+
+// Waiting on new results
+BUG_DCHENG : editing/pasteboard/drag-image-to-contenteditable-in-iframe.html = FAIL
+BUG_DCHENG : editing/selection/drag-to-contenteditable-iframe.html = FAIL

Modified: trunk/LayoutTests/platform/chromium-win/editing/pasteboard/drag-image-to-contenteditable-in-iframe-expected.txt (97877 => 97878)


--- trunk/LayoutTests/platform/chromium-win/editing/pasteboard/drag-image-to-contenteditable-in-iframe-expected.txt	2011-10-19 21:28:36 UTC (rev 97877)
+++ trunk/LayoutTests/platform/chromium-win/editing/pasteboard/drag-image-to-contenteditable-in-iframe-expected.txt	2011-10-19 21:38:03 UTC (rev 97878)
@@ -22,5 +22,3 @@
                   RenderImage {IMG} at (21,1) size 76x103
         RenderText {#text} at (0,0) size 0x0
       RenderBlock {UL} at (0,231) size 784x0
-selection start: position 0 of child 3 {IMG} of body
-selection end:   position 1 of child 3 {IMG} of body

Modified: trunk/LayoutTests/platform/chromium-win/editing/selection/drag-to-contenteditable-iframe-expected.txt (97877 => 97878)


--- trunk/LayoutTests/platform/chromium-win/editing/selection/drag-to-contenteditable-iframe-expected.txt	2011-10-19 21:28:36 UTC (rev 97877)
+++ trunk/LayoutTests/platform/chromium-win/editing/selection/drag-to-contenteditable-iframe-expected.txt	2011-10-19 21:38:03 UTC (rev 97878)
@@ -1,4 +1,3 @@
-EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: shouldInsertNode:#document-fragment replacingDOMRange:range from 0 of BODY > HTML > #document to 0 of BODY > HTML > #document givenAction:WebViewInsertActionDropped
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of BODY > HTML > #document to 0 of BODY > HTML > #document toDOMRange:range from 0 of BODY > HTML > #document to 1 of BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
@@ -27,5 +26,3 @@
           RenderListMarker at (-18,0) size 7x19: bullet
           RenderText {#text} at (0,0) size 274x19
             text run at (0,0) width 274: "Abe should be outside the frame and inside it."
-selection start: position 0 of child 3 {IMG} of body
-selection end:   position 1 of child 3 {IMG} of body

Modified: trunk/Source/WebCore/ChangeLog (97877 => 97878)


--- trunk/Source/WebCore/ChangeLog	2011-10-19 21:28:36 UTC (rev 97877)
+++ trunk/Source/WebCore/ChangeLog	2011-10-19 21:38:03 UTC (rev 97878)
@@ -1,3 +1,20 @@
+2011-10-19  Daniel Cheng  <[email protected]>
+
+        Don't always select images during an image drag.
+        https://bugs.webkit.org/show_bug.cgi?id=62998
+
+        Reviewed by Tony Chang.
+
+        Only select an image being dragged if it is contenteditable.
+
+        Test: fast/events/drag-selects-image.html
+
+        * dom/Node.cpp:
+        (WebCore::Node::isContentRichlyEditable):
+        * dom/Node.h:
+        * page/DragController.cpp:
+        (WebCore::prepareClipboardForImageDrag):
+
 2011-10-19  Andreas Kling  <[email protected]>
 
         HTMLBodyElement: Simplify link/alink/vlink attribute parsing.

Modified: trunk/Source/WebCore/dom/Node.cpp (97877 => 97878)


--- trunk/Source/WebCore/dom/Node.cpp	2011-10-19 21:28:36 UTC (rev 97877)
+++ trunk/Source/WebCore/dom/Node.cpp	2011-10-19 21:38:03 UTC (rev 97878)
@@ -775,6 +775,12 @@
     return rendererIsEditable(Editable);
 }
 
+bool Node::isContentRichlyEditable()
+{
+    document()->updateLayoutIgnorePendingStylesheets();
+    return rendererIsEditable(RichlyEditable);
+}
+
 bool Node::rendererIsEditable(EditableLevel editableLevel) const
 {
     if (document()->frame() && document()->frame()->page() && document()->frame()->page()->isEditable() && !shadowTreeRootNode())

Modified: trunk/Source/WebCore/dom/Node.h (97877 => 97878)


--- trunk/Source/WebCore/dom/Node.h	2011-10-19 21:28:36 UTC (rev 97877)
+++ trunk/Source/WebCore/dom/Node.h	2011-10-19 21:38:03 UTC (rev 97878)
@@ -342,6 +342,7 @@
     virtual Node* focusDelegate();
 
     bool isContentEditable();
+    bool isContentRichlyEditable();
 
     bool rendererIsEditable() const { return rendererIsEditable(Editable); }
     bool rendererIsRichlyEditable() const { return rendererIsEditable(RichlyEditable); }

Modified: trunk/Source/WebCore/page/DragController.cpp (97877 => 97878)


--- trunk/Source/WebCore/page/DragController.cpp	2011-10-19 21:28:36 UTC (rev 97877)
+++ trunk/Source/WebCore/page/DragController.cpp	2011-10-19 21:38:03 UTC (rev 97878)
@@ -614,14 +614,16 @@
         cachedImage->imageForRenderer(element->renderer()) : 0;
 }
 
-static void prepareClipboardForImageDrag(Frame* src, Clipboard* clipboard, Element* node, const KURL& linkURL, const KURL& imageURL, const String& label)
+static void prepareClipboardForImageDrag(Frame* source, Clipboard* clipboard, Element* node, const KURL& linkURL, const KURL& imageURL, const String& label)
 {
-    RefPtr<Range> range = src->document()->createRange();
-    ExceptionCode ec = 0;
-    range->selectNode(node, ec);
-    ASSERT(!ec);
-    src->selection()->setSelection(VisibleSelection(range.get(), DOWNSTREAM));
-    clipboard->declareAndWriteDragImage(node, !linkURL.isEmpty() ? linkURL : imageURL, label, src);
+    if (node->isContentRichlyEditable()) {
+        RefPtr<Range> range = source->document()->createRange();
+        ExceptionCode ec = 0;
+        range->selectNode(node, ec);
+        ASSERT(!ec);
+        source->selection()->setSelection(VisibleSelection(range.get(), DOWNSTREAM));
+    }
+    clipboard->declareAndWriteDragImage(node, !linkURL.isEmpty() ? linkURL : imageURL, label, source);
 }
 
 static IntPoint dragLocForDHTMLDrag(const IntPoint& mouseDraggedPoint, const IntPoint& dragOrigin, const IntPoint& dragImageOffset, bool isLinkImage)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to