Title: [283043] trunk/Source/WebCore
Revision
283043
Author
[email protected]
Date
2021-09-24 08:49:28 -0700 (Fri, 24 Sep 2021)

Log Message

[LFC][IFC] Line::Run only needs a handful of style properties
https://bugs.webkit.org/show_bug.cgi?id=230730

Reviewed by Antti Koivisto.

This patch is in preparation for supporting first-line style.

Line::Run is the first structure that we use to construct line objects after line breaking (or last in the context of the series of patches going backwards from the final display box structure towards line breaking) where
we could retain the fist-line dependent property values.

* layout/formattingContexts/inline/InlineLine.cpp:
(WebCore::Layout::Line::removeCollapsibleContent):
(WebCore::Layout::Line::applyRunExpansion):
(WebCore::Layout::Line::visuallyCollapseHangingOverflow):
(WebCore::Layout::Line::appendNonBreakableSpace):
(WebCore::Layout::Line::appendTextContent):
(WebCore::Layout::Line::appendNonReplacedInlineLevelBox):
(WebCore::Layout::Line::appendLineBreak):
(WebCore::Layout::Line::appendWordBreakOpportunity):
(WebCore::Layout::Line::Run::Run):
(WebCore::Layout::m_style):
(WebCore::Layout::Line::Run::hasTrailingLetterSpacing const):
(WebCore::Layout::Line::Run::trailingLetterSpacing const):
(WebCore::Layout::Line::Run::removeTrailingLetterSpacing):
(WebCore::Layout::Line::visuallyCollapsePreWrapOverflowContent): Deleted.
* layout/formattingContexts/inline/InlineLine.h:
(WebCore::Layout::Line::Run::layoutBox const):
(WebCore::Layout::Line::Run::isOverflowWhitespaceHanging const):
(WebCore::Layout::Line::Run::inlineDirection const):
(WebCore::Layout::Line::Run::letterSpacing const):
(WebCore::Layout::Line::Run::hasTextCombine const):
(WebCore::Layout::Line::Run::style const): Deleted.
* layout/formattingContexts/inline/InlineLineBoxBuilder.cpp:
(WebCore::Layout::hangingGlyphWidth):
(WebCore::Layout::LineBoxBuilder::constructAndAlignInlineLevelBoxes):
* layout/formattingContexts/inline/text/TextUtil.cpp:
(WebCore::Layout::TextUtil::fallbackFontsForRun):
* layout/formattingContexts/inline/text/TextUtil.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (283042 => 283043)


--- trunk/Source/WebCore/ChangeLog	2021-09-24 14:39:02 UTC (rev 283042)
+++ trunk/Source/WebCore/ChangeLog	2021-09-24 15:49:28 UTC (rev 283043)
@@ -1,5 +1,46 @@
 2021-09-24  Alan Bujtas  <[email protected]>
 
+        [LFC][IFC] Line::Run only needs a handful of style properties
+        https://bugs.webkit.org/show_bug.cgi?id=230730
+
+        Reviewed by Antti Koivisto.
+
+        This patch is in preparation for supporting first-line style.
+
+        Line::Run is the first structure that we use to construct line objects after line breaking (or last in the context of the series of patches going backwards from the final display box structure towards line breaking) where
+        we could retain the fist-line dependent property values.
+
+        * layout/formattingContexts/inline/InlineLine.cpp:
+        (WebCore::Layout::Line::removeCollapsibleContent):
+        (WebCore::Layout::Line::applyRunExpansion):
+        (WebCore::Layout::Line::visuallyCollapseHangingOverflow):
+        (WebCore::Layout::Line::appendNonBreakableSpace):
+        (WebCore::Layout::Line::appendTextContent):
+        (WebCore::Layout::Line::appendNonReplacedInlineLevelBox):
+        (WebCore::Layout::Line::appendLineBreak):
+        (WebCore::Layout::Line::appendWordBreakOpportunity):
+        (WebCore::Layout::Line::Run::Run):
+        (WebCore::Layout::m_style):
+        (WebCore::Layout::Line::Run::hasTrailingLetterSpacing const):
+        (WebCore::Layout::Line::Run::trailingLetterSpacing const):
+        (WebCore::Layout::Line::Run::removeTrailingLetterSpacing):
+        (WebCore::Layout::Line::visuallyCollapsePreWrapOverflowContent): Deleted.
+        * layout/formattingContexts/inline/InlineLine.h:
+        (WebCore::Layout::Line::Run::layoutBox const):
+        (WebCore::Layout::Line::Run::isOverflowWhitespaceHanging const):
+        (WebCore::Layout::Line::Run::inlineDirection const):
+        (WebCore::Layout::Line::Run::letterSpacing const):
+        (WebCore::Layout::Line::Run::hasTextCombine const):
+        (WebCore::Layout::Line::Run::style const): Deleted.
+        * layout/formattingContexts/inline/InlineLineBoxBuilder.cpp:
+        (WebCore::Layout::hangingGlyphWidth):
+        (WebCore::Layout::LineBoxBuilder::constructAndAlignInlineLevelBoxes):
+        * layout/formattingContexts/inline/text/TextUtil.cpp:
+        (WebCore::Layout::TextUtil::fallbackFontsForRun):
+        * layout/formattingContexts/inline/text/TextUtil.h:
+
+2021-09-24  Alan Bujtas  <[email protected]>
+
         [LFC][IFC] InlineLevelBox only needs a handful of style properties
         https://bugs.webkit.org/show_bug.cgi?id=230724
 

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


