Title: [271052] trunk/Source/WebCore
Revision
271052
Author
[email protected]
Date
2020-12-22 06:33:47 -0800 (Tue, 22 Dec 2020)

Log Message

[LFC][Integration] Compute enclosing top and bottom while constructing the inline runs
https://bugs.webkit.org/show_bug.cgi?id=220064
<rdar://problem/72556810>

Reviewed by Antti Koivisto.

Let's pre-compute the enclosing top and bottom coordinates while constructing the line runs.
(This saves a loop on the inline level boxes while constructing the lines at InlineContentBuilder::createDisplayLines)

* layout/inlineformatting/InlineFormattingContext.cpp:
(WebCore::Layout::InlineFormattingContext::computeGeometryForLineContent):
* layout/inlineformatting/InlineLineGeometry.h:
(WebCore::Layout::InlineLineGeometry::enclosingTopAndBottom const):
(WebCore::Layout::InlineLineGeometry::InlineLineGeometry):
* layout/integration/LayoutIntegrationInlineContentBuilder.cpp:
(WebCore::LayoutIntegration::InlineContentBuilder::createDisplayLineRuns const):
(WebCore::LayoutIntegration::InlineContentBuilder::createDisplayLines const):
* layout/integration/LayoutIntegrationLine.h:
(WebCore::LayoutIntegration::Line::Line):
(WebCore::LayoutIntegration::Line::enclosingContentTop const):
(WebCore::LayoutIntegration::Line::enclosingContentBottom const):
* layout/integration/LayoutIntegrationPagination.cpp:
(WebCore::LayoutIntegration::makeAdjustedContent):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (271051 => 271052)


--- trunk/Source/WebCore/ChangeLog	2020-12-22 12:42:38 UTC (rev 271051)
+++ trunk/Source/WebCore/ChangeLog	2020-12-22 14:33:47 UTC (rev 271052)
@@ -1,3 +1,29 @@
+2020-12-22  Zalan Bujtas  <[email protected]>
+
+        [LFC][Integration] Compute enclosing top and bottom while constructing the inline runs
+        https://bugs.webkit.org/show_bug.cgi?id=220064
+        <rdar://problem/72556810>
+
+        Reviewed by Antti Koivisto.
+
+        Let's pre-compute the enclosing top and bottom coordinates while constructing the line runs.
+        (This saves a loop on the inline level boxes while constructing the lines at InlineContentBuilder::createDisplayLines) 
+
+        * layout/inlineformatting/InlineFormattingContext.cpp:
+        (WebCore::Layout::InlineFormattingContext::computeGeometryForLineContent):
+        * layout/inlineformatting/InlineLineGeometry.h:
+        (WebCore::Layout::InlineLineGeometry::enclosingTopAndBottom const):
+        (WebCore::Layout::InlineLineGeometry::InlineLineGeometry):
+        * layout/integration/LayoutIntegrationInlineContentBuilder.cpp:
+        (WebCore::LayoutIntegration::InlineContentBuilder::createDisplayLineRuns const):
+        (WebCore::LayoutIntegration::InlineContentBuilder::createDisplayLines const):
+        * layout/integration/LayoutIntegrationLine.h:
+        (WebCore::LayoutIntegration::Line::Line):
+        (WebCore::LayoutIntegration::Line::enclosingContentTop const):
+        (WebCore::LayoutIntegration::Line::enclosingContentBottom const):
+        * layout/integration/LayoutIntegrationPagination.cpp:
+        (WebCore::LayoutIntegration::makeAdjustedContent):
+
 2020-12-22  Youenn Fablet  <[email protected]>
 
         [iOS] Do extensive search for microphone devices when trying to capture

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp (271051 => 271052)


--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp	2020-12-22 12:42:38 UTC (rev 271051)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp	2020-12-22 14:33:47 UTC (rev 271052)
@@ -438,6 +438,8 @@
     const auto& lineBox = formattingState.lineBoxes().last();
     auto lineIndex = formattingState.lines().size();
     auto& lineBoxLogicalRect = lineBox.logicalRect();
