Title: [240467] trunk/Source/WebCore
Revision
240467
Author
[email protected]
Date
2019-01-24 20:14:32 -0800 (Thu, 24 Jan 2019)

Log Message

[LFC][BFC][MarginCollapsing] Refactor MarginCollapse::updateCollapsedMarginAfter
https://bugs.webkit.org/show_bug.cgi?id=193807

Reviewed by Simon Fraser.

Rename updateCollapsedMarginAfter to updateMarginAfterForPreviousSibling and make the margin updating logic more explicit.

* layout/blockformatting/BlockFormattingContext.cpp:
(WebCore::Layout::BlockFormattingContext::computeHeightAndMargin const):
* layout/blockformatting/BlockFormattingContext.h:
* layout/blockformatting/BlockMarginCollapse.cpp:
(WebCore::Layout::BlockFormattingContext::MarginCollapse::updateMarginAfterForPreviousSibling):
(WebCore::Layout::BlockFormattingContext::MarginCollapse::updateCollapsedMarginAfter): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (240466 => 240467)


--- trunk/Source/WebCore/ChangeLog	2019-01-25 02:53:27 UTC (rev 240466)
+++ trunk/Source/WebCore/ChangeLog	2019-01-25 04:14:32 UTC (rev 240467)
@@ -1,3 +1,19 @@
+2019-01-24  Zalan Bujtas  <[email protected]>
+
+        [LFC][BFC][MarginCollapsing] Refactor MarginCollapse::updateCollapsedMarginAfter
+        https://bugs.webkit.org/show_bug.cgi?id=193807
+
+        Reviewed by Simon Fraser.
+
+        Rename updateCollapsedMarginAfter to updateMarginAfterForPreviousSibling and make the margin updating logic more explicit.
+
+        * layout/blockformatting/BlockFormattingContext.cpp:
+        (WebCore::Layout::BlockFormattingContext::computeHeightAndMargin const):
+        * layout/blockformatting/BlockFormattingContext.h:
+        * layout/blockformatting/BlockMarginCollapse.cpp:
+        (WebCore::Layout::BlockFormattingContext::MarginCollapse::updateMarginAfterForPreviousSibling):
+        (WebCore::Layout::BlockFormattingContext::MarginCollapse::updateCollapsedMarginAfter): Deleted.
+
 2019-01-24  Joseph Pecoraro  <[email protected]>
 
         Web Inspector: CPU Usage Timeline

Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp (240466 => 240467)


--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp	2019-01-25 02:53:27 UTC (rev 240466)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp	2019-01-25 04:14:32 UTC (rev 240467)
@@ -429,12 +429,10 @@
     ASSERT(!hasEstimatedMarginBefore(layoutBox) || estimatedMarginBefore(layoutBox).usedValue() == verticalMargin.before());
     removeEstimatedMarginBefore(layoutBox);
     displayBox.setTop(adjustedVerticalPositionAfterMarginCollapsing(layoutBox, verticalMargin));
-    // Adjust the previous sibling's margin bottom now that this box's vertical margin is computed.
-    if (MarginCollapse::marginBeforeCollapsesWithPreviousSiblingMarginAfter(layoutState, layoutBox))
-        MarginCollapse::updateCollapsedMarginAfter(layoutState, *layoutBox.previousInFlowSibling(), verticalMargin);
-
     displayBox.setContentBoxHeight(heightAndMargin.height);
     displayBox.setVerticalMargin(verticalMargin);
+    // Adjust the previous sibling's margin bottom now that this box's vertical margin is computed.
+    MarginCollapse::updateMarginAfterForPreviousSibling(layoutState, layoutBox);
 }
 
 FormattingContext::InstrinsicWidthConstraints BlockFormattingContext::instrinsicWidthConstraints() const

Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h (240466 => 240467)


--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h	2019-01-25 02:53:27 UTC (rev 240466)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h	2019-01-25 04:14:32 UTC (rev 240467)
@@ -96,7 +96,7 @@
 
         static EstimatedMarginBefore estimatedMarginBefore(const LayoutState&, const Box&);
         static LayoutUnit marginBeforeIgnoringCollapsingThrough(const LayoutState&, const Box&, const UsedVerticalMargin::NonCollapsedValues&);
-        static void updateCollapsedMarginAfter(const LayoutState&, const Box&, const UsedVerticalMargin& nextSiblingVerticalMargin);
+        static void updateMarginAfterForPreviousSibling(const LayoutState&, const Box&);
 
         static bool marginBeforeCollapsesWithParentMarginBefore(const LayoutState&, const Box&);
         static bool marginBeforeCollapsesWithFirstInFlowChildMarginBefore(const LayoutState&, const Box&);

Modified: trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp (240466 => 240467)


--- trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp	2019-01-25 02:53:27 UTC (rev 240466)
+++ trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp	2019-01-25 04:14:32 UTC (rev 240467)
@@ -481,7 +481,7 @@
     return *marginValues.positive + *marginValues.negative;
 }
 
