Title: [283042] trunk/Source/WebCore
Revision
283042
Author
[email protected]
Date
2021-09-24 07:39:02 -0700 (Fri, 24 Sep 2021)

Log Message

[LFC][IFC] InlineLevelBox only needs a handful of style properties
https://bugs.webkit.org/show_bug.cgi?id=230724

Reviewed by Antti Koivisto.

This is in preparation for supporting first-line style where the incoming RenderStyle& depends on whether the inline level box is on the first line or not.

* layout/formattingContexts/inline/InlineLevelBox.h:
(WebCore::Layout::InlineLevelBox::InlineLevelBox):
(WebCore::Layout::m_style):
(WebCore::Layout::InlineLevelBox::isPreferredLineHeightFontMetricsBased const):
(WebCore::Layout::InlineLevelBox::primaryFontMetrics const):
(WebCore::Layout::InlineLevelBox::fontSize const):
(WebCore::Layout::InlineLevelBox::createAtomicInlineLevelBox):
(WebCore::Layout::InlineLevelBox::createInlineBox):
(WebCore::Layout::InlineLevelBox::createLineBreakBox):
(WebCore::Layout::InlineLevelBox::createGenericInlineLevelBox):
(WebCore::Layout::m_type): Deleted.
* layout/formattingContexts/inline/InlineLineBox.cpp:
(WebCore::Layout::LineBox::LineBox):
* layout/formattingContexts/inline/InlineLineBoxBuilder.cpp:
(WebCore::Layout::LineBoxBuilder::constructAndAlignInlineLevelBoxes):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (283041 => 283042)


--- trunk/Source/WebCore/ChangeLog	2021-09-24 14:06:44 UTC (rev 283041)
+++ trunk/Source/WebCore/ChangeLog	2021-09-24 14:39:02 UTC (rev 283042)
@@ -1,5 +1,30 @@
 2021-09-24  Alan Bujtas  <[email protected]>
 
+        [LFC][IFC] InlineLevelBox only needs a handful of style properties
+        https://bugs.webkit.org/show_bug.cgi?id=230724
+
+        Reviewed by Antti Koivisto.
+
+        This is in preparation for supporting first-line style where the incoming RenderStyle& depends on whether the inline level box is on the first line or not.
+
+        * layout/formattingContexts/inline/InlineLevelBox.h:
+        (WebCore::Layout::InlineLevelBox::InlineLevelBox):
+        (WebCore::Layout::m_style):
+        (WebCore::Layout::InlineLevelBox::isPreferredLineHeightFontMetricsBased const):
+        (WebCore::Layout::InlineLevelBox::primaryFontMetrics const):
+        (WebCore::Layout::InlineLevelBox::fontSize const):
+        (WebCore::Layout::InlineLevelBox::createAtomicInlineLevelBox):
+        (WebCore::Layout::InlineLevelBox::createInlineBox):
+        (WebCore::Layout::InlineLevelBox::createLineBreakBox):
+        (WebCore::Layout::InlineLevelBox::createGenericInlineLevelBox):
+        (WebCore::Layout::m_type): Deleted.
+        * layout/formattingContexts/inline/InlineLineBox.cpp:
+        (WebCore::Layout::LineBox::LineBox):
+        * layout/formattingContexts/inline/InlineLineBoxBuilder.cpp:
+        (WebCore::Layout::LineBoxBuilder::constructAndAlignInlineLevelBoxes):
+
+2021-09-24  Alan Bujtas  <[email protected]>
+
         [IFC][LFC] InlineLevelBox needs to retain only a small set of style properties
         https://bugs.webkit.org/show_bug.cgi?id=230718
 

Modified: trunk/Source/WebCore/layout/formattingContexts/inline/InlineLevelBox.h (283041 => 283042)


