Title: [120991] trunk
Revision
120991
Author
[email protected]
Date
2012-06-21 19:02:38 -0700 (Thu, 21 Jun 2012)

Log Message

[Shadow][Editing] Assertion in VisibleSelection::adjuseSelectionToAvoidCrossingBoundaries() is triggered.
https://bugs.webkit.org/show_bug.cgi?id=89081

Reviewed by Ryosuke Niwa.

Source/WebCore:

firstEditablePositionAfterPositionInRoot and lastEditablePositionBeforePositionInRoot did not
consider a case that an argument hiehestRoot can be in Shadow DOM. So when adjusting selection to
avoid crossing editing boundaries, VisiblePosition can break shadow boundaries, and it causes
an assertion trigger.

By this patch, firstEditablePositionAfterPositionInRoot and lastEditablePositionBeforePositionInRoot will
adjust position to the tree scope of highestRoot instead of its parent tree scope.

Test: editing/shadow/adjusting-editing-boundary-with-table-in-shadow.html

* editing/htmlediting.cpp:
(WebCore::firstEditablePositionAfterPositionInRoot):
(WebCore::lastEditablePositionBeforePositionInRoot):

LayoutTests:

* editing/shadow/adjusting-editing-boundary-with-table-in-shadow-expected.txt: Added.
* editing/shadow/adjusting-editing-boundary-with-table-in-shadow.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (120990 => 120991)


--- trunk/LayoutTests/ChangeLog	2012-06-22 01:46:12 UTC (rev 120990)
+++ trunk/LayoutTests/ChangeLog	2012-06-22 02:02:38 UTC (rev 120991)
@@ -1,3 +1,13 @@
+2012-06-21  Shinya Kawanaka  <[email protected]>
+
+        [Shadow][Editing] Assertion in VisibleSelection::adjuseSelectionToAvoidCrossingBoundaries() is triggered.
+        https://bugs.webkit.org/show_bug.cgi?id=89081
+
+        Reviewed by Ryosuke Niwa.
+
+        * editing/shadow/adjusting-editing-boundary-with-table-in-shadow-expected.txt: Added.
+        * editing/shadow/adjusting-editing-boundary-with-table-in-shadow.html: Added.
+
 2012-06-21  Gregg Tavares  <[email protected]>
 
         Make GL error messages consistent in LayoutTests

Added: trunk/LayoutTests/editing/shadow/adjusting-editing-boundary-with-table-in-shadow-expected.txt (0 => 120991)


--- trunk/LayoutTests/editing/shadow/adjusting-editing-boundary-with-table-in-shadow-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/editing/shadow/adjusting-editing-boundary-with-table-in-shadow-expected.txt	2012-06-22 02:02:38 UTC (rev 120991)
@@ -0,0 +1,3 @@
+Selecting around a table which is distributed from shadow subtree to nested shadow subtree will trigger an assertion. To try manually, select from "shadow 2" to around "after" and confirm a crash does not occur.
+
+PASS

Added: trunk/LayoutTests/editing/shadow/adjusting-editing-boundary-with-table-in-shadow.html (0 => 120991)


--- trunk/LayoutTests/editing/shadow/adjusting-editing-boundary-with-table-in-shadow.html	                        (rev 0)
+++ trunk/LayoutTests/editing/shadow/adjusting-editing-boundary-with-table-in-shadow.html	2012-06-22 02:02:38 UTC (rev 120991)
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+<script src=""
+
+<div id="container" contenteditable>
+    <table border="1" id="host" contenteditable>
+        <tr><td>host 1</td></tr>
+        <tr><td>host 2</td></tr>
+    </table>
+</div>
+
+<p id="description">Selecting around a table which is distributed from shadow subtree to nested shadow subtree will trigger an assertion. To try manually, select from "shadow 2" to around "after" and confirm a crash does not occur.</p>
+
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+var shadowRoot = new WebKitShadowRoot(host);
+var div = document.createElement('div');
+shadowRoot.appendChild(div);
+div.innerHTML = "<table border='1'><tr><td>shadow 1</td></tr><tr><td id='src'>shadow 2</td></tr></table>";
+
+var nestedShadowRoot = new WebKitShadowRoot(div);
+nestedShadowRoot.innerHTML = "<div contenteditable>before<shadow></shadow>after</div>";
+
+var src = ""
+
+if (window.eventSender) {
+    eventSender.mouseMoveTo(src.offsetLeft + 10, src.offsetTop + src.offsetHeight / 2);
+    eventSender.mouseDown();
+    eventSender.mouseMoveTo(src.offsetLeft - 10, src.offsetTop + src.offsetHeight / 2);
+    eventSender.mouseUp();
+
+    container.innerHTML = "PASS";
+}
+
+// When description comes before container, this test will not fail if code is wrong. So let's move here.
+container.parentNode.insertBefore(description, container);
+</script>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (120990 => 120991)


