Title: [288801] trunk
Revision
288801
Author
[email protected]
Date
2022-01-30 08:11:22 -0800 (Sun, 30 Jan 2022)

Log Message

(REGRESSION)[IFC][RTL] wpt/css/css-text/white-space/trailing-space-and-text-alignment-rtl-003.html
https://bugs.webkit.org/show_bug.cgi?id=235823
<rdar://problem/88186663>

Reviewed by Antti Koivisto.

Source/WebCore:

Reset the trailing whitespace bidi level before handing them over to visual reordering.
see https://unicode.org/reports/tr9/#L1
"L1. On each line, reset the embedding level of the following characters to the paragraph embedding level:
  ...
  Any sequence of whitespace characters ... at the end of the line."

It ensures that
    <div style="width: 2ch; direction: rtl">AB C</div>
and
    <div style="direction: rtl">AB </div>
both have the trailing whitespace positioned _visually_ as trailing (and not leading) content.

After the bidi paragraph processing "AB C" gets a uniform bidi level of 2, while "AB " is split into "AB" and " "
with bidi levels of 2 and 1 respectively.
In the latter case, the difference in bidi levels makes the runs flip visually at reordering.
It makes the trailing whitespace "pushed" to the left side of the "AB" making it _visually_ trailing (the content renders as " AB").
However in case of "AB C" with the line breaking position after " ", we would end up with a single run of "AB " with the bidi level of 2.
This run would render as "AB " turning the trailing whitespace into a _visually_ leading whitespace.

In this patch we ensure that the trailing (non-collapsible) whitespace runs
1. are detached from their adjoining non-whitespace text runs and
2. they get their bidi levels reset

Test: fast/text/rtl-pre-wrap-hanging-offset.html

* layout/formattingContexts/inline/display/InlineDisplayLineBuilder.cpp:
(WebCore::Layout::InlineDisplayLineBuilder::build const):

LayoutTests:

* fast/text/rtl-pre-wrap-hanging-offset-expected.html: Added.
* fast/text/rtl-pre-wrap-hanging-offset.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (288800 => 288801)


--- trunk/LayoutTests/ChangeLog	2022-01-30 15:58:47 UTC (rev 288800)
+++ trunk/LayoutTests/ChangeLog	2022-01-30 16:11:22 UTC (rev 288801)
@@ -1,5 +1,16 @@
 2022-01-30  Alan Bujtas  <[email protected]>
 
+        (REGRESSION)[IFC][RTL] wpt/css/css-text/white-space/trailing-space-and-text-alignment-rtl-003.html
+        https://bugs.webkit.org/show_bug.cgi?id=235823
+        <rdar://problem/88186663>
+
+        Reviewed by Antti Koivisto.
+
+        * fast/text/rtl-pre-wrap-hanging-offset-expected.html: Added.
+        * fast/text/rtl-pre-wrap-hanging-offset.html: Added.
+
+2022-01-30  Alan Bujtas  <[email protected]>
+
         [LFC][IFC] Do not break content at an inline box boundary
         https://bugs.webkit.org/show_bug.cgi?id=235868
 

Added: trunk/LayoutTests/fast/text/rtl-pre-wrap-hanging-offset-expected.html (0 => 288801)


--- trunk/LayoutTests/fast/text/rtl-pre-wrap-hanging-offset-expected.html	                        (rev 0)
+++ trunk/LayoutTests/fast/text/rtl-pre-wrap-hanging-offset-expected.html	2022-01-30 16:11:22 UTC (rev 288801)
@@ -0,0 +1,10 @@
+<style>
+div {
+  font-family: Ahem;
+  font-size: 20px;
+  color: green;
+  white-space: pre;
+}
+</style>
+<div>XX
+ X</div>

Added: trunk/LayoutTests/fast/text/rtl-pre-wrap-hanging-offset.html (0 => 288801)


--- trunk/LayoutTests/fast/text/rtl-pre-wrap-hanging-offset.html	                        (rev 0)
+++ trunk/LayoutTests/fast/text/rtl-pre-wrap-hanging-offset.html	2022-01-30 16:11:22 UTC (rev 288801)
@@ -0,0 +1,23 @@
+<style>
+body {
+  font-family: Ahem;
+  font-size: 20px;
+}
+
+.test {
+  width: 2ch;
+  white-space: pre-wrap;
+  direction: rtl;
+  color: red;
+}
+
+.ref {
+  position: relative;
+  top: -40px;
+  color: green;
+  white-space: pre;
+}
+</style>
+<div class=test>XX X</div>
+<div class=ref>XX
+ X</div>

