Changeset 240467 in webkit


Ignore:
Timestamp:
Jan 24, 2019 8:14:32 PM (5 years ago)
Author:
Alan Bujtas
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.

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r240457 r240467  
     12019-01-24  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][BFC][MarginCollapsing] Refactor MarginCollapse::updateCollapsedMarginAfter
     4        https://bugs.webkit.org/show_bug.cgi?id=193807
     5
     6        Reviewed by Simon Fraser.
     7
     8        Rename updateCollapsedMarginAfter to updateMarginAfterForPreviousSibling and make the margin updating logic more explicit.
     9
     10        * layout/blockformatting/BlockFormattingContext.cpp:
     11        (WebCore::Layout::BlockFormattingContext::computeHeightAndMargin const):
     12        * layout/blockformatting/BlockFormattingContext.h:
     13        * layout/blockformatting/BlockMarginCollapse.cpp:
     14        (WebCore::Layout::BlockFormattingContext::MarginCollapse::updateMarginAfterForPreviousSibling):
     15        (WebCore::Layout::BlockFormattingContext::MarginCollapse::updateCollapsedMarginAfter): Deleted.
     16
    1172019-01-24  Joseph Pecoraro  <pecoraro@apple.com>
    218
  • trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp

    r240337 r240467  
    430430    removeEstimatedMarginBefore(layoutBox);
    431431    displayBox.setTop(adjustedVerticalPositionAfterMarginCollapsing(layoutBox, verticalMargin));
    432     // Adjust the previous sibling's margin bottom now that this box's vertical margin is computed.
    433     if (MarginCollapse::marginBeforeCollapsesWithPreviousSiblingMarginAfter(layoutState, layoutBox))
    434         MarginCollapse::updateCollapsedMarginAfter(layoutState, *layoutBox.previousInFlowSibling(), verticalMargin);
    435 
    436432    displayBox.setContentBoxHeight(heightAndMargin.height);
    437433    displayBox.setVerticalMargin(verticalMargin);
     434    // Adjust the previous sibling's margin bottom now that this box's vertical margin is computed.
     435    MarginCollapse::updateMarginAfterForPreviousSibling(layoutState, layoutBox);
    438436}
    439437
  • trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h

    r240337 r240467  
    9797        static EstimatedMarginBefore estimatedMarginBefore(const LayoutState&, const Box&);
    9898        static LayoutUnit marginBeforeIgnoringCollapsingThrough(const LayoutState&, const Box&, const UsedVerticalMargin::NonCollapsedValues&);
    99         static void updateCollapsedMarginAfter(const LayoutState&, const Box&, const UsedVerticalMargin& nextSiblingVerticalMargin);
     99        static void updateMarginAfterForPreviousSibling(const LayoutState&, const Box&);
    100100
    101101        static bool marginBeforeCollapsesWithParentMarginBefore(const LayoutState&, const Box&);
  • trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp

    r240436 r240467  
    482482}
    483483
    484 void BlockFormattingContext::MarginCollapse::updateCollapsedMarginAfter(const LayoutState& layoutState, const Box& layoutBox, const UsedVerticalMargin& nextSiblingVerticalMargin)
     484void BlockFormattingContext::MarginCollapse::updateMarginAfterForPreviousSibling(const LayoutState& layoutState, const Box& layoutBox)
    485485{
    486486    // 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.
     
    490490    // 5. In case of collapsed through margins check if the before margin collapes with the previous inflow sibling's after margin.
    491491    // 6. If so, jump to #2.
    492     if (!marginAfterCollapsesWithNextSiblingMarginBefore(layoutState, layoutBox))
    493         return;
    494 
    495     auto& displayBox = layoutState.displayBoxForLayoutBox(layoutBox);
    496     auto verticalMargin = displayBox.verticalMargin();
    497     auto verticalMarginAfter = nextSiblingVerticalMargin.before();
    498     Optional<LayoutUnit> verticalMarginBefore;
    499 
    500     auto marginsCollapseThrough = MarginCollapse::marginsCollapseThrough(layoutState, layoutBox);
    501     if (marginsCollapseThrough)
    502         verticalMarginBefore = verticalMarginAfter;
    503     else if (verticalMargin.hasCollapsedValues())
    504         verticalMarginBefore = verticalMargin.collapsedValues().before;
    505 
    506     // Update vertical margin values.
    507     verticalMargin.setCollapsedValues({ verticalMarginBefore, verticalMarginAfter });
    508     displayBox.setVerticalMargin(verticalMargin);
    509 
    510     // Update positive/negative cache.
    511     auto& blockFormattingState = downcast<BlockFormattingState>(layoutState.formattingStateForBox(layoutBox));
    512     auto positiveNegativeMargin = blockFormattingState.positiveAndNegativeVerticalMargin(layoutBox);
    513     auto nextSiblingPositiveNegativeMarginBefore = blockFormattingState.positiveAndNegativeVerticalMargin(*layoutBox.nextInFlowSibling()).before;
    514 
    515     positiveNegativeMargin.after = computedPositiveAndNegativeMargin(nextSiblingPositiveNegativeMarginBefore, positiveNegativeMargin.after);
    516     if (marginsCollapseThrough) {
    517         positiveNegativeMargin.before = computedPositiveAndNegativeMargin(positiveNegativeMargin.before, positiveNegativeMargin.after);
    518         positiveNegativeMargin.after = positiveNegativeMargin.before;
    519     }
    520     blockFormattingState.setPositiveAndNegativeVerticalMargin(layoutBox, positiveNegativeMargin);
    521 
    522     if (!marginsCollapseThrough || !marginBeforeCollapsesWithPreviousSiblingMarginAfter(layoutState, layoutBox))
    523         return;
    524 
    525     updateCollapsedMarginAfter(layoutState, *layoutBox.previousInFlowSibling(), verticalMargin);
     492    // 7. No need to propagate to parent because its margin is not computed yet (estimated at most).
     493    auto* currentBox = &layoutBox;
     494    while (marginBeforeCollapsesWithPreviousSiblingMarginAfter(layoutState, *currentBox)) {
     495        auto& previousSibling = *currentBox->previousInFlowSibling();
     496        auto& previousSiblingDisplayBox = layoutState.displayBoxForLayoutBox(previousSibling);
     497        auto previousSiblingVerticalMargin = previousSiblingDisplayBox.verticalMargin();
     498
     499        auto collapsedVerticalMarginBefore = previousSiblingVerticalMargin.collapsedValues().before;
     500        auto collapsedVerticalMarginAfter = layoutState.displayBoxForLayoutBox(*currentBox).verticalMargin().before();
     501
     502        auto marginsCollapseThrough = MarginCollapse::marginsCollapseThrough(layoutState, previousSibling);
     503        if (marginsCollapseThrough)
     504            collapsedVerticalMarginBefore = collapsedVerticalMarginAfter;
     505
     506        // Update collapsed vertical margin values.
     507        previousSiblingVerticalMargin.setCollapsedValues({ collapsedVerticalMarginBefore, collapsedVerticalMarginAfter });
     508        previousSiblingDisplayBox.setVerticalMargin(previousSiblingVerticalMargin);
     509
     510        // Update positive/negative cache.
     511        auto& blockFormattingState = downcast<BlockFormattingState>(layoutState.formattingStateForBox(previousSibling));
     512        auto previousSiblingPositiveNegativeMargin = blockFormattingState.positiveAndNegativeVerticalMargin(previousSibling);
     513        auto positiveNegativeMarginBefore = blockFormattingState.positiveAndNegativeVerticalMargin(*currentBox).before;
     514
     515        previousSiblingPositiveNegativeMargin.after = computedPositiveAndNegativeMargin(positiveNegativeMarginBefore, previousSiblingPositiveNegativeMargin.after);
     516        if (marginsCollapseThrough) {
     517            previousSiblingPositiveNegativeMargin.before = computedPositiveAndNegativeMargin(previousSiblingPositiveNegativeMargin.before, previousSiblingPositiveNegativeMargin.after);
     518            previousSiblingPositiveNegativeMargin.after = previousSiblingPositiveNegativeMargin.before;
     519        }
     520        blockFormattingState.setPositiveAndNegativeVerticalMargin(previousSibling, previousSiblingPositiveNegativeMargin);
     521
     522        if (!marginsCollapseThrough)
     523            break;
     524
     525        currentBox = &previousSibling;
     526    }
    526527}
    527528
Note: See TracChangeset for help on using the changeset viewer.