Title: [277540] trunk/Source/WebCore
Revision
277540
Author
[email protected]
Date
2021-05-15 09:21:39 -0700 (Sat, 15 May 2021)

Log Message

[LFC] Move BlockMarginCollapse to its own class
https://bugs.webkit.org/show_bug.cgi?id=225762

Reviewed by Antti Koivisto.

* WebCore.xcodeproj/project.pbxproj:
* layout/formattingContexts/FormattingContext.h:
(WebCore::Layout::FormattingContext::formattingState const):
* layout/formattingContexts/block/BlockFormattingContext.cpp:
(WebCore::Layout::BlockFormattingContext::computeHeightAndMargin):
(WebCore::Layout::BlockFormattingContext::updateMarginAfterForPreviousSibling):
(WebCore::Layout::BlockFormattingContext::marginCollapse const):
* layout/formattingContexts/block/BlockFormattingContext.h:
(WebCore::Layout::BlockFormattingContext::formattingState const):
(WebCore::Layout::BlockFormattingContext::Quirks::formattingContext const):
(WebCore::Layout::BlockFormattingContext::Quirks::geometry const):
(WebCore::Layout::BlockFormattingContext::quirks const):
(WebCore::Layout::BlockFormattingContext::MarginCollapse::layoutState): Deleted.
(WebCore::Layout::BlockFormattingContext::MarginCollapse::layoutState const): Deleted.
(WebCore::Layout::BlockFormattingContext::MarginCollapse::formattingContext const): Deleted.
(WebCore::Layout::BlockFormattingContext::marginCollapse const): Deleted.
(WebCore::Layout::BlockFormattingContext::MarginCollapse::MarginCollapse): Deleted.
* layout/formattingContexts/block/BlockMarginCollapse.cpp:
(WebCore::Layout::BlockMarginCollapse::BlockMarginCollapse):
(WebCore::Layout::BlockMarginCollapse::hasClearance const):
(WebCore::Layout::BlockMarginCollapse::marginBeforeCollapsesWithParentMarginAfter const):
(WebCore::Layout::BlockMarginCollapse::marginBeforeCollapsesWithParentMarginBefore const):
(WebCore::Layout::BlockMarginCollapse::marginBeforeCollapsesWithPreviousSiblingMarginAfter const):
(WebCore::Layout::BlockMarginCollapse::marginBeforeCollapsesWithFirstInFlowChildMarginBefore const):
(WebCore::Layout::BlockMarginCollapse::marginAfterCollapsesWithSiblingMarginBeforeWithClearance const):
(WebCore::Layout::BlockMarginCollapse::marginAfterCollapsesWithParentMarginBefore const):
(WebCore::Layout::BlockMarginCollapse::marginAfterCollapsesWithParentMarginAfter const):
(WebCore::Layout::BlockMarginCollapse::marginAfterCollapsesWithLastInFlowChildMarginAfter const):
(WebCore::Layout::BlockMarginCollapse::marginAfterCollapsesWithNextSiblingMarginBefore const):
(WebCore::Layout::BlockMarginCollapse::marginsCollapseThrough const):
(WebCore::Layout::BlockMarginCollapse::computedPositiveAndNegativeMargin const):
(WebCore::Layout::BlockMarginCollapse::marginValue const):
(WebCore::Layout::BlockMarginCollapse::positiveNegativeValues const):
(WebCore::Layout::BlockMarginCollapse::positiveNegativeMarginBefore const):
(WebCore::Layout::BlockMarginCollapse::positiveNegativeMarginAfter const):
(WebCore::Layout::BlockMarginCollapse::marginBeforeIgnoringCollapsingThrough):
(WebCore::Layout::BlockMarginCollapse::collapsedVerticalValues):
(WebCore::Layout::BlockFormattingContext::MarginCollapse::hasClearance const): Deleted.
(WebCore::Layout::BlockFormattingContext::MarginCollapse::marginBeforeCollapsesWithParentMarginAfter const): Deleted.
(WebCore::Layout::BlockFormattingContext::MarginCollapse::marginBeforeCollapsesWithParentMarginBefore const): Deleted.
(WebCore::Layout::BlockFormattingContext::MarginCollapse::marginBeforeCollapsesWithPreviousSiblingMarginAfter const): Deleted.
(WebCore::Layout::BlockFormattingContext::MarginCollapse::marginBeforeCollapsesWithFirstInFlowChildMarginBefore const): Deleted.
(WebCore::Layout::BlockFormattingContext::MarginCollapse::marginAfterCollapsesWithSiblingMarginBeforeWithClearance const): Deleted.
(WebCore::Layout::BlockFormattingContext::MarginCollapse::marginAfterCollapsesWithParentMarginBefore const): Deleted.
(WebCore::Layout::BlockFormattingContext::MarginCollapse::marginAfterCollapsesWithParentMarginAfter const): Deleted.
(WebCore::Layout::BlockFormattingContext::MarginCollapse::marginAfterCollapsesWithLastInFlowChildMarginAfter const): Deleted.
(WebCore::Layout::BlockFormattingContext::MarginCollapse::marginAfterCollapsesWithNextSiblingMarginBefore const): Deleted.
(WebCore::Layout::BlockFormattingContext::MarginCollapse::marginsCollapseThrough const): Deleted.
(WebCore::Layout::BlockFormattingContext::MarginCollapse::computedPositiveAndNegativeMargin const): Deleted.
(WebCore::Layout::BlockFormattingContext::MarginCollapse::marginValue const): Deleted.
(WebCore::Layout::BlockFormattingContext::MarginCollapse::updateMarginAfterForPreviousSibling): Deleted.
(WebCore::Layout::BlockFormattingContext::MarginCollapse::positiveNegativeValues const): Deleted.
(WebCore::Layout::BlockFormattingContext::MarginCollapse::positiveNegativeMarginBefore const): Deleted.
(WebCore::Layout::BlockFormattingContext::MarginCollapse::positiveNegativeMarginAfter const): Deleted.
(WebCore::Layout::BlockFormattingContext::MarginCollapse::marginBeforeIgnoringCollapsingThrough): Deleted.
(WebCore::Layout::BlockFormattingContext::MarginCollapse::collapsedVerticalValues): Deleted.
* layout/formattingContexts/block/PrecomputedBlockMarginCollapse.cpp:
(WebCore::Layout::BlockMarginCollapse::precomputedPositiveNegativeValues const):
(WebCore::Layout::BlockMarginCollapse::precomputedPositiveNegativeMarginBefore const):
(WebCore::Layout::BlockMarginCollapse::precomputedMarginBefore):
(WebCore::Layout::BlockFormattingContext::MarginCollapse::precomputedPositiveNegativeValues const): Deleted.
(WebCore::Layout::BlockFormattingContext::MarginCollapse::precomputedPositiveNegativeMarginBefore const): Deleted.
(WebCore::Layout::BlockFormattingContext::MarginCollapse::precomputedMarginBefore): Deleted.
* layout/formattingContexts/block/tablewrapper/TableWrapperBlockFormattingContext.cpp:
(WebCore::Layout::TableWrapperBlockFormattingContext::computeHeightAndMarginForTableBox):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (277539 => 277540)


