Title: [266231] trunk/Source/WebCore
Revision
266231
Author
[email protected]
Date
2020-08-27 06:42:49 -0700 (Thu, 27 Aug 2020)

Log Message

[LFC][IFC] Move LineBox out of LineBuilder
https://bugs.webkit.org/show_bug.cgi?id=215048

Reviewed by Antti Koivisto.

Since none of the LineBox related operations (content alignment, line sizing etc) is done during line building,
we don't really need to construct a LineBox until after we finished placing all the runs on the current line.
It enables us to decouple the LineBuilder and the LineBox.
Let the LineBuilder place the runs and compute horizontal geometry, while LineBox takes care of the final alignment of those runs.

* layout/inlineformatting/InlineFormattingContext.cpp:
(WebCore::Layout::LineContentAligner::adjustBaselineAndLineHeight):
(WebCore::Layout::InlineFormattingContext::lineLayout):
(WebCore::Layout::InlineFormattingContext::computedIntrinsicWidthForConstraint const):
(WebCore::Layout::InlineFormattingContext::constraintsForLine):
(WebCore::Layout::InlineFormattingContext::setDisplayBoxesForLine):
* layout/inlineformatting/InlineFormattingContext.h:
* layout/inlineformatting/InlineFormattingContextQuirks.cpp:
(WebCore::Layout::InlineFormattingContext::Quirks::initialLineHeight const):
* layout/inlineformatting/InlineLineBox.h:
(WebCore::Layout::LineBox::halfLeadingMetrics):
* layout/inlineformatting/InlineLineBuilder.cpp:
(WebCore::Layout::LineBuilder::open):
(WebCore::Layout::LineBuilder::clearContent):
(WebCore::Layout::LineBuilder::close):
(WebCore::Layout::LineBuilder::removeTrailingTrimmableContent):
(WebCore::Layout::LineBuilder::visuallyCollapsePreWrapOverflowContent):
(WebCore::Layout::LineBuilder::moveLogicalLeft):
(WebCore::Layout::LineBuilder::appendWith):
(WebCore::Layout::LineBuilder::appendNonBreakableSpace):
(WebCore::Layout::LineBuilder::appendInlineContainerEnd):
(WebCore::Layout::LineBuilder::appendTextContent):
(WebCore::Layout::LineBuilder::appendNonReplacedInlineBox):
(WebCore::Layout::LineBuilder::isRunVisuallyNonEmpty const):
(WebCore::Layout::LineBuilder::initialize): Deleted.
(WebCore::Layout::LineBuilder::clear): Deleted.
(WebCore::Layout::LineBuilder::isVisuallyNonEmpty const): Deleted.
(WebCore::Layout::LineBuilder::halfLeadingMetrics): Deleted.
* layout/inlineformatting/InlineLineBuilder.h:
(WebCore::Layout::LineBuilder::setHasIntrusiveFloat):
(WebCore::Layout::LineBuilder::hasIntrusiveFloat const):
(WebCore::Layout::LineBuilder::isVisuallyEmpty const):
(WebCore::Layout::LineBuilder::contentLogicalWidth const):
(WebCore::Layout::LineBuilder::contentLogicalRight const):
(WebCore::Layout::LineBuilder::lineBox const): Deleted.
(WebCore::Layout::LineBuilder::lineBox): Deleted.
* layout/inlineformatting/LineLayoutContext.cpp:
(WebCore::Layout::LineLayoutContext::layoutInlineContent):
(WebCore::Layout::LineLayoutContext::commitFloats):
(WebCore::Layout::LineLayoutContext::rebuildLine):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (266230 => 266231)


