Title: [270114] trunk/Source/WebCore
Revision
270114
Author
[email protected]
Date
2020-11-20 06:57:43 -0800 (Fri, 20 Nov 2020)

Log Message

[LFC][IFC] Move horizontal space tracking from Line to LineBuilder
https://bugs.webkit.org/show_bug.cgi?id=219185

Reviewed by Antti Koivisto.

Let's move the available horizontal space tracking from Line to LineBuilder. Since the LineBuilder decides what to put on the line
the Line object does not need to know how much available space there is.
This is also in preparation for adding float support on (vertically) stretchy lines where the horizontal available space may vary
depending on how much the inline level boxes stretch the line vertically.

* layout/inlineformatting/InlineLine.cpp:
(WebCore::Layout::Line::initialize):
(WebCore::Layout::Line::removeCollapsibleContent):
(WebCore::Layout::Line::applyRunExpansion):
(WebCore::Layout::Line::removeTrailingTrimmableContent):
(WebCore::Layout::Line::visuallyCollapsePreWrapOverflowContent):
(WebCore::Layout::Line::moveLogicalLeft):
(WebCore::Layout::Line::moveLogicalRight): Deleted.
* layout/inlineformatting/InlineLine.h:
(WebCore::Layout::Line::contentLogicalWidth const):
(WebCore::Layout::Line::horizontalConstraint const): Deleted.
(WebCore::Layout::Line::availableWidth const): Deleted.
* layout/inlineformatting/InlineLineBuilder.cpp:
(WebCore::Layout::LineBuilder::layoutInlineContent):
(WebCore::Layout::LineBuilder::initialize):
(WebCore::Layout::LineBuilder::placeInlineContent):
(WebCore::Layout::LineBuilder::close):
(WebCore::Layout::LineBuilder::commitFloats):
(WebCore::Layout::LineBuilder::handleFloatsAndInlineContent):
(WebCore::Layout::LineBuilder::rebuildLine):
(WebCore::Layout::LineBuilder::rebuildLineForTrailingSoftHyphen):
* layout/inlineformatting/InlineLineBuilder.h:
(WebCore::Layout::LineBuilder::availableWidth const):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (270113 => 270114)


--- trunk/Source/WebCore/ChangeLog	2020-11-20 14:57:32 UTC (rev 270113)
+++ trunk/Source/WebCore/ChangeLog	2020-11-20 14:57:43 UTC (rev 270114)
@@ -1,3 +1,39 @@
+2020-11-20  Zalan Bujtas  <[email protected]>
+
+        [LFC][IFC] Move horizontal space tracking from Line to LineBuilder
+        https://bugs.webkit.org/show_bug.cgi?id=219185
+
+        Reviewed by Antti Koivisto.
+
+        Let's move the available horizontal space tracking from Line to LineBuilder. Since the LineBuilder decides what to put on the line
+        the Line object does not need to know how much available space there is.
+        This is also in preparation for adding float support on (vertically) stretchy lines where the horizontal available space may vary
+        depending on how much the inline level boxes stretch the line vertically.  
+
+        * layout/inlineformatting/InlineLine.cpp:
+        (WebCore::Layout::Line::initialize):
+        (WebCore::Layout::Line::removeCollapsibleContent):
+        (WebCore::Layout::Line::applyRunExpansion):
+        (WebCore::Layout::Line::removeTrailingTrimmableContent):
+        (WebCore::Layout::Line::visuallyCollapsePreWrapOverflowContent):
+        (WebCore::Layout::Line::moveLogicalLeft):
+        (WebCore::Layout::Line::moveLogicalRight): Deleted.
+        * layout/inlineformatting/InlineLine.h:
+        (WebCore::Layout::Line::contentLogicalWidth const):
+        (WebCore::Layout::Line::horizontalConstraint const): Deleted.
+        (WebCore::Layout::Line::availableWidth const): Deleted.
+        * layout/inlineformatting/InlineLineBuilder.cpp:
+        (WebCore::Layout::LineBuilder::layoutInlineContent):
+        (WebCore::Layout::LineBuilder::initialize):
+        (WebCore::Layout::LineBuilder::placeInlineContent):
+        (WebCore::Layout::LineBuilder::close):
+        (WebCore::Layout::LineBuilder::commitFloats):
+        (WebCore::Layout::LineBuilder::handleFloatsAndInlineContent):
+        (WebCore::Layout::LineBuilder::rebuildLine):
+        (WebCore::Layout::LineBuilder::rebuildLineForTrailingSoftHyphen):
+        * layout/inlineformatting/InlineLineBuilder.h:
+        (WebCore::Layout::LineBuilder::availableWidth const):
+
 2020-11-20  Antti Koivisto  <[email protected]>
 
         [LFC][Integration] Take alignment offset into account when computing line iterator logicalLeft

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLine.cpp (270113 => 270114)