Modified: trunk/LayoutTests/platform/ios/fast/text/international/rtl-white-space-pre-wrap-expected.txt (288800 => 288801)


--- trunk/LayoutTests/platform/ios/fast/text/international/rtl-white-space-pre-wrap-expected.txt	2022-01-30 15:58:47 UTC (rev 288800)
+++ trunk/LayoutTests/platform/ios/fast/text/international/rtl-white-space-pre-wrap-expected.txt	2022-01-30 16:11:22 UTC (rev 288801)
@@ -22,7 +22,8 @@
       RenderBlock {HR} at (0,92) size 784x2 [border: (1px inset #000000)]
       RenderBlock {DIV} at (0,102) size 191x68 [bgcolor=#FFFF00]
         RenderText {#text} at (6,0) size 185x65
-          text run at (6,0) width 185 RTL: "\x{5D0}\x{5DB}\x{5DC}\x{5EA} \x{5E4}\x{5DC}\x{5E4}\x{5DC}? \x{5E9}\x{5EA}\x{5D4} "
+          text run at (6,0) width 9 RTL: " "
+          text run at (14,0) width 177 RTL: "\x{5D0}\x{5DB}\x{5DC}\x{5EA} \x{5E4}\x{5DC}\x{5E4}\x{5DC}? \x{5E9}\x{5EA}\x{5D4}"
           text run at (150,34) width 41 RTL: "\x{5DE}\x{5D9}\x{5E5}!"
       RenderBlock (anonymous) at (0,170) size 784x92
         RenderBR {BR} at (0,0) size 0x19

Modified: trunk/LayoutTests/platform/ios-wk2/fast/text/international/rtl-white-space-pre-wrap-expected.txt (288800 => 288801)


--- trunk/LayoutTests/platform/ios-wk2/fast/text/international/rtl-white-space-pre-wrap-expected.txt	2022-01-30 15:58:47 UTC (rev 288800)
+++ trunk/LayoutTests/platform/ios-wk2/fast/text/international/rtl-white-space-pre-wrap-expected.txt	2022-01-30 16:11:22 UTC (rev 288801)
@@ -22,7 +22,8 @@
       RenderBlock {HR} at (0,92) size 784x2 [border: (1px inset #000000)]
       RenderBlock {DIV} at (0,102) size 191x68 [bgcolor=#FFFF00]
         RenderText {#text} at (6,0) size 185x65
-          text run at (6,0) width 185 RTL: "\x{5D0}\x{5DB}\x{5DC}\x{5EA} \x{5E4}\x{5DC}\x{5E4}\x{5DC}? \x{5E9}\x{5EA}\x{5D4} "
+          text run at (6,0) width 9 RTL: " "
+          text run at (14,0) width 177 RTL: "\x{5D0}\x{5DB}\x{5DC}\x{5EA} \x{5E4}\x{5DC}\x{5E4}\x{5DC}? \x{5E9}\x{5EA}\x{5D4}"
           text run at (150,34) width 41 RTL: "\x{5DE}\x{5D9}\x{5E5}!"
       RenderBlock (anonymous) at (0,170) size 784x92
         RenderBR {BR} at (0,0) size 0x19

Modified: trunk/LayoutTests/platform/mac/fast/text/international/rtl-white-space-pre-wrap-expected.txt (288800 => 288801)


--- trunk/LayoutTests/platform/mac/fast/text/international/rtl-white-space-pre-wrap-expected.txt	2022-01-30 15:58:47 UTC (rev 288800)
+++ trunk/LayoutTests/platform/mac/fast/text/international/rtl-white-space-pre-wrap-expected.txt	2022-01-30 16:11:22 UTC (rev 288801)
@@ -22,7 +22,8 @@
       RenderBlock {HR} at (0,86) size 784x2 [border: (1px inset #000000)]
       RenderBlock {DIV} at (0,96) size 191x56 [bgcolor=#FFFF00]
         RenderText {#text} at (-4,0) size 196x56
-          text run at (-4,0) width 195 RTL: "\x{5D0}\x{5DB}\x{5DC}\x{5EA} \x{5E4}\x{5DC}\x{5E4}\x{5DC}? \x{5E9}\x{5EA}\x{5D4} "
+          text run at (-4,0) width 8 RTL: " "
+          text run at (3,0) width 188 RTL: "\x{5D0}\x{5DB}\x{5DC}\x{5EA} \x{5E4}\x{5DC}\x{5E4}\x{5DC}? \x{5E9}\x{5EA}\x{5D4}"
           text run at (147,28) width 44 RTL: "\x{5DE}\x{5D9}\x{5E5}!"
       RenderBlock (anonymous) at (0,152) size 784x84
         RenderBR {BR} at (0,0) size 0x18
@@ -36,5 +37,6 @@
   RenderTextControl {TEXTAREA} at (0,20) size 199x62 [bgcolor=#FFFFFF] [border: (1px solid #000000)]
     RenderBlock {DIV} at (3,3) size 193x56
       RenderText {#text} at (-2,0) size 196x56
-        text run at (-2,0) width 195 RTL: "\x{5D0}\x{5DB}\x{5DC}\x{5EA} \x{5E4}\x{5DC}\x{5E4}\x{5DC}? \x{5E9}\x{5EA}\x{5D4} "
+        text run at (-2,0) width 8 RTL: " "
+        text run at (5,0) width 188 RTL: "\x{5D0}\x{5DB}\x{5DC}\x{5EA} \x{5E4}\x{5DC}\x{5E4}\x{5DC}? \x{5E9}\x{5EA}\x{5D4}"
         text run at (149,28) width 44 RTL: "\x{5DE}\x{5D9}\x{5E5}!"

Modified: trunk/Source/WebCore/ChangeLog (288800 => 288801)


--- trunk/Source/WebCore/ChangeLog	2022-01-30 15:58:47 UTC (rev 288800)
+++ trunk/Source/WebCore/ChangeLog	2022-01-30 16:11:22 UTC (rev 288801)
@@ -1,5 +1,41 @@
 2022-01-30  Alan Bujtas  <[email protected]>
 
+        (REGRESSION)[IFC][RTL] wpt/css/css-text/white-space/trailing-space-and-text-alignment-rtl-003.html
+        https://bugs.webkit.org/show_bug.cgi?id=235823
+        <rdar://problem/88186663>
+
+        Reviewed by Antti Koivisto.
+
+        Reset the trailing whitespace bidi level before handing them over to visual reordering.
+        see https://unicode.org/reports/tr9/#L1
+        "L1. On each line, reset the embedding level of the following characters to the paragraph embedding level:
+          ...
+          Any sequence of whitespace characters ... at the end of the line."
+
+        It ensures that
+            <div style="width: 2ch; direction: rtl">AB C</div>
+        and
+            <div style="direction: rtl">AB </div>
+        both have the trailing whitespace positioned _visually_ as trailing (and not leading) content.
+
+        After the bidi paragraph processing "AB C" gets a uniform bidi level of 2, while "AB " is split into "AB" and " "
+        with bidi levels of 2 and 1 respectively.
+        In the latter case, the difference in bidi levels makes the runs flip visually at reordering.
+        It makes the trailing whitespace "pushed" to the left side of the "AB" making it _visually_ trailing (the content renders as " AB").
+        However in case of "AB C" with the line breaking position after " ", we would end up with a single run of "AB " with the bidi level of 2.
+        This run would render as "AB " turning the trailing whitespace into a _visually_ leading whitespace.
+
+        In this patch we ensure that the trailing (non-collapsible) whitespace runs
+        1. are detached from their adjoining non-whitespace text runs and
+        2. they get their bidi levels reset
+
+        Test: fast/text/rtl-pre-wrap-hanging-offset.html
+
+        * layout/formattingContexts/inline/display/InlineDisplayLineBuilder.cpp:
+        (WebCore::Layout::InlineDisplayLineBuilder::build const):
+
+2022-01-30  Alan Bujtas  <[email protected]>
+
         [LFC][IFC] Do not break content at an inline box boundary
         https://bugs.webkit.org/show_bug.cgi?id=235868
 

Modified: trunk/Source/WebCore/layout/formattingContexts/inline/InlineLine.cpp (288800 => 288801)


--- trunk/Source/WebCore/layout/formattingContexts/inline/InlineLine.cpp	2022-01-30 15:58:47 UTC (rev 288800)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/InlineLine.cpp	2022-01-30 16:11:22 UTC (rev 288801)
@@ -201,6 +201,38 @@
     m_hangingTrailingContent.reset();
 }
 
+void Line::resetBidiLevelForTrailingWhitespace(UBiDiLevel rootBidiLevel)
+{
+    ASSERT(m_trimmableTrailingContent.isEmpty());
+    if (!m_hasNonDefaultBidiLevelRun)
+        return;
+    // UAX#9 L1: trailing whitespace should use paragraph direction.
+    // see https://unicode.org/reports/tr9/#L1
+    for (auto index = m_runs.size(); index--;) {
+        auto& run = m_runs[index];
+        if (run.isBox() || run.isLineBreak() || (run.isText() && !run.hasTrailingWhitespace()))
+            break;
+
+        if (!run.hasTrailingWhitespace()) {
+            // Skip non-content type of runs e.g. <span>
+            continue;
+        }
+
+        if (run.isWhitespaceOnly())
+            run.setBidiLevel(rootBidiLevel);
+        else {
+            auto detachedTrailingRun = *run.detachTrailingWhitespace();
+            detachedTrailingRun.setBidiLevel(rootBidiLevel);
+            if (index == m_runs.size() - 1)
+                m_runs.append(detachedTrailingRun);
+            else
+                m_runs.insert(index + 1, detachedTrailingRun);
+            // There can't be any trailing whitespace in front of this partially whitespace content.
+            break;
+        }
+    }
+}
+
 void Line::append(const InlineItem& inlineItem, const RenderStyle& style, InlineLayoutUnit logicalWidth)
 {
     if (inlineItem.isText())
@@ -620,9 +652,9 @@
     auto length = inlineTextItem.length();
     auto whitespaceType = trailingWhitespaceType(inlineTextItem);
     if (whitespaceType) {
-        m_trailingWhitespace = { *whitespaceType, logicalWidth };
         if (*whitespaceType == TrailingWhitespace::Type::Collapsed)
             length =  1;
+        m_trailingWhitespace = { *whitespaceType, logicalWidth, length };
     }
     m_textContent = { inlineTextItem.start(), length };
 }
@@ -644,10 +676,35 @@
         return;
     }
     auto whitespaceWidth = !m_trailingWhitespace ? logicalWidth : m_trailingWhitespace->width + logicalWidth;
-    m_trailingWhitespace = TrailingWhitespace { *whitespaceType, whitespaceWidth };
-    m_textContent->length += *whitespaceType == TrailingWhitespace::Type::Collapsed ? 1 : inlineTextItem.length();
+    auto trailingWhitespaceLength = *whitespaceType == TrailingWhitespace::Type::Collapsed ? 1 : inlineTextItem.length(); 
+    m_trailingWhitespace = { *whitespaceType, whitespaceWidth, trailingWhitespaceLength };
+    m_textContent->length += trailingWhitespaceLength;
 }
 
+std::optional<Line::Run> Line::Run::detachTrailingWhitespace()
+{
+    if (!m_trailingWhitespace || isWhitespaceOnly())
+        return { };
+
+    ASSERT(m_trailingWhitespace->length < m_textContent->length);
+    auto trailingWhitespaceRun = *this;
+
+    auto leadingNonWhitespaceContentLength = m_textContent->length - m_trailingWhitespace->length;
+    trailingWhitespaceRun.m_textContent = { m_textContent->start + leadingNonWhitespaceContentLength, m_trailingWhitespace->length, false };
+
+    trailingWhitespaceRun.m_logicalWidth = m_trailingWhitespace->width;
+    trailingWhitespaceRun.m_logicalLeft = logicalRight() - m_trailingWhitespace->width;
+
+    trailingWhitespaceRun.m_trailingWhitespace = { };
+    trailingWhitespaceRun.m_lastNonWhitespaceContentStart = { };
+
+    m_logicalWidth -= trailingWhitespaceRun.logicalWidth();
+    m_textContent->length = leadingNonWhitespaceContentLength;
+    m_trailingWhitespace = { };
+
+    return trailingWhitespaceRun;
+}
+
 bool Line::Run::hasTrailingLetterSpacing() const
 {
     return !hasTrailingWhitespace() && letterSpacing() > 0;

Modified: trunk/Source/WebCore/layout/formattingContexts/inline/InlineLine.h (288800 => 288801)


--- trunk/Source/WebCore/layout/formattingContexts/inline/InlineLine.h	2022-01-30 15:58:47 UTC (rev 288800)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/InlineLine.h	2022-01-30 16:11:22 UTC (rev 288801)
@@ -66,6 +66,7 @@
     enum class ShouldApplyTrailingWhiteSpaceFollowedByBRQuirk { No, Yes };
     void removeTrailingTrimmableContent(ShouldApplyTrailingWhiteSpaceFollowedByBRQuirk);
     void removeHangingGlyphs();
+    void resetBidiLevelForTrailingWhitespace(UBiDiLevel rootBidiLevel);
     void applyRunExpansion(InlineLayoutUnit horizontalAvailableSpace);
 
     struct Run {
@@ -108,6 +109,7 @@
 
         bool hasTrailingWhitespace() const { return m_trailingWhitespace.has_value(); }
         InlineLayoutUnit trailingWhitespaceWidth() const { return m_trailingWhitespace ? m_trailingWhitespace->width : 0.f; }
+        bool isWhitespaceOnly() const { return hasTrailingWhitespace() && m_trailingWhitespace->length == m_textContent->length; }
 
         bool shouldTrailingWhitespaceHang() const;
         TextDirection inlineDirection() const;
@@ -130,6 +132,7 @@
         void shrinkHorizontally(InlineLayoutUnit width) { m_logicalWidth -= width; }
         void setExpansion(InlineDisplay::Box::Expansion expansion) { m_expansion = expansion; }
         void setNeedsHyphen(InlineLayoutUnit hyphenLogicalWidth);
+        void setBidiLevel(UBiDiLevel bidiLevel) { m_bidiLevel = bidiLevel; }
 
         struct TrailingWhitespace {
             enum class Type {
@@ -139,6 +142,7 @@
             };
             Type type { Type::NotCollapsible };
             InlineLayoutUnit width { 0 };
+            size_t length { 0 };
         };
         bool hasCollapsibleTrailingWhitespace() const { return m_trailingWhitespace && (m_trailingWhitespace->type == TrailingWhitespace::Type::Collapsible || hasCollapsedTrailingWhitespace()); }
         bool hasCollapsedTrailingWhitespace() const { return m_trailingWhitespace && m_trailingWhitespace->type == TrailingWhitespace::Type::Collapsed; }
@@ -145,6 +149,8 @@
         static std::optional<TrailingWhitespace::Type> trailingWhitespaceType(const InlineTextItem&);
         InlineLayoutUnit removeTrailingWhitespace();
 
+        std::optional<Run> detachTrailingWhitespace();
+
         bool hasTrailingLetterSpacing() const;
         InlineLayoutUnit trailingLetterSpacing() const;
         InlineLayoutUnit removeTrailingLetterSpacing();

Modified: trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBuilder.cpp (288800 => 288801)


--- trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBuilder.cpp	2022-01-30 15:58:47 UTC (rev 288800)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBuilder.cpp	2022-01-30 16:11:22 UTC (rev 288801)
@@ -549,7 +549,12 @@
                 m_line.removeHangingGlyphs();
         }
     }
-    auto horizontalAlignment = root().style().textAlign();
+
+    auto& rootStyle = root().style();
+    // On each line, reset the embedding level of any sequence of whitespace characters at the end of the line
+    // to the paragraph embedding level
+    m_line.resetBidiLevelForTrailingWhitespace(rootStyle.isLeftToRightDirection() ? UBIDI_LTR : UBIDI_RTL);
+    auto horizontalAlignment = rootStyle.textAlign();
     auto runsExpandHorizontally = horizontalAlignment == TextAlignMode::Justify && !isLastLine;
     if (runsExpandHorizontally)
         m_line.applyRunExpansion(horizontalAvailableSpace);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to