--- trunk/Source/WebCore/ChangeLog	2020-08-27 10:44:26 UTC (rev 266230)
+++ trunk/Source/WebCore/ChangeLog	2020-08-27 13:42:49 UTC (rev 266231)
@@ -1,3 +1,56 @@
+2020-08-27  Zalan Bujtas  <[email protected]>
+
+        [LFC][IFC] Move LineBox out of LineBuilder
+        https://bugs.webkit.org/show_bug.cgi?id=215048
+
+        Reviewed by Antti Koivisto.
+
+        Since none of the LineBox related operations (content alignment, line sizing etc) is done during line building,
+        we don't really need to construct a LineBox until after we finished placing all the runs on the current line.
+        It enables us to decouple the LineBuilder and the LineBox.
+        Let the LineBuilder place the runs and compute horizontal geometry, while LineBox takes care of the final alignment of those runs. 
+
+        * layout/inlineformatting/InlineFormattingContext.cpp:
+        (WebCore::Layout::LineContentAligner::adjustBaselineAndLineHeight):
+        (WebCore::Layout::InlineFormattingContext::lineLayout):
+        (WebCore::Layout::InlineFormattingContext::computedIntrinsicWidthForConstraint const):
+        (WebCore::Layout::InlineFormattingContext::constraintsForLine):
+        (WebCore::Layout::InlineFormattingContext::setDisplayBoxesForLine):
+        * layout/inlineformatting/InlineFormattingContext.h:
+        * layout/inlineformatting/InlineFormattingContextQuirks.cpp:
+        (WebCore::Layout::InlineFormattingContext::Quirks::initialLineHeight const):
+        * layout/inlineformatting/InlineLineBox.h:
+        (WebCore::Layout::LineBox::halfLeadingMetrics):
+        * layout/inlineformatting/InlineLineBuilder.cpp:
+        (WebCore::Layout::LineBuilder::open):
+        (WebCore::Layout::LineBuilder::clearContent):
+        (WebCore::Layout::LineBuilder::close):
+        (WebCore::Layout::LineBuilder::removeTrailingTrimmableContent):
+        (WebCore::Layout::LineBuilder::visuallyCollapsePreWrapOverflowContent):
+        (WebCore::Layout::LineBuilder::moveLogicalLeft):
+        (WebCore::Layout::LineBuilder::appendWith):
+        (WebCore::Layout::LineBuilder::appendNonBreakableSpace):
+        (WebCore::Layout::LineBuilder::appendInlineContainerEnd):
+        (WebCore::Layout::LineBuilder::appendTextContent):
+        (WebCore::Layout::LineBuilder::appendNonReplacedInlineBox):
+        (WebCore::Layout::LineBuilder::isRunVisuallyNonEmpty const):
+        (WebCore::Layout::LineBuilder::initialize): Deleted.
+        (WebCore::Layout::LineBuilder::clear): Deleted.
+        (WebCore::Layout::LineBuilder::isVisuallyNonEmpty const): Deleted.
+        (WebCore::Layout::LineBuilder::halfLeadingMetrics): Deleted.
+        * layout/inlineformatting/InlineLineBuilder.h:
+        (WebCore::Layout::LineBuilder::setHasIntrusiveFloat):
+        (WebCore::Layout::LineBuilder::hasIntrusiveFloat const):
+        (WebCore::Layout::LineBuilder::isVisuallyEmpty const):
+        (WebCore::Layout::LineBuilder::contentLogicalWidth const):
+        (WebCore::Layout::LineBuilder::contentLogicalRight const):
+        (WebCore::Layout::LineBuilder::lineBox const): Deleted.
+        (WebCore::Layout::LineBuilder::lineBox): Deleted.
+        * layout/inlineformatting/LineLayoutContext.cpp:
+        (WebCore::Layout::LineLayoutContext::layoutInlineContent):
+        (WebCore::Layout::LineLayoutContext::commitFloats):
+        (WebCore::Layout::LineLayoutContext::rebuildLine):
+
 2020-08-27  Antti Koivisto  <[email protected]>
 
         Animation are invalidating too much

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp (266230 => 266231)