--- trunk/Source/WebCore/layout/inlineformatting/InlineLine.cpp	2020-11-20 14:57:32 UTC (rev 270113)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLine.cpp	2020-11-20 14:57:43 UTC (rev 270114)
@@ -56,9 +56,8 @@
 {
 }
 
-void Line::initialize(InlineLayoutUnit horizontalConstraint)
+void Line::initialize()
 {
-    m_horizontalConstraint = horizontalConstraint;
     m_contentLogicalWidth = { };
     m_runs.clear();
     m_trailingSoftHyphenWidth = { };
@@ -67,13 +66,13 @@
     m_isConsideredEmptyBeforeTrimmableTrailingContent = { };
 }
 
-void Line::removeCollapsibleContent()
+void Line::removeCollapsibleContent(InlineLayoutUnit extraHorizontalSpace)
 {
     removeTrailingTrimmableContent();
-    visuallyCollapsePreWrapOverflowContent();
+    visuallyCollapsePreWrapOverflowContent(extraHorizontalSpace);
 }
 
-void Line::applyRunExpansion()
+void Line::applyRunExpansion(InlineLayoutUnit extraHorizontalSpace)
 {
     ASSERT(formattingContext().root().style().textAlign() == TextAlignMode::Justify);
     // Text is justified according to the method specified by the text-justify property,
@@ -97,10 +96,10 @@
         lastRunWithContent->setExpansionBehavior(leadingExpansion | ForbidRightExpansion);
     }
     // Anything to distribute?
-    if (!expansionOpportunityCount || !availableWidth())
+    if (!expansionOpportunityCount || !extraHorizontalSpace)
         return;
     // Distribute the extra space.
-    auto expansionToDistribute = availableWidth() / expansionOpportunityCount;
+    auto expansionToDistribute = extraHorizontalSpace / expansionOpportunityCount;
     auto accumulatedExpansion = InlineLayoutUnit { };
     for (auto& run : m_runs) {
         // Expand and move runs by the accumulated expansion.
@@ -116,7 +115,6 @@
     }
     // Content grows as runs expand.
     m_contentLogicalWidth += accumulatedExpansion;
-    ASSERT(m_contentLogicalWidth == m_horizontalConstraint);
 }
 
 void Line::removeTrailingTrimmableContent()
@@ -133,7 +131,7 @@
                 || textAlign == TextAlignMode::End;
             }();
 
-        if (m_runs.last().isLineBreak() && availableWidth() >= 0 && !isTextAlignRight) {
+        if (m_runs.last().isLineBreak() && !isTextAlignRight) {
             m_trimmableTrailingContent.reset();
             return;
         }
@@ -155,13 +153,13 @@
     }
 }
 
-void Line::visuallyCollapsePreWrapOverflowContent()
+void Line::visuallyCollapsePreWrapOverflowContent(InlineLayoutUnit extraHorizontalSpace)
 {
     ASSERT(m_trimmableTrailingContent.isEmpty());
     // If white-space is set to pre-wrap, the UA must
     // ...
     // It may also visually collapse the character advance widths of any that would otherwise overflow.
-    auto overflowWidth = -availableWidth();
+    auto overflowWidth = -extraHorizontalSpace;
     if (overflowWidth <= 0)
         return;
     // Let's just find the trailing pre-wrap whitespace content for now (e.g check if there are multiple trailing runs with
@@ -200,15 +198,8 @@
         return;
     ASSERT(delta > 0);
     m_lineLogicalLeft += delta;
-    m_horizontalConstraint -= delta;
 }
 