-void BlockFormattingContext::MarginCollapse::updateCollapsedMarginAfter(const LayoutState& layoutState, const Box& layoutBox, const UsedVerticalMargin& nextSiblingVerticalMargin)
+void BlockFormattingContext::MarginCollapse::updateMarginAfterForPreviousSibling(const LayoutState& layoutState, const Box& layoutBox)
 {
     // 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.
@@ -489,40 +489,41 @@
     // 4. If so, update the collapsed margin before value as well as 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.
-    if (!marginAfterCollapsesWithNextSiblingMarginBefore(layoutState, layoutBox))
-        return;
+    // 7. No need to propagate to parent because its margin is not computed yet (estimated at most).
+    auto* currentBox = &layoutBox;
+    while (marginBeforeCollapsesWithPreviousSiblingMarginAfter(layoutState, *currentBox)) {
+        auto& previousSibling = *currentBox->previousInFlowSibling();
+        auto& previousSiblingDisplayBox = layoutState.displayBoxForLayoutBox(previousSibling);
+        auto previousSiblingVerticalMargin = previousSiblingDisplayBox.verticalMargin();
 
-    auto& displayBox = layoutState.displayBoxForLayoutBox(layoutBox);
-    auto verticalMargin = displayBox.verticalMargin();
-    auto verticalMarginAfter = nextSiblingVerticalMargin.before();
-    Optional<LayoutUnit> verticalMarginBefore;
+        auto collapsedVerticalMarginBefore = previousSiblingVerticalMargin.collapsedValues().before;
+        auto collapsedVerticalMarginAfter = layoutState.displayBoxForLayoutBox(*currentBox).verticalMargin().before();
 
-    auto marginsCollapseThrough = MarginCollapse::marginsCollapseThrough(layoutState, layoutBox);
-    if (marginsCollapseThrough)
-        verticalMarginBefore = verticalMarginAfter; 
-    else if (verticalMargin.hasCollapsedValues())
-        verticalMarginBefore = verticalMargin.collapsedValues().before;
+        auto marginsCollapseThrough = MarginCollapse::marginsCollapseThrough(layoutState, previousSibling);
+        if (marginsCollapseThrough)
+            collapsedVerticalMarginBefore = collapsedVerticalMarginAfter;
 
-    // Update vertical margin values.
-    verticalMargin.setCollapsedValues({ verticalMarginBefore, verticalMarginAfter });
-    displayBox.setVerticalMargin(verticalMargin);
+        // Update collapsed vertical margin values.
+        previousSiblingVerticalMargin.setCollapsedValues({ collapsedVerticalMarginBefore, collapsedVerticalMarginAfter });
+        previousSiblingDisplayBox.setVerticalMargin(previousSiblingVerticalMargin);
 
-    // Update positive/negative cache.
-    auto& blockFormattingState = downcast<BlockFormattingState>(layoutState.formattingStateForBox(layoutBox));
-    auto positiveNegativeMargin = blockFormattingState.positiveAndNegativeVerticalMargin(layoutBox);
-    auto nextSiblingPositiveNegativeMarginBefore = blockFormattingState.positiveAndNegativeVerticalMargin(*layoutBox.nextInFlowSibling()).before;
+        // Update positive/negative cache.
+        auto& blockFormattingState = downcast<BlockFormattingState>(layoutState.formattingStateForBox(previousSibling));
+        auto previousSiblingPositiveNegativeMargin = blockFormattingState.positiveAndNegativeVerticalMargin(previousSibling);
+        auto positiveNegativeMarginBefore = blockFormattingState.positiveAndNegativeVerticalMargin(*currentBox).before;
 
-    positiveNegativeMargin.after = computedPositiveAndNegativeMargin(nextSiblingPositiveNegativeMarginBefore, positiveNegativeMargin.after);
-    if (marginsCollapseThrough) {
-        positiveNegativeMargin.before = computedPositiveAndNegativeMargin(positiveNegativeMargin.before, positiveNegativeMargin.after);
-        positiveNegativeMargin.after = positiveNegativeMargin.before; 
-    }
-    blockFormattingState.setPositiveAndNegativeVerticalMargin(layoutBox, positiveNegativeMargin);
+        previousSiblingPositiveNegativeMargin.after = computedPositiveAndNegativeMargin(positiveNegativeMarginBefore, previousSiblingPositiveNegativeMargin.after);
+        if (marginsCollapseThrough) {
+            previousSiblingPositiveNegativeMargin.before = computedPositiveAndNegativeMargin(previousSiblingPositiveNegativeMargin.before, previousSiblingPositiveNegativeMargin.after);
+            previousSiblingPositiveNegativeMargin.after = previousSiblingPositiveNegativeMargin.before;
+        }
+        blockFormattingState.setPositiveAndNegativeVerticalMargin(previousSibling, previousSiblingPositiveNegativeMargin);
 
-    if (!marginsCollapseThrough || !marginBeforeCollapsesWithPreviousSiblingMarginAfter(layoutState, layoutBox))
-        return;
+        if (!marginsCollapseThrough)
+            break;
 
-    updateCollapsedMarginAfter(layoutState, *layoutBox.previousInFlowSibling(), verticalMargin);
+        currentBox = &previousSibling;
+    }
 }
 
 PositiveAndNegativeVerticalMargin::Values BlockFormattingContext::MarginCollapse::positiveNegativeValues(const LayoutState& layoutState, const Box& layoutBox, MarginType marginType)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to