--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp	2020-08-27 10:44:26 UTC (rev 266230)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp	2020-08-27 13:42:49 UTC (rev 266231)
@@ -299,7 +299,7 @@
             // Vertical margins, paddings and borders don't contribute to the line height.
             auto& fontMetrics = style.fontMetrics();
             if (style.verticalAlign() == VerticalAlign::Baseline) {
-                auto halfLeading = LineBuilder::halfLeadingMetrics(fontMetrics, style.computedLineHeight());
+                auto halfLeading = LineBox::halfLeadingMetrics(fontMetrics, style.computedLineHeight());
                 // Both halfleading ascent and descent could be negative (tall font vs. small line-height value)
                 if (halfLeading.descent > 0)
                     m_lineBox.setDescentIfGreater(halfLeading.descent);
@@ -470,13 +470,16 @@
     auto lineLayoutContext = LineLayoutContext { *this, root(), inlineItems };
 
     while (!needsLayoutRange.isEmpty()) {
-        line.initialize(constraintsForLine(constraints.horizontal, lineLogicalTop));
+        auto lineConstraints = constraintsForLine(constraints.horizontal, lineLogicalTop);
+        line.open(lineConstraints.availableLogicalWidth);
+        line.setHasIntrusiveFloat(lineConstraints.lineIsConstrainedByFloat);
         // Turn previous line's overflow content length into the next line's leading content partial length.
         // "sp[<-line break->]lit_content" -> overflow length: 11 -> leading partial content length: 11.
         auto partialLeadingContentLength = previousLine ? previousLine->overflowContentLength : WTF::nullopt;
         auto lineContent = lineLayoutContext.layoutInlineContent(line, needsLayoutRange, partialLeadingContentLength);
-        auto& lineBox = line.lineBox();
+
         auto lineContentRange = lineContent.inlineItemRange;
+        auto lineBox = LineBox { Display::InlineRect { lineConstraints.logicalTopLeft, line.contentLogicalWidth(), lineConstraints.lineHeight }, LineBox::halfLeadingMetrics(root().style().fontMetrics(), lineConstraints.lineHeight) };
 
         // FIXME: This is temporary and will eventually get merged to LineBox.
         auto alignLineContent = [&] {
@@ -522,11 +525,11 @@
         };
 
         alignLineContent();
-        setDisplayBoxesForLine(line, lineContent, constraints.horizontal);
+        setDisplayBoxesForLine(line, lineBox, lineContent, constraints.horizontal);
 
         if (!lineContentRange.isEmpty()) {
             ASSERT(needsLayoutRange.start < lineContentRange.end);
-            lineLogicalTop = line.lineBox().logicalBottom();
+            lineLogicalTop = lineBox.logicalBottom();
             // When the trailing content is partial, we need to reuse the last InlineTextItem.
             auto lastInlineItemNeedsPartialLayout = lineContent.partialContent.hasValue();
             if (lastInlineItemNeedsPartialLayout) {
@@ -550,7 +553,7 @@
         ASSERT(line.hasIntrusiveFloat());
         // Move the next line below the intrusive float.
         auto floatingContext = FloatingContext { root(), *this, formattingState().floatingState() };
-        auto floatConstraints = floatingContext.constraints(lineLogicalTop, toLayoutUnit(line.lineBox().logicalBottom()));
+        auto floatConstraints = floatingContext.constraints(lineLogicalTop, toLayoutUnit(lineBox.logicalBottom()));
         ASSERT(floatConstraints.left || floatConstraints.right);
         static auto inifitePoint = PointInContextRoot::max();
         // In case of left and right constraints, we need to pick the one that's closer to the current line.
@@ -626,11 +629,11 @@
     auto layoutRange = LineLayoutContext::InlineItemRange { 0 , inlineItems.size() };
     while (!layoutRange.isEmpty()) {
         // Only the horiztonal available width is constrained when computing intrinsic width.
-        line.initialize(LineBuilder::Constraints { { }, availableWidth, { }, false });
+        line.open(availableWidth);
         auto lineContent = lineLayoutContext.layoutInlineContent(line, layoutRange, { });
         layoutRange.start = lineContent.inlineItemRange.end;
         // FIXME: Use line logical left and right to take floats into account.
-        maximumLineWidth = std::max(maximumLineWidth, line.lineBox().logicalWidth());
+        maximumLineWidth = std::max(maximumLineWidth, line.contentLogicalWidth());
     }
     return maximumLineWidth;
 }
@@ -764,7 +767,7 @@
     }
 }
 
-LineBuilder::Constraints InlineFormattingContext::constraintsForLine(const HorizontalConstraints& horizontalConstraints, InlineLayoutUnit lineLogicalTop)
+InlineFormattingContext::LineConstraints InlineFormattingContext::constraintsForLine(const HorizontalConstraints& horizontalConstraints, InlineLayoutUnit lineLogicalTop)
 {
     auto lineLogicalLeft = horizontalConstraints.logicalLeft;
     auto lineLogicalRight = lineLogicalLeft + horizontalConstraints.logicalWidth;
@@ -831,13 +834,12 @@
         return geometry().computedTextIndent(root, horizontalConstraints).valueOr(InlineLayoutUnit { });
     };
     lineLogicalLeft += computedTextIndent();
-    return LineBuilder::Constraints { { lineLogicalLeft, lineLogicalTop }, lineLogicalRight - lineLogicalLeft, initialLineHeight, lineIsConstrainedByFloat };
+    return LineConstraints { { lineLogicalLeft, lineLogicalTop }, lineLogicalRight - lineLogicalLeft, initialLineHeight, lineIsConstrainedByFloat };
 }
 