--- trunk/Source/WebCore/ChangeLog	2021-05-15 14:26:42 UTC (rev 277539)
+++ trunk/Source/WebCore/ChangeLog	2021-05-15 16:21:39 UTC (rev 277540)
@@ -1,3 +1,76 @@
+2021-05-15  Alan Bujtas  <[email protected]>
+
+        [LFC] Move BlockMarginCollapse to its own class
+        https://bugs.webkit.org/show_bug.cgi?id=225762
+
+        Reviewed by Antti Koivisto.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * layout/formattingContexts/FormattingContext.h:
+        (WebCore::Layout::FormattingContext::formattingState const):
+        * layout/formattingContexts/block/BlockFormattingContext.cpp:
+        (WebCore::Layout::BlockFormattingContext::computeHeightAndMargin):
+        (WebCore::Layout::BlockFormattingContext::updateMarginAfterForPreviousSibling):
+        (WebCore::Layout::BlockFormattingContext::marginCollapse const):
+        * layout/formattingContexts/block/BlockFormattingContext.h:
+        (WebCore::Layout::BlockFormattingContext::formattingState const):
+        (WebCore::Layout::BlockFormattingContext::Quirks::formattingContext const):
+        (WebCore::Layout::BlockFormattingContext::Quirks::geometry const):
+        (WebCore::Layout::BlockFormattingContext::quirks const):
+        (WebCore::Layout::BlockFormattingContext::MarginCollapse::layoutState): Deleted.
+        (WebCore::Layout::BlockFormattingContext::MarginCollapse::layoutState const): Deleted.
+        (WebCore::Layout::BlockFormattingContext::MarginCollapse::formattingContext const): Deleted.
+        (WebCore::Layout::BlockFormattingContext::marginCollapse const): Deleted.
+        (WebCore::Layout::BlockFormattingContext::MarginCollapse::MarginCollapse): Deleted.
+        * layout/formattingContexts/block/BlockMarginCollapse.cpp:
+        (WebCore::Layout::BlockMarginCollapse::BlockMarginCollapse):
+        (WebCore::Layout::BlockMarginCollapse::hasClearance const):
+        (WebCore::Layout::BlockMarginCollapse::marginBeforeCollapsesWithParentMarginAfter const):
+        (WebCore::Layout::BlockMarginCollapse::marginBeforeCollapsesWithParentMarginBefore const):
+        (WebCore::Layout::BlockMarginCollapse::marginBeforeCollapsesWithPreviousSiblingMarginAfter const):
+        (WebCore::Layout::BlockMarginCollapse::marginBeforeCollapsesWithFirstInFlowChildMarginBefore const):
+        (WebCore::Layout::BlockMarginCollapse::marginAfterCollapsesWithSiblingMarginBeforeWithClearance const):
+        (WebCore::Layout::BlockMarginCollapse::marginAfterCollapsesWithParentMarginBefore const):
+        (WebCore::Layout::BlockMarginCollapse::marginAfterCollapsesWithParentMarginAfter const):
+        (WebCore::Layout::BlockMarginCollapse::marginAfterCollapsesWithLastInFlowChildMarginAfter const):
+        (WebCore::Layout::BlockMarginCollapse::marginAfterCollapsesWithNextSiblingMarginBefore const):
+        (WebCore::Layout::BlockMarginCollapse::marginsCollapseThrough const):
+        (WebCore::Layout::BlockMarginCollapse::computedPositiveAndNegativeMargin const):
+        (WebCore::Layout::BlockMarginCollapse::marginValue const):
+        (WebCore::Layout::BlockMarginCollapse::positiveNegativeValues const):
+        (WebCore::Layout::BlockMarginCollapse::positiveNegativeMarginBefore const):
+        (WebCore::Layout::BlockMarginCollapse::positiveNegativeMarginAfter const):
+        (WebCore::Layout::BlockMarginCollapse::marginBeforeIgnoringCollapsingThrough):
+        (WebCore::Layout::BlockMarginCollapse::collapsedVerticalValues):
+        (WebCore::Layout::BlockFormattingContext::MarginCollapse::hasClearance const): Deleted.
+        (WebCore::Layout::BlockFormattingContext::MarginCollapse::marginBeforeCollapsesWithParentMarginAfter const): Deleted.
+        (WebCore::Layout::BlockFormattingContext::MarginCollapse::marginBeforeCollapsesWithParentMarginBefore const): Deleted.
+        (WebCore::Layout::BlockFormattingContext::MarginCollapse::marginBeforeCollapsesWithPreviousSiblingMarginAfter const): Deleted.
+        (WebCore::Layout::BlockFormattingContext::MarginCollapse::marginBeforeCollapsesWithFirstInFlowChildMarginBefore const): Deleted.
+        (WebCore::Layout::BlockFormattingContext::MarginCollapse::marginAfterCollapsesWithSiblingMarginBeforeWithClearance const): Deleted.
+        (WebCore::Layout::BlockFormattingContext::MarginCollapse::marginAfterCollapsesWithParentMarginBefore const): Deleted.
+        (WebCore::Layout::BlockFormattingContext::MarginCollapse::marginAfterCollapsesWithParentMarginAfter const): Deleted.
+        (WebCore::Layout::BlockFormattingContext::MarginCollapse::marginAfterCollapsesWithLastInFlowChildMarginAfter const): Deleted.
+        (WebCore::Layout::BlockFormattingContext::MarginCollapse::marginAfterCollapsesWithNextSiblingMarginBefore const): Deleted.
+        (WebCore::Layout::BlockFormattingContext::MarginCollapse::marginsCollapseThrough const): Deleted.
+        (WebCore::Layout::BlockFormattingContext::MarginCollapse::computedPositiveAndNegativeMargin const): Deleted.
+        (WebCore::Layout::BlockFormattingContext::MarginCollapse::marginValue const): Deleted.
+        (WebCore::Layout::BlockFormattingContext::MarginCollapse::updateMarginAfterForPreviousSibling): Deleted.
+        (WebCore::Layout::BlockFormattingContext::MarginCollapse::positiveNegativeValues const): Deleted.
+        (WebCore::Layout::BlockFormattingContext::MarginCollapse::positiveNegativeMarginBefore const): Deleted.
+        (WebCore::Layout::BlockFormattingContext::MarginCollapse::positiveNegativeMarginAfter const): Deleted.
+        (WebCore::Layout::BlockFormattingContext::MarginCollapse::marginBeforeIgnoringCollapsingThrough): Deleted.
+        (WebCore::Layout::BlockFormattingContext::MarginCollapse::collapsedVerticalValues): Deleted.
+        * layout/formattingContexts/block/PrecomputedBlockMarginCollapse.cpp:
+        (WebCore::Layout::BlockMarginCollapse::precomputedPositiveNegativeValues const):
+        (WebCore::Layout::BlockMarginCollapse::precomputedPositiveNegativeMarginBefore const):
+        (WebCore::Layout::BlockMarginCollapse::precomputedMarginBefore):
+        (WebCore::Layout::BlockFormattingContext::MarginCollapse::precomputedPositiveNegativeValues const): Deleted.
+        (WebCore::Layout::BlockFormattingContext::MarginCollapse::precomputedPositiveNegativeMarginBefore const): Deleted.
+        (WebCore::Layout::BlockFormattingContext::MarginCollapse::precomputedMarginBefore): Deleted.
+        * layout/formattingContexts/block/tablewrapper/TableWrapperBlockFormattingContext.cpp:
+        (WebCore::Layout::TableWrapperBlockFormattingContext::computeHeightAndMarginForTableBox):
+
 2021-05-15  Alexander Mikhaylenko  <[email protected]>
 
         [GTK] REGRESSION: Kinetic scrolling on touchpad doesn't work with async scrolling off

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (277539 => 277540)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-05-15 14:26:42 UTC (rev 277539)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-05-15 16:21:39 UTC (rev 277540)
@@ -2134,6 +2134,7 @@
 		6F3FBA982556E313003530FD /* LayoutIntegrationInlineContentBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = 6F3FBA972556E312003530FD /* LayoutIntegrationInlineContentBuilder.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		6F40DA822513033A00EC04B7 /* InlineRect.h in Headers */ = {isa = PBXBuildFile; fileRef = 6F40DA812513033A00EC04B7 /* InlineRect.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		6F6383F62427AF4A00DABA53 /* LayoutInitialContainingBlock.h in Headers */ = {isa = PBXBuildFile; fileRef = 6F6383F42427AF4900DABA53 /* LayoutInitialContainingBlock.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		6F6DF36F264722EA0093E834 /* BlockMarginCollapse.h in Headers */ = {isa = PBXBuildFile; fileRef = 6F6DF36E264722EA0093E834 /* BlockMarginCollapse.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		6F7CA3C6208C2957002F29AB /* LayoutState.h in Headers */ = {isa = PBXBuildFile; fileRef = 6F7CA3C4208C2956002F29AB /* LayoutState.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		6F7CA3CA208C2B2E002F29AB /* InlineFormattingContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 6F7CA3C8208C2B2E002F29AB /* InlineFormattingContext.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		6F91421125152138004E4FEA /* InlineLineGeometry.h in Headers */ = {isa = PBXBuildFile; fileRef = 6F91420F25152137004E4FEA /* InlineLineGeometry.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -9963,6 +9964,7 @@
 		6F6383F42427AF4900DABA53 /* LayoutInitialContainingBlock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LayoutInitialContainingBlock.h; sourceTree = "<group>"; };
 		6F6638D4249E268B001925FC /* TableWrapperBlockFormattingContextQuirks.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TableWrapperBlockFormattingContextQuirks.cpp; sourceTree = "<group>"; };
 		6F69A79924D6FAB800E6B85D /* InlineLineBox.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = InlineLineBox.cpp; sourceTree = "<group>"; };
+		6F6DF36E264722EA0093E834 /* BlockMarginCollapse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BlockMarginCollapse.h; sourceTree = "<group>"; };
 		6F70DEDD251126F300F0FC78 /* FlexFormattingContextGeometry.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = FlexFormattingContextGeometry.cpp; sourceTree = "<group>"; };
 		6F73918C2106CEDD006AF262 /* LayoutUnits.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LayoutUnits.h; sourceTree = "<group>"; };
 		6F7B8CEC23626E6600C9FF15 /* InlineItem.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = InlineItem.cpp; sourceTree = "<group>"; };
@@ -18232,6 +18234,7 @@
 				115CFA79208B8D9D001E6991 /* BlockFormattingState.cpp */,
 				115CFA78208B8D9D001E6991 /* BlockFormattingState.h */,
 				115CFA89208B921A001E6991 /* BlockMarginCollapse.cpp */,
+				6F6DF36E264722EA0093E834 /* BlockMarginCollapse.h */,
 				6FAE16BA2406DE7E00A48414 /* PrecomputedBlockMarginCollapse.cpp */,
 			);
 			path = block;
@@ -31665,6 +31668,7 @@
 				976D6C7F122B8A3D001FD1F7 /* BlobURL.h in Headers */,
 				115CFA6E208AFAB7001E6991 /* BlockFormattingContext.h in Headers */,
 				115CFA7A208B8D9D001E6991 /* BlockFormattingState.h in Headers */,
+				6F6DF36F264722EA0093E834 /* BlockMarginCollapse.h in Headers */,
 				BC5EB5E10E81BE8700B25965 /* BorderData.h in Headers */,
 				589556ED18D4A44000764B03 /* BorderEdge.h in Headers */,
 				BC5EB5DB0E81B7EA00B25965 /* BorderValue.h in Headers */,

Modified: trunk/Source/WebCore/layout/formattingContexts/FormattingContext.h (277539 => 277540)


--- trunk/Source/WebCore/layout/formattingContexts/FormattingContext.h	2021-05-15 14:26:42 UTC (rev 277539)
+++ trunk/Source/WebCore/layout/formattingContexts/FormattingContext.h	2021-05-15 16:21:39 UTC (rev 277540)
@@ -108,11 +108,11 @@
     const ContainerBox& root() const { return *m_root; }
 
     LayoutState& layoutState() const;
+    const FormattingState& formattingState() const { return m_formattingState; }
 
 protected:
     using LayoutQueue = Vector<const Box*>;
 
-    const FormattingState& formattingState() const { return m_formattingState; }
     FormattingState& formattingState() { return m_formattingState; }
 
     void computeBorderAndPadding(const Box&, const HorizontalConstraints&);

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


--- trunk/Source/WebCore/layout/formattingContexts/block/BlockFormattingContext.cpp	2021-05-15 14:26:42 UTC (rev 277539)
+++ trunk/Source/WebCore/layout/formattingContexts/block/BlockFormattingContext.cpp	2021-05-15 16:21:39 UTC (rev 277540)
@@ -29,6 +29,7 @@
 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)
 
 #include "BlockFormattingState.h"
+#include "BlockMarginCollapse.h"
 #include "FloatingContext.h"
 #include "FloatingState.h"
 #include "InvalidationState.h"
@@ -420,7 +421,7 @@
     boxGeometry.setContentBoxHeight(contentHeightAndMargin.contentHeight);
     boxGeometry.setVerticalMargin({ marginBefore(verticalMargin), marginAfter(verticalMargin) });
     // Adjust the previous sibling's margin bottom now that this box's vertical margin is computed.
-    MarginCollapse::updateMarginAfterForPreviousSibling(*this, marginCollapse, layoutBox);
+    updateMarginAfterForPreviousSibling(layoutBox);
 }
 
 FormattingContext::IntrinsicWidthConstraints BlockFormattingContext::computedIntrinsicWidthConstraints()
@@ -557,7 +558,54 @@
     return containingBlockContentBoxTop + marginBefore(verticalMargin);
 }
 
+void BlockFormattingContext::updateMarginAfterForPreviousSibling(const Box& layoutBox)
+{
+    auto marginCollapse = this->marginCollapse();
+    auto& formattingState = this->formattingState();
+    // 1. Get the margin before value from the next in-flow sibling. This is the same as this box's margin after value now since they are collapsed.
+    // 2. Update the collapsed margin after value as well as the positive/negative cache.
+    // 3. Check if the box's margins collapse through.
+    // 4. If so, update the positive/negative cache.
+    // 5. In case of collapsed through margins check if the before margin collapes with the previous inflow sibling's after margin.
+    // 6. If so, jump to #2.
+    // 7. No need to propagate to parent because its margin is not computed yet (pre-computed at most).
+    auto* currentBox = &layoutBox;
+    while (marginCollapse.marginBeforeCollapsesWithPreviousSiblingMarginAfter(*currentBox)) {
+        auto& previousSibling = *currentBox->previousInFlowSibling();
+        auto previousSiblingVerticalMargin = formattingState.usedVerticalMargin(previousSibling);
+
+        auto collapsedVerticalMarginBefore = previousSiblingVerticalMargin.collapsedValues.before;
+        auto collapsedVerticalMarginAfter = geometryForBox(*currentBox).marginBefore();
+
+        auto marginsCollapseThrough = marginCollapse.marginsCollapseThrough(previousSibling);
+        if (marginsCollapseThrough)
+            collapsedVerticalMarginBefore = collapsedVerticalMarginAfter;
+
+        // Update positive/negative cache.
+        auto previousSiblingPositiveNegativeMargin = formattingState.usedVerticalMargin(previousSibling).positiveAndNegativeValues;
+        auto positiveNegativeMarginBefore = formattingState.usedVerticalMargin(*currentBox).positiveAndNegativeValues.before;
+
+        auto adjustedPreviousSiblingVerticalMargin = previousSiblingVerticalMargin;
+        adjustedPreviousSiblingVerticalMargin.positiveAndNegativeValues.after = marginCollapse.computedPositiveAndNegativeMargin(positiveNegativeMarginBefore, previousSiblingPositiveNegativeMargin.after);
+        if (marginsCollapseThrough) {
+            adjustedPreviousSiblingVerticalMargin.positiveAndNegativeValues.before = marginCollapse.computedPositiveAndNegativeMargin(previousSiblingPositiveNegativeMargin.before, adjustedPreviousSiblingVerticalMargin.positiveAndNegativeValues.after);
+            adjustedPreviousSiblingVerticalMargin.positiveAndNegativeValues.after = adjustedPreviousSiblingVerticalMargin.positiveAndNegativeValues.before;
+        }
+        formattingState.setUsedVerticalMargin(previousSibling, adjustedPreviousSiblingVerticalMargin);
+
+        if (!marginsCollapseThrough)
+            break;
+
+        currentBox = &previousSibling;
+    }
 }
+
+BlockMarginCollapse BlockFormattingContext::marginCollapse() const
+{
+    return BlockMarginCollapse(*this);
 }
 
+}
+}
+
 #endif