--- trunk/Source/WebCore/layout/formattingContexts/inline/InlineLine.cpp	2021-09-24 14:39:02 UTC (rev 283042)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/InlineLine.cpp	2021-09-24 15:49:28 UTC (rev 283043)
@@ -62,7 +62,7 @@
 void Line::removeCollapsibleContent(InlineLayoutUnit extraHorizontalSpace)
 {
     removeTrailingTrimmableContent();
-    visuallyCollapsePreWrapOverflowContent(extraHorizontalSpace);
+    visuallyCollapseHangingOverflow(extraHorizontalSpace);
 }
 
 void Line::applyRunExpansion(InlineLayoutUnit extraHorizontalSpace)
@@ -87,16 +87,15 @@
     auto runIsAfterExpansion = true;
     for (size_t runIndex = 0; runIndex < m_runs.size(); ++runIndex) {
         auto& run = m_runs[runIndex];
-        auto& style = run.style();
         int expansionBehavior = DefaultExpansion;
         size_t expansionOpportunitiesInRun = 0;
 
         if (run.isText() && !TextUtil::shouldPreserveSpacesAndTabs(run.layoutBox())) {
-            if (style.textCombine() == TextCombine::Horizontal)
+            if (run.hasTextCombine())
                 expansionBehavior = ForbidLeftExpansion | ForbidRightExpansion;
             else {
                 expansionBehavior = (runIsAfterExpansion ? ForbidLeftExpansion : AllowLeftExpansion) | AllowRightExpansion;
-                std::tie(expansionOpportunitiesInRun, runIsAfterExpansion) = FontCascade::expansionOpportunityCount(StringView(downcast<InlineTextBox>(run.layoutBox()).content()).substring(run.textContent()->start, run.textContent()->length), run.style().direction(), expansionBehavior);
+                std::tie(expansionOpportunitiesInRun, runIsAfterExpansion) = FontCascade::expansionOpportunityCount(StringView(downcast<InlineTextBox>(run.layoutBox()).content()).substring(run.textContent()->start, run.textContent()->length), run.inlineDirection(), expansionBehavior);
             }
         } else if (run.isBox())
             runIsAfterExpansion = false;
@@ -163,7 +162,7 @@
     m_contentLogicalWidth -= m_trimmableTrailingContent.remove();
 }
 