-void InlineFormattingContext::setDisplayBoxesForLine(const LineBuilder& line, const LineLayoutContext::LineContent& lineContent, const HorizontalConstraints& horizontalConstraints)
+void InlineFormattingContext::setDisplayBoxesForLine(const LineBuilder& line, const LineBox& lineBox,  const LineLayoutContext::LineContent& lineContent, const HorizontalConstraints& horizontalConstraints)
 {
     auto& formattingState = this->formattingState();
-    auto& lineBox = line.lineBox();
 
     if (!lineContent.floats.isEmpty()) {
         auto floatingContext = FloatingContext { root(), *this, formattingState.floatingState() };

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.h (266230 => 266231)


--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.h	2020-08-27 10:44:26 UTC (rev 266230)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.h	2020-08-27 13:42:49 UTC (rev 266231)
@@ -87,8 +87,14 @@
     void computeWidthAndMargin(const Box&, const HorizontalConstraints&);
 
     void collectInlineContentIfNeeded();
-    LineBuilder::Constraints constraintsForLine(const HorizontalConstraints&, InlineLayoutUnit lineLogicalTop);
-    void setDisplayBoxesForLine(const LineBuilder&, const LineLayoutContext::LineContent&, const HorizontalConstraints&);
+    struct LineConstraints {
+        InlineLayoutPoint logicalTopLeft;
+        InlineLayoutUnit availableLogicalWidth { 0 };
+        InlineLayoutUnit lineHeight { 0 };
+        bool lineIsConstrainedByFloat { false };
+    };
+    LineConstraints constraintsForLine(const HorizontalConstraints&, InlineLayoutUnit lineLogicalTop);
+    void setDisplayBoxesForLine(const LineBuilder&, const LineBox&, const LineLayoutContext::LineContent&, const HorizontalConstraints&);
     void invalidateFormattingState(const InvalidationState&);
 
     const InlineFormattingState& formattingState() const { return downcast<InlineFormattingState>(FormattingContext::formattingState()); }

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextQuirks.cpp (266230 => 266231)


--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextQuirks.cpp	2020-08-27 10:44:26 UTC (rev 266230)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextQuirks.cpp	2020-08-27 13:42:49 UTC (rev 266231)
@@ -74,7 +74,7 @@
     // Negative lineHeight value means the line-height is not set
     if (layoutState().inNoQuirksMode() || !formattingRoot.style().lineHeight().isNegative())
         return computedLineHeight;
-    return LineBuilder::halfLeadingMetrics(formattingRoot.style().fontMetrics(), computedLineHeight).height();
+    return LineBox::halfLeadingMetrics(formattingRoot.style().fontMetrics(), computedLineHeight).height();
 }
 
 }

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.h (266230 => 266231)


--- trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.h	2020-08-27 10:44:26 UTC (rev 266230)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.h	2020-08-27 13:42:49 UTC (rev 266231)
@@ -114,6 +114,8 @@
     void setIsConsideredEmpty() { m_isConsideredEmpty = true; }
     void setIsConsideredNonEmpty() { m_isConsideredEmpty = false; }
 
+    static AscentAndDescent halfLeadingMetrics(const FontMetrics&, InlineLayoutUnit lineLogicalHeight);
+
 private:
 #if ASSERT_ENABLED
     bool m_hasValidAlignmentBaseline { false };
@@ -186,7 +188,19 @@
     m_rootInlineBox.ascentAndDescent.ascent = { };
 }
 
+inline AscentAndDescent LineBox::halfLeadingMetrics(const FontMetrics& fontMetrics, InlineLayoutUnit lineLogicalHeight)
+{
+    auto ascent = fontMetrics.ascent();
+    auto descent = fontMetrics.descent();
+    // 10.8.1 Leading and half-leading
+    auto halfLeading = (lineLogicalHeight - (ascent + descent)) / 2;
+    // Inline tree height is all integer based.
+    auto adjustedAscent = std::max<InlineLayoutUnit>(floorf(ascent + halfLeading), 0);
+    auto adjustedDescent = std::max<InlineLayoutUnit>(ceilf(descent + halfLeading), 0);
+    return { adjustedAscent, adjustedDescent };
 }
+
 }
+}
 
 #endif

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.cpp (266230 => 266231)


--- trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.cpp	2020-08-27 10:44:26 UTC (rev 266230)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.cpp	2020-08-27 13:42:49 UTC (rev 266231)
@@ -54,24 +54,19 @@
 {
 }
 
-void LineBuilder::initialize(const Constraints& constraints)
+void LineBuilder::open(InlineLayoutUnit availableWidth)
 {
-    m_lineLogicalWidth = constraints.availableLogicalWidth;
-    m_hasIntrusiveFloat = constraints.lineIsConstrainedByFloat;
-    auto initialLineHeight = constraints.lineHeight;
-    auto lineRect = Display::InlineRect { constraints.logicalTopLeft, 0_lu, initialLineHeight };
-    auto ascentAndDescent = LineBuilder::halfLeadingMetrics(formattingContext().root().style().fontMetrics(), initialLineHeight);
-    m_lineBox = LineBox { lineRect, ascentAndDescent };
-    clear();
+    m_lineLogicalWidth = availableWidth;
+    clearContent();
 #if ASSERT_ENABLED
     m_isClosed = false;
 #endif
 }
 
-void LineBuilder::clear()
+void LineBuilder::clearContent()
 {
-    m_lineBox.setLogicalWidth({ });
-    m_lineBox.setIsConsideredEmpty();
+    m_contentLogicalWidth = { };
+    m_isVisuallyEmpty = true;
     m_runs.clear();
     m_trimmableTrailingContent.reset();
     m_lineIsVisuallyEmptyBeforeTrimmableTrailingContent = { };
@@ -82,8 +77,6 @@
 #if ASSERT_ENABLED
     m_isClosed = true;
 #endif
-    // 1. Remove trimmable trailing content.
-    // 2. Align merged runs both vertically and horizontally.
     removeTrailingTrimmableContent();
     visuallyCollapsePreWrapOverflowContent();
 }
@@ -108,7 +101,7 @@
         }
     }
 
