Title: [183413] trunk
Revision
183413
Author
[email protected]
Date
2015-04-27 13:19:13 -0700 (Mon, 27 Apr 2015)

Log Message

Simple line layout: Wrong text offsetting when range does not start from the first renderer.
https://bugs.webkit.org/show_bug.cgi?id=144167
rdar://problem/20639857

Reviewed by Simon Fraser.

This patch ensures that TextIterator returns the right text when the input range starts
from a sibling node.

TextIterator::m_previousTextLengthInFlow keeps track of the current node offset from the parent.
Source/WebCore:

It is required to map simple line layout runs to RenderText positions.
This patch sets the offset value when the iteration start with a sibling node.

Test: fast/text/range-text-with-simple-line-layout.html

* editing/TextIterator.cpp:
(WebCore::TextIterator::TextIterator):
(WebCore::TextIterator::handleTextNode):

LayoutTests:

it is required to map simple line layout runs to RenderText positions.
This patch sets the offset value when the iteration start with a sibling node.

* fast/text/range-text-with-simple-line-layout-expected.txt: Added.
* fast/text/range-text-with-simple-line-layout.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (183412 => 183413)


--- trunk/LayoutTests/ChangeLog	2015-04-27 20:15:12 UTC (rev 183412)
+++ trunk/LayoutTests/ChangeLog	2015-04-27 20:19:13 UTC (rev 183413)
@@ -1,3 +1,21 @@
+2015-04-27  Zalan Bujtas  <[email protected]>
+
+        Simple line layout: Wrong text offsetting when range does not start from the first renderer.
+        https://bugs.webkit.org/show_bug.cgi?id=144167
+        rdar://problem/20639857
+
+        Reviewed by Simon Fraser.
+
+        This patch ensures that TextIterator returns the right text when the input range starts
+        from a sibling node.
+
+        TextIterator::m_previousTextLengthInFlow keeps track of the current node offset from the parent.
+        it is required to map simple line layout runs to RenderText positions.
+        This patch sets the offset value when the iteration start with a sibling node.
+
+        * fast/text/range-text-with-simple-line-layout-expected.txt: Added.
+        * fast/text/range-text-with-simple-line-layout.html: Added.
+
 2015-04-27  Commit Queue  <[email protected]>
 
         Unreviewed, rolling out r183393.

Added: trunk/LayoutTests/fast/text/range-text-with-simple-line-layout-expected.txt (0 => 183413)


--- trunk/LayoutTests/fast/text/range-text-with-simple-line-layout-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/text/range-text-with-simple-line-layout-expected.txt	2015-04-27 20:19:13 UTC (rev 183413)
@@ -0,0 +1,14 @@
+PASS internals.rangeAsText(range1) is 'foobar1'
+PASS internals.rangeAsText(range2) is 'oba'
+PASS internals.rangeAsText(range3) is 'a'
+PASS internals.rangeAsText(range4) is 'foobar4'
+PASS internals.rangeAsText(range5) is ''
+PASS successfullyParsed is true
+
+TEST COMPLETE
+moobar
+foobar1
+foobar2
+foobar3
+foobar4
+foobar5

Added: trunk/LayoutTests/fast/text/range-text-with-simple-line-layout.html (0 => 183413)