Modified: trunk/Source/WebCore/layout/formattingContexts/block/BlockFormattingContext.h (277539 => 277540)


--- trunk/Source/WebCore/layout/formattingContexts/block/BlockFormattingContext.h	2021-05-15 14:26:42 UTC (rev 277539)
+++ trunk/Source/WebCore/layout/formattingContexts/block/BlockFormattingContext.h	2021-05-15 16:21:39 UTC (rev 277540)
@@ -39,6 +39,7 @@
 namespace Layout {
 
 class Box;
+class BlockMarginCollapse;
 class FloatingContext;
 
 // This class implements the layout logic for block formatting contexts.
@@ -51,26 +52,24 @@
     void layoutInFlowContent(InvalidationState&, const ConstraintsForInFlowContent&) override;
     LayoutUnit usedContentHeight() const override;
 
-protected:
-    struct ConstraintsPair {
-        ConstraintsForInFlowContent formattingContextRoot;
-        ConstraintsForInFlowContent containingBlock;
-    };
-    void placeInFlowPositionedChildren(const ContainerBox&, const HorizontalConstraints&);
+    const BlockFormattingState& formattingState() const { return downcast<BlockFormattingState>(FormattingContext::formattingState()); }
 
-    void computeWidthAndMargin(const FloatingContext&, const Box&, const ConstraintsPair&);
-    void computeHeightAndMargin(const Box&, const ConstraintsForInFlowContent&);
+    class Quirks : public FormattingContext::Quirks {
+    public:
+        Quirks(const BlockFormattingContext&);
 
-    void computeStaticHorizontalPosition(const Box&, const HorizontalConstraints&);
-    void computeStaticVerticalPosition(const Box&, const VerticalConstraints&);
-    void computePositionToAvoidFloats(const FloatingContext&, const Box&, const ConstraintsPair&);
-    void computeVerticalPositionForFloatClear(const FloatingContext&, const Box&);
+        bool needsStretching(const Box&) const;
+        LayoutUnit stretchedInFlowHeight(const Box&, ContentHeightAndMargin);
 
-    void precomputeVerticalPositionForBoxAndAncestors(const Box&, const ConstraintsPair&);
+        bool shouldIgnoreCollapsedQuirkMargin(const Box&) const;
+        bool shouldCollapseMarginBeforeWithParentMarginBefore(const Box&) const;
+        bool shouldCollapseMarginAfterWithParentMarginAfter(const Box&) const;
 
-    IntrinsicWidthConstraints computedIntrinsicWidthConstraints() override;
+        const BlockFormattingContext& formattingContext() const { return downcast<BlockFormattingContext>(FormattingContext::Quirks::formattingContext()); }
+        BlockFormattingContext::Geometry geometry() const { return formattingContext().geometry(); }
 
-    LayoutUnit verticalPositionWithMargin(const Box&, const UsedVerticalMargin&, const VerticalConstraints&) const;
+    };
+    BlockFormattingContext::Quirks quirks() const { return Quirks(*this); }
 
     // This class implements positioning and sizing for boxes participating in a block formatting context.
     class Geometry : public FormattingContext::Geometry {
@@ -97,73 +96,31 @@
     };
     BlockFormattingContext::Geometry geometry() const { return Geometry(*this); }
 
-    // This class implements margin collapsing for block formatting context.
-    class MarginCollapse {
-    public:
-        UsedVerticalMargin collapsedVerticalValues(const Box&, UsedVerticalMargin::NonCollapsedValues);
-
-        PrecomputedMarginBefore precomputedMarginBefore(const Box&, UsedVerticalMargin::NonCollapsedValues);
-        LayoutUnit marginBeforeIgnoringCollapsingThrough(const Box&, UsedVerticalMargin::NonCollapsedValues);
-        static void updateMarginAfterForPreviousSibling(BlockFormattingContext&, const MarginCollapse&, const Box&);
-
-        bool marginBeforeCollapsesWithParentMarginBefore(const Box&) const;
-        bool marginBeforeCollapsesWithFirstInFlowChildMarginBefore(const Box&) const;
-        bool marginBeforeCollapsesWithParentMarginAfter(const Box&) const;
-        bool marginBeforeCollapsesWithPreviousSiblingMarginAfter(const Box&) const;
-
-        bool marginAfterCollapsesWithParentMarginAfter(const Box&) const;
-        bool marginAfterCollapsesWithLastInFlowChildMarginAfter(const Box&) const;
-        bool marginAfterCollapsesWithParentMarginBefore(const Box&) const;
-        bool marginAfterCollapsesWithNextSiblingMarginBefore(const Box&) const;
-        bool marginAfterCollapsesWithSiblingMarginBeforeWithClearance(const Box&) const;
-
-        bool marginsCollapseThrough(const Box&) const;
-
-    private:
-        friend class BlockFormattingContext;
-        MarginCollapse(const BlockFormattingContext&);
-
-        enum class MarginType { Before, After };
-        UsedVerticalMargin::PositiveAndNegativePair::Values positiveNegativeValues(const Box&, MarginType) const;
-        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 computedPositiveAndNegativeMargin(UsedVerticalMargin::PositiveAndNegativePair::Values, UsedVerticalMargin::PositiveAndNegativePair::Values) 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; }
-
-        const BlockFormattingContext& m_blockFormattingContext;
+protected:
+    struct ConstraintsPair {
+        ConstraintsForInFlowContent formattingContextRoot;
+        ConstraintsForInFlowContent containingBlock;
     };
-    MarginCollapse marginCollapse() const { return MarginCollapse(*this); }
+    void placeInFlowPositionedChildren(const ContainerBox&, const HorizontalConstraints&);
 
-    class Quirks : public FormattingContext::Quirks {
-    public:
-        Quirks(const BlockFormattingContext&);
+    void computeWidthAndMargin(const FloatingContext&, const Box&, const ConstraintsPair&);
+    void computeHeightAndMargin(const Box&, const ConstraintsForInFlowContent&);
 
-        bool needsStretching(const Box&) const;
-        LayoutUnit stretchedInFlowHeight(const Box&, ContentHeightAndMargin);
+    void computeStaticHorizontalPosition(const Box&, const HorizontalConstraints&);
+    void computeStaticVerticalPosition(const Box&, const VerticalConstraints&);
+    void computePositionToAvoidFloats(const FloatingContext&, const Box&, const ConstraintsPair&);
+    void computeVerticalPositionForFloatClear(const FloatingContext&, const Box&);
 
-        bool shouldIgnoreCollapsedQuirkMargin(const Box&) const;
-        bool shouldCollapseMarginBeforeWithParentMarginBefore(const Box&) const;
-        bool shouldCollapseMarginAfterWithParentMarginAfter(const Box&) const;
+    void precomputeVerticalPositionForBoxAndAncestors(const Box&, const ConstraintsPair&);
 
-        const BlockFormattingContext& formattingContext() const { return downcast<BlockFormattingContext>(FormattingContext::Quirks::formattingContext()); }
-        BlockFormattingContext::Geometry geometry() const { return formattingContext().geometry(); }
+    IntrinsicWidthConstraints computedIntrinsicWidthConstraints() override;
 
-    };
-    BlockFormattingContext::Quirks quirks() const { return Quirks(*this); }
+    LayoutUnit verticalPositionWithMargin(const Box&, const UsedVerticalMargin&, const VerticalConstraints&) const;
 
     Optional<LayoutUnit> usedAvailableWidthForFloatAvoider(const FloatingContext&, const Box&, const ConstraintsPair&);
+    void updateMarginAfterForPreviousSibling(const Box&);
 
-    const BlockFormattingState& formattingState() const { return downcast<BlockFormattingState>(FormattingContext::formattingState()); }
+    BlockMarginCollapse marginCollapse() const;
     BlockFormattingState& formattingState() { return downcast<BlockFormattingState>(FormattingContext::formattingState()); }
 
 #if ASSERT_ENABLED
@@ -185,13 +142,8 @@
 {
 }
 
-inline BlockFormattingContext::MarginCollapse::MarginCollapse(const BlockFormattingContext& blockFormattingContext)
-    : m_blockFormattingContext(blockFormattingContext)
-{
 }
-
 }