-    m_lineBox.shrinkHorizontally(m_trimmableTrailingContent.remove());
+    m_contentLogicalWidth -= m_trimmableTrailingContent.remove();
     // If we removed the first visible run on the line, we need to re-check the visibility status.
     if (m_lineIsVisuallyEmptyBeforeTrimmableTrailingContent) {
         // Just because the line was visually empty before the removed content, it does not necessarily mean it is still visually empty.
@@ -115,14 +108,13 @@
         // <span>  </span><span style="padding-left: 10px"></span>  <- non-empty
         auto lineIsVisuallyEmpty = [&] {
             for (auto& run : m_runs) {
-                if (isVisuallyNonEmpty(run))
+                if (isRunVisuallyNonEmpty(run))
                     return false;
             }
             return true;
         };
         // We could only go from visually non empty -> to visually empty. Trimmed runs should never make the line visible.
-        if (lineIsVisuallyEmpty())
-            m_lineBox.setIsConsideredEmpty();
+        m_isVisuallyEmpty = lineIsVisuallyEmpty();
         m_lineIsVisuallyEmptyBeforeTrimmableTrailingContent = { };
     }
 }
@@ -163,7 +155,7 @@
         if (overflowWidth <= 0)
             break;
     }
-    m_lineBox.shrinkHorizontally(trimmedContentWidth);
+    m_contentLogicalWidth -= trimmedContentWidth;
 }
 
 void LineBuilder::moveLogicalLeft(InlineLayoutUnit delta)
@@ -171,7 +163,7 @@
     if (!delta)
         return;
     ASSERT(delta > 0);
-    m_lineBox.moveHorizontally(delta);
+    m_lineLogicalLeft += delta;
     m_lineLogicalWidth -= delta;
 }
 
@@ -210,14 +202,14 @@
         ASSERT_NOT_REACHED();
 
     // Check if this freshly appended content makes the line visually non-empty.
-    if (m_lineBox.isConsideredEmpty() && !m_runs.isEmpty() && isVisuallyNonEmpty(m_runs.last()))
-        m_lineBox.setIsConsideredNonEmpty();
+    if (m_isVisuallyEmpty && !m_runs.isEmpty() && isRunVisuallyNonEmpty(m_runs.last()))
+        m_isVisuallyEmpty = false;
 }
 
 void LineBuilder::appendNonBreakableSpace(const InlineItem& inlineItem, InlineLayoutUnit logicalLeft, InlineLayoutUnit logicalWidth)
 {
     m_runs.append({ inlineItem, logicalLeft, logicalWidth });
-    m_lineBox.expandHorizontally(logicalWidth);
+    m_contentLogicalWidth += logicalWidth;
 }
 
 void LineBuilder::appendInlineContainerStart(const InlineItem& inlineItem, InlineLayoutUnit logicalWidth)
@@ -232,7 +224,7 @@
     auto removeTrailingLetterSpacing = [&] {
         if (!m_trimmableTrailingContent.isTrailingRunPartiallyTrimmable())
             return;
-        m_lineBox.shrinkHorizontally(m_trimmableTrailingContent.removePartiallyTrimmableContent());
+        m_contentLogicalWidth -= m_trimmableTrailingContent.removePartiallyTrimmableContent();
     };
     // Prevent trailing letter-spacing from spilling out of the inline container.
     // https://drafts.csswg.org/css-text-3/#letter-spacing-property See example 21.
@@ -281,9 +273,7 @@
     }
     if (inlineTextItemNeedsNewRun)
         m_runs.append({ inlineTextItem, contentLogicalWidth(), logicalWidth, needsHyphen });
-
-    m_lineBox.expandHorizontally(logicalWidth);
-
+    m_contentLogicalWidth += logicalWidth;
     // Set the trailing trimmable content.
     if (inlineTextItem.isWhitespace() && !TextUtil::shouldPreserveTrailingWhitespace(inlineTextItem.style())) {
         m_trimmableTrailingContent.addFullyTrimmableContent(m_runs.size() - 1, logicalWidth);
@@ -304,7 +294,7 @@
     auto& boxGeometry = formattingContext().geometryForBox(layoutBox);
     auto horizontalMargin = boxGeometry.horizontalMargin();
     m_runs.append({ inlineItem, contentLogicalWidth() + horizontalMargin.start, logicalWidth });
-    m_lineBox.expandHorizontally(logicalWidth + horizontalMargin.start + horizontalMargin.end);
+    m_contentLogicalWidth += logicalWidth + horizontalMargin.start + horizontalMargin.end;
     m_trimmableTrailingContent.reset();
 }
 