-void Line::visuallyCollapsePreWrapOverflowContent(InlineLayoutUnit extraHorizontalSpace)
+void Line::visuallyCollapseHangingOverflow(InlineLayoutUnit extraHorizontalSpace)
 {
     ASSERT(m_trimmableTrailingContent.isEmpty());
     // If white-space is set to pre-wrap, the UA must
@@ -176,10 +175,8 @@
     // different set of white-space values and decide if the in-between pre-wrap content should be collapsed as well.)
     auto trimmedContentWidth = InlineLayoutUnit { };
     for (auto& run : WTF::makeReversedRange(m_runs)) {
-        if (run.style().whiteSpace() != WhiteSpace::PreWrap) {
-            // We are only interested in pre-wrap trailing content.
+        if (!run.isOverflowWhitespaceHanging())
             break;
-        }
         auto visuallyCollapsibleInlineItem = run.isInlineBoxStart() || run.isInlineBoxEnd() || run.hasTrailingWhitespace();
         if (!visuallyCollapsibleInlineItem)
             break;
@@ -223,7 +220,7 @@
 
 void Line::appendNonBreakableSpace(const InlineItem& inlineItem, InlineLayoutUnit logicalLeft, InlineLayoutUnit logicalWidth)
 {
-    m_runs.append({ inlineItem, logicalLeft, logicalWidth });
+    m_runs.append({ inlineItem, inlineItem.style(), logicalLeft, logicalWidth });
     // Do not let negative margin make the content shorter than it already is.
     auto runLogicalRight = logicalLeft + logicalWidth;
     m_contentLogicalWidth = std::max(m_contentLogicalWidth, runLogicalRight);
@@ -298,7 +295,7 @@
     if (needsNewRun) {
         // Note, negative words spacing may cause glyph overlap.
         auto runLogicalLeft = contentLogicalRight() + (inlineTextItem.isWordSeparator() ? style.fontCascade().wordSpacing() : 0.0f);
-        m_runs.append({ inlineTextItem, runLogicalLeft, logicalWidth });
+        m_runs.append({ inlineTextItem, inlineTextItem.style(), runLogicalLeft, logicalWidth });
         m_contentLogicalWidth = std::max(oldContentLogicalWidth, runLogicalLeft + logicalWidth);
     } else {
         m_runs.last().expand(inlineTextItem, logicalWidth);
@@ -325,7 +322,7 @@
     ++m_nonSpanningInlineLevelBoxCount;
     auto marginStart = formattingContext().geometryForBox(inlineItem.layoutBox()).marginStart();
     if (marginStart >= 0) {
-        m_runs.append({ inlineItem, contentLogicalRight(), marginBoxLogicalWidth });
+        m_runs.append({ inlineItem, inlineItem.style(), contentLogicalRight(), marginBoxLogicalWidth });
         return;
     }
     // Negative margin-start pulls the content to the logical left direction.
@@ -332,7 +329,7 @@
     // Negative margin also squeezes the margin box, we need to stretch it to make sure the subsequent content won't overlap.
     // e.g. <img style="width: 100px; margin-left: -100px;"> pulls the replaced box to -100px with the margin box width of 0px.
     // Instead we need to position it at -100px and size it to 100px so the subsequent content starts at 0px. 
-    m_runs.append({ inlineItem, contentLogicalRight() + marginStart, marginBoxLogicalWidth - marginStart });
+    m_runs.append({ inlineItem, inlineItem.style(), contentLogicalRight() + marginStart, marginBoxLogicalWidth - marginStart });
 }
 
 void Line::appendReplacedInlineLevelBox(const InlineItem& inlineItem, InlineLayoutUnit marginBoxLogicalWidth)
@@ -347,7 +344,7 @@
     m_trailingSoftHyphenWidth = { };
     if (inlineItem.isHardLineBreak()) {
         ++m_nonSpanningInlineLevelBoxCount;
-        return m_runs.append({ inlineItem, contentLogicalRight(), 0_lu });
+        return m_runs.append({ inlineItem, contentLogicalRight() });
     }
     // Soft line breaks (preserved new line characters) require inline text boxes for compatibility reasons.
     ASSERT(inlineItem.isSoftLineBreak());
@@ -356,7 +353,7 @@
 
 void Line::appendWordBreakOpportunity(const InlineItem& inlineItem)
 {
-    m_runs.append({ inlineItem, contentLogicalRight(), 0_lu });
+    m_runs.append({ inlineItem, contentLogicalRight() });
 }
 
 void Line::addTrailingHyphen(InlineLayoutUnit hyphenLogicalWidth)
@@ -445,14 +442,22 @@
     return remove();
 }
 
-Line::Run::Run(const InlineItem& inlineItem, InlineLayoutUnit logicalLeft, InlineLayoutUnit logicalWidth)
+Line::Run::Run(const InlineItem& inlineItem, const RenderStyle& style, InlineLayoutUnit logicalLeft, InlineLayoutUnit logicalWidth)
     : m_type(inlineItem.type())
     , m_layoutBox(&inlineItem.layoutBox())
     , m_logicalLeft(logicalLeft)
     , m_logicalWidth(logicalWidth)
+    , m_style({ { }, style.direction(), { }, { } })
 {
 }
 
+Line::Run::Run(const InlineItem& zeroWidhtInlineItem, InlineLayoutUnit logicalLeft)
+    : m_type(zeroWidhtInlineItem.type())
+    , m_layoutBox(&zeroWidhtInlineItem.layoutBox())
+    , m_logicalLeft(logicalLeft)
+{
+}
+
 Line::Run::Run(const InlineSoftLineBreakItem& softLineBreakItem, InlineLayoutUnit logicalLeft)
     : m_type(softLineBreakItem.type())
     , m_layoutBox(&softLineBreakItem.layoutBox())
@@ -461,7 +466,7 @@
 {
 }
 
-Line::Run::Run(const InlineTextItem& inlineTextItem, InlineLayoutUnit logicalLeft, InlineLayoutUnit logicalWidth)
+Line::Run::Run(const InlineTextItem& inlineTextItem, const RenderStyle& style, InlineLayoutUnit logicalLeft, InlineLayoutUnit logicalWidth)
     : m_type(InlineItem::Type::Text)
     , m_layoutBox(&inlineTextItem.layoutBox())
     , m_logicalLeft(logicalLeft)
@@ -469,6 +474,7 @@
     , m_trailingWhitespaceType(trailingWhitespaceType(inlineTextItem))
     , m_trailingWhitespaceWidth(m_trailingWhitespaceType != TrailingWhitespace::None ? logicalWidth : InlineLayoutUnit { })
     , m_textContent({ inlineTextItem.start(), m_trailingWhitespaceType == TrailingWhitespace::Collapsed ? 1 : inlineTextItem.length() })
+    , m_style({ style.whiteSpace() == WhiteSpace::PreWrap, style.direction(), style.letterSpacing(), style.hasTextCombine() })
 {
 }
 
@@ -492,7 +498,7 @@
 
 bool Line::Run::hasTrailingLetterSpacing() const
 {
-    return !hasTrailingWhitespace() && style().letterSpacing() > 0;
+    return !hasTrailingWhitespace() && letterSpacing() > 0;
 }
 
 InlineLayoutUnit Line::Run::trailingLetterSpacing() const
@@ -499,7 +505,7 @@
 {
     if (!hasTrailingLetterSpacing())
         return { };
-    return InlineLayoutUnit { style().letterSpacing() };
+    return InlineLayoutUnit { letterSpacing() };
 }
 
 void Line::Run::removeTrailingLetterSpacing()
@@ -506,7 +512,7 @@
 {
     ASSERT(hasTrailingLetterSpacing());
     shrinkHorizontally(trailingLetterSpacing());
-    ASSERT(logicalWidth() > 0 || (!logicalWidth() && style().letterSpacing() >= static_cast<float>(intMaxForLayoutUnit)));
+    ASSERT(logicalWidth() > 0 || (!logicalWidth() && letterSpacing() >= static_cast<float>(intMaxForLayoutUnit)));
 }
 
 void Line::Run::removeTrailingWhitespace()

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


--- trunk/Source/WebCore/layout/formattingContexts/inline/InlineLine.h	2021-09-24 14:39:02 UTC (rev 283042)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/InlineLine.h	2021-09-24 15:49:28 UTC (rev 283043)
@@ -71,7 +71,6 @@
         auto type() const { return m_type; }
 
         const Box& layoutBox() const { return *m_layoutBox; }
-        const RenderStyle& style() const { return m_layoutBox->style(); }
         struct Text {
             size_t start { 0 };
             size_t length { 0 };
@@ -88,12 +87,18 @@
         bool hasTrailingWhitespace() const { return m_trailingWhitespaceType != TrailingWhitespace::None; }
         InlineLayoutUnit trailingWhitespaceWidth() const { return m_trailingWhitespaceWidth; }
 
+        bool isOverflowWhitespaceHanging() const;
+        TextDirection inlineDirection() const;
+        InlineLayoutUnit letterSpacing() const;
+        bool hasTextCombine() const;
+
     private:
         friend class Line;
 
-        Run(const InlineTextItem&, InlineLayoutUnit logicalLeft, InlineLayoutUnit logicalWidth);
+        Run(const InlineTextItem&, const RenderStyle&, InlineLayoutUnit logicalLeft, InlineLayoutUnit logicalWidth);
         Run(const InlineSoftLineBreakItem&, InlineLayoutUnit logicalLeft);
-        Run(const InlineItem&, InlineLayoutUnit logicalLeft, InlineLayoutUnit logicalWidth);
+        Run(const InlineItem&, const RenderStyle&, InlineLayoutUnit logicalLeft, InlineLayoutUnit logicalWidth);
+        Run(const InlineItem&, InlineLayoutUnit logicalLeft);
 
         void expand(const InlineTextItem&, InlineLayoutUnit logicalWidth);
         void moveHorizontally(InlineLayoutUnit offset) { m_logicalLeft += offset; }
@@ -125,6 +130,13 @@
         InlineLayoutUnit m_trailingWhitespaceWidth { 0 };
         std::optional<Text> m_textContent;
         InlineDisplay::Box::Expansion m_expansion;
+        struct Style {
+            bool isOverflowWhitespaceHanging { false };
+            TextDirection inlineDirection { TextDirection::RTL };
+            InlineLayoutUnit letterSpacing { 0 };
+            bool hasTextCombine { false };
+        };
+        Style m_style { };
     };
     using RunList = Vector<Run, 10>;
     const RunList& runs() const { return m_runs; }
@@ -140,7 +152,7 @@
     void appendWordBreakOpportunity(const InlineItem&);
 
     void removeTrailingTrimmableContent();
-    void visuallyCollapsePreWrapOverflowContent(InlineLayoutUnit extraHorizontalSpace);
+    void visuallyCollapseHangingOverflow(InlineLayoutUnit extraHorizontalSpace);
 
     const InlineFormattingContext& formattingContext() const;
 
@@ -201,6 +213,26 @@
     m_logicalWidth += hyphenLogicalWidth;
 }
 
+inline bool Line::Run::isOverflowWhitespaceHanging() const
+{
+    return m_style.isOverflowWhitespaceHanging;
 }
+
+inline TextDirection Line::Run::inlineDirection() const
+{
+    return m_style.inlineDirection;
 }
+
+inline InlineLayoutUnit Line::Run::letterSpacing() const
+{
+    return m_style.letterSpacing;
+}
+
+inline bool Line::Run::hasTextCombine() const
+{
+    return m_style.hasTextCombine;
+}
+
+}
+}
 #endif