-}
 
 SPECIALIZE_TYPE_TRAITS_LAYOUT_FORMATTING_CONTEXT(BlockFormattingContext, isBlockFormattingContext())
 

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


--- trunk/Source/WebCore/layout/formattingContexts/block/BlockMarginCollapse.cpp	2021-05-15 14:26:42 UTC (rev 277539)
+++ trunk/Source/WebCore/layout/formattingContexts/block/BlockMarginCollapse.cpp	2021-05-15 16:21:39 UTC (rev 277540)
@@ -24,7 +24,7 @@
  */
 
 #include "config.h"
-#include "BlockFormattingContext.h"
+#include "BlockMarginCollapse.h"
 
 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)
 
@@ -81,8 +81,13 @@
     return layoutBox.establishesBlockFormattingContext();
 }
 
-bool BlockFormattingContext::MarginCollapse::hasClearance(const Box& layoutBox) const
+BlockMarginCollapse::BlockMarginCollapse(const BlockFormattingContext& blockFormattingContext)
+    : m_blockFormattingContext(blockFormattingContext)
 {
+}
+
+bool BlockMarginCollapse::hasClearance(const Box& layoutBox) const
+{
     if (!layoutBox.hasFloatClear())
         return false;
     // FIXME: precomputedVerticalPositionForFormattingRoot logic ends up calling into this function when the layoutBox (first inflow child) has
@@ -90,7 +95,7 @@
     return formattingContext().formattingState().hasClearance(layoutBox);
 }
 