--- trunk/Source/WebCore/layout/formattingContexts/inline/InlineLevelBox.h	2021-09-24 14:06:44 UTC (rev 283041)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/InlineLevelBox.h	2021-09-24 14:39:02 UTC (rev 283042)
@@ -43,10 +43,10 @@
 class InlineLevelBox {
 public:
     enum class LineSpanningInlineBox { Yes, No };
-    static InlineLevelBox createInlineBox(const Box&, InlineLayoutUnit logicalLeft, InlineLayoutUnit logicalWidth, LineSpanningInlineBox = LineSpanningInlineBox::No);
-    static InlineLevelBox createAtomicInlineLevelBox(const Box&, InlineLayoutUnit logicalLeft, InlineLayoutSize);
-    static InlineLevelBox createLineBreakBox(const Box&, InlineLayoutUnit logicalLeft);
-    static InlineLevelBox createGenericInlineLevelBox(const Box&, InlineLayoutUnit logicalLeft);
+    static InlineLevelBox createInlineBox(const Box&, const RenderStyle&, InlineLayoutUnit logicalLeft, InlineLayoutUnit logicalWidth, LineSpanningInlineBox = LineSpanningInlineBox::No);
+    static InlineLevelBox createAtomicInlineLevelBox(const Box&, const RenderStyle&, InlineLayoutUnit logicalLeft, InlineLayoutSize);
+    static InlineLevelBox createLineBreakBox(const Box&, const RenderStyle&, InlineLayoutUnit logicalLeft);
+    static InlineLevelBox createGenericInlineLevelBox(const Box&, const RenderStyle&, InlineLayoutUnit logicalLeft);
 
     InlineLayoutUnit baseline() const { return m_baseline; }
     std::optional<InlineLayoutUnit> descent() const { return m_descent; }
@@ -69,9 +69,9 @@
     };
     VerticalAlignment verticalAlign() const;
     InlineLayoutUnit preferredLineHeight() const;
-    bool isPreferredLineHeightFontMetricsBased() const { return layoutBox().style().lineHeight().isNegative(); }
-    const FontMetrics& primaryFontMetrics() const { return layoutBox().style().fontCascade().primaryFont().fontMetrics(); }
-    InlineLayoutUnit fontSize() const { return layoutBox().style().fontCascade().fontDescription().computedPixelSize(); }
+    bool isPreferredLineHeightFontMetricsBased() const;
+    const FontMetrics& primaryFontMetrics() const;
+    InlineLayoutUnit fontSize() const;
 
     bool isInlineBox() const { return m_type == Type::InlineBox || isRootInlineBox() || isLineSpanningInlineBox(); }
     bool isRootInlineBox() const { return m_type == Type::RootInlineBox; }
@@ -92,8 +92,7 @@
 
     const Box& layoutBox() const { return *m_layoutBox; }
 
-    InlineLevelBox(const Box&, InlineLayoutUnit logicalLeft, InlineLayoutSize, Type);
-    InlineLevelBox() = default;
+    InlineLevelBox(const Box&, const RenderStyle&, InlineLayoutUnit logicalLeft, InlineLayoutSize, Type);
 
 private:
     friend class LineBox;
@@ -124,13 +123,26 @@
     std::optional<InlineLayoutUnit> m_descent;
     bool m_hasContent { false };
     Type m_type { Type::InlineBox };
+
+    struct Style {
+        const FontMetrics& primaryFontMetrics;
+        const Length& lineHeight;
+        InlineLayoutUnit primaryFontSize { 0 };
+        VerticalAlignment verticalAlignment { };
+    };
+    Style m_style;
 };
 
-inline InlineLevelBox::InlineLevelBox(const Box& layoutBox, InlineLayoutUnit logicalLeft, InlineLayoutSize logicalSize, Type type)
+inline InlineLevelBox::InlineLevelBox(const Box& layoutBox, const RenderStyle& style, InlineLayoutUnit logicalLeft, InlineLayoutSize logicalSize, Type type)
     : m_layoutBox(makeWeakPtr(layoutBox))
     , m_logicalRect({ }, logicalLeft, logicalSize.width(), logicalSize.height())
     , m_type(type)