Modified: trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBoxBuilder.cpp (283042 => 283043)


--- trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBoxBuilder.cpp	2021-09-24 14:39:02 UTC (rev 283042)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBoxBuilder.cpp	2021-09-24 15:49:28 UTC (rev 283043)
@@ -53,7 +53,7 @@
         if (!run.hasTrailingWhitespace())
             break;
         // Check if we have a preserved or hung whitespace.
-        if (run.style().whiteSpace() != WhiteSpace::PreWrap)
+        if (!run.isOverflowWhitespaceHanging())
             break;
         // This is either a normal or conditionally hanging trailing whitespace.
         hangingWidth += run.trailingWhitespaceWidth();
@@ -359,7 +359,7 @@
         if (run.isText()) {
             auto& parentInlineBox = lineBox.inlineLevelBoxForLayoutBox(layoutBox.parent());
             parentInlineBox.setHasContent();
-            auto fallbackFonts = TextUtil::fallbackFontsForRun(run);
+            auto fallbackFonts = TextUtil::fallbackFontsForRun(run, style);
             if (!fallbackFonts.isEmpty()) {
                 // Adjust non-empty inline box height when glyphs from the non-primary font stretch the box.
                 adjustVerticalGeometryForInlineBoxWithFallbackFonts(parentInlineBox, fallbackFonts);

Modified: trunk/Source/WebCore/layout/formattingContexts/inline/text/TextUtil.cpp (283042 => 283043)


--- trunk/Source/WebCore/layout/formattingContexts/inline/text/TextUtil.cpp	2021-09-24 14:39:02 UTC (rev 283042)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/text/TextUtil.cpp	2021-09-24 15:49:28 UTC (rev 283043)
@@ -110,7 +110,7 @@
     }
 }
 