-bool BlockFormattingContext::MarginCollapse::marginBeforeCollapsesWithParentMarginAfter(const Box& layoutBox) const
+bool BlockMarginCollapse::marginBeforeCollapsesWithParentMarginAfter(const Box& layoutBox) const
 {
     // 1. This is the last in-flow child and its margins collapse through and the margin after collapses with parent's margin after or
     // 2. This box's margin after collapses with the next sibling's margin before and that sibling collapses through and
@@ -108,7 +113,7 @@
     return false;
 }
 
-bool BlockFormattingContext::MarginCollapse::marginBeforeCollapsesWithParentMarginBefore(const Box& layoutBox) const
+bool BlockMarginCollapse::marginBeforeCollapsesWithParentMarginBefore(const Box& layoutBox) const
 {
     // The first inflow child could propagate its top margin to parent.
     // https://www.w3.org/TR/CSS21/box.html#collapsing-margins
@@ -151,7 +156,7 @@
     return true;
 }
 
-bool BlockFormattingContext::MarginCollapse::marginBeforeCollapsesWithPreviousSiblingMarginAfter(const Box& layoutBox) const
+bool BlockMarginCollapse::marginBeforeCollapsesWithPreviousSiblingMarginAfter(const Box& layoutBox) const
 {
     ASSERT(layoutBox.isBlockLevelBox());
 
@@ -180,7 +185,7 @@
     return true;
 }
 