@@ -324,7 +314,7 @@
     m_runs.append({ downcast<InlineSoftLineBreakItem>(inlineItem), contentLogicalWidth() });
 }
 
-bool LineBuilder::isVisuallyNonEmpty(const Run& run) const
+bool LineBuilder::isRunVisuallyNonEmpty(const Run& run) const
 {
     if (run.isText())
         return true;
@@ -354,18 +344,6 @@
     return false;
 }
 
-AscentAndDescent LineBuilder::halfLeadingMetrics(const FontMetrics& fontMetrics, InlineLayoutUnit lineLogicalHeight)
-{
-    auto ascent = fontMetrics.ascent();
-    auto descent = fontMetrics.descent();
-    // 10.8.1 Leading and half-leading
-    auto halfLeading = (lineLogicalHeight - (ascent + descent)) / 2;
-    // Inline tree height is all integer based.
-    auto adjustedAscent = std::max<InlineLayoutUnit>(floorf(ascent + halfLeading), 0);
-    auto adjustedDescent = std::max<InlineLayoutUnit>(ceilf(descent + halfLeading), 0);
-    return { adjustedAscent, adjustedDescent };
-}
-
 const InlineFormattingContext& LineBuilder::formattingContext() const
 {
     return m_inlineFormattingContext;

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.h (266230 => 266231)


--- trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.h	2020-08-27 10:44:26 UTC (rev 266230)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.h	2020-08-27 13:42:49 UTC (rev 266231)
@@ -41,34 +41,29 @@
 
 class LineBuilder {
 public:
-    struct Constraints {
-        InlineLayoutPoint logicalTopLeft;
-        InlineLayoutUnit availableLogicalWidth { 0 };
-        InlineLayoutUnit lineHeight { 0 };
-        bool lineIsConstrainedByFloat { false };
-    };
-
     LineBuilder(const InlineFormattingContext&);
     ~LineBuilder();
 
-    void initialize(const Constraints&);
+    void open(InlineLayoutUnit availableLogicalWidth);
     void close();
+    void clearContent();
 
+    void setHasIntrusiveFloat(bool hasIntrusiveFloat) { m_hasIntrusiveFloat = hasIntrusiveFloat; }
+    bool hasIntrusiveFloat() const { return m_hasIntrusiveFloat; }
+
     void append(const InlineItem&, InlineLayoutUnit logicalWidth);
     void appendPartialTrailingTextItem(const InlineTextItem&, InlineLayoutUnit logicalWidth, bool needsHypen);
-    void clear();
-    bool isVisuallyEmpty() const { return m_lineBox.isConsideredEmpty(); }
-    bool hasIntrusiveFloat() const { return m_hasIntrusiveFloat; }
+
+    bool isVisuallyEmpty() const { return m_isVisuallyEmpty; }
+
     InlineLayoutUnit availableWidth() const { return m_lineLogicalWidth - contentLogicalWidth(); }
+    InlineLayoutUnit contentLogicalWidth() const { return m_contentLogicalWidth; }
 
     InlineLayoutUnit trimmableTrailingWidth() const { return m_trimmableTrailingContent.width(); }
     bool isTrailingRunFullyTrimmable() const { return m_trimmableTrailingContent.isTrailingRunFullyTrimmable(); }
 
-    const LineBox& lineBox() const { return m_lineBox; }
-    LineBox& lineBox() { return m_lineBox; }
     void moveLogicalLeft(InlineLayoutUnit);
     void moveLogicalRight(InlineLayoutUnit);
-    void setHasIntrusiveFloat() { m_hasIntrusiveFloat = true; }
 
     struct Run {
         bool isText() const { return m_type == InlineItem::Type::Text; }
@@ -144,11 +139,8 @@
     const RunList& runs() const { return m_runs; }
     RunList& runs() { return m_runs; }
 
-    static AscentAndDescent halfLeadingMetrics(const FontMetrics&, InlineLayoutUnit lineLogicalHeight);
-
 private:
-    InlineLayoutUnit contentLogicalWidth() const { return m_lineBox.logicalWidth(); }
-    InlineLayoutUnit contentLogicalRight() const { return m_lineBox.logicalRight(); }
+    InlineLayoutUnit contentLogicalRight() const { return m_lineLogicalLeft + m_contentLogicalWidth; }
 
     struct InlineRunDetails {
         InlineLayoutUnit logicalWidth { 0 };
@@ -166,8 +158,7 @@
     void removeTrailingTrimmableContent();
     void visuallyCollapsePreWrapOverflowContent();
 
-    bool isVisuallyNonEmpty(const Run&) const;
-
+    bool isRunVisuallyNonEmpty(const Run&) const;
     const InlineFormattingContext& formattingContext() const;
 
     struct TrimmableTrailingContent {
@@ -196,9 +187,11 @@
     const InlineFormattingContext& m_inlineFormattingContext;
     RunList m_runs;
     TrimmableTrailingContent m_trimmableTrailingContent;
+    InlineLayoutUnit m_lineLogicalLeft { 0 };
     InlineLayoutUnit m_lineLogicalWidth { 0 };
+    InlineLayoutUnit m_contentLogicalWidth { 0 };
     bool m_hasIntrusiveFloat { false };
-    LineBox m_lineBox;
+    bool m_isVisuallyEmpty { true };
     Optional<bool> m_lineIsVisuallyEmptyBeforeTrimmableTrailingContent;
     bool m_shouldIgnoreTrailingLetterSpacing { false };
 #if ASSERT_ENABLED

Modified: trunk/Source/WebCore/layout/inlineformatting/LineLayoutContext.cpp (266230 => 266231)


--- trunk/Source/WebCore/layout/inlineformatting/LineLayoutContext.cpp	2020-08-27 10:44:26 UTC (rev 266230)
+++ trunk/Source/WebCore/layout/inlineformatting/LineLayoutContext.cpp	2020-08-27 13:42:49 UTC (rev 266231)
@@ -300,7 +300,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, layoutRange, partialLeadingContentLength, line.availableWidth() + line.trimmableTrailingWidth(), line.lineBox().logicalWidth());
+        nextContentForLine(lineCandidate, currentItemIndex, layoutRange, partialLeadingContentLength, line.availableWidth() + line.trimmableTrailingWidth(), line.contentLogicalWidth());
         // Now check if we can put this content on the current line.
         auto result = handleFloatsAndInlineContent(lineBreaker, line, layoutRange, lineCandidate);
         committedInlineItemCount = result.committedCount.isRevert ? result.committedCount.value : committedInlineItemCount + result.committedCount.value;
@@ -405,8 +405,7 @@
                 rightIntrusiveFloatsWidth += floatCandidate.logicalWidth;
         }
     }
-    if (hasIntrusiveFloat)
-        line.setHasIntrusiveFloat();
+    line.setHasIntrusiveFloat(hasIntrusiveFloat);
     if (leftIntrusiveFloatsWidth || rightIntrusiveFloatsWidth) {
         if (leftIntrusiveFloatsWidth)
             line.moveLogicalLeft(leftIntrusiveFloatsWidth);
@@ -505,7 +504,7 @@
 size_t LineLayoutContext::rebuildLine(LineBuilder& line, const InlineItemRange& layoutRange)
 {
     // Clear the line and start appending the inline items closing with the last wrap opportunity run.
-    line.clear();
+    line.clearContent();
     auto currentItemIndex = layoutRange.start;
     auto logicalRight = InlineLayoutUnit { };
     if (m_partialLeadingTextItem) {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to