+    , m_style({ style.fontCascade().primaryFont().fontMetrics(), style.lineHeight(), InlineLayoutUnit(style.fontCascade().fontDescription().computedPixelSize()), { } })
 {
+    m_style.verticalAlignment.type = style.verticalAlign();
+    if (m_style.verticalAlignment.type == VerticalAlign::Length)
+        m_style.verticalAlignment.baselineOffset = floatValueForLength(style.verticalAlignLength(), preferredLineHeight());
+
 }
 
 inline void InlineLevelBox::setHasContent()
@@ -145,48 +157,58 @@
     if (isPreferredLineHeightFontMetricsBased())
         return primaryFontMetrics().lineSpacing();
 
-    auto& lineHeight = layoutBox().style().lineHeight();
-    if (lineHeight.isPercentOrCalculated())
-        return floorf(minimumValueForLength(lineHeight, fontSize()));
-    return floorf(lineHeight.value());
+    if (m_style.lineHeight.isPercentOrCalculated())
+        return floorf(minimumValueForLength(m_style.lineHeight, fontSize()));
+    return floorf(m_style.lineHeight.value());
 }
 
 inline InlineLevelBox::VerticalAlignment InlineLevelBox::verticalAlign() const
 {
-    auto& style = layoutBox().style();
-    auto verticalAlign = style.verticalAlign();
-    if (verticalAlign != VerticalAlign::Length)
-        return { verticalAlign, { } };
-    return { verticalAlign, floatValueForLength(style.verticalAlignLength(), preferredLineHeight()) };
+    return m_style.verticalAlignment;
 }
 
 inline bool InlineLevelBox::hasLineBoxRelativeAlignment() const
 {
-    auto verticalAlignment = layoutBox().style().verticalAlign();
+    auto verticalAlignment = verticalAlign().type;
     return verticalAlignment == VerticalAlign::Top || verticalAlignment == VerticalAlign::Bottom;
 }
 
-inline InlineLevelBox InlineLevelBox::createAtomicInlineLevelBox(const Box& layoutBox, InlineLayoutUnit logicalLeft, InlineLayoutSize logicalSize)
+inline bool InlineLevelBox::isPreferredLineHeightFontMetricsBased() const
 {
-    return InlineLevelBox { layoutBox, logicalLeft, logicalSize, Type::AtomicInlineLevelBox };
+    return m_style.lineHeight.isNegative();
 }
 
-inline InlineLevelBox InlineLevelBox::createInlineBox(const Box& layoutBox, InlineLayoutUnit logicalLeft, InlineLayoutUnit logicalWidth, LineSpanningInlineBox isLineSpanning)
+inline const FontMetrics& InlineLevelBox::primaryFontMetrics() const
 {
-    return InlineLevelBox { layoutBox, logicalLeft, InlineLayoutSize { logicalWidth, { } }, isLineSpanning == LineSpanningInlineBox::Yes ? Type::LineSpanningInlineBox : Type::InlineBox };
+    return m_style.primaryFontMetrics;
 }
 
-inline InlineLevelBox InlineLevelBox::createLineBreakBox(const Box& layoutBox, InlineLayoutUnit logicalLeft)
+inline InlineLayoutUnit InlineLevelBox::fontSize() const
 {
-    return InlineLevelBox { layoutBox, logicalLeft, InlineLayoutSize { }, Type::LineBreakBox };
+    return m_style.primaryFontSize;
 }
 
