Title: [277568] trunk/Source/WebCore
Revision
277568
Author
za...@apple.com
Date
2021-05-16 08:00:51 -0700 (Sun, 16 May 2021)

Log Message

[LFC] Cleanup margin collapsing class
https://bugs.webkit.org/show_bug.cgi?id=225745

Reviewed by Antti Koivisto.

BlockMarginCollapse needs LayoutState and BlockFormattingState only.

* layout/MarginTypes.h:
* layout/formattingContexts/FormattingGeometry.cpp:
(WebCore::Layout::FormattingGeometry::constraintsForInFlowContent const):
(WebCore::Layout::FormattingGeometry::constraintsForInFlowContent): Deleted.
* layout/formattingContexts/FormattingGeometry.h:
* layout/formattingContexts/block/BlockFormattingContext.cpp:
(WebCore::Layout::BlockFormattingContext::precomputeVerticalPositionForBoxAndAncestors):
(WebCore::Layout::BlockFormattingContext::geometry const):
(WebCore::Layout::BlockFormattingContext::marginCollapse const):
* layout/formattingContexts/block/BlockFormattingGeometry.cpp:
(WebCore::Layout::BlockFormattingGeometry::inFlowNonReplacedContentHeightAndMargin):
* layout/formattingContexts/block/BlockFormattingQuirks.cpp:
(WebCore::Layout::BlockFormattingQuirks::stretchedInFlowHeightIfApplicable const):
* layout/formattingContexts/block/BlockFormattingQuirks.h:
* layout/formattingContexts/block/BlockMarginCollapse.cpp:
(WebCore::Layout::BlockMarginCollapse::BlockMarginCollapse):
(WebCore::Layout::BlockMarginCollapse::hasClearance const):
(WebCore::Layout::BlockMarginCollapse::marginBeforeCollapsesWithParentMarginBefore const):
(WebCore::Layout::BlockMarginCollapse::marginAfterCollapsesWithParentMarginAfter const):
(WebCore::Layout::BlockMarginCollapse::marginAfterCollapsesWithLastInFlowChildMarginAfter const):
(WebCore::Layout::BlockMarginCollapse::positiveNegativeValues const):
(WebCore::Layout::BlockMarginCollapse::positiveNegativeMarginBefore const):
* layout/formattingContexts/block/BlockMarginCollapse.h:
(WebCore::Layout::BlockMarginCollapse::inQuirksMode const):
(WebCore::Layout::BlockMarginCollapse::layoutState const):
(WebCore::Layout::BlockMarginCollapse::formattingState const):
(WebCore::Layout::BlockMarginCollapse::layoutState): Deleted.
(WebCore::Layout::BlockMarginCollapse::formattingContext const): Deleted.
* layout/formattingContexts/block/PrecomputedBlockMarginCollapse.cpp:
(WebCore::Layout::BlockMarginCollapse::precomputedPositiveNegativeValues const):
(WebCore::Layout::BlockMarginCollapse::precomputedPositiveNegativeMarginBefore const):
(WebCore::Layout::BlockMarginCollapse::precomputedMarginBefore):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (277567 => 277568)


--- trunk/Source/WebCore/ChangeLog	2021-05-16 13:50:51 UTC (rev 277567)
+++ trunk/Source/WebCore/ChangeLog	2021-05-16 15:00:51 UTC (rev 277568)
@@ -1,5 +1,47 @@
 2021-05-16  Alan Bujtas  <za...@apple.com>
 