-bool BlockFormattingContext::MarginCollapse::marginBeforeCollapsesWithFirstInFlowChildMarginBefore(const Box& layoutBox) const
+bool BlockMarginCollapse::marginBeforeCollapsesWithFirstInFlowChildMarginBefore(const Box& layoutBox) const
 {
     ASSERT(layoutBox.isBlockLevelBox());
     // Margins of elements that establish new block formatting contexts do not collapse with their in-flow children.
@@ -214,7 +219,7 @@
     return true;
 }
 
-bool BlockFormattingContext::MarginCollapse::marginAfterCollapsesWithSiblingMarginBeforeWithClearance(const Box& layoutBox) const
+bool BlockMarginCollapse::marginAfterCollapsesWithSiblingMarginBeforeWithClearance(const Box& layoutBox) const
 {
     // If the top and bottom margins of an element with clearance are adjoining, its margins collapse with the adjoining margins
     // of following siblings but that resulting margin does not collapse with the bottom margin of the parent block.
@@ -230,7 +235,7 @@
     return false;
 }
 
-bool BlockFormattingContext::MarginCollapse::marginAfterCollapsesWithParentMarginBefore(const Box& layoutBox) const
+bool BlockMarginCollapse::marginAfterCollapsesWithParentMarginBefore(const Box& layoutBox) const
 {
     // 1. This is the first in-flow child and its margins collapse through and the margin before collapses with parent's margin before or
     // 2. This box's margin before collapses with the previous sibling's margin after and that sibling collapses through and
@@ -248,7 +253,7 @@
     return false;
 }
 
-bool BlockFormattingContext::MarginCollapse::marginAfterCollapsesWithParentMarginAfter(const Box& layoutBox) const
+bool BlockMarginCollapse::marginAfterCollapsesWithParentMarginAfter(const Box& layoutBox) const
 {
     ASSERT(layoutBox.isBlockLevelBox());
 
@@ -300,7 +305,7 @@
     return true;
 }
 
-bool BlockFormattingContext::MarginCollapse::marginAfterCollapsesWithLastInFlowChildMarginAfter(const Box& layoutBox) const
+bool BlockMarginCollapse::marginAfterCollapsesWithLastInFlowChildMarginAfter(const Box& layoutBox) const
 {
     ASSERT(layoutBox.isBlockLevelBox());
 
@@ -349,7 +354,7 @@
     return true;
 }
 
-bool BlockFormattingContext::MarginCollapse::marginAfterCollapsesWithNextSiblingMarginBefore(const Box& layoutBox) const
+bool BlockMarginCollapse::marginAfterCollapsesWithNextSiblingMarginBefore(const Box& layoutBox) const
 {
     ASSERT(layoutBox.isBlockLevelBox());
 
@@ -359,7 +364,7 @@
     return marginBeforeCollapsesWithPreviousSiblingMarginAfter(*layoutBox.nextInFlowSibling());
 }
 
-bool BlockFormattingContext::MarginCollapse::marginsCollapseThrough(const Box& layoutBox) const
+bool BlockMarginCollapse::marginsCollapseThrough(const Box& layoutBox) const
 {
     ASSERT(layoutBox.isBlockLevelBox());
 
@@ -431,7 +436,7 @@
     return true;
 }
 
-UsedVerticalMargin::PositiveAndNegativePair::Values BlockFormattingContext::MarginCollapse::computedPositiveAndNegativeMargin(UsedVerticalMargin::PositiveAndNegativePair::Values a, UsedVerticalMargin::PositiveAndNegativePair::Values b) const
+UsedVerticalMargin::PositiveAndNegativePair::Values BlockMarginCollapse::computedPositiveAndNegativeMargin(UsedVerticalMargin::PositiveAndNegativePair::Values a, UsedVerticalMargin::PositiveAndNegativePair::Values b) const
 {
     UsedVerticalMargin::PositiveAndNegativePair::Values computedValues;
     if (a.positive && b.positive)
@@ -454,7 +459,7 @@
     return computedValues;
 }
 
