Changeset 240337 in webkit


Ignore:
Timestamp:
Jan 23, 2019 8:29:53 AM (5 years ago)
Author:
Alan Bujtas
Message:

[LFC][BFC] computeStaticPosition should include estimated computation as well.
https://bugs.webkit.org/show_bug.cgi?id=193719

Reviewed by Antti Koivisto.

Consolidate all static position (non-estimated, estimated) computation in BlockFormattingContext::computeStaticPosition.
It requires to compute width/horizontal margin first, since vertical top estimation needs valid horizontal widths (margin-top: 5% is computed using
the containing block's width).
This is also in preparation for moving 'clear' positioning to computeStaticPosition.

  • layout/blockformatting/BlockFormattingContext.cpp:

(WebCore::Layout::BlockFormattingContext::layout const):
(WebCore::Layout::BlockFormattingContext::layoutFormattingContextRoot const):
(WebCore::Layout::BlockFormattingContext::computeStaticPosition const):
(WebCore::Layout::BlockFormattingContext::computeEstimatedVerticalPosition const):
(WebCore::Layout::BlockFormattingContext::computeEstimatedVerticalPositionForAncestors const):
(WebCore::Layout::BlockFormattingContext::computeEstimatedVerticalPositionForFormattingRoot const):
(WebCore::Layout::BlockFormattingContext::computeEstimatedVerticalPositionForFloatClear const):
(WebCore::Layout::BlockFormattingContext::computeVerticalPositionForFloatClear const):
(WebCore::Layout::BlockFormattingContext::computeWidthAndMargin const):
(WebCore::Layout::BlockFormattingContext::computeHeightAndMargin const):
(WebCore::Layout::BlockFormattingContext::adjustedVerticalPositionAfterMarginCollapsing const):
(WebCore::Layout::BlockFormattingContext::computeEstimatedMarginBefore const): Deleted.
(WebCore::Layout::BlockFormattingContext::computeEstimatedMarginBeforeForAncestors const): Deleted.
(WebCore::Layout::BlockFormattingContext::precomputeVerticalPositionForFormattingRootIfNeeded const): Deleted.

  • layout/blockformatting/BlockFormattingContext.h:
  • layout/blockformatting/BlockFormattingContextGeometry.cpp:

(WebCore::Layout::BlockFormattingContext::Geometry::staticPosition):

  • layout/blockformatting/BlockMarginCollapse.cpp:

(WebCore::Layout::BlockFormattingContext::MarginCollapse::marginBeforeCollapsesWithFirstInFlowChildMarginBefore):

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r240336 r240337  
     12019-01-23  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][BFC] computeStaticPosition should include estimated computation as well.
     4        https://bugs.webkit.org/show_bug.cgi?id=193719
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Consolidate all static position (non-estimated, estimated) computation in BlockFormattingContext::computeStaticPosition.
     9        It requires to compute width/horizontal margin first, since vertical top estimation needs valid horizontal widths (margin-top: 5% is computed using
     10        the containing block's width).
     11        This is also in preparation for moving 'clear' positioning to computeStaticPosition.
     12
     13        * layout/blockformatting/BlockFormattingContext.cpp:
     14        (WebCore::Layout::BlockFormattingContext::layout const):
     15        (WebCore::Layout::BlockFormattingContext::layoutFormattingContextRoot const):
     16        (WebCore::Layout::BlockFormattingContext::computeStaticPosition const):
     17        (WebCore::Layout::BlockFormattingContext::computeEstimatedVerticalPosition const):
     18        (WebCore::Layout::BlockFormattingContext::computeEstimatedVerticalPositionForAncestors const):
     19        (WebCore::Layout::BlockFormattingContext::computeEstimatedVerticalPositionForFormattingRoot const):
     20        (WebCore::Layout::BlockFormattingContext::computeEstimatedVerticalPositionForFloatClear const):
     21        (WebCore::Layout::BlockFormattingContext::computeVerticalPositionForFloatClear const):
     22        (WebCore::Layout::BlockFormattingContext::computeWidthAndMargin const):
     23        (WebCore::Layout::BlockFormattingContext::computeHeightAndMargin const):
     24        (WebCore::Layout::BlockFormattingContext::adjustedVerticalPositionAfterMarginCollapsing const):
     25        (WebCore::Layout::BlockFormattingContext::computeEstimatedMarginBefore const): Deleted.
     26        (WebCore::Layout::BlockFormattingContext::computeEstimatedMarginBeforeForAncestors const): Deleted.
     27        (WebCore::Layout::BlockFormattingContext::precomputeVerticalPositionForFormattingRootIfNeeded const): Deleted.
     28        * layout/blockformatting/BlockFormattingContext.h:
     29        * layout/blockformatting/BlockFormattingContextGeometry.cpp:
     30        (WebCore::Layout::BlockFormattingContext::Geometry::staticPosition):
     31        * layout/blockformatting/BlockMarginCollapse.cpp:
     32        (WebCore::Layout::BlockFormattingContext::MarginCollapse::marginBeforeCollapsesWithFirstInFlowChildMarginBefore):
     33
    1342019-01-22  Simon Fraser  <simon.fraser@apple.com>
    235
  • trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp

    r240253 r240337  
    8989
    9090            LOG_WITH_STREAM(FormattingContextLayout, stream << "[Compute] -> [Position][Border][Padding][Width][Margin] -> for layoutBox(" << &layoutBox << ")");
    91             computeStaticPosition(layoutBox);
    9291            computeBorderAndPadding(layoutBox);
    9392            computeWidthAndMargin(layoutBox);
     93            computeStaticPosition(layoutBox);
    9494            if (!is<Container>(layoutBox) || !downcast<Container>(layoutBox).hasInFlowOrFloatingChild())
    9595                break;
     
    129129    // Start laying out this formatting root in the formatting contenxt it lives in.
    130130    LOG_WITH_STREAM(FormattingContextLayout, stream << "[Compute] -> [Position][Border][Padding][Width][Margin] -> for layoutBox(" << &layoutBox << ")");
    131     computeStaticPosition(layoutBox);
    132131    computeBorderAndPadding(layoutBox);
    133132    computeWidthAndMargin(layoutBox);
    134 
    135     precomputeVerticalPositionForFormattingRootIfNeeded(layoutBox);
     133    computeStaticPosition(layoutBox);
    136134    // Swich over to the new formatting context (the one that the root creates).
    137135    auto formattingContext = layoutState().createFormattingContext(layoutBox);
     
    183181    auto& layoutState = this->layoutState();
    184182    layoutState.displayBoxForLayoutBox(layoutBox).setTopLeft(Geometry::staticPosition(layoutState, layoutBox));
    185 }
    186 
    187 void BlockFormattingContext::computeEstimatedMarginBefore(const Box& layoutBox) const
     183    if (layoutBox.hasFloatClear())
     184        computeEstimatedVerticalPositionForFloatClear(layoutBox);
     185    else if (layoutBox.establishesFormattingContext())
     186        computeEstimatedVerticalPositionForFormattingRoot(layoutBox);
     187}
     188
     189void BlockFormattingContext::computeEstimatedVerticalPosition(const Box& layoutBox) const
    188190{
    189191    auto& layoutState = this->layoutState();
     
    195197    auto collapsedValues = UsedVerticalMargin::CollapsedValues { estimatedMarginBefore.collapsedValue, { }, estimatedMarginBefore.isCollapsedThrough };
    196198    auto verticalMargin = UsedVerticalMargin { nonCollapsedValues, collapsedValues };
     199    displayBox.setVerticalMargin(verticalMargin);
    197200    displayBox.setTop(adjustedVerticalPositionAfterMarginCollapsing(layoutBox, verticalMargin));
    198201#if !ASSERT_DISABLED
     
    201204}
    202205
    203 void BlockFormattingContext::computeEstimatedMarginBeforeForAncestors(const Box& layoutBox) const
     206void BlockFormattingContext::computeEstimatedVerticalPositionForAncestors(const Box& layoutBox) const
    204207{
    205208    // We only need to estimate margin top for float related layout (formatting context roots avoid floats).
     
    214217    // So when we get to the point where we intersect the box with the float to decide if the box needs to move, we don't yet have the final vertical position.
    215218    //
    216     // 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 margin.
     219    // 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.
    217220    for (auto* ancestor = layoutBox.containingBlock(); ancestor && !ancestor->establishesBlockFormattingContext(); ancestor = ancestor->containingBlock()) {
    218221        // FIXME: with incremental layout, we might actually have a valid (non-estimated) margin top as well.
    219222        if (hasEstimatedMarginBefore(*ancestor))
    220223            return;
    221 
    222         computeEstimatedMarginBefore(*ancestor);
    223     }
    224 }
    225 
    226 void BlockFormattingContext::precomputeVerticalPositionForFormattingRootIfNeeded(const Box& layoutBox) const
     224        computeEstimatedVerticalPosition(*ancestor);
     225    }
     226}
     227
     228void BlockFormattingContext::computeEstimatedVerticalPositionForFormattingRoot(const Box& layoutBox) const
    227229{
    228230    ASSERT(layoutBox.establishesFormattingContext());
    229 
    230     auto avoidsFloats = layoutBox.isFloatingPositioned() || layoutBox.establishesBlockFormattingContext() || layoutBox.hasFloatClear();
     231    ASSERT(!layoutBox.hasFloatClear());
     232
     233    auto avoidsFloats = layoutBox.isFloatingPositioned() || layoutBox.establishesBlockFormattingContext();
    231234    if (avoidsFloats)
    232         computeEstimatedMarginBeforeForAncestors(layoutBox);
     235        computeEstimatedVerticalPositionForAncestors(layoutBox);
    233236
    234237    // If the inline formatting root is also the root for the floats (happens when the root box also establishes a block formatting context)
     
    236239    auto inlineContextInheritsFloats = layoutBox.establishesInlineFormattingContext() && !layoutBox.establishesBlockFormattingContext();
    237240    if (inlineContextInheritsFloats) {
    238         computeEstimatedMarginBefore(layoutBox);
    239         computeEstimatedMarginBeforeForAncestors(layoutBox);
    240     }
     241        computeEstimatedVerticalPosition(layoutBox);
     242        computeEstimatedVerticalPositionForAncestors(layoutBox);
     243    }
     244}
     245
     246void BlockFormattingContext::computeEstimatedVerticalPositionForFloatClear(const Box&) const
     247{
    241248}
    242249
     
    294301    // For formatting roots, we already precomputed final position.
    295302    if (!layoutBox.establishesFormattingContext())
    296         computeEstimatedMarginBeforeForAncestors(layoutBox);
     303        computeEstimatedVerticalPositionForAncestors(layoutBox);
    297304    ASSERT(hasPrecomputedMarginBefore(layoutBox));
    298305
     
    366373    auto& displayBox = layoutState.displayBoxForLayoutBox(layoutBox);
    367374    displayBox.setContentBoxWidth(widthAndMargin.width);
    368     displayBox.moveHorizontally(widthAndMargin.usedMargin.start);
    369375    displayBox.setHorizontalMargin(widthAndMargin.usedMargin);
    370376    displayBox.setHorizontalComputedMargin(widthAndMargin.computedMargin);
     
    407413
    408414    // 1. Compute collapsed margins.
    409     // 2. Adjust vertical position using the collaped values
     415    // 2. Adjust vertical position using the collapsed values
    410416    // 3. Adjust previous in-flow sibling margin after using this margin.
    411417    auto collapsedMargin = MarginCollapse::collapsedVerticalValues(layoutState, layoutBox, heightAndMargin.nonCollapsedMargin);
     
    500506    ASSERT(!layoutBox.isOutOfFlowPositioned());
    501507    // Now that we've computed the final margin before, let's shift the box's vertical position.
    502     // 1. Check if the margin before collapses with the previous box's margin after. if not -> return previous box's bottom inlcuding margin after + marginBefore
     508    // 1. Check if the margin before collapses with the previous box's margin after. if not -> return previous box's bottom including margin after + marginBefore
    503509    // 2. Check if the previous box's margins collapse through. If not -> return previous box' bottom excluding margin after + marginBefore (they are supposed to be equal)
    504510    // 3. Go to previous box and start from step #1 until we hit the parent box.
  • trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h

    r239903 r240337  
    6464    void computeVerticalPositionForFloatClear(const FloatingContext&, const Box&) const;
    6565
    66     void computeEstimatedMarginBeforeForAncestors(const Box&) const;
    67     void computeEstimatedMarginBefore(const Box&) const;
    68 
    69     void precomputeVerticalPositionForFormattingRootIfNeeded(const Box&) const;
     66    void computeEstimatedVerticalPosition(const Box&) const;
     67    void computeEstimatedVerticalPositionForAncestors(const Box&) const;
     68    void computeEstimatedVerticalPositionForFormattingRoot(const Box&) const;
     69    void computeEstimatedVerticalPositionForFloatClear(const Box&) const;
    7070
    7171    InstrinsicWidthConstraints instrinsicWidthConstraints() const override;
  • trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp

    r240108 r240337  
    237237        top = containingBlockDisplayBox.contentBoxTop();
    238238
    239     auto left = containingBlockDisplayBox.contentBoxLeft();
     239    auto left = containingBlockDisplayBox.contentBoxLeft() + layoutState.displayBoxForLayoutBox(layoutBox).marginStart();
    240240    LOG_WITH_STREAM(FormattingContextLayout, stream << "[Position] -> static -> top(" << top << "px) left(" << left << "px) layoutBox(" << &layoutBox << ")");
    241241    return { left, top };
  • trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp

    r240146 r240337  
    188188        return false;
    189189
    190     // Margins of elements that establish new block formatting contexts do not collapse with their in-flow children.
    191     if (establishesBlockFormattingContext(layoutBox))
    192         return false;
    193 
    194190    // The top margin of an in-flow block element collapses with its first in-flow block-level
    195191    // child's top margin if the element has no top border...
Note: See TracChangeset for help on using the changeset viewer.