+        [LFC] Cleanup margin collapsing class
+        https://bugs.webkit.org/show_bug.cgi?id=225745
+
+        Reviewed by Antti Koivisto.
+
+        BlockMarginCollapse needs LayoutState and BlockFormattingState only.
+
+        * layout/MarginTypes.h:
+        * layout/formattingContexts/FormattingGeometry.cpp:
+        (WebCore::Layout::FormattingGeometry::constraintsForInFlowContent const):
+        (WebCore::Layout::FormattingGeometry::constraintsForInFlowContent): Deleted.
+        * layout/formattingContexts/FormattingGeometry.h:
+        * layout/formattingContexts/block/BlockFormattingContext.cpp:
+        (WebCore::Layout::BlockFormattingContext::precomputeVerticalPositionForBoxAndAncestors):
+        (WebCore::Layout::BlockFormattingContext::geometry const):
+        (WebCore::Layout::BlockFormattingContext::marginCollapse const):
+        * layout/formattingContexts/block/BlockFormattingGeometry.cpp:
+        (WebCore::Layout::BlockFormattingGeometry::inFlowNonReplacedContentHeightAndMargin):
+        * layout/formattingContexts/block/BlockFormattingQuirks.cpp:
+        (WebCore::Layout::BlockFormattingQuirks::stretchedInFlowHeightIfApplicable const):
+        * layout/formattingContexts/block/BlockFormattingQuirks.h:
+        * layout/formattingContexts/block/BlockMarginCollapse.cpp:
+        (WebCore::Layout::BlockMarginCollapse::BlockMarginCollapse):
+        (WebCore::Layout::BlockMarginCollapse::hasClearance const):
+        (WebCore::Layout::BlockMarginCollapse::marginBeforeCollapsesWithParentMarginBefore const):
+        (WebCore::Layout::BlockMarginCollapse::marginAfterCollapsesWithParentMarginAfter const):
+        (WebCore::Layout::BlockMarginCollapse::marginAfterCollapsesWithLastInFlowChildMarginAfter const):
+        (WebCore::Layout::BlockMarginCollapse::positiveNegativeValues const):
+        (WebCore::Layout::BlockMarginCollapse::positiveNegativeMarginBefore const):
+        * layout/formattingContexts/block/BlockMarginCollapse.h:
+        (WebCore::Layout::BlockMarginCollapse::inQuirksMode const):
+        (WebCore::Layout::BlockMarginCollapse::layoutState const):
+        (WebCore::Layout::BlockMarginCollapse::formattingState const):
+        (WebCore::Layout::BlockMarginCollapse::layoutState): Deleted.
+        (WebCore::Layout::BlockMarginCollapse::formattingContext const): Deleted.
+        * layout/formattingContexts/block/PrecomputedBlockMarginCollapse.cpp:
+        (WebCore::Layout::BlockMarginCollapse::precomputedPositiveNegativeValues const):
+        (WebCore::Layout::BlockMarginCollapse::precomputedPositiveNegativeMarginBefore const):
+        (WebCore::Layout::BlockMarginCollapse::precomputedMarginBefore):
+
+2021-05-16  Alan Bujtas  <za...@apple.com>
+
         [LFC] Cleanup FormattingQuirk classes
         https://bugs.webkit.org/show_bug.cgi?id=225746
 

Modified: trunk/Source/WebCore/layout/MarginTypes.h (277567 => 277568)


--- trunk/Source/WebCore/layout/MarginTypes.h	2021-05-16 13:50:51 UTC (rev 277567)
+++ trunk/Source/WebCore/layout/MarginTypes.h	2021-05-16 15:00:51 UTC (rev 277568)
@@ -27,6 +27,7 @@
 
 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)
 
+#include "LayoutUnit.h"
 #include <wtf/Optional.h>
 
 namespace WebCore {

Modified: trunk/Source/WebCore/layout/formattingContexts/FormattingGeometry.cpp (277567 => 277568)


--- trunk/Source/WebCore/layout/formattingContexts/FormattingGeometry.cpp	2021-05-16 13:50:51 UTC (rev 277567)
+++ trunk/Source/WebCore/layout/formattingContexts/FormattingGeometry.cpp	2021-05-16 15:00:51 UTC (rev 277568)
@@ -1159,7 +1159,7 @@
         boxGeometry.contentBoxWidth() };
 }
 
