Title: [287824] trunk/Source/WebCore
Revision
287824
Author
za...@apple.com
Date
2022-01-09 10:22:51 -0800 (Sun, 09 Jan 2022)

Log Message

[LFC][IFC] Introduce a dedicated structure for Line::Run's trailing whitespace information
https://bugs.webkit.org/show_bug.cgi?id=235010

Reviewed by Antti Koivisto.

* layout/formattingContexts/inline/InlineLine.cpp:
(WebCore::Layout::Line::Run::trailingWhitespaceType):
(WebCore::Layout::Line::Run::Run):
(WebCore::Layout::Line::Run::expand):
(WebCore::Layout::Line::Run::removeTrailingWhitespace):
(WebCore::Layout::m_bidiLevel): Deleted.
(WebCore::Layout::m_textContent): Deleted.
* layout/formattingContexts/inline/InlineLine.h:
(WebCore::Layout::Line::Run::hasTrailingWhitespace const):
(WebCore::Layout::Line::Run::trailingWhitespaceWidth const):
(WebCore::Layout::Line::Run::hasCollapsibleTrailingWhitespace const):
(WebCore::Layout::Line::Run::hasCollapsedTrailingWhitespace const):
(WebCore::Layout::Line::Run::trailingWhitespaceType const): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (287823 => 287824)


--- trunk/Source/WebCore/ChangeLog	2022-01-09 18:18:14 UTC (rev 287823)
+++ trunk/Source/WebCore/ChangeLog	2022-01-09 18:22:51 UTC (rev 287824)
@@ -1,3 +1,24 @@
+2022-01-09  Alan Bujtas  <za...@apple.com>
+
+        [LFC][IFC] Introduce a dedicated structure for Line::Run's trailing whitespace information
+        https://bugs.webkit.org/show_bug.cgi?id=235010
+
+        Reviewed by Antti Koivisto.
+
+        * layout/formattingContexts/inline/InlineLine.cpp:
+        (WebCore::Layout::Line::Run::trailingWhitespaceType):
+        (WebCore::Layout::Line::Run::Run):
+        (WebCore::Layout::Line::Run::expand):
+        (WebCore::Layout::Line::Run::removeTrailingWhitespace):
+        (WebCore::Layout::m_bidiLevel): Deleted.
+        (WebCore::Layout::m_textContent): Deleted.
+        * layout/formattingContexts/inline/InlineLine.h:
+        (WebCore::Layout::Line::Run::hasTrailingWhitespace const):
+        (WebCore::Layout::Line::Run::trailingWhitespaceWidth const):
+        (WebCore::Layout::Line::Run::hasCollapsibleTrailingWhitespace const):
+        (WebCore::Layout::Line::Run::hasCollapsedTrailingWhitespace const):
+        (WebCore::Layout::Line::Run::trailingWhitespaceType const): Deleted.
+
 2022-01-09  Antoine Quint  <grao...@webkit.org>
 
         translate() function in transform property should remove trailing 0 value when parsing

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


--- trunk/Source/WebCore/layout/formattingContexts/inline/InlineLine.cpp	2022-01-09 18:18:14 UTC (rev 287823)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/InlineLine.cpp	2022-01-09 18:22:51 UTC (rev 287824)
@@ -535,6 +535,17 @@
     return { };
 }
 
+std::optional<Line::Run::TrailingWhitespace::Type> Line::Run::trailingWhitespaceType(const InlineTextItem& inlineTextItem)
+{
+    if (!inlineTextItem.isWhitespace())
+        return { };
+    if (InlineTextItem::shouldPreserveSpacesAndTabs(inlineTextItem))
+        return { TrailingWhitespace::Type::NotCollapsible };
+    if (inlineTextItem.length() == 1)
+        return { TrailingWhitespace::Type::Collapsible };
+    return { TrailingWhitespace::Type::Collapsed };
+}
+
 Line::Run::Run(const InlineItem& inlineItem, const RenderStyle& style, InlineLayoutUnit logicalLeft, InlineLayoutUnit logicalWidth)
     : m_type(toLineRunType(inlineItem.type()))
     , m_layoutBox(&inlineItem.layoutBox())
@@ -570,8 +581,8 @@
     , m_layoutBox(&softLineBreakItem.layoutBox())
     , m_style(style)
     , m_logicalLeft(logicalLeft)
+    , m_bidiLevel(softLineBreakItem.bidiLevel())
     , m_textContent({ softLineBreakItem.position(), 1 })
-    , m_bidiLevel(softLineBreakItem.bidiLevel())
 {
 }
 
@@ -581,11 +592,16 @@
     , m_style(style)
     , m_logicalLeft(logicalLeft)
     , m_logicalWidth(logicalWidth)
-    , m_trailingWhitespaceType(trailingWhitespaceType(inlineTextItem))
-    , m_trailingWhitespaceWidth(m_trailingWhitespaceType != TrailingWhitespace::None ? logicalWidth : InlineLayoutUnit { })
-    , m_textContent({ inlineTextItem.start(), m_trailingWhitespaceType == TrailingWhitespace::Collapsed ? 1 : inlineTextItem.length() })
     , m_bidiLevel(inlineTextItem.bidiLevel())
 {
+    auto length = inlineTextItem.length();
+    auto whitespaceType = trailingWhitespaceType(inlineTextItem);
+    if (whitespaceType) {
+        m_trailingWhitespace = { *whitespaceType, logicalWidth };
+        if (*whitespaceType == TrailingWhitespace::Type::Collapsed)
+            length =  1;
+    }
+    m_textContent = { inlineTextItem.start(), length };
 }
 
 void Line::Run::expand(const InlineTextItem& inlineTextItem, InlineLayoutUnit logicalWidth)
