Title: [273722] trunk/Source/WebCore
Revision
273722
Author
za...@apple.com
Date
2021-03-01 20:21:47 -0800 (Mon, 01 Mar 2021)

Log Message

[LFC][IFC] Move simplified vertical alignment computation to struct SimplifiedVerticalAlignment
https://bugs.webkit.org/show_bug.cgi?id=222562

Reviewed by Antti Koivisto.

This is in preparation for supporting non-atomic inline level boxes (by just calling simplifiedVerticalAlignment.adjust(inlineLevelBox)).

* layout/inlineformatting/InlineFormattingContextGeometry.cpp:
(WebCore::Layout::SimplifiedVerticalAlignment::SimplifiedVerticalAlignment):
(WebCore::Layout::SimplifiedVerticalAlignment::rootInlineBoxLogicalTop const):
(WebCore::Layout::SimplifiedVerticalAlignment::lineBoxHeight const):
(WebCore::Layout::SimplifiedVerticalAlignment::adjust):
(WebCore::Layout::LineBoxBuilder::constructInlineLevelBoxes):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (273721 => 273722)


--- trunk/Source/WebCore/ChangeLog	2021-03-02 04:17:16 UTC (rev 273721)
+++ trunk/Source/WebCore/ChangeLog	2021-03-02 04:21:47 UTC (rev 273722)
@@ -1,3 +1,19 @@
+2021-03-01  Zalan Bujtas  <za...@apple.com>
+
+        [LFC][IFC] Move simplified vertical alignment computation to struct SimplifiedVerticalAlignment
+        https://bugs.webkit.org/show_bug.cgi?id=222562
+
+        Reviewed by Antti Koivisto.
+
+        This is in preparation for supporting non-atomic inline level boxes (by just calling simplifiedVerticalAlignment.adjust(inlineLevelBox)).
+
+        * layout/inlineformatting/InlineFormattingContextGeometry.cpp:
+        (WebCore::Layout::SimplifiedVerticalAlignment::SimplifiedVerticalAlignment):
+        (WebCore::Layout::SimplifiedVerticalAlignment::rootInlineBoxLogicalTop const):
+        (WebCore::Layout::SimplifiedVerticalAlignment::lineBoxHeight const):
+        (WebCore::Layout::SimplifiedVerticalAlignment::adjust):
+        (WebCore::Layout::LineBoxBuilder::constructInlineLevelBoxes):
+
 2021-03-01  Alex Christensen  <achristen...@webkit.org>
 
         Make DictionaryLookup::rangeAtHitTestResult more robust

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextGeometry.cpp (273721 => 273722)


--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextGeometry.cpp	2021-03-02 04:17:16 UTC (rev 273721)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextGeometry.cpp	2021-03-02 04:21:47 UTC (rev 273722)
@@ -201,18 +201,36 @@
     inlineLevelBox.setLayoutBounds(LineBox::InlineLevelBox::LayoutBounds { floorf(ascent), ceil(descent) });
 }
 
+struct SimplifiedVerticalAlignment {
+    SimplifiedVerticalAlignment(const LineBox::InlineLevelBox& rootInlineBox)
+        : m_rootInlineBox(rootInlineBox)
+    {
+        adjust(rootInlineBox);
+    }
+
+    InlineLayoutUnit rootInlineBoxLogicalTop() const { return m_rootInlineBoxLogicalTop; }
+    InlineLayoutUnit lineBoxHeight() const { return m_lineBoxLogicalBottom - m_lineBoxLogicalTop; }
+
+    void adjust(const LineBox::InlineLevelBox& inlineLevelBox)
+    {
+        auto layoutBoundsLogicalTop = m_rootInlineBox.layoutBounds().ascent - inlineLevelBox.layoutBounds().ascent;
+        m_lineBoxLogicalTop = std::min(m_lineBoxLogicalTop, layoutBoundsLogicalTop);
+        m_lineBoxLogicalBottom = std::max(m_lineBoxLogicalBottom, layoutBoundsLogicalTop + inlineLevelBox.layoutBounds().height());
+        m_rootInlineBoxLogicalTop = std::max(m_rootInlineBoxLogicalTop, inlineLevelBox.layoutBounds().ascent - m_rootInlineBox.baseline());
+    }
+
+private:
+    const LineBox::InlineLevelBox& m_rootInlineBox;
+
+    InlineLayoutUnit m_lineBoxLogicalTop { 0 };
+    InlineLayoutUnit m_lineBoxLogicalBottom { 0 };
+    InlineLayoutUnit m_rootInlineBoxLogicalTop { 0 };
+};
 void LineBoxBuilder::constructInlineLevelBoxes(LineBox& lineBox, const Line::RunList& runs)
 {
-    struct SimplifiedVerticalAlignment {
-        InlineLayoutUnit lineBoxTop { 0 };
-        InlineLayoutUnit lineBoxBottom { 0 };
-        InlineLayoutUnit rootInlineBoxTop { 0 };
-
-        InlineLayoutUnit lineBoxHeight() const { return lineBoxBottom - lineBoxTop; }
-    };
     auto& rootInlineBox = lineBox.rootInlineBox();
     setVerticalGeometryForInlineBox(rootInlineBox);
-    auto simplifiedVerticalAlignment = SimplifiedVerticalAlignment { { } , rootInlineBox.layoutBounds().height(), rootInlineBox.layoutBounds().ascent - rootInlineBox.baseline() };
+    auto simplifiedVerticalAlignment = SimplifiedVerticalAlignment { rootInlineBox };
 
     auto createWrappedInlineBoxes = [&] {
         if (runs.isEmpty())
@@ -315,11 +333,8 @@
                 }
                 // Only baseline alignment for now.
                 auto logicalTop = rootInlineBox.baseline() - ascent;
-                auto layoutBoundsTop = rootInlineBox.layoutBounds().ascent - ascent;
-                simplifiedVerticalAlignment.lineBoxTop = std::min(simplifiedVerticalAlignment.lineBoxTop, layoutBoundsTop);
-                simplifiedVerticalAlignment.lineBoxBottom = std::max(simplifiedVerticalAlignment.lineBoxBottom, layoutBoundsTop + marginBoxHeight);
-                simplifiedVerticalAlignment.rootInlineBoxTop = std::max(simplifiedVerticalAlignment.rootInlineBoxTop, ascent - rootInlineBox.baseline());
                 atomicInlineLevelBox->setLogicalTop(logicalTop);
+                simplifiedVerticalAlignment.adjust(*atomicInlineLevelBox);
             };
             alignInlineBoxIfEligible();
             lineBox.addInlineLevelBox(WTFMove(atomicInlineLevelBox));
@@ -375,7 +390,7 @@
     // We should always be able to exercise the fast path when the line has no content at all, even in non-standards mode or with line-height set.
     m_useSimplifiedVerticalAlignment = m_useSimplifiedVerticalAlignment || !lineHasContent;
     if (m_useSimplifiedVerticalAlignment) {
-        rootInlineBox.setLogicalTop(lineHasContent ? simplifiedVerticalAlignment.rootInlineBoxTop : -rootInlineBox.baseline());
+        rootInlineBox.setLogicalTop(lineHasContent ? simplifiedVerticalAlignment.rootInlineBoxLogicalTop() : -rootInlineBox.baseline());
         lineBox.setLogicalHeight(lineHasContent ? simplifiedVerticalAlignment.lineBoxHeight() : InlineLayoutUnit());
     }
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to