-FormattingContext::ConstraintsForInFlowContent FormattingGeometry::constraintsForInFlowContent(const ContainerBox& containerBox, Optional<FormattingContext::EscapeReason> escapeReason)
+FormattingContext::ConstraintsForInFlowContent FormattingGeometry::constraintsForInFlowContent(const ContainerBox& containerBox, Optional<FormattingContext::EscapeReason> escapeReason) const
 {
     auto& boxGeometry = formattingContext().geometryForBox(containerBox, escapeReason);
     return { { boxGeometry.contentBoxLeft(), boxGeometry.contentBoxWidth() }, { boxGeometry.contentBoxTop(), computedHeight(containerBox) } };

Modified: trunk/Source/WebCore/layout/formattingContexts/FormattingGeometry.h (277567 => 277568)


--- trunk/Source/WebCore/layout/formattingContexts/FormattingGeometry.h	2021-05-16 13:50:51 UTC (rev 277567)
+++ trunk/Source/WebCore/layout/formattingContexts/FormattingGeometry.h	2021-05-16 15:00:51 UTC (rev 277568)
@@ -84,7 +84,7 @@
     LayoutUnit contentHeightForFormattingContextRoot(const ContainerBox&) const;
 
     FormattingContext::ConstraintsForOutOfFlowContent constraintsForOutOfFlowContent(const ContainerBox&);
-    FormattingContext::ConstraintsForInFlowContent constraintsForInFlowContent(const ContainerBox&, Optional<FormattingContext::EscapeReason> = WTF::nullopt);
+    FormattingContext::ConstraintsForInFlowContent constraintsForInFlowContent(const ContainerBox&, Optional<FormattingContext::EscapeReason> = WTF::nullopt) const;
 
     Optional<LayoutUnit> computedHeight(const Box&, Optional<LayoutUnit> containingBlockHeight = WTF::nullopt) const;
     Optional<LayoutUnit> computedWidth(const Box&, LayoutUnit containingBlockWidth);

Modified: trunk/Source/WebCore/layout/formattingContexts/block/BlockFormattingContext.cpp (277567 => 277568)


--- trunk/Source/WebCore/layout/formattingContexts/block/BlockFormattingContext.cpp	2021-05-16 13:50:51 UTC (rev 277567)
+++ trunk/Source/WebCore/layout/formattingContexts/block/BlockFormattingContext.cpp	2021-05-16 15:00:51 UTC (rev 277568)
@@ -286,15 +286,16 @@
     //
     // The idea here is that as long as we don't cross the block formatting context boundary, we should be able to pre-compute the final top position.
     // FIXME: we currently don't account for the "clear" property when computing the final position for an ancestor.
+    auto formattingGeometry = geometry();
     for (auto* ancestor = &layoutBox; ancestor && ancestor != &root(); ancestor = &ancestor->containingBlock()) {
         auto constraintsForAncestor = [&] {
             auto& containingBlock = ancestor->containingBlock();
-            return &containingBlock == &root() ? constraintsPair.formattingContextRoot : geometry().constraintsForInFlowContent(containingBlock);
+            return &containingBlock == &root() ? constraintsPair.formattingContextRoot : formattingGeometry.constraintsForInFlowContent(containingBlock);
         }();
 
-        auto computedVerticalMargin = geometry().computedVerticalMargin(*ancestor, constraintsForAncestor.horizontal);
+        auto computedVerticalMargin = formattingGeometry.computedVerticalMargin(*ancestor, constraintsForAncestor.horizontal);
         auto usedNonCollapsedMargin = UsedVerticalMargin::NonCollapsedValues { computedVerticalMargin.before.valueOr(0), computedVerticalMargin.after.valueOr(0) };
-        auto precomputedMarginBefore = marginCollapse().precomputedMarginBefore(*ancestor, usedNonCollapsedMargin);
+        auto precomputedMarginBefore = marginCollapse().precomputedMarginBefore(*ancestor, usedNonCollapsedMargin, formattingGeometry);
 
         auto& boxGeometry = formattingState().boxGeometry(*ancestor);
         auto nonCollapsedValues = UsedVerticalMargin::NonCollapsedValues { precomputedMarginBefore.nonCollapsedValue, { } };
@@ -603,12 +604,12 @@
 
 BlockFormattingGeometry BlockFormattingContext::geometry() const
 {
-    return BlockFormattingGeometry(*this);
+    return BlockFormattingGeometry { *this };
 }
 
 BlockMarginCollapse BlockFormattingContext::marginCollapse() const
 {
-    return BlockMarginCollapse(*this);
+    return BlockMarginCollapse { layoutState(), formattingState() };
 }
 
 }

Modified: trunk/Source/WebCore/layout/formattingContexts/block/BlockFormattingGeometry.cpp (277567 => 277568)


--- trunk/Source/WebCore/layout/formattingContexts/block/BlockFormattingGeometry.cpp	2021-05-16 13:50:51 UTC (rev 277567)
+++ trunk/Source/WebCore/layout/formattingContexts/block/BlockFormattingGeometry.cpp	2021-05-16 15:00:51 UTC (rev 277568)
@@ -90,7 +90,7 @@
         }
 
         // 2. the bottom edge of the bottom (possibly collapsed) margin of its last in-flow child, if the child's bottom margin...