+    auto rootInlineBoxLogicalRect = lineBox.logicalRectForRootInlineBox();
+    auto enclosingTopAndBottom = InlineLineGeometry::EnclosingTopAndBottom { lineBoxLogicalRect.top() + rootInlineBoxLogicalRect.top(), lineBoxLogicalRect.top() + rootInlineBoxLogicalRect.bottom() };
     HashSet<const Box*> inlineBoxStartSet;
     HashSet<const Box*> inlineBoxEndSet;
 
@@ -470,12 +472,19 @@
                 auto logicalMarginRect = lineBox.logicalMarginRectForInlineLevelBox(layoutBox, boxGeometry);
                 formattingState.addLineRun({ lineIndex, layoutBox, logicalMarginRect, lineRun.expansion(), { } });
 
-                auto borderBoxLogicalTopLeft = lineBoxLogicalRect.topLeft();
-                borderBoxLogicalTopLeft.move(logicalMarginRect.left() + boxGeometry.marginStart(), logicalMarginRect.top() + boxGeometry.marginBefore());
+                auto borderBoxLogicalTopLeft = logicalMarginRect.topLeft();
+                borderBoxLogicalTopLeft.move(std::max(0_lu, boxGeometry.marginStart()), std::max(0_lu, boxGeometry.marginBefore()));
+                // Note that inline boxes are relative to the line and their top position can be negative.
+                borderBoxLogicalTopLeft.moveBy(lineBoxLogicalRect.topLeft());
                 if (layoutBox.isInFlowPositioned())
                     borderBoxLogicalTopLeft += geometry.inFlowPositionedPositionOffset(layoutBox, horizontalConstraints);
                 // Atomic inline boxes are all set. Their margin/border/content box geometries are already computed. We just have to position them here.
                 boxGeometry.setLogicalTopLeft(toLayoutPoint(borderBoxLogicalTopLeft));
