Title: [271014] trunk/Source/WebCore
Revision
271014
Author
[email protected]
Date
2020-12-20 10:56:15 -0800 (Sun, 20 Dec 2020)

Log Message

[LFC][IFC] Let's create the run and update the box geometry in one go for atomic inline level boxes
https://bugs.webkit.org/show_bug.cgi?id=220045

Reviewed by Antti Koivisto.

Let's not run the "same" loop twice on atomic inline level boxes (first when we create the line run and the second time we
we update the associated the box geometry). Unfortunately we still have to run a second pass on the inline boxes (e.g <span>) as
they behave as containers (there's room for improvement here too).

* layout/inlineformatting/InlineFormattingContext.cpp:
(WebCore::Layout::InlineFormattingContext::computeGeometryForLineContent):
* layout/inlineformatting/InlineLineBox.cpp:
(WebCore::Layout::LineBox::addInlineLevelBox):
* layout/inlineformatting/InlineLineBox.h:
(WebCore::Layout::LineBox::hasInlineBox const):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (271013 => 271014)


--- trunk/Source/WebCore/ChangeLog	2020-12-20 16:29:14 UTC (rev 271013)
+++ trunk/Source/WebCore/ChangeLog	2020-12-20 18:56:15 UTC (rev 271014)
@@ -1,3 +1,21 @@
+2020-12-20  Zalan Bujtas  <[email protected]>
+
+        [LFC][IFC] Let's create the run and update the box geometry in one go for atomic inline level boxes
+        https://bugs.webkit.org/show_bug.cgi?id=220045
+
+        Reviewed by Antti Koivisto.
+
+        Let's not run the "same" loop twice on atomic inline level boxes (first when we create the line run and the second time we
+        we update the associated the box geometry). Unfortunately we still have to run a second pass on the inline boxes (e.g <span>) as
+        they behave as containers (there's room for improvement here too).
+
+        * layout/inlineformatting/InlineFormattingContext.cpp:
+        (WebCore::Layout::InlineFormattingContext::computeGeometryForLineContent):
+        * layout/inlineformatting/InlineLineBox.cpp:
+        (WebCore::Layout::LineBox::addInlineLevelBox):
+        * layout/inlineformatting/InlineLineBox.h:
+        (WebCore::Layout::LineBox::hasInlineBox const):
+
 2020-12-20  Rob Buis  <[email protected]>
 
         Convert remaining FrameLoaderType enums to enum classes

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp (271013 => 271014)


--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp	2020-12-20 16:29:14 UTC (rev 271013)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp	2020-12-20 18:56:15 UTC (rev 271014)
@@ -436,36 +436,72 @@
 
     formattingState.addLineBox(geometry.lineBoxForLineContent(lineContent));
     const auto& lineBox = formattingState.lineBoxes().last();
+    auto lineIndex = formattingState.lines().size();
     auto& lineBoxLogicalRect = lineBox.logicalRect();
     HashSet<const Box*> inlineBoxStartSet;
     HashSet<const Box*> inlineBoxEndSet;
 
-    auto constructLineRuns = [&] {
-        auto lineIndex = formattingState.lines().size();
+    auto constructLineRunsAndUpdateBoxGeometry = [&] {
         // Create the inline runs on the current line. This is mostly text and atomic inline runs.
         formattingState.lineRuns().reserveCapacity(lineContent.runs.size());
         for (auto& lineRun : lineContent.runs) {
             // FIXME: We should not need to construct a line run for <br>.
             auto& layoutBox = lineRun.layoutBox();
-            if (lineRun.isText() || lineRun.isLineBreak())
-                formattingState.addLineRun({ lineIndex, lineRun.layoutBox(), lineBox.logicalRectForTextRun(lineRun), lineRun.expansion(), lineRun.textContent() });
-            else if (lineRun.isBox() || lineRun.isInlineBoxStart()) {
+            if (lineRun.isText()) {
+                formattingState.addLineRun({ lineIndex, layoutBox, lineBox.logicalRectForTextRun(lineRun), lineRun.expansion(), lineRun.textContent() });
+                continue;
+            }
+            if (lineRun.isLineBreak()) {
+                auto lineBreakBoxRect = lineBox.logicalRectForTextRun(lineRun);
+                formattingState.addLineRun({ lineIndex, layoutBox, lineBreakBoxRect, lineRun.expansion(), lineRun.textContent() });
+
+                if (layoutBox.isLineBreakBox()) {
+                    // Only hard linebreaks have associated layout boxes.
+                    auto& boxGeometry = formattingState.boxGeometry(layoutBox);
+                    lineBreakBoxRect.moveBy(lineBoxLogicalRect.topLeft());
+                    boxGeometry.setLogicalTopLeft(toLayoutPoint(lineBreakBoxRect.topLeft()));
+                    boxGeometry.setContentBoxHeight(toLayoutUnit(lineBreakBoxRect.height()));
+                }
+                continue;
+            }
+            if (lineRun.isBox()) {
+                ASSERT(layoutBox.isAtomicInlineLevelBox());
                 auto& boxGeometry = formattingState.boxGeometry(layoutBox);
-                formattingState.addLineRun({ lineIndex, lineRun.layoutBox(), lineBox.logicalMarginRectForInlineLevelBox(lineRun.layoutBox(), boxGeometry), lineRun.expansion(), { } });
-                if (lineRun.isInlineBoxStart())
-                    inlineBoxStartSet.add(&layoutBox);
-            } else if (lineRun.isInlineBoxEnd())
+                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());
+                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));
+                continue;
+            }
+            if (lineRun.isInlineBoxStart()) {
+                auto& boxGeometry = formattingState.boxGeometry(layoutBox);
+                formattingState.addLineRun({ lineIndex, layoutBox, lineBox.logicalMarginRectForInlineLevelBox(layoutBox, boxGeometry), lineRun.expansion(), { } });
+                inlineBoxStartSet.add(&layoutBox);
+                continue;
+            }
+            if (lineRun.isInlineBoxEnd()) {
                 inlineBoxEndSet.add(&layoutBox);
-            else
-                ASSERT(lineRun.isWordBreakOpportunity());
+                continue;
+            }
+            ASSERT(lineRun.isWordBreakOpportunity());
         }
     };