--- trunk/LayoutTests/fast/text/range-text-with-simple-line-layout.html	                        (rev 0)
+++ trunk/LayoutTests/fast/text/range-text-with-simple-line-layout.html	2015-04-27 20:19:13 UTC (rev 183413)
@@ -0,0 +1,49 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+  <title>This tests that range returns the right text when the selection starts from a sibling node.</title>
+  <script src=""
+  <script>
+    if (window.testRunner)
+      testRunner.dumpAsText();
+  </script>
+</head>
+<body>
+<div id=flow>moobar<br>foobar1<br>foobar2<br>foobar3<br>foobar4<br>foobar5</div>
+<script>
+  var f1 = document.getElementById("flow").firstChild.nextSibling.nextSibling;
+  var f2 = f1.nextSibling.nextSibling;
+  var f3 = f2.nextSibling.nextSibling;
+  var f4 = f3.nextSibling.nextSibling;
+  var f5 = f4.nextSibling.nextSibling;
+  
+  if (window.internals) {
+	var range1 = document.createRange();
+    range1.setStart(f1, 0);
+    range1.setEnd(f1, 7);
+    shouldBe("internals.rangeAsText(range1)", "'foobar1'");
+
+	var range2 = document.createRange();
+    range2.setStart(f2, 2);
+    range2.setEnd(f2, 5);
+    shouldBe("internals.rangeAsText(range2)", "'oba'");
+
+	var range3 = document.createRange();
+    range3.setStart(f3, 4);
+    range3.setEnd(f3, 5);
+    shouldBe("internals.rangeAsText(range3)", "'a'");
+
+	var range4 = document.createRange();
+    range4.setStart(f4, 0);
+    range4.setEnd(f4, 7);
+    shouldBe("internals.rangeAsText(range4)", "'foobar4'");
+
+	var range5 = document.createRange();
+    range5.setStart(f5, 7);
+    range5.setEnd(f5, 7);
+    shouldBe("internals.rangeAsText(range5)", "''");
+  }
+</script>
+<script src=""
+</body>
+</html>
\ No newline at end of file

Modified: trunk/Source/WebCore/ChangeLog (183412 => 183413)


--- trunk/Source/WebCore/ChangeLog	2015-04-27 20:15:12 UTC (rev 183412)
+++ trunk/Source/WebCore/ChangeLog	2015-04-27 20:19:13 UTC (rev 183413)
@@ -1,3 +1,24 @@
+2015-04-27  Zalan Bujtas  <[email protected]>
+
+        Simple line layout: Wrong text offsetting when range does not start from the first renderer.
+        https://bugs.webkit.org/show_bug.cgi?id=144167
+        rdar://problem/20639857
+
+        Reviewed by Simon Fraser.
+
+        This patch ensures that TextIterator returns the right text when the input range starts
+        from a sibling node.
+
+        TextIterator::m_previousTextLengthInFlow keeps track of the current node offset from the parent.
+        It is required to map simple line layout runs to RenderText positions.
+        This patch sets the offset value when the iteration start with a sibling node.
+
+        Test: fast/text/range-text-with-simple-line-layout.html
+
+        * editing/TextIterator.cpp:
+        (WebCore::TextIterator::TextIterator):
+        (WebCore::TextIterator::handleTextNode):
+
 2015-04-27  Commit Queue  <[email protected]>
 
         Unreviewed, rolling out r183393.

Modified: trunk/Source/WebCore/editing/TextIterator.cpp (183412 => 183413)


--- trunk/Source/WebCore/editing/TextIterator.cpp	2015-04-27 20:15:12 UTC (rev 183412)
+++ trunk/Source/WebCore/editing/TextIterator.cpp	2015-04-27 20:19:13 UTC (rev 183413)
@@ -501,6 +501,20 @@
     return false;
 }
 
+static unsigned textNodeOffsetInFlow(const Text& firstTextNodeInRange)
+{
+    // Calculate the text offset for simple lines.
+    RenderObject* renderer = firstTextNodeInRange.renderer();
+    if (!renderer)
+        return 0;
+    unsigned textOffset = 0;
+    for (renderer = renderer->previousSibling(); renderer; renderer = renderer->previousSibling()) {
+        if (is<RenderText>(renderer))
+            textOffset += downcast<RenderText>(renderer)->textLength();
+    }
+    return textOffset;
+}
+
 bool TextIterator::handleTextNode()
 {
     Text& textNode = downcast<Text>(*m_node);
@@ -551,8 +565,8 @@
         unsigned endPosition = (m_node == m_endContainer) ? static_cast<unsigned>(m_endOffset) : rendererText.length();
         const auto& blockFlow = downcast<RenderBlockFlow>(*renderer.parent());
         if (!m_flowRunResolverCache || &m_flowRunResolverCache->flow() != &blockFlow) {
+            m_previousTextLengthInFlow = m_flowRunResolverCache ? 0 : textNodeOffsetInFlow(textNode);
             m_flowRunResolverCache = std::make_unique<SimpleLineLayout::RunResolver>(blockFlow, *layout);
-            m_previousTextLengthInFlow = 0;
         } else if (previousTextNode && previousTextNode != &textNode) {
             // Simple line layout run positions are all absolute to the parent flow.
             // Offsetting is required when multiple renderers are present.
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to