Title: [145195] trunk
Revision
145195
Author
ser...@webkit.org
Date
2013-03-08 01:58:28 -0800 (Fri, 08 Mar 2013)

Log Message

Improve drag&drop of list items in contentEditable divs
https://bugs.webkit.org/show_bug.cgi?id=111556

Reviewed by Ryosuke Niwa.

Source/WebCore:

A single fully selected <li> should generate the same markup as if
we were selecting some of them, i.e., we should preserve the list
structure and appearance.

Test: editing/selection/drag-list-item.html

* editing/htmlediting.cpp:
(WebCore::isListItem): modified constness.
* editing/htmlediting.h:
(WebCore): ditto.
* editing/markup.cpp:
(WebCore::highestAncestorToWrapMarkup):

LayoutTests:

Added a new test case. The test performs 2 drag&drops, first of
all a selection of a single list item, and secondly a selection of
two list items. It checks that both behave the same way, i.e, the
whole <li> is moved and not only the text.

* editing/selection/drag-list-item-expected.txt: Added.
* editing/selection/drag-list-item.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (145194 => 145195)


--- trunk/LayoutTests/ChangeLog	2013-03-08 09:27:38 UTC (rev 145194)
+++ trunk/LayoutTests/ChangeLog	2013-03-08 09:58:28 UTC (rev 145195)
@@ -1,3 +1,18 @@
+2013-03-08  Sergio Villar Senin  <svil...@igalia.com>
+
+        Improve drag&drop of list items in contentEditable divs
+        https://bugs.webkit.org/show_bug.cgi?id=111556
+
+        Reviewed by Ryosuke Niwa.
+
+        Added a new test case. The test performs 2 drag&drops, first of
+        all a selection of a single list item, and secondly a selection of
+        two list items. It checks that both behave the same way, i.e, the
+        whole <li> is moved and not only the text.
+
+        * editing/selection/drag-list-item-expected.txt: Added.
+        * editing/selection/drag-list-item.html: Added.
+
 2013-03-08  Zoltan Arvai  <zar...@inf.u-szeged.hu>
 
         [Qt] Unreviewed gardening.

Added: trunk/LayoutTests/editing/selection/drag-list-item-expected.txt (0 => 145195)


--- trunk/LayoutTests/editing/selection/drag-list-item-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/editing/selection/drag-list-item-expected.txt	2013-03-08 09:58:28 UTC (rev 145195)
@@ -0,0 +1,71 @@
+This test drags a selection of one <li> and drops them after another <li> in the first list. The same test is repeated in the second list but this time with two selected items instead of one. It verifies that the behavior is independent of how many fully selected items we move, i.e. fully selected <li> are moved as <li> and not just as plain text
+
+The original list looks like this. 'two' is going to be selected and pasted after 'four':
+| "
+"
+| <li>
+|   id="one"
+|   "one"
+| <li>
+|   id="two"
+|   "two"
+| <li>
+|   id="three"
+|   "three"
+| <li>
+|   id="four"
+|   "four"
+| "
+"
+
+'two' should appear as a new <li> after 'four':
+| "
+"
+| <li>
+|   id="one"
+|   "one"
+| <li>
+|   id="two"
+|   <br>
+| <li>
+|   id="three"
+|   "three"
+| <li>
+|   id="four"
+|   "four"
+| <li>
+|   id="two"
+|   "two"
+| "
+"
+
+The original list looks like this. 'two' and 'three' are going to be selected and pasted after 'four':
+| <li>
+|   id="one"
+|   "one"
+| <li>
+|   id="two"
+|   "two"
+| <li>
+|   id="three"
+|   "three"
+| <li>
+|   id="four"
+|   "four"
+
+'two' and 'three' should appear as <li> after 'four':
+| <li>
+|   id="one"
+|   "one"
+| <li>
+|   id="two"
+|   <br>
+| <li>
+|   id="four"
+|   "four"
+| <li>
+|   id="two"
+|   "two"
+| <li>
+|   id="three"
+|   "three"

Added: trunk/LayoutTests/editing/selection/drag-list-item.html (0 => 145195)


