Changeset 249963 in webkit


Ignore:
Timestamp:
Sep 17, 2019 10:31:20 AM (5 years ago)
Author:
Antti Koivisto
Message:

TextIterator should convert tabs to spaces
https://bugs.webkit.org/show_bug.cgi?id=201863

Reviewed by Zalan Bujtas.

LayoutTests/imported/w3c:

  • web-platform-tests/html/dom/elements/the-innertext-idl-attribute/getter-expected.txt:
  • web-platform-tests/innerText/getter-expected.txt:

Source/WebCore:

As seen in tests

imported/w3c/web-platform-tests/innerText/getter.html
imported/w3c/web-platform-tests/html/dom/elements/the-innertext-idl-attribute/getter.html

The old simple line layout path in TextIterator used to do this.

  • editing/TextIterator.cpp:

(WebCore::TextIterator::handleTextBox):

LayoutTests:

  • editing/pasteboard/5761530-1.html:

Set body to 'whitespace:pre' so tabs don't get lost in test output.

  • fast/tokenizer/script_extra_close-expected.txt:
  • imported/blink/fast/text/font-linux-normalize-expected.txt:
  • platform/mac/editing/pasteboard/5761530-1-expected.txt: Removed.

No need for platform specific result.

  • editing/pasteboard/5761530-1-expected.txt:
Location:
trunk
Files:
1 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r249961 r249963  
     12019-09-17  Antti Koivisto  <antti@apple.com>
     2
     3        TextIterator should convert tabs to spaces
     4        https://bugs.webkit.org/show_bug.cgi?id=201863
     5
     6        Reviewed by Zalan Bujtas.
     7
     8        * editing/pasteboard/5761530-1.html:
     9
     10        Set body to 'whitespace:pre' so tabs don't get lost in test output.
     11
     12        * fast/tokenizer/script_extra_close-expected.txt:
     13        * imported/blink/fast/text/font-linux-normalize-expected.txt:
     14        * platform/mac/editing/pasteboard/5761530-1-expected.txt: Removed.
     15
     16        No need for platform specific result.
     17
     18        * editing/pasteboard/5761530-1-expected.txt:
     19
    1202019-09-17  Chris Dumez  <cdumez@apple.com>
    221
  • trunk/LayoutTests/editing/pasteboard/5761530-1-expected.txt

    r180172 r249963  
    22
    33<span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space:pre;">   </span>xxx
     4
  • trunk/LayoutTests/editing/pasteboard/5761530-1.html

    r244854 r249963  
    22<div id="edit" contenteditable="true"><span class="Apple-tab-span" style="white-space:pre;">    </span>xxx</div>
    33<script>
    4 if (window.testRunner && window.internals) {
     4if (window.testRunner && window.internals)
    55    window.testRunner.dumpAsText();
    6     internals.settings.setSimpleLineLayoutEnabled(false);
    7 }
    86edit = document.getElementById("edit");
    97
     
    1311window.getSelection().modify("move", "backward", "character");
    1412document.execCommand("Paste");
    15 if (window.testRunner)
     13if (window.testRunner) {
    1614    document.body.innerText = document.getElementById("description").innerText + "\n\n" + edit.innerHTML;
     15    document.body.style.whiteSpace = 'pre';
     16}
    1717</script>
  • trunk/LayoutTests/fast/tokenizer/script_extra_close-expected.txt

    r249895 r249963  
    1 TEST... PASSED. This text should show up.
     1TEST... PASSED. This text should show up.
  • trunk/LayoutTests/imported/blink/fast/text/font-linux-normalize-expected.txt

    r190629 r249963  
    1 क़उ     
     1क़उ 
    22
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r249957 r249963  
     12019-09-17  Antti Koivisto  <antti@apple.com>
     2
     3        TextIterator should convert tabs to spaces
     4        https://bugs.webkit.org/show_bug.cgi?id=201863
     5
     6        Reviewed by Zalan Bujtas.
     7
     8        * web-platform-tests/html/dom/elements/the-innertext-idl-attribute/getter-expected.txt:
     9        * web-platform-tests/innerText/getter-expected.txt:
     10
    1112019-09-17  Chris Dumez  <cdumez@apple.com>
    212
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/dom/elements/the-innertext-idl-attribute/getter-expected.txt

    r249895 r249963  
    88PASS \n converted to space ("<div>abc\ndef")
    99PASS \r converted to space ("<div>abc\rdef")
    10 FAIL \t converted to space ("<div>abc\tdef") assert_equals: expected "abc def" but got "abc\tdef"
     10PASS \t converted to space ("<div>abc\tdef")
    1111FAIL Trailing whitespace before hard line break removed ("<div>abc <br>def") assert_equals: expected "abc\ndef" but got "abc \ndef"
    1212PASS Leading whitespace after hard line break removed ("<div>abc<br> def")
     
    3535FAIL \n preserved ("<div style='white-space:pre-line'>abc\ndef") assert_equals: expected "abc\ndef" but got "abc def"
    3636FAIL \r converted to newline ("<div style='white-space:pre-line'>abc\rdef") assert_equals: expected "abc\ndef" but got "abc def"
    37 FAIL \t converted to space ("<div style='white-space:pre-line'>abc\tdef") assert_equals: expected "abc def" but got "abc\tdef"
     37PASS \t converted to space ("<div style='white-space:pre-line'>abc\tdef")
    3838PASS Whitespace collapses across element boundaries ("<div><span>abc </span> def")
    3939PASS Whitespace collapses across element boundaries ("<div><span>abc </span><span></span> def")
  • trunk/LayoutTests/imported/w3c/web-platform-tests/innerText/getter-expected.txt

    r249895 r249963  
    88PASS \n converted to space ("<div>abc\ndef")
    99PASS \r converted to space ("<div>abc\rdef")
    10 FAIL \t converted to space ("<div>abc\tdef") assert_equals: expected "abc def" but got "abc\tdef"
     10PASS \t converted to space ("<div>abc\tdef")
    1111FAIL Trailing whitespace before hard line break removed ("<div>abc <br>def") assert_equals: expected "abc\ndef" but got "abc \ndef"
    1212PASS Leading whitespace preserved ("<pre> abc")
     
    3434FAIL \n preserved ("<div style='white-space:pre-line'>abc\ndef") assert_equals: expected "abc\ndef" but got "abc def"
    3535FAIL \r converted to newline ("<div style='white-space:pre-line'>abc\rdef") assert_equals: expected "abc\ndef" but got "abc def"
    36 FAIL \t converted to space ("<div style='white-space:pre-line'>abc\tdef") assert_equals: expected "abc def" but got "abc\tdef"
     36PASS \t converted to space ("<div style='white-space:pre-line'>abc\tdef")
    3737PASS Whitespace collapses across element boundaries ("<div><span>abc </span> def")
    3838PASS Whitespace collapses across element boundaries ("<div><span>abc </span><span></span> def")
  • trunk/Source/WebCore/ChangeLog

    r249955 r249963  
     12019-09-17  Antti Koivisto  <antti@apple.com>
     2
     3        TextIterator should convert tabs to spaces
     4        https://bugs.webkit.org/show_bug.cgi?id=201863
     5
     6        Reviewed by Zalan Bujtas.
     7
     8        As seen in tests
     9
     10        imported/w3c/web-platform-tests/innerText/getter.html
     11        imported/w3c/web-platform-tests/html/dom/elements/the-innertext-idl-attribute/getter.html
     12
     13        The old simple line layout path in TextIterator used to do this.
     14
     15        * editing/TextIterator.cpp:
     16        (WebCore::TextIterator::handleTextBox):
     17
    1182019-09-17  Zalan Bujtas  <zalan@apple.com>
    219
  • trunk/Source/WebCore/editing/TextIterator.cpp

    r249943 r249963  
    672672
    673673        if (runStart < runEnd) {
    674             // Handle either a single newline character (which becomes a space),
    675             // or a run of characters that does not include a newline.
    676             // This effectively translates newlines to spaces without copying the text.
    677             if (rendererText[runStart] == '\n') {
     674            auto isNewlineOrTab = [&](UChar character) {
     675                return character == '\n' || character == '\t';
     676            };
     677            // Handle either a single newline or tab character (which becomes a space),
     678            // or a run of characters that does not include newlines or tabs.
     679            // This effectively translates newlines and tabs to spaces without copying the text.
     680            if (isNewlineOrTab(rendererText[runStart])) {
    678681                emitCharacter(' ', textNode, nullptr, runStart, runStart + 1);
    679682                m_offset = runStart + 1;
    680683            } else {
    681                 size_t subrunEnd = rendererText.find('\n', runStart);
    682                 if (subrunEnd == notFound || subrunEnd > runEnd) {
    683                     subrunEnd = runEnd;
    684                     bool lastSpaceCollapsedByNextNonTextBox = !nextTextBox && (m_behavior & TextIteratorBehavesAsIfNodesFollowing) && rendererText.length() > runEnd;
     684                auto subrunEnd = runStart + 1;
     685                for (; subrunEnd < runEnd; ++subrunEnd) {
     686                    if (isNewlineOrTab(rendererText[subrunEnd]))
     687                        break;
     688                }
     689                if (subrunEnd == runEnd && (m_behavior & TextIteratorBehavesAsIfNodesFollowing)) {
     690                    bool lastSpaceCollapsedByNextNonTextBox = !nextTextBox && rendererText.length() > subrunEnd && rendererText[subrunEnd] == ' ';
    685691                    if (lastSpaceCollapsedByNextNonTextBox)
    686692                        ++subrunEnd; // runEnd stopped before last space. Increment by one to restore the space.
Note: See TracChangeset for help on using the changeset viewer.