@@ -596,15 +612,16 @@
     ASSERT(m_bidiLevel == inlineTextItem.bidiLevel());
 
     m_logicalWidth += logicalWidth;
-    m_trailingWhitespaceType = trailingWhitespaceType(inlineTextItem);
+    auto whitespaceType = trailingWhitespaceType(inlineTextItem);
 
-    if (m_trailingWhitespaceType == TrailingWhitespace::None) {
-        m_trailingWhitespaceWidth = { };
+    if (!whitespaceType) {
+        m_trailingWhitespace = { };
         m_textContent->length += inlineTextItem.length();
         return;
     }
-    m_trailingWhitespaceWidth += logicalWidth;
-    m_textContent->length += m_trailingWhitespaceType == TrailingWhitespace::Collapsed ? 1 : inlineTextItem.length();
+    auto whitespaceWidth = !m_trailingWhitespace ? logicalWidth : m_trailingWhitespace->width + logicalWidth;
+    m_trailingWhitespace = TrailingWhitespace { *whitespaceType, whitespaceWidth };
+    m_textContent->length += *whitespaceType == TrailingWhitespace::Type::Collapsed ? 1 : inlineTextItem.length();
 }
 
 bool Line::Run::hasTrailingLetterSpacing() const
@@ -628,14 +645,14 @@
 
 void Line::Run::removeTrailingWhitespace()
 {
+    ASSERT(m_trailingWhitespace);
     // According to https://www.w3.org/TR/css-text-3/#white-space-property matrix
     // Trimmable whitespace is always collapsible so the length of the trailing trimmable whitespace is always 1 (or non-existent).
     ASSERT(m_textContent->length);
     constexpr size_t trailingTrimmableContentLength = 1;
     m_textContent->length -= trailingTrimmableContentLength;
-    shrinkHorizontally(m_trailingWhitespaceWidth);
-    m_trailingWhitespaceWidth = { };
-    m_trailingWhitespaceType = TrailingWhitespace::None;
+    shrinkHorizontally(m_trailingWhitespace->width);
+    m_trailingWhitespace = { };
 }
 
 }

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


--- trunk/Source/WebCore/layout/formattingContexts/inline/InlineLine.h	2022-01-09 18:18:14 UTC (rev 287823)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/InlineLine.h	2022-01-09 18:22:51 UTC (rev 287824)
@@ -106,8 +106,8 @@
 
         const InlineDisplay::Box::Expansion& expansion() const { return m_expansion; }
 
-        bool hasTrailingWhitespace() const { return m_trailingWhitespaceType != TrailingWhitespace::None; }
-        InlineLayoutUnit trailingWhitespaceWidth() const { return m_trailingWhitespaceWidth; }
+        bool hasTrailingWhitespace() const { return m_trailingWhitespace.has_value(); }
+        InlineLayoutUnit trailingWhitespaceWidth() const { return m_trailingWhitespace ? m_trailingWhitespace->width : 0.f; }
 
         bool shouldTrailingWhitespaceHang() const;
         TextDirection inlineDirection() const;
@@ -131,15 +131,18 @@
         void setExpansion(InlineDisplay::Box::Expansion expansion) { m_expansion = expansion; }
         void setNeedsHyphen(InlineLayoutUnit hyphenLogicalWidth);
 
-        enum class TrailingWhitespace {
-            None,
-            NotCollapsible,
-            Collapsible,
-            Collapsed
+        struct TrailingWhitespace {
+            enum class Type {
+                NotCollapsible,
+                Collapsible,
+                Collapsed
+            };
+            Type type { Type::NotCollapsible };
+            InlineLayoutUnit width { 0 };
         };
-        bool hasCollapsibleTrailingWhitespace() const { return m_trailingWhitespaceType == TrailingWhitespace::Collapsible || hasCollapsedTrailingWhitespace(); }
-        bool hasCollapsedTrailingWhitespace() const { return m_trailingWhitespaceType == TrailingWhitespace::Collapsed; }
-        TrailingWhitespace trailingWhitespaceType(const InlineTextItem&) const;
+        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; }
+        static std::optional<TrailingWhitespace::Type> trailingWhitespaceType(const InlineTextItem&);
         void removeTrailingWhitespace();
 
         bool hasTrailingLetterSpacing() const;
@@ -151,11 +154,10 @@
         const RenderStyle& m_style;
         InlineLayoutUnit m_logicalLeft { 0 };
         InlineLayoutUnit m_logicalWidth { 0 };
-        TrailingWhitespace m_trailingWhitespaceType { TrailingWhitespace::None };
-        InlineLayoutUnit m_trailingWhitespaceWidth { 0 };
-        std::optional<Text> m_textContent;
         InlineDisplay::Box::Expansion m_expansion;
         UBiDiLevel m_bidiLevel { UBIDI_DEFAULT_LTR };
+        std::optional<TrailingWhitespace> m_trailingWhitespace { };
+        std::optional<Text> m_textContent;
     };
     using RunList = Vector<Run, 10>;
     const RunList& runs() const { return m_runs; }
@@ -251,17 +253,6 @@
     m_length = { };
 }
 
-inline Line::Run::TrailingWhitespace Line::Run::trailingWhitespaceType(const InlineTextItem& inlineTextItem) const
-{
-    if (!inlineTextItem.isWhitespace())
-        return TrailingWhitespace::None;
-    if (InlineTextItem::shouldPreserveSpacesAndTabs(inlineTextItem))
-        return TrailingWhitespace::NotCollapsible;
-    if (inlineTextItem.length() == 1)
-        return TrailingWhitespace::Collapsible;
-    return TrailingWhitespace::Collapsed;
-}
-
 inline void Line::Run::setNeedsHyphen(InlineLayoutUnit hyphenLogicalWidth)
 {
     ASSERT(m_textContent);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to