+
+                auto borderBoxTop = borderBoxLogicalTopLeft.y();
+                auto borderBoxBottom = borderBoxTop + boxGeometry.borderBoxHeight();
+                enclosingTopAndBottom.top = std::min(enclosingTopAndBottom.top, borderBoxTop);
+                enclosingTopAndBottom.bottom = std::max(enclosingTopAndBottom.bottom, borderBoxBottom);
                 continue;
             }
             if (lineRun.isInlineBoxStart()) {
@@ -482,6 +491,7 @@
                 auto& boxGeometry = formattingState.boxGeometry(layoutBox);
                 formattingState.addLineRun({ lineIndex, layoutBox, lineBox.logicalMarginRectForInlineLevelBox(layoutBox, boxGeometry), lineRun.expansion(), { } });
                 inlineBoxStartSet.add(&layoutBox);
+                // FIXME: Add enclosing top and bottom support.
                 continue;
             }
             if (lineRun.isInlineBoxEnd()) {
@@ -540,7 +550,7 @@
     updateBoxGeometryForInlineBoxes();
 
     auto constructLineGeometry = [&] {
-        formattingState.addLine({ lineBoxLogicalRect, lineBox.alignmentBaseline(), lineBox.horizontalAlignmentOffset().valueOr(InlineLayoutUnit { }), lineContent.contentLogicalWidth });
+        formattingState.addLine({ lineBoxLogicalRect, enclosingTopAndBottom, lineBox.alignmentBaseline(), lineBox.horizontalAlignmentOffset().valueOr(InlineLayoutUnit { }), lineContent.contentLogicalWidth });
     };
     constructLineGeometry();
 

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.h (271051 => 271052)


--- trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.h	2020-12-22 12:42:38 UTC (rev 271051)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.h	2020-12-22 14:33:47 UTC (rev 271052)
@@ -144,6 +144,7 @@
     const InlineLevelBox& inlineLevelBoxForLayoutBox(const Box& layoutBox) const { return *m_inlineLevelBoxRectMap.get(&layoutBox); }
 
     InlineRect logicalRectForTextRun(const Line::Run&) const;
+    InlineRect logicalRectForRootInlineBox() const { return m_rootInlineBox->logicalRect(); }
     InlineRect logicalMarginRectForInlineLevelBox(const Box&, const BoxGeometry&) const;
 
     auto inlineLevelBoxList() const { return m_inlineLevelBoxRectMap.values(); }

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLineGeometry.h (271051 => 271052)


--- trunk/Source/WebCore/layout/inlineformatting/InlineLineGeometry.h	2020-12-22 12:42:38 UTC (rev 271051)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLineGeometry.h	2020-12-22 14:33:47 UTC (rev 271052)
@@ -35,10 +35,17 @@
 class InlineLineGeometry {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    InlineLineGeometry(const InlineRect& lineBoxLogicalRect, InlineLayoutUnit aligmentBaseline, InlineLayoutUnit contentLogicalLeftOffset, InlineLayoutUnit contentLogicalWidth);
+    struct EnclosingTopAndBottom {
+        // This values encloses the root inline box and any other inline level box's border box.
+        float top { 0 };
+        float bottom { 0 };
+    };
+    InlineLineGeometry(const InlineRect& lineBoxLogicalRect, EnclosingTopAndBottom, InlineLayoutUnit aligmentBaseline, InlineLayoutUnit contentLogicalLeftOffset, InlineLayoutUnit contentLogicalWidth);
 
     const InlineRect& lineBoxLogicalRect() const { return m_lineBoxLogicalRect; }
 
+    EnclosingTopAndBottom enclosingTopAndBottom() const { return m_enclosingTopAndBottom; }
+
     InlineLayoutUnit baseline() const { return m_aligmentBaseline; }
 
     InlineLayoutUnit contentLogicalLeftOffset() const { return m_contentLogicalLeftOffset; }
@@ -47,14 +54,20 @@
     void moveVertically(InlineLayoutUnit offset) { m_lineBoxLogicalRect.moveVertically(offset); }
 
 private:
+    // This is line box geometry (see https://www.w3.org/TR/css-inline-3/#line-box).
     InlineRect m_lineBoxLogicalRect;
+    // Enclosing top and bottom includes all inline level boxes (border box) vertically.
+    // While the line box usually enclose them as well, its vertical geometry is based on
+    // the layout bounds of the inline level boxes which may be different when line-height is present.
+    EnclosingTopAndBottom m_enclosingTopAndBottom;
     InlineLayoutUnit m_aligmentBaseline { 0 };
     InlineLayoutUnit m_contentLogicalLeftOffset { 0 };
     InlineLayoutUnit m_contentLogicalWidth { 0 };
 };
 
-inline InlineLineGeometry::InlineLineGeometry(const InlineRect& lineBoxLogicalRect, InlineLayoutUnit aligmentBaseline, InlineLayoutUnit contentLogicalLeftOffset, InlineLayoutUnit contentLogicalWidth)
+inline InlineLineGeometry::InlineLineGeometry(const InlineRect& lineBoxLogicalRect, EnclosingTopAndBottom enclosingTopAndBottom, InlineLayoutUnit aligmentBaseline, InlineLayoutUnit contentLogicalLeftOffset, InlineLayoutUnit contentLogicalWidth)
     : m_lineBoxLogicalRect(lineBoxLogicalRect)
+    , m_enclosingTopAndBottom(enclosingTopAndBottom)
     , m_aligmentBaseline(aligmentBaseline)
     , m_contentLogicalLeftOffset(contentLogicalLeftOffset)
     , m_contentLogicalWidth(contentLogicalWidth)

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationInlineContentBuilder.cpp (271051 => 271052)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationInlineContentBuilder.cpp	2020-12-22 12:42:38 UTC (rev 271051)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationInlineContentBuilder.cpp	2020-12-22 14:33:47 UTC (rev 271052)
@@ -242,7 +242,7 @@
 
         auto& style = layoutBox.style();
         auto text = lineRun.text();
-        auto adjustedContentToRenderer = [&] {
+        auto adjustedContentToRender = [&] {
             auto originalContent = text->content().substring(text->start(), text->length());
             if (text->needsHyphen())
                 return makeString(originalContent, style.hyphenString());
@@ -280,7 +280,7 @@
         };
         RELEASE_ASSERT(startOffset >= text->start() && startOffset < text->end());
         RELEASE_ASSERT(endOffset > text->start() && endOffset <= text->end());
-        auto textContent = Run::TextContent { startOffset, endOffset - startOffset, text->content(), adjustedContentToRenderer(), text->needsHyphen() };
+        auto textContent = Run::TextContent { startOffset, endOffset - startOffset, text->content(), adjustedContentToRender(), text->needsHyphen() };
         auto expansion = Run::Expansion { lineRun.expansion().behavior, lineRun.expansion().horizontalExpansion };
         auto displayRun = Run { lineIndex, layoutBox, runRect, computedInkOverflow(runRect), expansion, textContent };
         inlineContent.runs.append(displayRun);
@@ -303,7 +303,6 @@
 void InlineContentBuilder::createDisplayLines(const Layout::InlineFormattingState& inlineFormattingState, InlineContent& inlineContent, const LineLevelVisualAdjustmentsForRunsList& lineLevelVisualAdjustmentsForRuns) const
 {
     auto& lines = inlineFormattingState.lines();
-    auto& lineBoxes = inlineFormattingState.lineBoxes();
     auto& runs = inlineContent.runs;
     size_t runIndex = 0;
     inlineContent.lines.reserveCapacity(lines.size());
@@ -318,35 +317,14 @@
         while (runIndex < runs.size() && runs[runIndex].lineIndex() == lineIndex)
             lineInkOverflowRect.unite(runs[runIndex++].inkOverflow());
         auto runCount = runIndex - firstRunIndex;
-        auto enclosingTopAndBottom = [&] {
-            // Let's (vertically)enclose all the inline level boxes.
-            // This mostly matches 'line box rect', unless line-height triggers line box overflow (not to be confused with ink or scroll overflow).
-            auto enclosingTop = Optional<float> { };
-            auto enclosingBottom = Optional<float> { };
-            auto& lineBox = lineBoxes[lineIndex];
-            for (auto& inlineLevelBox : lineBox.inlineLevelBoxList()) {
-                auto& layoutBox = inlineLevelBox->layoutBox();
-                auto& geometry = m_layoutState.geometryForBox(layoutBox);
-                auto inlineLevelBoxLogicalRect = lineBox.logicalMarginRectForInlineLevelBox(layoutBox, geometry);
-                // inlineLevelBoxLogicalRect encloses the margin box, but we need border box for the display line.
-                inlineLevelBoxLogicalRect.expandVertically(-std::max(0_lu, geometry.marginBefore() + geometry.marginAfter()));
-                inlineLevelBoxLogicalRect.moveVertically(std::max(0_lu, geometry.marginBefore()));
-
-                enclosingTop = std::min(enclosingTop.valueOr(inlineLevelBoxLogicalRect.top()), inlineLevelBoxLogicalRect.top());
-                enclosingBottom = std::max(enclosingBottom.valueOr(inlineLevelBoxLogicalRect.bottom()), inlineLevelBoxLogicalRect.bottom());
-            }
-            // There's always at least one inline level box, the root inline box.
-            ASSERT(enclosingBottom && enclosingTop);
-            // inline boxes are relative to the line, let's make them relative to the root's content box.
-            return Line::EnclosingTopAndBottom { lineBoxLogicalRect.top() + *enclosingTop, lineBoxLogicalRect.top() + *enclosingBottom };
-        }();
         auto adjustedLineBoxRect = FloatRect { lineBoxLogicalRect };
+        auto enclosingTopAndBottom = line.enclosingTopAndBottom();
         if (lineLevelVisualAdjustmentsForRuns[lineIndex].needsIntegralPosition) {
             adjustedLineBoxRect.setY(roundToInt(adjustedLineBoxRect.y()));
             enclosingTopAndBottom.top = roundToInt(enclosingTopAndBottom.top);
             enclosingTopAndBottom.bottom = roundToInt(enclosingTopAndBottom.bottom);
         }
-        inlineContent.lines.append({ firstRunIndex, runCount, adjustedLineBoxRect, enclosingTopAndBottom, scrollableOverflowRect, lineInkOverflowRect, line.baseline(), line.contentLogicalLeftOffset(), line.contentLogicalWidth() });
+        inlineContent.lines.append({ firstRunIndex, runCount, adjustedLineBoxRect, enclosingTopAndBottom.top, enclosingTopAndBottom.bottom, scrollableOverflowRect, lineInkOverflowRect, line.baseline(), line.contentLogicalLeftOffset(), line.contentLogicalWidth() });
     }
 }
 

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationLine.h (271051 => 271052)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationLine.h	2020-12-22 12:42:38 UTC (rev 271051)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationLine.h	2020-12-22 14:33:47 UTC (rev 271052)
@@ -35,16 +35,12 @@
 class Line {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    struct EnclosingTopAndBottom {
-        // This values encloses the root inline box and any other inline level box's border box.
-        float top { 0 };
-        float bottom { 0 };
-    };
-    Line(size_t firstRunIndex, size_t runCount, const FloatRect& lineBoxRect, EnclosingTopAndBottom enclosingTopAndBottom, const FloatRect& scrollableOverflow, const FloatRect& inkOverflow, float baseline, float contentLeftOffset, float contentWidth)
+    Line(size_t firstRunIndex, size_t runCount, const FloatRect& lineBoxRect, float enclosingContentTop, float enclosingContentBottom, const FloatRect& scrollableOverflow, const FloatRect& inkOverflow, float baseline, float contentLeftOffset, float contentWidth)
         : m_firstRunIndex(firstRunIndex)
         , m_runCount(runCount)
         , m_lineBoxRect(lineBoxRect)
-        , m_enclosingTopAndBottom(enclosingTopAndBottom)
+        , m_enclosingContentTop(enclosingContentTop)
+        , m_enclosingContentBottom(enclosingContentBottom)
         , m_scrollableOverflow(scrollableOverflow)
         , m_inkOverflow(inkOverflow)
         , m_baseline(baseline)
@@ -61,8 +57,8 @@
     float lineBoxLeft() const { return m_lineBoxRect.x(); }
     float lineBoxRight() const { return m_lineBoxRect.maxX(); }
 
-    float enclosingContentTop() const { return m_enclosingTopAndBottom.top; }
-    float enclosingContentBottom() const { return m_enclosingTopAndBottom.bottom; }
+    float enclosingContentTop() const { return m_enclosingContentTop; }
+    float enclosingContentBottom() const { return m_enclosingContentBottom; }
 
     const FloatRect& scrollableOverflow() const { return m_scrollableOverflow; }
     const FloatRect& inkOverflow() const { return m_inkOverflow; }
@@ -80,7 +76,8 @@
     // Enclosing top and bottom includes all inline level boxes (border box) vertically.
     // While the line box usually enclose them as well, its vertical geometry is based on
     // the layout bounds of the inline level boxes which may be different when line-height is present.
-    EnclosingTopAndBottom m_enclosingTopAndBottom;
+    float m_enclosingContentTop { 0 };
+    float m_enclosingContentBottom { 0 };
     FloatRect m_scrollableOverflow;
     FloatRect m_inkOverflow;
     float m_baseline { 0 };

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationPagination.cpp (271051 => 271052)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationPagination.cpp	2020-12-22 12:42:38 UTC (rev 271051)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationPagination.cpp	2020-12-22 14:33:47 UTC (rev 271052)
@@ -130,7 +130,8 @@
             line.firstRunIndex(),
             line.runCount(),
             moveVertically({ FloatPoint { line.lineBoxLeft(), line.lineBoxTop() }, FloatPoint { line.lineBoxRight(), line.lineBoxBottom() } }, offset),
-            { line.enclosingContentTop() + offset, line.enclosingContentBottom() + offset },
+            line.enclosingContentTop() + offset,
+            line.enclosingContentBottom() + offset,
             moveVertically(line.scrollableOverflow(), offset),
             moveVertically(line.inkOverflow(), offset),
             line.baseline(),
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to