Title: [271084] trunk/Source/WebCore
Revision
271084
Author
[email protected]
Date
2020-12-25 09:53:55 -0800 (Fri, 25 Dec 2020)

Log Message

[LFC][IFC] Fast vertical alignment should work with line-height
https://bugs.webkit.org/show_bug.cgi?id=220131

Reviewed by Antti Koivisto.

Adjust the line box height and the root inline box's logical top position as the layout bounds of the inline-block content stretches the line.

* layout/inlineformatting/InlineFormattingContextGeometry.cpp:
(WebCore::Layout::LineBoxBuilder::LineBoxBuilder):
(WebCore::Layout::LineBoxBuilder::constructInlineLevelBoxes):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (271083 => 271084)


--- trunk/Source/WebCore/ChangeLog	2020-12-25 10:35:21 UTC (rev 271083)
+++ trunk/Source/WebCore/ChangeLog	2020-12-25 17:53:55 UTC (rev 271084)
@@ -1,3 +1,16 @@
+2020-12-25  Zalan Bujtas  <[email protected]>
+
+        [LFC][IFC] Fast vertical alignment should work with line-height
+        https://bugs.webkit.org/show_bug.cgi?id=220131
+
+        Reviewed by Antti Koivisto.
+
+        Adjust the line box height and the root inline box's logical top position as the layout bounds of the inline-block content stretches the line.
+
+        * layout/inlineformatting/InlineFormattingContextGeometry.cpp:
+        (WebCore::Layout::LineBoxBuilder::LineBoxBuilder):
+        (WebCore::Layout::LineBoxBuilder::constructInlineLevelBoxes):
+
 2020-12-23  Simon Fraser  <[email protected]>
 
         Clean up some code related to scroll pinning

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextGeometry.cpp (271083 => 271084)


--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextGeometry.cpp	2020-12-25 10:35:21 UTC (rev 271083)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextGeometry.cpp	2020-12-25 17:53:55 UTC (rev 271084)
@@ -149,8 +149,7 @@
 
 LineBoxBuilder::LineBoxBuilder(const InlineFormattingContext& inlineFormattingContext)
     : m_inlineFormattingContext(inlineFormattingContext)
-    // FIXME: line-height should not require complex alignment in simple cases.
-    , m_inlineLevelBoxesNeedVerticalAlignment(!rootBox().style().lineHeight().isNegative() || !inlineFormattingContext.layoutState().inNoQuirksMode())
+    , m_inlineLevelBoxesNeedVerticalAlignment(!inlineFormattingContext.layoutState().inNoQuirksMode())
 {
 }
 
@@ -207,6 +206,12 @@
 void LineBoxBuilder::constructInlineLevelBoxes(LineBox& lineBox, const Line::RunList& runs)
 {
     auto horizontalAligmentOffset = lineBox.horizontalAlignmentOffset().valueOr(InlineLayoutUnit { });
+    struct SimplifiedVerticalAlignment {
+        InlineLayoutUnit inlineLevelBoxTop { 0 };
+        InlineLayoutUnit inlineLevelBoxBottom { 0 };
+        InlineLayoutUnit rootInlineBoxLogicalTop { 0 };
+    };
+    auto simplifiedVerticalAlignment = SimplifiedVerticalAlignment { };
     // Empty root inline boxes require special collapsing.
     m_inlineLevelBoxesNeedVerticalAlignment = m_inlineLevelBoxesNeedVerticalAlignment || runs.isEmpty();
 
@@ -218,7 +223,7 @@
         if (isInitiallyConsideredNonEmpty)
             rootInlineBox->setIsNonEmpty();
         setVerticalGeometryForInlineBox(*rootInlineBox);
-        m_inlineLevelBoxesNeedVerticalAlignment = m_inlineLevelBoxesNeedVerticalAlignment || rootInlineBox->baseline() != rootInlineBox->layoutBounds().ascent;
+        simplifiedVerticalAlignment = { { } , rootInlineBox->layoutBounds().height(), rootInlineBox->layoutBounds().ascent - rootInlineBox->baseline() };
         lineBox.addRootInlineBox(WTFMove(rootInlineBox));
     };
     createRootInlineBox();
@@ -296,7 +301,13 @@
                     m_inlineLevelBoxesNeedVerticalAlignment = true;
                     return;
                 }
-                atomicInlineLevelBox->setLogicalTop(rootInlineBox.baseline() - ascent);
+                // Only baseline alignment for now.
+                auto logicalTop = rootInlineBox.baseline() - ascent;
+                auto layoutBoundsTop = rootInlineBox.layoutBounds().ascent - ascent;
+                simplifiedVerticalAlignment.inlineLevelBoxTop = std::min(simplifiedVerticalAlignment.inlineLevelBoxTop, layoutBoundsTop);
+                simplifiedVerticalAlignment.inlineLevelBoxBottom = std::max(simplifiedVerticalAlignment.inlineLevelBoxBottom, layoutBoundsTop + marginBoxHeight);
+                simplifiedVerticalAlignment.rootInlineBoxLogicalTop = std::max(simplifiedVerticalAlignment.rootInlineBoxLogicalTop, ascent - rootInlineBox.baseline());
+                atomicInlineLevelBox->setLogicalTop(logicalTop);
             };
             alignInlineBoxIfEligible();
             lineBox.addInlineLevelBox(WTFMove(atomicInlineLevelBox));
@@ -338,8 +349,8 @@
         ASSERT_NOT_REACHED();
     }
     if (!m_inlineLevelBoxesNeedVerticalAlignment) {
-        rootInlineBox.setLogicalTop({ });
-        lineBox.setLogicalHeight(rootInlineBox.layoutBounds().height());
+        rootInlineBox.setLogicalTop(simplifiedVerticalAlignment.rootInlineBoxLogicalTop);
+        lineBox.setLogicalHeight(simplifiedVerticalAlignment.inlineLevelBoxBottom - simplifiedVerticalAlignment.inlineLevelBoxTop);
     }
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to