-Optional<LayoutUnit> BlockFormattingContext::MarginCollapse::marginValue(UsedVerticalMargin::PositiveAndNegativePair::Values marginValues) const
+Optional<LayoutUnit> BlockMarginCollapse::marginValue(UsedVerticalMargin::PositiveAndNegativePair::Values marginValues) const
 {
     // When two or more margins collapse, the resulting margin width is the maximum of the collapsing margins' widths.
     // In the case of negative margins, the maximum of the absolute values of the negative adjoining margins is deducted from the maximum
@@ -468,49 +473,8 @@
     return *marginValues.positive + *marginValues.negative;
 }
 
-void BlockFormattingContext::MarginCollapse::updateMarginAfterForPreviousSibling(BlockFormattingContext& blockFormattingContext, const MarginCollapse& marginCollapse, const Box& layoutBox)
+UsedVerticalMargin::PositiveAndNegativePair::Values BlockMarginCollapse::positiveNegativeValues(const Box& layoutBox, MarginType marginType) const
 {
-    // 1. Get the margin before value from the next in-flow sibling. This is the same as this box's margin after value now since they are collapsed.
-    // 2. Update the collapsed margin after value as well as the positive/negative cache.
-    // 3. Check if the box's margins collapse through.
-    // 4. If so, update the positive/negative cache.
-    // 5. In case of collapsed through margins check if the before margin collapes with the previous inflow sibling's after margin.
-    // 6. If so, jump to #2.
-    // 7. No need to propagate to parent because its margin is not computed yet (pre-computed at most).
-    auto* currentBox = &layoutBox;
-    auto& blockFormattingState = blockFormattingContext.formattingState();
-    while (marginCollapse.marginBeforeCollapsesWithPreviousSiblingMarginAfter(*currentBox)) {
-        auto& previousSibling = *currentBox->previousInFlowSibling();
-        auto previousSiblingVerticalMargin = blockFormattingState.usedVerticalMargin(previousSibling);
-
-        auto collapsedVerticalMarginBefore = previousSiblingVerticalMargin.collapsedValues.before;
-        auto collapsedVerticalMarginAfter = blockFormattingContext.geometryForBox(*currentBox).marginBefore();
-
-        auto marginsCollapseThrough = marginCollapse.marginsCollapseThrough(previousSibling);
-        if (marginsCollapseThrough)
-            collapsedVerticalMarginBefore = collapsedVerticalMarginAfter;
-
-        // Update positive/negative cache.
-        auto previousSiblingPositiveNegativeMargin = blockFormattingState.usedVerticalMargin(previousSibling).positiveAndNegativeValues;
-        auto positiveNegativeMarginBefore = blockFormattingState.usedVerticalMargin(*currentBox).positiveAndNegativeValues.before;
-
-        auto adjustedPreviousSiblingVerticalMargin = previousSiblingVerticalMargin;
-        adjustedPreviousSiblingVerticalMargin.positiveAndNegativeValues.after = marginCollapse.computedPositiveAndNegativeMargin(positiveNegativeMarginBefore, previousSiblingPositiveNegativeMargin.after);
-        if (marginsCollapseThrough) {
-            adjustedPreviousSiblingVerticalMargin.positiveAndNegativeValues.before = marginCollapse.computedPositiveAndNegativeMargin(previousSiblingPositiveNegativeMargin.before, adjustedPreviousSiblingVerticalMargin.positiveAndNegativeValues.after);
-            adjustedPreviousSiblingVerticalMargin.positiveAndNegativeValues.after = adjustedPreviousSiblingVerticalMargin.positiveAndNegativeValues.before;
-        }
-        blockFormattingState.setUsedVerticalMargin(previousSibling, adjustedPreviousSiblingVerticalMargin);
-
-        if (!marginsCollapseThrough)
-            break;
-
-        currentBox = &previousSibling;
-    }
-}
-
-UsedVerticalMargin::PositiveAndNegativePair::Values BlockFormattingContext::MarginCollapse::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.
@@ -519,7 +483,7 @@
     return marginType == MarginType::Before ? positiveAndNegativeVerticalMargin.before : positiveAndNegativeVerticalMargin.after; 
 }
 