-void Line::moveLogicalRight(InlineLayoutUnit delta)
-{
-    ASSERT(delta > 0);
-    m_horizontalConstraint -= delta;
-}
-
 void Line::append(const InlineItem& inlineItem, InlineLayoutUnit logicalWidth)
 {
     if (inlineItem.isText())

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLine.h (270113 => 270114)


--- trunk/Source/WebCore/layout/inlineformatting/InlineLine.h	2020-11-20 14:57:32 UTC (rev 270113)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLine.h	2020-11-20 14:57:43 UTC (rev 270114)
@@ -42,7 +42,7 @@
     Line(const InlineFormattingContext&);
     ~Line();
 
-    void initialize(InlineLayoutUnit horizontalConstraint);
+    void initialize();
 
     void append(const InlineItem&, InlineLayoutUnit logicalWidth);
 
@@ -52,9 +52,7 @@
     // <span style="padding: 10px"></span> is not considered empty. 
     bool isConsideredEmpty() const { return m_isConsideredEmpty; }
 
-    InlineLayoutUnit horizontalConstraint() const { return m_horizontalConstraint; }
     InlineLayoutUnit contentLogicalWidth() const { return m_contentLogicalWidth; }
-    InlineLayoutUnit availableWidth() const { return horizontalConstraint() - contentLogicalWidth(); }
 
     InlineLayoutUnit trimmableTrailingWidth() const { return m_trimmableTrailingContent.width(); }
     bool isTrailingRunFullyTrimmable() const { return m_trimmableTrailingContent.isTrailingRunFullyTrimmable(); }
@@ -63,10 +61,9 @@
     void addTrailingHyphen(InlineLayoutUnit hyphenLogicalWidth);
 
     void moveLogicalLeft(InlineLayoutUnit);
-    void moveLogicalRight(InlineLayoutUnit);
 
-    void removeCollapsibleContent();
-    void applyRunExpansion();
+    void removeCollapsibleContent(InlineLayoutUnit extraHorizontalSpace);
+    void applyRunExpansion(InlineLayoutUnit extraHorizontalSpace);
 
     struct Run {
         bool isText() const { return m_type == InlineItem::Type::Text; }
@@ -150,7 +147,7 @@
     void appendWordBreakOpportunity(const InlineItem&);
 
     void removeTrailingTrimmableContent();
-    void visuallyCollapsePreWrapOverflowContent();
+    void visuallyCollapsePreWrapOverflowContent(InlineLayoutUnit extraHorizontalSpace);
 
     bool isRunConsideredEmpty(const Run&) const;
     const InlineFormattingContext& formattingContext() const;
@@ -182,7 +179,6 @@
     RunList m_runs;
     TrimmableTrailingContent m_trimmableTrailingContent;
     InlineLayoutUnit m_lineLogicalLeft { 0 };
-    InlineLayoutUnit m_horizontalConstraint { 0 };
     InlineLayoutUnit m_contentLogicalWidth { 0 };
     Optional<InlineLayoutUnit> m_trailingSoftHyphenWidth { 0 };
     bool m_isConsideredEmpty { true };

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.cpp (270113 => 270114)


--- trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.cpp	2020-11-20 14:57:32 UTC (rev 270113)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.cpp	2020-11-20 14:57:43 UTC (rev 270114)
@@ -262,19 +262,19 @@
 {
 }
 
-LineBuilder::LineContent LineBuilder::layoutInlineContent(const InlineItemRange& needsLayoutRange, size_t partialLeadingContentLength, const InlineRect& lineLogicalConstraints, bool isFirstLine)
+LineBuilder::LineContent LineBuilder::layoutInlineContent(const InlineItemRange& needsLayoutRange, size_t partialLeadingContentLength, const InlineRect& initialConstraintsForLine, bool isFirstLine)
 {
-    auto usedConstraints = constraintsForLine(lineLogicalConstraints, isFirstLine);
+    auto usedConstraints = constraintsForLine(initialConstraintsForLine, isFirstLine);
     initialize(usedConstraints);
 
     auto committedContent = placeInlineContent(needsLayoutRange, partialLeadingContentLength);
     auto committedRange = close(needsLayoutRange, committedContent);
 
-    auto lineLogicalTopLeft = InlineLayoutPoint { usedConstraints.logicalLeft, lineLogicalConstraints.top() };
+    auto lineLogicalTopLeft = InlineLayoutPoint { usedConstraints.logicalLeft, initialConstraintsForLine.top() };
     auto isLastLine = isLastLineWithInlineContent(committedRange, needsLayoutRange.end, committedContent.partialTrailingContentLength);
     return LineContent { committedRange, committedContent.partialTrailingContentLength, m_floats, m_contentIsConstrainedByFloat
         , lineLogicalTopLeft
-        , m_line.horizontalConstraint()
+        , m_horizontalSpaceForLine
         , m_line.contentLogicalWidth()
         , m_line.isConsideredEmpty()
         , isLastLine
@@ -295,8 +295,9 @@
     m_partialLeadingTextItem = { };
     m_wrapOpportunityList.clear();
 
-    m_line.initialize(lineConstraints.availableLogicalWidth);
+    m_line.initialize();
     m_contentIsConstrainedByFloat = lineConstraints.isConstrainedByFloat;
+    m_horizontalSpaceForLine = lineConstraints.logicalWidth; 
 }
 
 LineBuilder::CommittedContent LineBuilder::placeInlineContent(const InlineItemRange& needsLayoutRange, size_t partialLeadingContentLength)
@@ -311,7 +312,7 @@
         // 2. Apply floats and shrink the available horizontal space e.g. <span>intru_<div style="float: left"></div>sive_float</span>.
         // 3. Check if the content fits the line and commit the content accordingly (full, partial or not commit at all).
         // 4. Return if we are at the end of the line either by not being able to fit more content or because of an explicit line break.
-        nextContentForLine(lineCandidate, currentItemIndex, needsLayoutRange, partialLeadingContentLength, m_line.availableWidth() + m_line.trimmableTrailingWidth(), m_line.contentLogicalWidth());
+        nextContentForLine(lineCandidate, currentItemIndex, needsLayoutRange, partialLeadingContentLength, availableWidth() + m_line.trimmableTrailingWidth(), m_line.contentLogicalWidth());
         // Now check if we can put this content on the current line.
         auto result = handleFloatsAndInlineContent(inlineContentBreaker, needsLayoutRange, lineCandidate);
         committedInlineItemCount = result.committedCount.isRevert ? result.committedCount.value : committedInlineItemCount + result.committedCount.value;
@@ -354,11 +355,11 @@
         // Line is empty, we only managed to place float boxes.
         return lineRange;
     }
-    m_line.removeCollapsibleContent();
+    m_line.removeCollapsibleContent(availableWidth());
     auto horizontalAlignment = root().style().textAlign();
     auto runsExpandHorizontally = horizontalAlignment == TextAlignMode::Justify && !isLastLineWithInlineContent(lineRange, needsLayoutRange.end, committedContent.partialTrailingContentLength);
     if (runsExpandHorizontally)
-        m_line.applyRunExpansion();
+        m_line.applyRunExpansion(availableWidth());
     auto lineEndsWithHyphen = false;
     if (!m_line.isConsideredEmpty()) {
         ASSERT(!m_line.runs().isEmpty());
@@ -571,10 +572,12 @@
         }
     }
     if (leftIntrusiveFloatsWidth || rightIntrusiveFloatsWidth) {
-        if (leftIntrusiveFloatsWidth)
+        if (leftIntrusiveFloatsWidth) {
             m_line.moveLogicalLeft(leftIntrusiveFloatsWidth);
+            m_horizontalSpaceForLine -= leftIntrusiveFloatsWidth;
+        }
         if (rightIntrusiveFloatsWidth)
-            m_line.moveLogicalRight(rightIntrusiveFloatsWidth);
+            m_horizontalSpaceForLine -= rightIntrusiveFloatsWidth;
     }
 }
 