-TextUtil::FallbackFontList TextUtil::fallbackFontsForRun(const Line::Run& run)
+TextUtil::FallbackFontList TextUtil::fallbackFontsForRun(const Line::Run& run, const RenderStyle& style)
 {
     ASSERT(run.isText());
     auto& inlineTextBox = downcast<InlineTextBox>(run.layoutBox());
@@ -119,7 +119,6 @@
         return { };
     }
 
-    auto& style = run.style();
     TextUtil::FallbackFontList fallbackFonts;
 
     auto collectFallbackFonts = [&](const auto& textRun) {

Modified: trunk/Source/WebCore/layout/formattingContexts/inline/text/TextUtil.h (283042 => 283043)


--- trunk/Source/WebCore/layout/formattingContexts/inline/text/TextUtil.h	2021-09-24 14:39:02 UTC (rev 283042)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/text/TextUtil.h	2021-09-24 15:49:28 UTC (rev 283043)
@@ -49,7 +49,7 @@
     static InlineLayoutUnit width(const InlineTextBox&, unsigned from, unsigned to, InlineLayoutUnit contentLogicalLeft);
 
     using FallbackFontList = HashSet<const Font*>;
-    static FallbackFontList fallbackFontsForRun(const Line::Run&);
+    static FallbackFontList fallbackFontsForRun(const Line::Run&, const RenderStyle&);
 
     struct MidWordBreak {
         size_t start { 0 };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to