-inline InlineLevelBox InlineLevelBox::createGenericInlineLevelBox(const Box& layoutBox, InlineLayoutUnit logicalLeft)
+inline InlineLevelBox InlineLevelBox::createAtomicInlineLevelBox(const Box& layoutBox, const RenderStyle& style, InlineLayoutUnit logicalLeft, InlineLayoutSize logicalSize)
 {
-    return InlineLevelBox { layoutBox, logicalLeft, InlineLayoutSize { }, Type::GenericInlineLevelBox };
+    return InlineLevelBox { layoutBox, style, logicalLeft, logicalSize, Type::AtomicInlineLevelBox };
 }
 
+inline InlineLevelBox InlineLevelBox::createInlineBox(const Box& layoutBox, const RenderStyle& style, InlineLayoutUnit logicalLeft, InlineLayoutUnit logicalWidth, LineSpanningInlineBox isLineSpanning)
+{
+    return InlineLevelBox { layoutBox, style, logicalLeft, InlineLayoutSize { logicalWidth, { } }, isLineSpanning == LineSpanningInlineBox::Yes ? Type::LineSpanningInlineBox : Type::InlineBox };
 }
+
+inline InlineLevelBox InlineLevelBox::createLineBreakBox(const Box& layoutBox, const RenderStyle& style, InlineLayoutUnit logicalLeft)
+{
+    return InlineLevelBox { layoutBox, style, logicalLeft, InlineLayoutSize { }, Type::LineBreakBox };
 }
 
+inline InlineLevelBox InlineLevelBox::createGenericInlineLevelBox(const Box& layoutBox, const RenderStyle& style, InlineLayoutUnit logicalLeft)
+{
+    return InlineLevelBox { layoutBox, style, logicalLeft, InlineLayoutSize { }, Type::GenericInlineLevelBox };
+}
+
+}
+}
+
 #endif

Modified: trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBox.cpp (283041 => 283042)


--- trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBox.cpp	2021-09-24 14:06:44 UTC (rev 283041)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBox.cpp	2021-09-24 14:39:02 UTC (rev 283042)
@@ -35,7 +35,7 @@
 namespace Layout {
 
 LineBox::LineBox(const Box& rootLayoutBox, InlineLayoutUnit contentLogicalLeft, InlineLayoutUnit contentLogicalWidth, size_t nonSpanningInlineLevelBoxCount)
-    : m_rootInlineBox(rootLayoutBox, contentLogicalLeft, InlineLayoutSize { contentLogicalWidth, { } }, InlineLevelBox::Type::RootInlineBox)
+    : m_rootInlineBox(rootLayoutBox, rootLayoutBox.style(), contentLogicalLeft, InlineLayoutSize { contentLogicalWidth, { } }, InlineLevelBox::Type::RootInlineBox)
 {
     m_nonRootInlineLevelBoxList.reserveInitialCapacity(nonSpanningInlineLevelBoxCount);
     m_nonRootInlineLevelBoxMap.reserveInitialCapacity(nonSpanningInlineLevelBoxCount);

Modified: trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBoxBuilder.cpp (283041 => 283042)


--- trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBoxBuilder.cpp	2021-09-24 14:06:44 UTC (rev 283041)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBoxBuilder.cpp	2021-09-24 14:39:02 UTC (rev 283042)
@@ -265,7 +265,7 @@
         }
         // Construct the missing LineBox::InlineBoxes starting with the topmost layout box.
         for (auto* layoutBox : WTF::makeReversedRange(layoutBoxesWithoutInlineBoxes)) {
-            auto inlineBox = InlineLevelBox::createInlineBox(*layoutBox, rootInlineBox.logicalLeft(), rootInlineBox.logicalWidth(), InlineLevelBox::LineSpanningInlineBox::Yes);
+            auto inlineBox = InlineLevelBox::createInlineBox(*layoutBox, layoutBox->style(), rootInlineBox.logicalLeft(), rootInlineBox.logicalWidth(), InlineLevelBox::LineSpanningInlineBox::Yes);
             setInitialVerticalGeometryForInlineBox(inlineBox);
             updateCanUseSimplifiedAlignment(inlineBox);
             lineBox.addInlineLevelBox(WTFMove(inlineBox));
@@ -276,6 +276,8 @@
     auto lineHasContent = false;
     for (auto& run : runs) {
         auto& layoutBox = run.layoutBox();
+        // FIXME: Make this line index dependent to support first-line style.
+        auto& style = layoutBox.style();
         auto runHasContent = [&] () -> bool {
             ASSERT(!lineHasContent);
             if (run.isText() || run.isBox() || run.isSoftLineBreak() || run.isHardLineBreak())
@@ -304,7 +306,7 @@
             } else if (layoutBox.isInlineBlockBox()) {
                 // The baseline of an 'inline-block' is the baseline of its last line box in the normal flow, unless it has either no in-flow line boxes or
                 // if its 'overflow' property has a computed value other than 'visible', in which case the baseline is the bottom margin edge.
-                auto synthesizeBaseline = !layoutBox.establishesInlineFormattingContext() || !layoutBox.style().isOverflowVisible();
+                auto synthesizeBaseline = !layoutBox.establishesInlineFormattingContext() || !style.isOverflowVisible();
                 if (synthesizeBaseline)
                     ascent = marginBoxHeight;
                 else {
@@ -318,7 +320,7 @@
             else
                 ascent = marginBoxHeight;
             logicalLeft += std::max(0_lu, inlineLevelBoxGeometry.marginStart());
-            auto atomicInlineLevelBox = InlineLevelBox::createAtomicInlineLevelBox(layoutBox, logicalLeft, { inlineLevelBoxGeometry.borderBoxWidth(), marginBoxHeight });
+            auto atomicInlineLevelBox = InlineLevelBox::createAtomicInlineLevelBox(layoutBox, style, logicalLeft, { inlineLevelBoxGeometry.borderBoxWidth(), marginBoxHeight });
             atomicInlineLevelBox.setBaseline(ascent);
             atomicInlineLevelBox.setLayoutBounds(InlineLevelBox::LayoutBounds { ascent, marginBoxHeight - ascent });
             updateCanUseSimplifiedAlignment(atomicInlineLevelBox, inlineLevelBoxGeometry);
@@ -332,7 +334,7 @@
             auto marginStart = formattingContext().geometryForBox(layoutBox).marginStart();
             auto initialLogicalWidth = rootInlineBox.logicalWidth() - (run.logicalLeft() + marginStart);
             ASSERT(initialLogicalWidth >= 0);
-            auto inlineBox = InlineLevelBox::createInlineBox(layoutBox, logicalLeft + marginStart, initialLogicalWidth);
+            auto inlineBox = InlineLevelBox::createInlineBox(layoutBox, style, logicalLeft + marginStart, initialLogicalWidth);
             setInitialVerticalGeometryForInlineBox(inlineBox);
             updateCanUseSimplifiedAlignment(inlineBox);
             lineBox.addInlineLevelBox(WTFMove(inlineBox));
@@ -370,7 +372,7 @@
             continue;
         }
         if (run.isHardLineBreak()) {
-            auto lineBreakBox = InlineLevelBox::createLineBreakBox(layoutBox, logicalLeft);
+            auto lineBreakBox = InlineLevelBox::createLineBreakBox(layoutBox, style, logicalLeft);
             setInitialVerticalGeometryForInlineBox(lineBreakBox);
             updateCanUseSimplifiedAlignment(lineBreakBox);
             lineBox.addInlineLevelBox(WTFMove(lineBreakBox));
@@ -377,7 +379,7 @@
             continue;
         }
         if (run.isWordBreakOpportunity()) {
-            lineBox.addInlineLevelBox(InlineLevelBox::createGenericInlineLevelBox(layoutBox, logicalLeft));
+            lineBox.addInlineLevelBox(InlineLevelBox::createGenericInlineLevelBox(layoutBox, style, logicalLeft));
             continue;
         }
         ASSERT_NOT_REACHED();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to