-UsedVerticalMargin::PositiveAndNegativePair::Values BlockFormattingContext::MarginCollapse::positiveNegativeMarginBefore(const Box& layoutBox, UsedVerticalMargin::NonCollapsedValues nonCollapsedValues) const
+UsedVerticalMargin::PositiveAndNegativePair::Values BlockMarginCollapse::positiveNegativeMarginBefore(const Box& layoutBox, UsedVerticalMargin::NonCollapsedValues nonCollapsedValues) const
 {
     auto firstChildCollapsedMarginBefore = [&]() -> UsedVerticalMargin::PositiveAndNegativePair::Values {
         if (!marginBeforeCollapsesWithFirstInFlowChildMarginBefore(layoutBox))
@@ -549,7 +513,7 @@
     return computedPositiveAndNegativeMargin(collapsedMarginBefore, nonCollapsedBefore);
 }
 
-UsedVerticalMargin::PositiveAndNegativePair::Values BlockFormattingContext::MarginCollapse::positiveNegativeMarginAfter(const Box& layoutBox, UsedVerticalMargin::NonCollapsedValues nonCollapsedValues) const
+UsedVerticalMargin::PositiveAndNegativePair::Values BlockMarginCollapse::positiveNegativeMarginAfter(const Box& layoutBox, UsedVerticalMargin::NonCollapsedValues nonCollapsedValues) const
 {
     auto lastChildCollapsedMarginAfter = [&]() -> UsedVerticalMargin::PositiveAndNegativePair::Values {
         if (!marginAfterCollapsesWithLastInFlowChildMarginAfter(layoutBox))
@@ -568,13 +532,13 @@
     return computedPositiveAndNegativeMargin(lastChildCollapsedMarginAfter(), nonCollapsedAfter);
 }
 
-LayoutUnit BlockFormattingContext::MarginCollapse::marginBeforeIgnoringCollapsingThrough(const Box& layoutBox, UsedVerticalMargin::NonCollapsedValues nonCollapsedValues)
+LayoutUnit BlockMarginCollapse::marginBeforeIgnoringCollapsingThrough(const Box& layoutBox, UsedVerticalMargin::NonCollapsedValues nonCollapsedValues)
 {
     ASSERT(layoutBox.isBlockLevelBox());
     return marginValue(positiveNegativeMarginBefore(layoutBox, nonCollapsedValues)).valueOr(nonCollapsedValues.before);
 }
 
-UsedVerticalMargin BlockFormattingContext::MarginCollapse::collapsedVerticalValues(const Box& layoutBox, UsedVerticalMargin::NonCollapsedValues nonCollapsedValues)
+UsedVerticalMargin BlockMarginCollapse::collapsedVerticalValues(const Box& layoutBox, UsedVerticalMargin::NonCollapsedValues nonCollapsedValues)
 {
     ASSERT(layoutBox.isBlockLevelBox());
     // 1. Get min/max margin top values from the first in-flow child if we are collapsing margin top with it.

Added: trunk/Source/WebCore/layout/formattingContexts/block/BlockMarginCollapse.h (0 => 277540)


--- trunk/Source/WebCore/layout/formattingContexts/block/BlockMarginCollapse.h	                        (rev 0)
+++ trunk/Source/WebCore/layout/formattingContexts/block/BlockMarginCollapse.h	2021-05-15 16:21:39 UTC (rev 277540)
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
+
+#include "BlockFormattingContext.h"
+
+namespace WebCore {
+namespace Layout {
+
+// This class implements margin collapsing for block formatting context.
+class BlockMarginCollapse {
+public:
+    UsedVerticalMargin collapsedVerticalValues(const Box&, UsedVerticalMargin::NonCollapsedValues);
+
+    PrecomputedMarginBefore precomputedMarginBefore(const Box&, UsedVerticalMargin::NonCollapsedValues);
+    LayoutUnit marginBeforeIgnoringCollapsingThrough(const Box&, UsedVerticalMargin::NonCollapsedValues);
+
+    bool marginBeforeCollapsesWithParentMarginBefore(const Box&) const;
+    bool marginBeforeCollapsesWithFirstInFlowChildMarginBefore(const Box&) const;
+    bool marginBeforeCollapsesWithParentMarginAfter(const Box&) const;
+    bool marginBeforeCollapsesWithPreviousSiblingMarginAfter(const Box&) const;
+
+    bool marginAfterCollapsesWithParentMarginAfter(const Box&) const;
+    bool marginAfterCollapsesWithLastInFlowChildMarginAfter(const Box&) const;
+    bool marginAfterCollapsesWithParentMarginBefore(const Box&) const;
+    bool marginAfterCollapsesWithNextSiblingMarginBefore(const Box&) const;
+    bool marginAfterCollapsesWithSiblingMarginBeforeWithClearance(const Box&) const;
+
+    bool marginsCollapseThrough(const Box&) const;
+
+private:
+    friend class BlockFormattingContext;
+    BlockMarginCollapse(const BlockFormattingContext&);
+
+    enum class MarginType { Before, After };
+    UsedVerticalMargin::PositiveAndNegativePair::Values positiveNegativeValues(const Box&, MarginType) const;
+    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 computedPositiveAndNegativeMargin(UsedVerticalMargin::PositiveAndNegativePair::Values, UsedVerticalMargin::PositiveAndNegativePair::Values) 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; }
+
+    const BlockFormattingContext& m_blockFormattingContext;
+};
+
+}
+}
+
+#endif

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


--- trunk/Source/WebCore/layout/formattingContexts/block/PrecomputedBlockMarginCollapse.cpp	2021-05-15 14:26:42 UTC (rev 277539)
+++ trunk/Source/WebCore/layout/formattingContexts/block/PrecomputedBlockMarginCollapse.cpp	2021-05-15 16:21:39 UTC (rev 277540)
@@ -24,7 +24,7 @@
  */
 
 #include "config.h"
-#include "BlockFormattingContext.h"
+#include "BlockMarginCollapse.h"
 
 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)
 
@@ -38,7 +38,7 @@
 namespace WebCore {
 namespace Layout {
 
-UsedVerticalMargin::PositiveAndNegativePair::Values BlockFormattingContext::MarginCollapse::precomputedPositiveNegativeValues(const Box& layoutBox) const
+UsedVerticalMargin::PositiveAndNegativePair::Values BlockMarginCollapse::precomputedPositiveNegativeValues(const Box& layoutBox) const
 {
     auto& blockFormattingState = downcast<BlockFormattingState>(layoutState().formattingStateForBox(layoutBox));
     if (blockFormattingState.hasUsedVerticalMargin(layoutBox))
@@ -51,7 +51,7 @@
     return precomputedPositiveNegativeMarginBefore(layoutBox, nonCollapsedMargin);
 }
 
-UsedVerticalMargin::PositiveAndNegativePair::Values BlockFormattingContext::MarginCollapse::precomputedPositiveNegativeMarginBefore(const Box& layoutBox, UsedVerticalMargin::NonCollapsedValues nonCollapsedValues) const
+UsedVerticalMargin::PositiveAndNegativePair::Values BlockMarginCollapse::precomputedPositiveNegativeMarginBefore(const Box& layoutBox, UsedVerticalMargin::NonCollapsedValues nonCollapsedValues) const
 {
     auto firstChildCollapsedMarginBefore = [&]() -> UsedVerticalMargin::PositiveAndNegativePair::Values {
         if (!marginBeforeCollapsesWithFirstInFlowChildMarginBefore(layoutBox))
@@ -83,7 +83,7 @@
     return computedPositiveAndNegativeMargin(collapsedMarginBefore, nonCollapsedBefore);
 }
 
-PrecomputedMarginBefore BlockFormattingContext::MarginCollapse::precomputedMarginBefore(const Box& layoutBox, UsedVerticalMargin::NonCollapsedValues usedNonCollapsedMargin)
+PrecomputedMarginBefore BlockMarginCollapse::precomputedMarginBefore(const Box& layoutBox, UsedVerticalMargin::NonCollapsedValues usedNonCollapsedMargin)
 {
     ASSERT(layoutBox.isBlockLevelBox());
     // Don't pre-compute vertical margins for out of flow boxes.

Modified: trunk/Source/WebCore/layout/formattingContexts/block/tablewrapper/TableWrapperBlockFormattingContext.cpp (277539 => 277540)


--- trunk/Source/WebCore/layout/formattingContexts/block/tablewrapper/TableWrapperBlockFormattingContext.cpp	2021-05-15 14:26:42 UTC (rev 277539)
+++ trunk/Source/WebCore/layout/formattingContexts/block/tablewrapper/TableWrapperBlockFormattingContext.cpp	2021-05-15 16:21:39 UTC (rev 277540)
@@ -229,7 +229,7 @@
     boxGeometry.setContentBoxHeight(heightAndMargin.contentHeight);
     boxGeometry.setVerticalMargin({ marginBefore(verticalMargin), marginAfter(verticalMargin) });
     // Adjust the previous sibling's margin bottom now that this box's vertical margin is computed.
-    MarginCollapse::updateMarginAfterForPreviousSibling(*this, marginCollapse, tableBox);
+    updateMarginAfterForPreviousSibling(tableBox);
 }
 
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to