@@ -596,7 +599,7 @@
 
     auto& floatContent = lineCandidate.floatContent;
     // Check if this new content fits.
-    auto availableWidth = m_line.availableWidth() - floatContent.intrusiveWidth();
+    auto availableWidth = this->availableWidth() - floatContent.intrusiveWidth();
     auto isLineConsideredEmpty = m_line.isConsideredEmpty() && !m_contentIsConstrainedByFloat;
     auto lineStatus = InlineContentBreaker::LineStatus { availableWidth, m_line.trimmableTrailingWidth(), m_line.trailingSoftHyphenWidth(), m_line.isTrailingRunFullyTrimmable(), isLineConsideredEmpty };
     auto result = inlineContentBreaker.processInlineContent(continuousInlineContent, lineStatus);
@@ -685,7 +688,7 @@
     ASSERT(!m_wrapOpportunityList.isEmpty());
     // We might already have added intrusive floats. They shrink the avilable horizontal space for the line.
     // Let's just reuse what the line has at this point.
-    m_line.initialize(m_line.horizontalConstraint());
+    m_line.initialize();
     auto currentItemIndex = layoutRange.start;
     if (m_partialLeadingTextItem) {
         m_line.append(*m_partialLeadingTextItem, inlineItemWidth(*m_partialLeadingTextItem, { }));
@@ -713,7 +716,7 @@
         auto committedCount = rebuildLine(layoutRange, softWrapOpportunityItem);
         auto trailingSoftHyphenWidth = m_line.trailingSoftHyphenWidth();
         // Check if the trailing hyphen now fits the line (or we don't need hyhen anymore).
-        if (!trailingSoftHyphenWidth || trailingSoftHyphenWidth <= m_line.availableWidth()) {
+        if (!trailingSoftHyphenWidth || trailingSoftHyphenWidth <= availableWidth()) {
             if (trailingSoftHyphenWidth)
                 m_line.addTrailingHyphen(*trailingSoftHyphenWidth);
             return committedCount;

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.h (270113 => 270114)


--- trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.h	2020-11-20 14:57:32 UTC (rev 270113)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.h	2020-11-20 14:57:43 UTC (rev 270114)
@@ -64,7 +64,7 @@
         bool isLastLineWithInlineContent { true };
         const Line::RunList& runs;
     };
-    LineContent layoutInlineContent(const InlineItemRange&, size_t partialLeadingContentLength, const InlineRect& initialLineConstraints, bool isFirstLine);
+    LineContent layoutInlineContent(const InlineItemRange&, size_t partialLeadingContentLength, const InlineRect& initialConstraintsForLine, bool isFirstLine);
 
     struct IntrinsicContent {
         InlineItemRange inlineItemRange;
@@ -88,7 +88,7 @@
     enum class CommitIntrusiveFloatsOnly { No, Yes };
     struct UsedConstraints {
         InlineLayoutUnit logicalLeft { 0 };
-        InlineLayoutUnit availableLogicalWidth { 0 };
+        InlineLayoutUnit logicalWidth { 0 };
         bool isConstrainedByFloat { false };
     };
     UsedConstraints constraintsForLine(const InlineRect& initialLineConstraints, bool isFirstLine);
@@ -107,6 +107,7 @@
 
     InlineLayoutUnit inlineItemWidth(const InlineItem&, InlineLayoutUnit contentLogicalLeft) const;
     bool isLastLineWithInlineContent(const InlineItemRange& lineRange, size_t lastInlineItemIndex, bool hasPartialTrailingContent) const;
+    InlineLayoutUnit availableWidth() const { return m_horizontalSpaceForLine - m_line.contentLogicalWidth(); }
 
     const InlineFormattingContext& formattingContext() const { return m_inlineFormattingContext; }
     const ContainerBox& root() const { return m_formattingContextRoot; }
@@ -116,6 +117,7 @@
     const FloatingContext& m_floatingContext;
     const ContainerBox& m_formattingContextRoot;
     Line m_line;
+    InlineLayoutUnit m_horizontalSpaceForLine { 0 };
     const InlineItems& m_inlineItems;
     LineContent::FloatList m_floats;
     Optional<InlineTextItem> m_partialLeadingTextItem;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to