Do not skip <slot> children when collecting content for innerText.
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 17 May 2017 02:33:28 +0000 (02:33 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 17 May 2017 02:33:28 +0000 (02:33 +0000)
https://bugs.webkit.org/show_bug.cgi?id=172113
<rdar://problem/30362324>

Reviewed by Ryosuke Niwa and Brent Fulgham.

Source/WebCore:

"display: contents" elements do not generate renderers but their children might.
This patch ensure that we don't skip them while collecting text content.

Test: fast/text/inner-text-should-include-slot-subtree.html

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

LayoutTests:

* fast/text/inner-text-should-include-slot-subtree-expected.txt: Added.
* fast/text/inner-text-should-include-slot-subtree.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/editing/text-iterator/find-string-on-flat-tree-expected.txt
LayoutTests/editing/text-iterator/find-string-on-flat-tree.html
LayoutTests/fast/text/inner-text-should-include-slot-subtree-expected.txt [new file with mode: 0644]
LayoutTests/fast/text/inner-text-should-include-slot-subtree.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/editing/TextIterator.cpp

index ff0d098..1f144cf 100644 (file)
@@ -1,3 +1,14 @@
+2017-05-16  Zalan Bujtas  <zalan@apple.com>
+
+        Do not skip <slot> children when collecting content for innerText.
+        https://bugs.webkit.org/show_bug.cgi?id=172113
+        <rdar://problem/30362324>
+
+        Reviewed by Ryosuke Niwa and Brent Fulgham.
+
+        * fast/text/inner-text-should-include-slot-subtree-expected.txt: Added.
+        * fast/text/inner-text-should-include-slot-subtree.html: Added.
+
 2017-05-16  Jiewen Tan  <jiewen_tan@apple.com>
 
         Unreviewed, fix LayoutTests/plugins/navigator-plugin-crash.html
index a3ce719..598d0d4 100644 (file)
@@ -77,6 +77,7 @@ PASS internals.countFindMatches('in-', ['DoNotTraverseFlatTree']) is 2
 PASS internals.countFindMatches('in-', []) is 4
 PASS internals.countFindMatches('in-shadow in-document', ['DoNotTraverseFlatTree']) is 0
 PASS internals.countFindMatches('in-shadow in-document', []) is 0
+PASS rangeText(internals.rangeOfString('inside-display-none', null, [])) is null
 PASS successfullyParsed is true
 
 TEST COMPLETE
index 438c9db..1905253 100644 (file)
@@ -2,6 +2,7 @@
 <html>
 <body>
 <div id="test-content">in-document <span id="host">unslotted <b id="slotted-element" slot="named-slot">slotted</b> unslotted</span> in-document<span id="user-agent-host"></span></div>
+<div id="display-none-content" style="display: none">inside-display-none</div>
 <script src="../../resources/js-test.js"></script>
 <script>
 
@@ -161,6 +162,8 @@ else {
     shouldBe("internals.countFindMatches('in-shadow in-document', ['DoNotTraverseFlatTree'])", "0");
     shouldBe("internals.countFindMatches('in-shadow in-document', [])", "0");
 
+    shouldBe("rangeText(internals.rangeOfString('inside-display-none', null, []))", "null");
+
     document.getElementById('console').style.display = null;
 }
 
diff --git a/LayoutTests/fast/text/inner-text-should-include-slot-subtree-expected.txt b/LayoutTests/fast/text/inner-text-should-include-slot-subtree-expected.txt
new file mode 100644 (file)
index 0000000..b447117
--- /dev/null
@@ -0,0 +1 @@
+Passif no crash orassert
diff --git a/LayoutTests/fast/text/inner-text-should-include-slot-subtree.html b/LayoutTests/fast/text/inner-text-should-include-slot-subtree.html
new file mode 100644 (file)
index 0000000..daaab16
--- /dev/null
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>This tests that slot subtree is included in innerText</title>
+<script>
+if (window.testRunner)
+    testRunner.dumpAsText();
+</script>
+</head>
+<body>
+<div id=container><slot id=sslot>if no crash or</slot></div>
+<script>
+container.insertBefore(document.createTextNode("Pass"), sslot);
+container.appendChild(document.createTextNode("assert"));
+document.body.offsetHeight;
+document.body.innerText;
+</script>
+</body>
+</html>
index c6b3bb2..72cd68a 100644 (file)
@@ -1,3 +1,19 @@
+2017-05-16  Zalan Bujtas  <zalan@apple.com>
+
+        Do not skip <slot> children when collecting content for innerText.
+        https://bugs.webkit.org/show_bug.cgi?id=172113
+        <rdar://problem/30362324>
+
+        Reviewed by Ryosuke Niwa and Brent Fulgham.
+
+        "display: contents" elements do not generate renderers but their children might.
+        This patch ensure that we don't skip them while collecting text content.  
+
+        Test: fast/text/inner-text-should-include-slot-subtree.html
+
+        * editing/TextIterator.cpp:
+        (WebCore::TextIterator::advance):
+
 2017-05-16  Filip Pizlo  <fpizlo@apple.com>
 
         GCController::garbageCollectNowIfNotDoneRecently should request Async Full GCs
index 1940412..63233db 100644 (file)
@@ -493,7 +493,7 @@ void TextIterator::advance()
         auto* renderer = m_node->renderer();
         if (!renderer) {
             m_handledNode = true;
-            m_handledChildren = !((m_behavior & TextIteratorTraversesFlatTree) && is<Element>(*m_node) && downcast<Element>(*m_node).hasDisplayContents());
+            m_handledChildren = !(is<Element>(*m_node) && downcast<Element>(*m_node).hasDisplayContents());
         } else {
             // handle current node according to its type
             if (!m_handledNode) {