--- trunk/Source/WebCore/ChangeLog	2012-06-22 01:46:12 UTC (rev 120990)
+++ trunk/Source/WebCore/ChangeLog	2012-06-22 02:02:38 UTC (rev 120991)
@@ -1,3 +1,24 @@
+2012-06-21  Shinya Kawanaka  <[email protected]>
+
+        [Shadow][Editing] Assertion in VisibleSelection::adjuseSelectionToAvoidCrossingBoundaries() is triggered.
+        https://bugs.webkit.org/show_bug.cgi?id=89081
+
+        Reviewed by Ryosuke Niwa.
+
+        firstEditablePositionAfterPositionInRoot and lastEditablePositionBeforePositionInRoot did not
+        consider a case that an argument hiehestRoot can be in Shadow DOM. So when adjusting selection to
+        avoid crossing editing boundaries, VisiblePosition can break shadow boundaries, and it causes
+        an assertion trigger.
+
+        By this patch, firstEditablePositionAfterPositionInRoot and lastEditablePositionBeforePositionInRoot will
+        adjust position to the tree scope of highestRoot instead of its parent tree scope.
+
+        Test: editing/shadow/adjusting-editing-boundary-with-table-in-shadow.html
+
+        * editing/htmlediting.cpp:
+        (WebCore::firstEditablePositionAfterPositionInRoot):
+        (WebCore::lastEditablePositionBeforePositionInRoot):
+
 2012-06-21  Andrey Kosyakov  <[email protected]>
 
         Web Inspector: exception in TimelinePresentationModel when recording timeline

Modified: trunk/Source/WebCore/editing/htmlediting.cpp (120990 => 120991)


--- trunk/Source/WebCore/editing/htmlediting.cpp	2012-06-22 01:46:12 UTC (rev 120990)
+++ trunk/Source/WebCore/editing/htmlediting.cpp	2012-06-22 02:02:38 UTC (rev 120991)
@@ -259,11 +259,15 @@
         return firstPositionInNode(highestRoot);
 
     Position p = position;
-    
-    if (Node* shadowAncestor = p.deprecatedNode()->shadowAncestorNode())
-        if (shadowAncestor != p.deprecatedNode())
-            p = positionAfterNode(shadowAncestor);
-    
+
+    if (position.deprecatedNode()->treeScope() != highestRoot->treeScope()) {
+        Node* shadowAncestor = highestRoot->treeScope()->ancestorInThisScope(p.deprecatedNode());
+        if (!shadowAncestor)
+            return VisiblePosition();
+
+        p = positionAfterNode(shadowAncestor);
+    }
+
     while (p.deprecatedNode() && !isEditablePosition(p) && p.deprecatedNode()->isDescendantOf(highestRoot))
         p = isAtomicNode(p.deprecatedNode()) ? positionInParentAfterNode(p.deprecatedNode()) : nextVisuallyDistinctCandidate(p);
     
@@ -281,9 +285,12 @@
 
     Position p = position;
 
-    if (Node* shadowAncestor = p.deprecatedNode()->shadowAncestorNode()) {
-        if (shadowAncestor != p.deprecatedNode())
-            p = firstPositionInOrBeforeNode(shadowAncestor);
+    if (position.deprecatedNode()->treeScope() != highestRoot->treeScope()) {
+        Node* shadowAncestor = highestRoot->treeScope()->ancestorInThisScope(p.deprecatedNode());
+        if (!shadowAncestor)
+            return VisiblePosition();
+
+        p = firstPositionInOrBeforeNode(shadowAncestor);
     }
     
     while (p.deprecatedNode() && !isEditablePosition(p) && p.deprecatedNode()->isDescendantOf(highestRoot))
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to