Title: [281979] trunk
Revision
281979
Author
[email protected]
Date
2021-09-03 00:25:34 -0700 (Fri, 03 Sep 2021)

Log Message

Use isRendererReplacedElement for SimplifiedBackwardsTextIterator
https://bugs.webkit.org/show_bug.cgi?id=229798

Patch by Frédéric Wang <[email protected]> on 2021-09-03
Reviewed by Darin Adler.

Source/WebCore:

TextIterator::advance() relies on isRendererReplacedElement to determine whether an element
should be treated as a replaced element and emit a comma ','. SimplifiedBackwardsTextIterator
has similar logic to check for replaced elements, but it has not been updated and is now
out-of-sync. This patch makes SimplifiedBackwardsTextIterator use the same function
isRendererReplacedElement, adding support for attachment (r200509), media (r158743),
element with a11y role "img" (r152388) as well as various control elements (r15966).
This makes the two iterators more consistent and facilitates code maintenance.

Tests: editing/text-iterator/backwards-text-iterator-attachment.html
       editing/text-iterator/backwards-text-iterator.html

* editing/TextIterator.cpp:
(WebCore::SimplifiedBackwardsTextIterator::advance): Use isRendererReplacedElement.

LayoutTests:

Add new tests for SimplifiedBackwardsTextIterator, covering all new cases except media
elements. media-emits-object-replacement.html was added in r158743 but removed in r274810
with all the tests relying on ModernMediaControlsEnabled=false. Also, similar tests for
TextIterator (plainTextWithTextIterator) are note added, because its handleReplacedElement
function is more more complex and does not emit a comma by default.

* editing/text-iterator/backwards-text-iterator-attachment-expected.txt: Added.
* editing/text-iterator/backwards-text-iterator-attachment.html: Added. Checks that a comma
is emited for <attachment> element.
* editing/text-iterator/backwards-text-iterator-basic-expected.txt: Add the new result.
* editing/text-iterator/backwards-text-iterator-basic.html: Check the remaining cases besides
attachment and media.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (281978 => 281979)


--- trunk/LayoutTests/ChangeLog	2021-09-03 04:34:59 UTC (rev 281978)
+++ trunk/LayoutTests/ChangeLog	2021-09-03 07:25:34 UTC (rev 281979)
@@ -1,3 +1,23 @@
+2021-09-03  Frédéric Wang  <[email protected]>
+
+        Use isRendererReplacedElement for SimplifiedBackwardsTextIterator
+        https://bugs.webkit.org/show_bug.cgi?id=229798
+
+        Reviewed by Darin Adler.
+
+        Add new tests for SimplifiedBackwardsTextIterator, covering all new cases except media
+        elements. media-emits-object-replacement.html was added in r158743 but removed in r274810
+        with all the tests relying on ModernMediaControlsEnabled=false. Also, similar tests for
+        TextIterator (plainTextWithTextIterator) are note added, because its handleReplacedElement
+        function is more more complex and does not emit a comma by default.
+
+        * editing/text-iterator/backwards-text-iterator-attachment-expected.txt: Added.
+        * editing/text-iterator/backwards-text-iterator-attachment.html: Added. Checks that a comma
+        is emited for <attachment> element.
+        * editing/text-iterator/backwards-text-iterator-basic-expected.txt: Add the new result.
+        * editing/text-iterator/backwards-text-iterator-basic.html: Check the remaining cases besides
+        attachment and media.
+
 2021-09-02  Arcady Goldmints-Orlov  <[email protected]>
 
         [GLIB] Mark fast/text/trak-optimizeLegibility.html as ImageOnlyFailure rather than Skip

Added: trunk/LayoutTests/editing/text-iterator/backwards-text-iterator-attachment-expected.txt (0 => 281979)


--- trunk/LayoutTests/editing/text-iterator/backwards-text-iterator-attachment-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/editing/text-iterator/backwards-text-iterator-attachment-expected.txt	2021-09-03 07:25:34 UTC (rev 281979)
@@ -0,0 +1,10 @@
+Verify that SimplifiedBackwardsTextIterator treats
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS internals.rangeAsTextUsingBackwardsTextIterator(range) is "some,text"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/editing/text-iterator/backwards-text-iterator-attachment.html (0 => 281979)


--- trunk/LayoutTests/editing/text-iterator/backwards-text-iterator-attachment.html	                        (rev 0)
+++ trunk/LayoutTests/editing/text-iterator/backwards-text-iterator-attachment.html	2021-09-03 07:25:34 UTC (rev 281979)
@@ -0,0 +1,19 @@
+<!DOCTYPE html><!-- webkit-test-runner [ AttachmentElementEnabled=true ] -->
+<html>
+<body>
+<div id="container">some<attachment id="attachment" title="title" subtitle="subtitle" action="" progress="0.5"></attachment>text</div>
+<script src=""
+<script>
+
+description('Verify that SimplifiedBackwardsTextIterator treats <attachment> as elements as replaced element');
+
+const range = new Range;
+range.selectNodeContents(container);
+shouldBe('internals.rangeAsTextUsingBackwardsTextIterator(range)', '"some,text"');
+
+container.innerHTML = '';
+
+successfullyParsed = true;
+</script>
+</body>
+</html>