--- trunk/LayoutTests/editing/selection/drag-list-item.html	                        (rev 0)
+++ trunk/LayoutTests/editing/selection/drag-list-item.html	2013-03-08 09:58:28 UTC (rev 145195)
@@ -0,0 +1,54 @@
+<!DOCTYPE html>
+
+<body>
+<script src=""
+<div contenteditable="true">
+<ol id="test">
+<li id="one">one</li><li id="two">two</li><li id="three">three</li><li id="four">four</li>
+</ol>
+</div>
+
+<script>
+Markup.description('This test drags a selection of one <li> and drops them after another <li> in the first list. The same test is repeated in the second list but this time with two selected items instead of one. It verifies that the behavior is independent of how many fully selected items we move, i.e. fully selected <li> are moved as <li> and not just as plain text');
+
+function editingTest(testElement, startSelectionElement, endSelectionElement, endSelectionElementOffset, targetElement) {
+
+    var testElement = document.getElementById(testElement);
+    var selection = window.getSelection();
+    selection.setPosition(testElement, 0);
+
+    var start = document.getElementById(startSelectionElement);
+    var startx = start.offsetLeft;
+    var starty = start.offsetTop + start.offsetHeight / 2;
+    selection.setBaseAndExtent(start, 0, document.getElementById(endSelectionElement), endSelectionElementOffset);
+
+    eventSender.mouseMoveTo(startx, starty);
+    eventSender.mouseDown();
+
+    eventSender.leapForward(200);
+
+    var target = document.getElementById(targetElement);
+    var targetx = target.parentNode.offsetLeft + target.offsetLeft + target.offsetWidth / 2;
+    var targety = target.offsetTop + target.offsetHeight / 2;
+
+    eventSender.mouseMoveTo(targetx, targety);
+    eventSender.mouseUp();
+
+    selection.collapse();
+}
+
+if (window.testRunner) {
+
+    Markup.dump("test", "The original list looks like this. 'two' is going to be selected and pasted after 'four'");
+    editingTest("test", "two", "two", 4, "four");
+    Markup.dump("test", "'two' should appear as a new <li> after 'four'");
+
+    document.getElementById("test").innerHTML = "<li id=\"one\">one</li><li id=\"two\">two</li>"
+        + "<li id=\"three\">three</li><li id=\"four\">four</li>";
+    Markup.dump("test", "The original list looks like this. 'two' and 'three' are going to be selected and pasted after 'four'");
+    editingTest("test", "two", "three", 5, "four");
+    Markup.dump("test", "'two' and 'three' should appear as <li> after 'four'");
+}
+</script>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (145194 => 145195)


--- trunk/Source/WebCore/ChangeLog	2013-03-08 09:27:38 UTC (rev 145194)
+++ trunk/Source/WebCore/ChangeLog	2013-03-08 09:58:28 UTC (rev 145195)
@@ -1,3 +1,23 @@
+2013-03-08  Sergio Villar Senin  <svil...@igalia.com>
+
+        Improve drag&drop of list items in contentEditable divs
+        https://bugs.webkit.org/show_bug.cgi?id=111556
+
+        Reviewed by Ryosuke Niwa.
+
+        A single fully selected <li> should generate the same markup as if
+        we were selecting some of them, i.e., we should preserve the list
+        structure and appearance.
+
+        Test: editing/selection/drag-list-item.html
+
+        * editing/htmlediting.cpp:
+        (WebCore::isListItem): modified constness.
+        * editing/htmlediting.h:
+        (WebCore): ditto.
+        * editing/markup.cpp:
+        (WebCore::highestAncestorToWrapMarkup):
+
 2013-03-08  Alberto Garcia  <agar...@igalia.com>
 
         [BlackBerry] LayerTiler: rename currentFrameHasAlpha as currentFrameKnownToBeOpaque

Modified: trunk/Source/WebCore/editing/htmlediting.cpp (145194 => 145195)


--- trunk/Source/WebCore/editing/htmlediting.cpp	2013-03-08 09:27:38 UTC (rev 145194)
+++ trunk/Source/WebCore/editing/htmlediting.cpp	2013-03-08 09:58:28 UTC (rev 145195)
@@ -580,7 +580,7 @@
     return (n && (n->hasTagName(ulTag) || n->hasTagName(olTag) || n->hasTagName(dlTag)));
 }
 
-bool isListItem(Node *n)
+bool isListItem(const Node *n)
 {
     return n && n->renderer() && n->renderer()->isListItem();
 }

Modified: trunk/Source/WebCore/editing/htmlediting.h (145194 => 145195)


--- trunk/Source/WebCore/editing/htmlediting.h	2013-03-08 09:27:38 UTC (rev 145194)
+++ trunk/Source/WebCore/editing/htmlediting.h	2013-03-08 09:58:28 UTC (rev 145195)
@@ -107,7 +107,7 @@
 bool isEmptyTableCell(const Node*);
 bool isTableStructureNode(const Node*);
 bool isListElement(Node*);
-bool isListItem(Node*);
+bool isListItem(const Node*);
 bool isNodeRendered(const Node*);
 bool isNodeVisiblyContainedWithin(Node*, const Range*);
 bool isRenderedAsNonInlineTableImageOrHR(const Node*);

Modified: trunk/Source/WebCore/editing/markup.cpp (145194 => 145195)


--- trunk/Source/WebCore/editing/markup.cpp	2013-03-08 09:27:38 UTC (rev 145194)
+++ trunk/Source/WebCore/editing/markup.cpp	2013-03-08 09:58:28 UTC (rev 145195)
@@ -516,6 +516,14 @@
         // the structure and appearance of the copied markup.
         specialCommonAncestor = ancestorToRetainStructureAndAppearance(commonAncestor);
 
+        if (Node* parentListNode = enclosingNodeOfType(firstPositionInOrBeforeNode(range->firstNode()), isListItem)) {
+            if (WebCore::areRangesEqual(VisibleSelection::selectionFromContentsOfNode(parentListNode).toNormalizedRange().get(), range)) {
+                specialCommonAncestor = parentListNode->parentNode();
+                while (specialCommonAncestor && !isListElement(specialCommonAncestor))
+                    specialCommonAncestor = specialCommonAncestor->parentNode();
+            }
+        }
+
         // Retain the Mail quote level by including all ancestor mail block quotes.
         if (Node* highestMailBlockquote = highestEnclosingNodeOfType(firstPositionInOrBeforeNode(range->firstNode()), isMailBlockquote, CanCrossEditingBoundary))
             specialCommonAncestor = highestMailBlockquote;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to