-    constructLineRuns();
+    constructLineRunsAndUpdateBoxGeometry();
 
-    auto updateBoxGeometry = [&] {
+    auto updateBoxGeometryForInlineBoxes = [&] {
+        // FIXME: We may want to keep around an inline box only set.
+        if (!lineBox.hasInlineBox())
+            return;
         // Grab the inline boxes (even those that don't have associated layout boxes on the current line due to line wrapping)
         // and update their geometries.
         for (auto& inlineLevelBox : lineBox.inlineLevelBoxList()) {
+            if (!inlineLevelBox->isInlineBox())
+                continue;
             auto& layoutBox = inlineLevelBox->layoutBox();
             if (&layoutBox == &root()) {
                 // Ignore root inline box.
@@ -472,27 +508,7 @@
                 continue;
             }
             auto& boxGeometry = formattingState.boxGeometry(layoutBox);
-            if (layoutBox.isAtomicInlineLevelBox()) {
-                auto logicalMarginRect = lineBox.logicalMarginRectForInlineLevelBox(layoutBox, boxGeometry);
-                auto borderBoxLogicalTopLeft = lineBoxLogicalRect.topLeft();
-                borderBoxLogicalTopLeft.move(logicalMarginRect.left() + boxGeometry.marginStart(), logicalMarginRect.top() + boxGeometry.marginBefore());
-
-                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));
-                continue;
-            }
-            if (layoutBox.isLineBreakBox()) {
-                auto lineBreakBoxRect = lineBox.logicalMarginRectForInlineLevelBox(layoutBox, boxGeometry);
-                lineBreakBoxRect.moveBy(lineBoxLogicalRect.topLeft());
-                boxGeometry.setLogicalTopLeft(toLayoutPoint(lineBreakBoxRect.topLeft()));
-                boxGeometry.setContentBoxHeight(toLayoutUnit(lineBreakBoxRect.height()));
-                continue;
-            }
-            ASSERT(layoutBox.isInlineBox());
             // Inline boxes may or may not be wrapped and have runs on multiple lines (e.g. <span>first line<br>second line<br>third line</span>)
-            // Inline box coordinates are relative to the line box. Let's convert top/left relative to the formatting context root.
             auto inlineBoxMarginRect = lineBox.logicalMarginRectForInlineLevelBox(layoutBox, boxGeometry);
             auto logicalRect = Rect { LayoutPoint { inlineBoxMarginRect.topLeft() }, LayoutSize { inlineBoxMarginRect.size() } };
             logicalRect.moveBy(LayoutPoint { lineBoxLogicalRect.topLeft() });
@@ -521,7 +537,7 @@
             boxGeometry.setContentBoxWidth(enclosingRect.width());
         }
     };
-    updateBoxGeometry();
+    updateBoxGeometryForInlineBoxes();
 
     auto constructLineGeometry = [&] {
         formattingState.addLine({ lineBoxLogicalRect, lineBox.alignmentBaseline(), lineBox.horizontalAlignmentOffset().valueOr(InlineLayoutUnit { }), lineContent.contentLogicalWidth });

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.cpp (271013 => 271014)


--- trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.cpp	2020-12-20 16:29:14 UTC (rev 271013)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.cpp	2020-12-20 18:56:15 UTC (rev 271014)
@@ -92,6 +92,7 @@
 
 void LineBox::addInlineLevelBox(std::unique_ptr<InlineLevelBox>&& inlineLevelBox)
 {
+    m_hasInlineBox = m_hasInlineBox || inlineLevelBox->isInlineBox();
     m_inlineLevelBoxRectMap.set(&inlineLevelBox->layoutBox(), inlineLevelBox.get());
     m_nonRootInlineLevelBoxList.append(WTFMove(inlineLevelBox));
 }

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.h (271013 => 271014)


--- trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.h	2020-12-20 16:29:14 UTC (rev 271013)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.h	2020-12-20 18:56:15 UTC (rev 271014)
@@ -139,6 +139,7 @@
 
     Optional<InlineLayoutUnit> horizontalAlignmentOffset() const { return m_horizontalAlignmentOffset; }
     bool isConsideredEmpty() const { return m_isConsideredEmpty; }
+    bool hasInlineBox() const { return m_hasInlineBox; }
 
     const InlineLevelBox& inlineLevelBoxForLayoutBox(const Box& layoutBox) const { return *m_inlineLevelBoxRectMap.get(&layoutBox); }
 
@@ -171,6 +172,7 @@
     InlineRect m_logicalRect;
     Optional<InlineLayoutUnit> m_horizontalAlignmentOffset;
     bool m_isConsideredEmpty { true };
+    bool m_hasInlineBox { false };
 
     std::unique_ptr<InlineLevelBox> m_rootInlineBox;
     InlineLevelBoxList m_nonRootInlineLevelBoxList;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to