Modified: trunk/LayoutTests/editing/text-iterator/backwards-text-iterator-basic-expected.txt (281978 => 281979)


--- trunk/LayoutTests/editing/text-iterator/backwards-text-iterator-basic-expected.txt	2021-09-03 04:34:59 UTC (rev 281978)
+++ trunk/LayoutTests/editing/text-iterator/backwards-text-iterator-basic-expected.txt	2021-09-03 07:25:34 UTC (rev 281979)
@@ -20,6 +20,8 @@
 
 PASS plainTextWithTextIterator("<table><tr><td>hello</td><td>world</td></table>") is "hello	world"
 PASS plainTextWithBackwardsTextIterator("<table><tr><td>hello</td><td>world</td></table>") is "\n\nhello\nworld"
+
+PASS plainTextWithBackwardsTextIterator("img<img>iframe<iframe></iframe>meter<meter></meter>progress<progress></progress><legend>legend</legend>imgrole<span role='img'></span><button>button</button>") is "img,iframe,meter,progress,\nlegend,imgrole,button,"
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/editing/text-iterator/backwards-text-iterator-basic.html (281978 => 281979)


--- trunk/LayoutTests/editing/text-iterator/backwards-text-iterator-basic.html	2021-09-03 04:34:59 UTC (rev 281978)
+++ trunk/LayoutTests/editing/text-iterator/backwards-text-iterator-basic.html	2021-09-03 07:25:34 UTC (rev 281979)
@@ -50,6 +50,11 @@
 shouldBe('plainTextWithTextIterator("<table><tr><td>hello</td><td>world</td></table>")', '"hello\tworld"');
 shouldBe('plainTextWithBackwardsTextIterator("<table><tr><td>hello</td><td>world</td></table>")', '"\\n\\nhello\\nworld"');
 
+debug('');
+
+// Verify that replaced elements emit a comma.
+shouldBe(`plainTextWithBackwardsTextIterator("img<img>iframe<iframe></iframe>meter<meter></meter>progress<progress></progress><legend>legend</legend>imgrole<span role='img'></span><button>button</button>")`, '"img,iframe,meter,progress,\\nlegend,imgrole,button,"');
+
 container.innerHTML = '';
 
 successfullyParsed = true;

Modified: trunk/Source/WebCore/ChangeLog (281978 => 281979)


--- trunk/Source/WebCore/ChangeLog	2021-09-03 04:34:59 UTC (rev 281978)
+++ trunk/Source/WebCore/ChangeLog	2021-09-03 07:25:34 UTC (rev 281979)
@@ -1,3 +1,24 @@
+2021-09-03  Frédéric Wang  <[email protected]>
+
+        Use isRendererReplacedElement for SimplifiedBackwardsTextIterator
+        https://bugs.webkit.org/show_bug.cgi?id=229798
+
+        Reviewed by Darin Adler.
+
+        TextIterator::advance() relies on isRendererReplacedElement to determine whether an element
+        should be treated as a replaced element and emit a comma ','. SimplifiedBackwardsTextIterator
+        has similar logic to check for replaced elements, but it has not been updated and is now
+        out-of-sync. This patch makes SimplifiedBackwardsTextIterator use the same function
+        isRendererReplacedElement, adding support for attachment (r200509), media (r158743),
+        element with a11y role "img" (r152388) as well as various control elements (r15966).
+        This makes the two iterators more consistent and facilitates code maintenance.
+
+        Tests: editing/text-iterator/backwards-text-iterator-attachment.html
+               editing/text-iterator/backwards-text-iterator.html
+
+        * editing/TextIterator.cpp:
+        (WebCore::SimplifiedBackwardsTextIterator::advance): Use isRendererReplacedElement.
+
 2021-09-02  Alan Bujtas  <[email protected]>
 
         Let content with newlineCharacter be measured by FontCascade::widthForSimpleText

Modified: trunk/Source/WebCore/editing/TextIterator.cpp (281978 => 281979)


--- trunk/Source/WebCore/editing/TextIterator.cpp	2021-09-03 04:34:59 UTC (rev 281978)
+++ trunk/Source/WebCore/editing/TextIterator.cpp	2021-09-03 07:25:34 UTC (rev 281979)
@@ -1199,7 +1199,7 @@
             if (renderer && renderer->isText() && m_node->isTextNode()) {
                 if (renderer->style().visibility() == Visibility::Visible && m_offset > 0)
                     m_handledNode = handleTextNode();
-            } else if (renderer && (renderer->isImage() || renderer->isWidget())) {
+            } else if (isRendererReplacedElement(renderer)) {
                 if (renderer->style().visibility() == Visibility::Visible && m_offset > 0)
                     m_handledNode = handleReplacedElement();
             } else
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to