-        auto marginCollapse = BlockMarginCollapse { formattingContext() };
+        auto marginCollapse = BlockMarginCollapse { layoutState(), formattingContext().formattingState() };
         auto& lastInFlowChild = *layoutContainer.lastInFlowChild();
         if (!marginCollapse.marginAfterCollapsesWithParentMarginAfter(lastInFlowChild)) {
             auto& lastInFlowBoxGeometry = formattingContext().geometryForBox(lastInFlowChild);

Modified: trunk/Source/WebCore/layout/formattingContexts/block/BlockFormattingQuirks.cpp (277567 => 277568)


--- trunk/Source/WebCore/layout/formattingContexts/block/BlockFormattingQuirks.cpp	2021-05-16 13:50:51 UTC (rev 277567)
+++ trunk/Source/WebCore/layout/formattingContexts/block/BlockFormattingQuirks.cpp	2021-05-16 15:00:51 UTC (rev 277568)
@@ -86,7 +86,7 @@
     bodyBoxContentHeight -= bodyBoxGeometry.verticalBorder() + bodyBoxGeometry.verticalPadding().valueOr(0);
     // Body box never collapses its vertical margins with the document box but it might collapse its margin with its descendants.
     auto nonCollapsedMargin = contentHeightAndMargin.nonCollapsedMargin;
-    auto marginCollapse = BlockMarginCollapse { formattingContext };
+    auto marginCollapse = BlockMarginCollapse { formattingContext.layoutState(), formattingContext.formattingState() };
     auto collapsedMargin = marginCollapse.collapsedVerticalValues(layoutBox, nonCollapsedMargin).collapsedValues;
     auto usedVerticalMargin = collapsedMargin.before.valueOr(nonCollapsedMargin.before);
     usedVerticalMargin += collapsedMargin.isCollapsedThrough ? nonCollapsedMargin.after : collapsedMargin.after.valueOr(nonCollapsedMargin.after);

Modified: trunk/Source/WebCore/layout/formattingContexts/block/BlockFormattingQuirks.h (277567 => 277568)


--- trunk/Source/WebCore/layout/formattingContexts/block/BlockFormattingQuirks.h	2021-05-16 13:50:51 UTC (rev 277567)
+++ trunk/Source/WebCore/layout/formattingContexts/block/BlockFormattingQuirks.h	2021-05-16 15:00:51 UTC (rev 277568)
@@ -32,6 +32,8 @@
 namespace WebCore {
 namespace Layout {
 
+class BlockFormattingContext;
+
 class BlockFormattingQuirks : public FormattingQuirks {
 public:
     BlockFormattingQuirks(const BlockFormattingContext&);

Modified: trunk/Source/WebCore/layout/formattingContexts/block/BlockMarginCollapse.cpp (277567 => 277568)


--- trunk/Source/WebCore/layout/formattingContexts/block/BlockMarginCollapse.cpp	2021-05-16 13:50:51 UTC (rev 277567)
+++ trunk/Source/WebCore/layout/formattingContexts/block/BlockMarginCollapse.cpp	2021-05-16 15:00:51 UTC (rev 277568)
@@ -82,8 +82,10 @@
     return layoutBox.establishesBlockFormattingContext();
 }
 
-BlockMarginCollapse::BlockMarginCollapse(const BlockFormattingContext& blockFormattingContext)
-    : m_blockFormattingContext(blockFormattingContext)
+BlockMarginCollapse::BlockMarginCollapse(const LayoutState& layoutState, const BlockFormattingState& blockFormattingState)
+    : m_layoutState(layoutState)
+    , m_blockFormattingState(blockFormattingState)
+    , m_inQuirksMode(layoutState.inQuirksMode())
 {
 }
 
@@ -93,7 +95,7 @@
         return false;
     // FIXME: precomputedVerticalPositionForFormattingRoot logic ends up calling into this function when the layoutBox (first inflow child) has
     // not been laid out.
-    return formattingContext().formattingState().hasClearance(layoutBox);
+    return formattingState().hasClearance(layoutBox);
 }
 
 bool BlockMarginCollapse::marginBeforeCollapsesWithParentMarginAfter(const Box& layoutBox) const
@@ -120,7 +122,7 @@
     // https://www.w3.org/TR/CSS21/box.html#collapsing-margins
     ASSERT(layoutBox.isBlockLevelBox());
 
-    if (layoutState().inQuirksMode() && BlockFormattingQuirks::shouldCollapseMarginBeforeWithParentMarginBefore(layoutBox))
+    if (inQuirksMode() && BlockFormattingQuirks::shouldCollapseMarginBeforeWithParentMarginBefore(layoutBox))
         return true;
 
     // Margins between a floated box and any other box do not collapse.
@@ -258,7 +260,7 @@
 {
     ASSERT(layoutBox.isBlockLevelBox());
 
-    if (layoutState().inQuirksMode() && BlockFormattingQuirks::shouldCollapseMarginAfterWithParentMarginAfter(layoutBox))
+    if (inQuirksMode() && BlockFormattingQuirks::shouldCollapseMarginAfterWithParentMarginAfter(layoutBox))
         return true;
 
     // Margins between a floated box and any other box do not collapse.
@@ -349,7 +351,7 @@
 
     // This is a quirk behavior: When the margin after of the last inflow child (or a previous sibling with collapsed through margins)
     // collapses with a quirk parent's the margin before, then the same margin after does not collapses with the parent's margin after.
-    auto shouldIgnoreCollapsedMargin = layoutState().inQuirksMode() && BlockFormattingQuirks::shouldIgnoreCollapsedQuirkMargin(layoutBox);
+    auto shouldIgnoreCollapsedMargin = inQuirksMode() && BlockFormattingQuirks::shouldIgnoreCollapsedQuirkMargin(layoutBox);
     if (shouldIgnoreCollapsedMargin && marginAfterCollapsesWithParentMarginBefore(lastInFlowChild))
         return false;
 
@@ -477,11 +479,10 @@
 
 UsedVerticalMargin::PositiveAndNegativePair::Values BlockMarginCollapse::positiveNegativeValues(const Box& layoutBox, MarginType marginType) const
 {
-    auto& formattingState = formattingContext().formattingState();
     // By the time we get here in BFC layout to gather positive and negative margin values for either a previous sibling or a child box,
     // we mush have computed and cached those values.
-    ASSERT(formattingState.hasUsedVerticalMargin(layoutBox));
-    auto positiveAndNegativeVerticalMargin = formattingState.usedVerticalMargin(layoutBox).positiveAndNegativeValues;
+    ASSERT(formattingState().hasUsedVerticalMargin(layoutBox));
+    auto positiveAndNegativeVerticalMargin = formattingState().usedVerticalMargin(layoutBox).positiveAndNegativeValues;
     return marginType == MarginType::Before ? positiveAndNegativeVerticalMargin.before : positiveAndNegativeVerticalMargin.after; 
 }
 
@@ -503,7 +504,7 @@
     // 2. Gather positive and negative margin values from previous inflow sibling if margins are adjoining.
     // 3. Compute min/max positive and negative collapsed margin values using non-collpased computed margin before.
     auto collapsedMarginBefore = computedPositiveAndNegativeMargin(firstChildCollapsedMarginBefore(), previouSiblingCollapsedMarginAfter());
-    auto shouldIgnoreCollapsedMargin = collapsedMarginBefore.isQuirk && layoutState().inQuirksMode() && BlockFormattingQuirks::shouldIgnoreCollapsedQuirkMargin(layoutBox);
+    auto shouldIgnoreCollapsedMargin = collapsedMarginBefore.isQuirk && inQuirksMode() && BlockFormattingQuirks::shouldIgnoreCollapsedQuirkMargin(layoutBox);
     if (shouldIgnoreCollapsedMargin)
         collapsedMarginBefore = { };
 

Modified: trunk/Source/WebCore/layout/formattingContexts/block/BlockMarginCollapse.h (277567 => 277568)


--- trunk/Source/WebCore/layout/formattingContexts/block/BlockMarginCollapse.h	2021-05-16 13:50:51 UTC (rev 277567)
+++ trunk/Source/WebCore/layout/formattingContexts/block/BlockMarginCollapse.h	2021-05-16 15:00:51 UTC (rev 277568)
@@ -27,19 +27,23 @@
 
 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)
 
-#include "BlockFormattingContext.h"
+#include "MarginTypes.h"
 
 namespace WebCore {
 namespace Layout {
 
+class Box;
+class BlockFormattingGeometry;
+class BlockFormattingState;
+class LayoutState;
+
 // This class implements margin collapsing for block formatting context.
 class BlockMarginCollapse {
 public:
-    BlockMarginCollapse(const BlockFormattingContext&);
+    BlockMarginCollapse(const LayoutState&, const BlockFormattingState&);
 
     UsedVerticalMargin collapsedVerticalValues(const Box&, UsedVerticalMargin::NonCollapsedValues);
 
-    PrecomputedMarginBefore precomputedMarginBefore(const Box&, UsedVerticalMargin::NonCollapsedValues);
     LayoutUnit marginBeforeIgnoringCollapsingThrough(const Box&, UsedVerticalMargin::NonCollapsedValues);
 
     bool marginBeforeCollapsesWithParentMarginBefore(const Box&) const;
@@ -57,6 +61,8 @@
 
     bool marginsCollapseThrough(const Box&) const;
 
+    PrecomputedMarginBefore precomputedMarginBefore(const Box&, UsedVerticalMargin::NonCollapsedValues, const BlockFormattingGeometry&);
+
 private:
     enum class MarginType { Before, After };
     UsedVerticalMargin::PositiveAndNegativePair::Values positiveNegativeValues(const Box&, MarginType) const;
@@ -63,18 +69,20 @@
     UsedVerticalMargin::PositiveAndNegativePair::Values positiveNegativeMarginBefore(const Box&, UsedVerticalMargin::NonCollapsedValues) const;
     UsedVerticalMargin::PositiveAndNegativePair::Values positiveNegativeMarginAfter(const Box&, UsedVerticalMargin::NonCollapsedValues) const;
 
-    UsedVerticalMargin::PositiveAndNegativePair::Values precomputedPositiveNegativeMarginBefore(const Box&, UsedVerticalMargin::NonCollapsedValues) const;
-    UsedVerticalMargin::PositiveAndNegativePair::Values precomputedPositiveNegativeValues(const Box&) const;
+    UsedVerticalMargin::PositiveAndNegativePair::Values precomputedPositiveNegativeMarginBefore(const Box&, UsedVerticalMargin::NonCollapsedValues, const BlockFormattingGeometry&) const;
+    UsedVerticalMargin::PositiveAndNegativePair::Values precomputedPositiveNegativeValues(const Box&, const BlockFormattingGeometry&) const;
 
     Optional<LayoutUnit> marginValue(UsedVerticalMargin::PositiveAndNegativePair::Values) const;
 
     bool hasClearance(const Box&) const;
 
-    LayoutState& layoutState() { return m_blockFormattingContext.layoutState(); }
-    const LayoutState& layoutState() const { return m_blockFormattingContext.layoutState(); }
-    const BlockFormattingContext& formattingContext() const { return m_blockFormattingContext; }
+    bool inQuirksMode() const { return m_inQuirksMode; }
+    const LayoutState& layoutState() const { return m_layoutState; }
+    const BlockFormattingState& formattingState() const { return m_blockFormattingState; }
 
-    const BlockFormattingContext& m_blockFormattingContext;
+    const LayoutState& m_layoutState;
+    const BlockFormattingState& m_blockFormattingState;
+    bool m_inQuirksMode { false };
 };
 
 }

Modified: trunk/Source/WebCore/layout/formattingContexts/block/PrecomputedBlockMarginCollapse.cpp (277567 => 277568)


--- trunk/Source/WebCore/layout/formattingContexts/block/PrecomputedBlockMarginCollapse.cpp	2021-05-16 13:50:51 UTC (rev 277567)
+++ trunk/Source/WebCore/layout/formattingContexts/block/PrecomputedBlockMarginCollapse.cpp	2021-05-16 15:00:51 UTC (rev 277568)
@@ -39,25 +39,24 @@
 namespace WebCore {
 namespace Layout {
 
-UsedVerticalMargin::PositiveAndNegativePair::Values BlockMarginCollapse::precomputedPositiveNegativeValues(const Box& layoutBox) const
+UsedVerticalMargin::PositiveAndNegativePair::Values BlockMarginCollapse::precomputedPositiveNegativeValues(const Box& layoutBox, const BlockFormattingGeometry& formattingGeometry) const
 {
     auto& blockFormattingState = downcast<BlockFormattingState>(layoutState().formattingStateForBox(layoutBox));
     if (blockFormattingState.hasUsedVerticalMargin(layoutBox))
         return blockFormattingState.usedVerticalMargin(layoutBox).positiveAndNegativeValues.before;
 
-    auto geometry = BlockFormattingGeometry { formattingContext() };
-    auto horizontalConstraints = geometry.constraintsForInFlowContent(layoutBox.containingBlock()).horizontal;
-    auto computedVerticalMargin = geometry.computedVerticalMargin(layoutBox, horizontalConstraints);
+    auto horizontalConstraints = formattingGeometry.constraintsForInFlowContent(layoutBox.containingBlock()).horizontal;
+    auto computedVerticalMargin = formattingGeometry.computedVerticalMargin(layoutBox, horizontalConstraints);
     auto nonCollapsedMargin = UsedVerticalMargin::NonCollapsedValues { computedVerticalMargin.before.valueOr(0), computedVerticalMargin.after.valueOr(0) };
-    return precomputedPositiveNegativeMarginBefore(layoutBox, nonCollapsedMargin);
+    return precomputedPositiveNegativeMarginBefore(layoutBox, nonCollapsedMargin, formattingGeometry);
 }
 
-UsedVerticalMargin::PositiveAndNegativePair::Values BlockMarginCollapse::precomputedPositiveNegativeMarginBefore(const Box& layoutBox, UsedVerticalMargin::NonCollapsedValues nonCollapsedValues) const
+UsedVerticalMargin::PositiveAndNegativePair::Values BlockMarginCollapse::precomputedPositiveNegativeMarginBefore(const Box& layoutBox, UsedVerticalMargin::NonCollapsedValues nonCollapsedValues, const BlockFormattingGeometry& formattingGeometry) const
 {
     auto firstChildCollapsedMarginBefore = [&]() -> UsedVerticalMargin::PositiveAndNegativePair::Values {
         if (!marginBeforeCollapsesWithFirstInFlowChildMarginBefore(layoutBox))
             return { };
-        return precomputedPositiveNegativeValues(*downcast<ContainerBox>(layoutBox).firstInFlowChild());
+        return precomputedPositiveNegativeValues(*downcast<ContainerBox>(layoutBox).firstInFlowChild(), formattingGeometry);
     };
 
     auto previouSiblingCollapsedMarginAfter = [&]() -> UsedVerticalMargin::PositiveAndNegativePair::Values {
@@ -72,7 +71,7 @@
     // 2. Gather positive and negative margin values from previous inflow sibling if margins are adjoining.
     // 3. Compute min/max positive and negative collapsed margin values using non-collpased computed margin before.
     auto collapsedMarginBefore = computedPositiveAndNegativeMargin(firstChildCollapsedMarginBefore(), previouSiblingCollapsedMarginAfter());
-    auto shouldIgnoreCollapsedMargin = collapsedMarginBefore.isQuirk && layoutState().inQuirksMode() && BlockFormattingQuirks::shouldIgnoreCollapsedQuirkMargin(layoutBox);
+    auto shouldIgnoreCollapsedMargin = collapsedMarginBefore.isQuirk && inQuirksMode() && BlockFormattingQuirks::shouldIgnoreCollapsedQuirkMargin(layoutBox);
     if (shouldIgnoreCollapsedMargin)
         collapsedMarginBefore = { };
 
@@ -85,7 +84,7 @@
     return computedPositiveAndNegativeMargin(collapsedMarginBefore, nonCollapsedBefore);
 }
 
-PrecomputedMarginBefore BlockMarginCollapse::precomputedMarginBefore(const Box& layoutBox, UsedVerticalMargin::NonCollapsedValues usedNonCollapsedMargin)
+PrecomputedMarginBefore BlockMarginCollapse::precomputedMarginBefore(const Box& layoutBox, UsedVerticalMargin::NonCollapsedValues usedNonCollapsedMargin, const BlockFormattingGeometry& formattingGeometry)
 {
     ASSERT(layoutBox.isBlockLevelBox());
     // Don't pre-compute vertical margins for out of flow boxes.
@@ -92,7 +91,7 @@
     ASSERT(layoutBox.isInFlow() || layoutBox.isFloatingPositioned());
     ASSERT(!layoutBox.isReplacedBox());
 
-    auto positiveNegativeMarginBefore = precomputedPositiveNegativeMarginBefore(layoutBox, usedNonCollapsedMargin);
+    auto positiveNegativeMarginBefore = precomputedPositiveNegativeMarginBefore(layoutBox, usedNonCollapsedMargin, formattingGeometry);
     auto collapsedMarginBefore = marginValue(positiveNegativeMarginBefore);
     return { usedNonCollapsedMargin.before, collapsedMarginBefore, positiveNegativeMarginBefore };
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to