Changeset 258819 in webkit


Ignore:
Timestamp:
Mar 22, 2020 7:02:37 AM (4 years ago)
Author:
Alan Bujtas
Message:

[LFC] Layout::Box::containingBlock should return a const ContainerBox&
https://bugs.webkit.org/show_bug.cgi?id=209381
<rdar://problem/60732278>

Reviewed by Antti Koivisto.

Layout tree is immutable during layout, so every box should be able to return a valid containing block (except the ICB).
(This patch also removes the unused isDescendantOf() function and renames isDescendantOfFormattingRoot to isInFormattingContextOf).

  • layout/FormattingContext.cpp:

(WebCore::Layout::FormattingContext::layoutOutOfFlowContent):
(WebCore::Layout::FormattingContext::validateGeometryConstraintsAfterLayout const):

  • layout/FormattingContextGeometry.cpp:

(WebCore::Layout::isHeightAuto):
(WebCore::Layout::FormattingContext::Geometry::computedHeightValue const):
(WebCore::Layout::FormattingContext::Geometry::staticVerticalPositionForOutOfFlowPositioned const):
(WebCore::Layout::FormattingContext::Geometry::staticHorizontalPositionForOutOfFlowPositioned const):
(WebCore::Layout::FormattingContext::Geometry::outOfFlowNonReplacedHorizontalGeometry):
(WebCore::Layout::FormattingContext::Geometry::outOfFlowReplacedHorizontalGeometry const):
(WebCore::Layout::FormattingContext::Geometry::inFlowPositionedPositionOffset const):

  • layout/FormattingContextQuirks.cpp:

(WebCore::Layout::FormattingContext::Quirks::heightValueOfNearestContainingBlockWithFixedHeight):

  • layout/Verification.cpp:

(WebCore::Layout::outputMismatchingBlockBoxInformationIfNeeded):

  • layout/blockformatting/BlockFormattingContext.cpp:

(WebCore::Layout::BlockFormattingContext::layoutInFlowContent):
(WebCore::Layout::BlockFormattingContext::usedAvailableWidthForFloatAvoider):
(WebCore::Layout::BlockFormattingContext::precomputeVerticalPositionForAncestors):
(WebCore::Layout::BlockFormattingContext::precomputeVerticalPositionForBoxAndAncestors):
(WebCore::Layout::BlockFormattingContext::verticalPositionWithMargin const):

  • layout/blockformatting/BlockFormattingContextGeometry.cpp:

(WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedWidthAndMargin const):

  • layout/blockformatting/BlockFormattingContextQuirks.cpp:

(WebCore::Layout::BlockFormattingContext::Quirks::stretchedInFlowHeight):
(WebCore::Layout::initialContainingBlock): Deleted.

  • layout/blockformatting/BlockMarginCollapse.cpp:

(WebCore::Layout::BlockFormattingContext::MarginCollapse::marginsCollapseThrough const):

  • layout/blockformatting/PrecomputedBlockMarginCollapse.cpp:

(WebCore::Layout::BlockFormattingContext::MarginCollapse::precomputedPositiveNegativeValues const):

  • layout/displaytree/DisplayPainter.cpp:

(WebCore::Display::absoluteDisplayBox):

  • layout/floats/FloatingContext.cpp:

(WebCore::Layout::FloatingContext::verticalPositionWithClearance const):
(WebCore::Layout::FloatingContext::absoluteDisplayBoxCoordinates const):
(WebCore::Layout::FloatingContext::mapToFloatingStateRoot const):
(WebCore::Layout::FloatingContext::mapTopToFloatingStateRoot const):
(WebCore::Layout::FloatingContext::mapPointFromFormattingContextRootToFloatingStateRoot const):

  • layout/floats/FloatingState.cpp:

(WebCore::Layout::FloatingState::bottom const):
(WebCore::Layout::FloatingState::top const):

  • layout/floats/FloatingState.h:

(WebCore::Layout::FloatingState::FloatItem::isInFormattingContextOf const):
(WebCore::Layout::FloatingState::FloatItem::isDescendantOfFormattingRoot const): Deleted.

  • layout/layouttree/LayoutBox.cpp:

(WebCore::Layout::Box::containingBlock const):
(WebCore::Layout::Box::formattingContextRoot const):
(WebCore::Layout::Box::isInFormattingContextOf const):
(WebCore::Layout::Box::isDescendantOf const): Deleted.
(WebCore::Layout::Box::isContainingBlockDescendantOf const): Deleted.

  • layout/layouttree/LayoutBox.h:
Location:
trunk/Source/WebCore
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r258817 r258819  
     12020-03-22  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC] Layout::Box::containingBlock should return a const ContainerBox&
     4        https://bugs.webkit.org/show_bug.cgi?id=209381
     5        <rdar://problem/60732278>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        Layout tree is immutable during layout, so every box should be able to return a valid containing block (except the ICB).
     10        (This patch also removes the unused isDescendantOf() function and renames isDescendantOfFormattingRoot to isInFormattingContextOf).
     11
     12        * layout/FormattingContext.cpp:
     13        (WebCore::Layout::FormattingContext::layoutOutOfFlowContent):
     14        (WebCore::Layout::FormattingContext::validateGeometryConstraintsAfterLayout const):
     15        * layout/FormattingContextGeometry.cpp:
     16        (WebCore::Layout::isHeightAuto):
     17        (WebCore::Layout::FormattingContext::Geometry::computedHeightValue const):
     18        (WebCore::Layout::FormattingContext::Geometry::staticVerticalPositionForOutOfFlowPositioned const):
     19        (WebCore::Layout::FormattingContext::Geometry::staticHorizontalPositionForOutOfFlowPositioned const):
     20        (WebCore::Layout::FormattingContext::Geometry::outOfFlowNonReplacedHorizontalGeometry):
     21        (WebCore::Layout::FormattingContext::Geometry::outOfFlowReplacedHorizontalGeometry const):
     22        (WebCore::Layout::FormattingContext::Geometry::inFlowPositionedPositionOffset const):
     23        * layout/FormattingContextQuirks.cpp:
     24        (WebCore::Layout::FormattingContext::Quirks::heightValueOfNearestContainingBlockWithFixedHeight):
     25        * layout/Verification.cpp:
     26        (WebCore::Layout::outputMismatchingBlockBoxInformationIfNeeded):
     27        * layout/blockformatting/BlockFormattingContext.cpp:
     28        (WebCore::Layout::BlockFormattingContext::layoutInFlowContent):
     29        (WebCore::Layout::BlockFormattingContext::usedAvailableWidthForFloatAvoider):
     30        (WebCore::Layout::BlockFormattingContext::precomputeVerticalPositionForAncestors):
     31        (WebCore::Layout::BlockFormattingContext::precomputeVerticalPositionForBoxAndAncestors):
     32        (WebCore::Layout::BlockFormattingContext::verticalPositionWithMargin const):
     33        * layout/blockformatting/BlockFormattingContextGeometry.cpp:
     34        (WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedWidthAndMargin const):
     35        * layout/blockformatting/BlockFormattingContextQuirks.cpp:
     36        (WebCore::Layout::BlockFormattingContext::Quirks::stretchedInFlowHeight):
     37        (WebCore::Layout::initialContainingBlock): Deleted.
     38        * layout/blockformatting/BlockMarginCollapse.cpp:
     39        (WebCore::Layout::BlockFormattingContext::MarginCollapse::marginsCollapseThrough const):
     40        * layout/blockformatting/PrecomputedBlockMarginCollapse.cpp:
     41        (WebCore::Layout::BlockFormattingContext::MarginCollapse::precomputedPositiveNegativeValues const):
     42        * layout/displaytree/DisplayPainter.cpp:
     43        (WebCore::Display::absoluteDisplayBox):
     44        * layout/floats/FloatingContext.cpp:
     45        (WebCore::Layout::FloatingContext::verticalPositionWithClearance const):
     46        (WebCore::Layout::FloatingContext::absoluteDisplayBoxCoordinates const):
     47        (WebCore::Layout::FloatingContext::mapToFloatingStateRoot const):
     48        (WebCore::Layout::FloatingContext::mapTopToFloatingStateRoot const):
     49        (WebCore::Layout::FloatingContext::mapPointFromFormattingContextRootToFloatingStateRoot const):
     50        * layout/floats/FloatingState.cpp:
     51        (WebCore::Layout::FloatingState::bottom const):
     52        (WebCore::Layout::FloatingState::top const):
     53        * layout/floats/FloatingState.h:
     54        (WebCore::Layout::FloatingState::FloatItem::isInFormattingContextOf const):
     55        (WebCore::Layout::FloatingState::FloatItem::isDescendantOfFormattingRoot const): Deleted.
     56        * layout/layouttree/LayoutBox.cpp:
     57        (WebCore::Layout::Box::containingBlock const):
     58        (WebCore::Layout::Box::formattingContextRoot const):
     59        (WebCore::Layout::Box::isInFormattingContextOf const):
     60        (WebCore::Layout::Box::isDescendantOf const): Deleted.
     61        (WebCore::Layout::Box::isContainingBlockDescendantOf const): Deleted.
     62        * layout/layouttree/LayoutBox.h:
     63
    1642020-03-21  Said Abou-Hallawa  <sabouhallawa@apple.com>
    265
  • trunk/Source/WebCore/layout/FormattingContext.cpp

    r257059 r258819  
    140140
    141141    auto horizontalConstraintsForLayoutBox = [&] (const auto& outOfFlowBox) {
    142         auto* containingBlock = outOfFlowBox.containingBlock();
    143         ASSERT(containingBlock);
    144         if (containingBlock == &root())
     142        auto& containingBlock = outOfFlowBox.containingBlock();
     143        if (&containingBlock == &root())
    145144            return rootHorizontalConstraints;
    146         return Geometry::horizontalConstraintsForOutOfFlow(geometryForBox(*containingBlock));
     145        return Geometry::horizontalConstraintsForOutOfFlow(geometryForBox(containingBlock));
    147146    };
    148147
    149148    auto verticalConstraintsForLayoutBox = [&] (const auto& outOfFlowBox) {
    150         auto* containingBlock = outOfFlowBox.containingBlock();
    151         ASSERT(containingBlock);
    152         if (containingBlock == &root())
     149        auto& containingBlock = outOfFlowBox.containingBlock();
     150        if (&containingBlock == &root())
    153151            return rootVerticalConstraints;
    154         return Geometry::verticalConstraintsForOutOfFlow(geometryForBox(*containingBlock));
     152        return Geometry::verticalConstraintsForOutOfFlow(geometryForBox(containingBlock));
    155153    };
    156154
     
    304302        if (&layoutBox.formattingContextRoot() != &formattingContextRoot)
    305303            continue;
    306         auto& containingBlockGeometry = geometryForBox(*layoutBox.containingBlock());
     304        auto& containingBlockGeometry = geometryForBox(layoutBox.containingBlock());
    307305        auto& boxGeometry = geometryForBox(layoutBox);
    308306
  • trunk/Source/WebCore/layout/FormattingContextGeometry.cpp

    r257537 r258819  
    5555            return false;
    5656
    57         return !layoutBox.containingBlock()->style().logicalHeight().isFixed();
     57        return !layoutBox.containingBlock().style().logicalHeight().isFixed();
    5858    }
    5959
     
    7777            containingBlockHeight = formattingContext().quirks().heightValueOfNearestContainingBlockWithFixedHeight(layoutBox);
    7878        else {
    79             auto containingBlockHeightFromStyle = layoutBox.containingBlock()->style().logicalHeight();
     79            auto containingBlockHeightFromStyle = layoutBox.containingBlock().style().logicalHeight();
    8080            if (containingBlockHeightFromStyle.isFixed())
    8181                containingBlockHeight = LayoutUnit { containingBlockHeightFromStyle.value() };
     
    239239
    240240    // Resolve top all the way up to the containing block.
    241     auto& containingBlock = *layoutBox.containingBlock();
     241    auto& containingBlock = layoutBox.containingBlock();
    242242    // Start with the parent since we pretend that this box is normal flow.
    243     for (auto* containerBox = layoutBox.parent(); containerBox != &containingBlock; containerBox = containerBox->containingBlock()) {
    244         auto& boxGeometry = formattingContext.geometryForBox(*containerBox, EscapeReason::OutOfFlowBoxNeedsInFlowGeometry);
     243    for (auto* ancestor = layoutBox.parent(); ancestor != &containingBlock; ancestor = &ancestor->containingBlock()) {
     244        auto& boxGeometry = formattingContext.geometryForBox(*ancestor, EscapeReason::OutOfFlowBoxNeedsInFlowGeometry);
    245245        // Display::Box::top is the border box top position in its containing block's coordinate system.
    246246        top += boxGeometry.top();
    247         ASSERT(!containerBox->isPositioned() || layoutBox.isFixedPositioned());
     247        ASSERT(!ancestor->isPositioned() || layoutBox.isFixedPositioned());
    248248    }
    249249    // Move the static position relative to the padding box. This is very specific to abolutely positioned boxes.
     
    262262
    263263    // Resolve left all the way up to the containing block.
    264     auto& containingBlock = *layoutBox.containingBlock();
     264    auto& containingBlock = layoutBox.containingBlock();
    265265    // Start with the parent since we pretend that this box is normal flow.
    266     for (auto* containerBox = layoutBox.parent(); containerBox != &containingBlock; containerBox = containerBox->containingBlock()) {
    267         auto& boxGeometry = formattingContext.geometryForBox(*containerBox, EscapeReason::OutOfFlowBoxNeedsInFlowGeometry);
     266    for (auto* ancestor = layoutBox.parent(); ancestor != &containingBlock; ancestor = &ancestor->containingBlock()) {
     267        auto& boxGeometry = formattingContext.geometryForBox(*ancestor, EscapeReason::OutOfFlowBoxNeedsInFlowGeometry);
    268268        // Display::Box::left is the border box left position in its containing block's coordinate system.
    269269        left += boxGeometry.left();
    270         ASSERT(!containerBox->isPositioned() || layoutBox.isFixedPositioned());
     270        ASSERT(!ancestor->isPositioned() || layoutBox.isFixedPositioned());
    271271    }
    272272    // Move the static position relative to the padding box. This is very specific to abolutely positioned boxes.
     
    452452    auto& boxGeometry = formattingContext.geometryForBox(layoutBox);
    453453    auto containingBlockWidth = horizontalConstraints.logicalWidth;
    454     auto isLeftToRightDirection = layoutBox.containingBlock()->style().isLeftToRightDirection();
     454    auto isLeftToRightDirection = layoutBox.containingBlock().style().isLeftToRightDirection();
    455455   
    456456    auto left = computedValueIfNotAuto(style.logicalLeft(), containingBlockWidth);
     
    665665    auto& boxGeometry = formattingContext.geometryForBox(replacedBox);
    666666    auto containingBlockWidth = horizontalConstraints.logicalWidth;
    667     auto isLeftToRightDirection = replacedBox.containingBlock()->style().isLeftToRightDirection();
     667    auto isLeftToRightDirection = replacedBox.containingBlock().style().isLeftToRightDirection();
    668668
    669669    auto left = computedValueIfNotAuto(style.logicalLeft(), containingBlockWidth);
     
    10261026    } else {
    10271027        // #4
    1028         auto isLeftToRightDirection = layoutBox.containingBlock()->style().isLeftToRightDirection();
     1028        auto isLeftToRightDirection = layoutBox.containingBlock().style().isLeftToRightDirection();
    10291029        if (isLeftToRightDirection)
    10301030            right = -*left;
  • trunk/Source/WebCore/layout/FormattingContextQuirks.cpp

    r254666 r258819  
    4040    // the current formatting context. FIXME: surely we need to do some tricks here when block direction support is added.
    4141    auto& formattingContext = this->formattingContext();
    42     auto* containingBlock = layoutBox.containingBlock();
     42    auto* containingBlock = &layoutBox.containingBlock();
    4343    LayoutUnit bodyAndDocumentVerticalMarginPaddingAndBorder;
    4444    while (containingBlock) {
     
    5252            auto& boxGeometry = formattingContext.geometryForBox(*containingBlock, FormattingContext::EscapeReason::FindFixedHeightAncestorQuirk);
    5353
    54             auto& containingBlockDisplayBox = formattingContext.geometryForBox(*containingBlock->containingBlock(), FormattingContext::EscapeReason::FindFixedHeightAncestorQuirk);
     54            auto& containingBlockDisplayBox = formattingContext.geometryForBox(containingBlock->containingBlock(), FormattingContext::EscapeReason::FindFixedHeightAncestorQuirk);
    5555            auto horizontalConstraints = Geometry::horizontalConstraintsForInFlow(containingBlockDisplayBox);
    5656            auto verticalMargin = formattingContext.geometry().computedVerticalMargin(*containingBlock, horizontalConstraints);
     
    6060        }
    6161
    62         containingBlock = containingBlock->containingBlock();
     62        if (containingBlock->isInitialContainingBlock())
     63            break;
     64        containingBlock = &containingBlock->containingBlock();
    6365    }
    6466    // Initial containing block has to have a height.
  • trunk/Source/WebCore/layout/Verification.cpp

    r258079 r258819  
    252252        // When the <table> is out-of-flow positioned, the wrapper table box has the offset
    253253        // while the actual table box is static, inflow.
    254         auto& tableWrapperDisplayBox = context.displayBoxForLayoutBox(*layoutBox.containingBlock());
     254        auto& tableWrapperDisplayBox = context.displayBoxForLayoutBox(layoutBox.containingBlock());
    255255        displayBox.moveBy(tableWrapperDisplayBox.topLeft());
    256256    }
  • trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp

    r257718 r258819  
    9292
    9393    auto horizontalConstraintsForLayoutBox = [&] (const auto& layoutBox) {
    94         auto* containingBlock = layoutBox.containingBlock();
    95         ASSERT(containingBlock);
    96         if (containingBlock == &formattingRoot)
     94        auto& containingBlock = layoutBox.containingBlock();
     95        if (&containingBlock == &formattingRoot)
    9796            return rootHorizontalConstraints;
    98         return Geometry::horizontalConstraintsForInFlow(geometryForBox(*containingBlock));
     97        return Geometry::horizontalConstraintsForInFlow(geometryForBox(containingBlock));
    9998    };
    10099
    101100    auto verticalConstraintsForLayoutBox = [&] (const auto& layoutBox) {
    102         auto* containingBlock = layoutBox.containingBlock();
    103         ASSERT(containingBlock);
    104         if (containingBlock == &formattingRoot)
     101        auto& containingBlock = layoutBox.containingBlock();
     102        if (&containingBlock == &formattingRoot)
    105103            return rootVerticalConstraints;
    106         return Geometry::verticalConstraintsForInFlow(geometryForBox(*containingBlock));
     104        return Geometry::verticalConstraintsForInFlow(geometryForBox(containingBlock));
    107105    };
    108106
     
    212210    auto mapLogicalTopToFormattingContextRoot = [&] {
    213211        auto& formattingContextRoot = root();
    214         ASSERT(layoutBox.isContainingBlockDescendantOf(formattingContextRoot));
     212        ASSERT(layoutBox.isInFormattingContextOf(formattingContextRoot));
    215213        auto top = geometryForBox(layoutBox).top();
    216         for (auto* containerBox = layoutBox.containingBlock(); containerBox && containerBox != &formattingContextRoot; containerBox = containerBox->containingBlock())
    217             top += geometryForBox(*containerBox).top();
     214        for (auto* ancestor = &layoutBox.containingBlock(); ancestor != &formattingContextRoot; ancestor = &ancestor->containingBlock())
     215            top += geometryForBox(*ancestor).top();
    218216        return top;
    219217    };
     
    260258{
    261259    ASSERT(layoutBox.isFloatAvoider());
    262     precomputeVerticalPositionForBoxAndAncestors(*layoutBox.containingBlock(), horizontalConstraints, verticalConstraints);
     260    precomputeVerticalPositionForBoxAndAncestors(layoutBox.containingBlock(), horizontalConstraints, verticalConstraints);
    263261}
    264262
     
    275273    // 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.
    276274    // FIXME: we currently don't account for the "clear" property when computing the final position for an ancestor.
    277     for (auto* ancestor = &layoutBox; ancestor && ancestor != &root(); ancestor = ancestor->containingBlock()) {
     275    for (auto* ancestor = &layoutBox; ancestor && ancestor != &root(); ancestor = &ancestor->containingBlock()) {
    278276        auto horizontalConstraintsForAncestor = [&] {
    279             auto* containingBlock = ancestor->containingBlock();
    280             return containingBlock == &root() ? horizontalConstraints.root : Geometry::horizontalConstraintsForInFlow(geometryForBox(*containingBlock));
     277            auto& containingBlock = ancestor->containingBlock();
     278            return &containingBlock == &root() ? horizontalConstraints.root : Geometry::horizontalConstraintsForInFlow(geometryForBox(containingBlock));
    281279        };
    282280        auto verticalConstraintsForAncestor = [&] {
    283             auto* containingBlock = ancestor->containingBlock();
    284             return containingBlock == &root() ? verticalConstraints.root : Geometry::verticalConstraintsForInFlow(geometryForBox(*containingBlock));
     281            auto& containingBlock = ancestor->containingBlock();
     282            return &containingBlock == &root() ? verticalConstraints.root : Geometry::verticalConstraintsForInFlow(geometryForBox(containingBlock));
    285283        };
    286284
     
    554552    }
    555553    // At this point this box indirectly (via collapsed through previous in-flow siblings) adjoins the parent. Let's check if it margin collapses with the parent.
    556     auto& containingBlock = *layoutBox.containingBlock();
     554    auto& containingBlock = layoutBox.containingBlock();
    557555    ASSERT(containingBlock.firstInFlowChild());
    558556    ASSERT(containingBlock.firstInFlowChild() != &layoutBox);
  • trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp

    r256840 r258819  
    159159        // #2
    160160        if (width && computedHorizontalMargin.start && computedHorizontalMargin.end) {
    161             if (layoutBox.containingBlock()->style().isLeftToRightDirection()) {
     161            if (layoutBox.containingBlock().style().isLeftToRightDirection()) {
    162162                usedHorizontalMargin.start = *computedHorizontalMargin.start;
    163163                usedHorizontalMargin.end = containingBlockWidth - (usedHorizontalMargin.start + borderLeft + paddingLeft + *width + paddingRight + borderRight);
  • trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextQuirks.cpp

    r257690 r258819  
    3838namespace Layout {
    3939
    40 static const ContainerBox& initialContainingBlock(const Box& layoutBox)
    41 {
    42     auto* containingBlock = layoutBox.containingBlock();
    43     while (containingBlock->containingBlock())
    44         containingBlock = containingBlock->containingBlock();
    45     return *containingBlock;
    46 }
    47 
    4840static bool isQuirkContainer(const Box& layoutBox)
    4941{
     
    7264    if (layoutBox.isDocumentBox()) {
    7365        // Let's stretch the inflow document box(<html>) to the height of the initial containing block (view).
    74         auto documentBoxContentHeight = formattingContext.geometryForBox(initialContainingBlock(layoutBox), EscapeReason::DocumentBoxStrechesToViewportQuirk).contentBoxHeight();
     66        auto documentBoxContentHeight = formattingContext.geometryForBox(layoutBox.initialContainingBlock(), EscapeReason::DocumentBoxStrechesToViewportQuirk).contentBoxHeight();
    7567        // Document box's own vertical margin/border/padding values always shrink the content height.
    7668        auto& documentBoxGeometry = formattingContext.geometryForBox(layoutBox);
     
    8173    // Here is the quirky part for body box when it stretches all the way to the ICB even when the document box does not (e.g. out-of-flow positioned).
    8274    ASSERT(layoutBox.isBodyBox());
    83     auto& initialContainingBlockGeometry = formattingContext.geometryForBox(initialContainingBlock(layoutBox), EscapeReason::BodyStrechesToViewportQuirk);
     75    auto& initialContainingBlockGeometry = formattingContext.geometryForBox(layoutBox.initialContainingBlock(), EscapeReason::BodyStrechesToViewportQuirk);
    8476    // Start the content height with the ICB.
    8577    auto bodyBoxContentHeight = initialContainingBlockGeometry.contentBoxHeight();
  • trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp

    r257701 r258819  
    407407                auto& floats = formattingState.floatingState().floats();
    408408                for (auto& floatItem : floats) {
    409                     if (floatItem.isDescendantOfFormattingRoot(containerBox))
     409                    if (floatItem.isInFormattingContextOf(containerBox))
    410410                        return false;
    411411                }
  • trunk/Source/WebCore/layout/blockformatting/PrecomputedBlockMarginCollapse.cpp

    r257748 r258819  
    4545        return blockFormattingState.positiveAndNegativeVerticalMargin(layoutBox).before;
    4646
    47     auto horizontalConstraints = Geometry::horizontalConstraintsForInFlow(formattingContext().geometryForBox(*layoutBox.containingBlock()));
     47    auto horizontalConstraints = Geometry::horizontalConstraintsForInFlow(formattingContext().geometryForBox(layoutBox.containingBlock()));
    4848    auto computedVerticalMargin = formattingContext().geometry().computedVerticalMargin(layoutBox, horizontalConstraints);
    4949    auto nonCollapsedMargin = UsedVerticalMargin::NonCollapsedValues { computedVerticalMargin.before.valueOr(0), computedVerticalMargin.after.valueOr(0) };
  • trunk/Source/WebCore/layout/displaytree/DisplayPainter.cpp

    r256701 r258819  
    151151
    152152    auto absoluteBox = Box { layoutState.displayBoxForLayoutBox(layoutBox) };
    153     for (auto* containerBox = layoutBox.containingBlock(); containerBox != &layoutBox.initialContainingBlock(); containerBox = containerBox->containingBlock())
    154         absoluteBox.moveBy(layoutState.displayBoxForLayoutBox(*containerBox).topLeft());
     153    for (auto* containingBlock = &layoutBox.containingBlock(); !containingBlock->isInitialContainingBlock(); containingBlock = &containingBlock->containingBlock())
     154        absoluteBox.moveBy(layoutState.displayBoxForLayoutBox(*containingBlock).topLeft());
    155155    return absoluteBox;
    156156}
  • trunk/Source/WebCore/layout/floats/FloatingContext.cpp

    r256928 r258819  
    252252
    253253        // The return vertical position is in the containing block's coordinate system. Convert it to the formatting root's coordinate system if needed.
    254         if (layoutBox.containingBlock() == &m_floatingState.root())
     254        if (&layoutBox.containingBlock() == &m_floatingState.root())
    255255            return { Position { rootRelativeTop }, clearance };
    256256
    257         auto containingBlockRootRelativeTop = mapTopToFloatingStateRoot(*layoutBox.containingBlock());
     257        auto containingBlockRootRelativeTop = mapTopToFloatingStateRoot(layoutBox.containingBlock());
    258258        return { Position { rootRelativeTop - containingBlockRootRelativeTop }, clearance };
    259259    };
     
    419419FloatingContext::AbsoluteCoordinateValuesForFloatAvoider FloatingContext::absoluteDisplayBoxCoordinates(const Box& floatAvoider) const
    420420{
    421     auto& containingBlock = *floatAvoider.containingBlock();
     421    auto& containingBlock = floatAvoider.containingBlock();
    422422    auto displayBox = mapToFloatingStateRoot(floatAvoider);
    423423
     
    436436    auto& boxGeometry = formattingContext().geometryForBox(floatBox, FormattingContext::EscapeReason::FloatBoxNeedsToBeInAbsoluteCoordinates);
    437437    auto topLeft = boxGeometry.topLeft();
    438     for (auto* containingBlock = floatBox.containingBlock(); containingBlock && containingBlock != &floatingStateRoot; containingBlock = containingBlock->containingBlock())
     438    for (auto* containingBlock = &floatBox.containingBlock(); containingBlock != &floatingStateRoot; containingBlock = &containingBlock->containingBlock())
    439439        topLeft.moveBy(formattingContext().geometryForBox(*containingBlock, FormattingContext::EscapeReason::FloatBoxNeedsToBeInAbsoluteCoordinates).topLeft());
    440440
     
    448448    auto& floatingStateRoot = floatingState().root();
    449449    auto top = formattingContext().geometryForBox(floatBox, FormattingContext::EscapeReason::FloatBoxNeedsToBeInAbsoluteCoordinates).top();
    450     for (auto* containerBox = floatBox.containingBlock(); containerBox && containerBox != &floatingStateRoot; containerBox = containerBox->containingBlock())
    451         top += formattingContext().geometryForBox(*containerBox, FormattingContext::EscapeReason::FloatBoxNeedsToBeInAbsoluteCoordinates).top();
     450    for (auto* containingBlock = &floatBox.containingBlock(); containingBlock != &floatingStateRoot; containingBlock = &containingBlock->containingBlock())
     451        top += formattingContext().geometryForBox(*containingBlock, FormattingContext::EscapeReason::FloatBoxNeedsToBeInAbsoluteCoordinates).top();
    452452    return top;
    453453}
     
    460460        return position;
    461461    auto mappedPosition = position;
    462     for (auto* containerBox = &from; containerBox && containerBox != &to; containerBox = containerBox->containingBlock())
    463         mappedPosition.moveBy(formattingContext().geometryForBox(*containerBox, FormattingContext::EscapeReason::FloatBoxNeedsToBeInAbsoluteCoordinates).topLeft());
     462    for (auto* containingBlock = &from; containingBlock != &to; containingBlock = &containingBlock->containingBlock())
     463        mappedPosition.moveBy(formattingContext().geometryForBox(*containingBlock, FormattingContext::EscapeReason::FloatBoxNeedsToBeInAbsoluteCoordinates).topLeft());
    464464    return mappedPosition;
    465465}
  • trunk/Source/WebCore/layout/floats/FloatingState.cpp

    r257683 r258819  
    9898    for (auto& floatItem : m_floats) {
    9999        // Ignore floats from ancestor formatting contexts when the floating state is inherited.
    100         if (!floatItem.isDescendantOfFormattingRoot(formattingContextRoot))
     100        if (!floatItem.isInFormattingContextOf(formattingContextRoot))
    101101            continue;
    102102
     
    123123    for (auto& floatItem : m_floats) {
    124124        // Ignore floats from ancestor formatting contexts when the floating state is inherited.
    125         if (!floatItem.isDescendantOfFormattingRoot(formattingContextRoot))
     125        if (!floatItem.isInFormattingContextOf(formattingContextRoot))
    126126            continue;
    127127
  • trunk/Source/WebCore/layout/floats/FloatingState.h

    r256417 r258819  
    6767
    6868        bool isLeftPositioned() const { return m_position == Position::Left; }
    69         bool isDescendantOfFormattingRoot(const ContainerBox&) const;
     69        bool isInFormattingContextOf(const ContainerBox& formattingContextRoot) const { return m_layoutBox->isInFormattingContextOf(formattingContextRoot); }
    7070
    7171        Display::Rect rectWithMargin() const { return m_absoluteDisplayBox.rectWithMargin(); }
     
    116116}
    117117
    118 inline bool FloatingState::FloatItem::isDescendantOfFormattingRoot(const ContainerBox& formattingContextRoot) const
    119 {
    120     ASSERT(formattingContextRoot.establishesFormattingContext());
    121     return m_layoutBox->isContainingBlockDescendantOf(downcast<ContainerBox>(formattingContextRoot));
    122 }
    123 
    124118}
    125119}
  • trunk/Source/WebCore/layout/layouttree/LayoutBox.cpp

    r257970 r258819  
    179179}
    180180
    181 const ContainerBox* Box::containingBlock() const
     181const ContainerBox& Box::containingBlock() const
    182182{
    183183    // Finding the containing block by traversing the tree during tree construction could provide incorrect result.
    184184    ASSERT(!Phase::isInTreeBuilding());
     185    // If we ever end up here with the ICB, we must be doing something not-so-great.
     186    RELEASE_ASSERT(!isInitialContainingBlock());
    185187    // The containing block in which the root element lives is a rectangle called the initial containing block.
    186188    // For other elements, if the element's position is 'relative' or 'static', the containing block is formed by the
     
    189191    // If the element has 'position: absolute', the containing block is established by the nearest ancestor with a
    190192    // 'position' of 'absolute', 'relative' or 'fixed'.
    191     if (!parent())
    192         return nullptr;
    193 
    194193    if (!isPositioned() || isInFlowPositioned()) {
    195         for (auto* nearestBlockContainerOrFormattingContextRoot = parent(); nearestBlockContainerOrFormattingContextRoot; nearestBlockContainerOrFormattingContextRoot = nearestBlockContainerOrFormattingContextRoot->parent()) {
    196             if (nearestBlockContainerOrFormattingContextRoot->isBlockContainerBox() || nearestBlockContainerOrFormattingContextRoot->establishesFormattingContext())
    197                 return nearestBlockContainerOrFormattingContextRoot;
     194        auto* ancestor = parent();
     195        for (; !ancestor->isInitialContainingBlock(); ancestor = ancestor->parent()) {
     196            if (ancestor->isBlockContainerBox() || ancestor->establishesFormattingContext())
     197                return *ancestor;
    198198        }
    199         // We should always manage to find the ICB.
    200         ASSERT_NOT_REACHED();
    201         return nullptr;
     199        return *ancestor;
    202200    }
    203201
    204202    if (isFixedPositioned()) {
    205203        auto* ancestor = parent();
    206         for (; ancestor->parent() && !ancestor->style().hasTransform(); ancestor = ancestor->parent()) { }
    207         return ancestor;
     204        for (; !ancestor->isInitialContainingBlock(); ancestor = ancestor->parent()) {
     205            if (ancestor->style().hasTransform())
     206                return *ancestor;
     207        }
     208        return *ancestor;
    208209    }
    209210
    210211    if (isOutOfFlowPositioned()) {
    211212        auto* ancestor = parent();
    212         for (; ancestor->parent() && !ancestor->isPositioned() && !ancestor->style().hasTransform(); ancestor = ancestor->parent()) { }
    213         return ancestor;
     213        for (; !ancestor->isInitialContainingBlock(); ancestor = ancestor->parent()) {
     214            if (ancestor->isPositioned() || ancestor->style().hasTransform())
     215                return *ancestor;
     216        }
     217        return *ancestor;
    214218    }
    215219
    216220    ASSERT_NOT_REACHED();
    217     return nullptr;
     221    return initialContainingBlock();
    218222}
    219223
     
    231235    // While the relatively positioned inline container (span) is placed relative to its containing block "outer", it lives in the inline
    232236    // formatting context established by "inner".
    233     const ContainerBox* ancestor = nullptr;
    234     if (isInlineLevelBox() && isInFlowPositioned())
    235         ancestor = parent();
    236     else
    237         ancestor = containingBlock();
    238     ASSERT(ancestor);
    239     if (ancestor->establishesFormattingContext())
    240         return *ancestor;
    241     return ancestor->formattingContextRoot();
     237    auto& ancestor = isInlineLevelBox() && isInFlowPositioned() ? *parent() : containingBlock();
     238    if (ancestor.establishesFormattingContext())
     239        return ancestor;
     240    return ancestor.formattingContextRoot();
    242241}
    243242
     
    253252}
    254253
    255 bool Box::isDescendantOf(const ContainerBox& ancestorCandidate) const
    256 {
    257     for (auto* ancestor = parent(); ancestor; ancestor = ancestor->parent()) {
    258         if (ancestor == &ancestorCandidate)
     254bool Box::isInFormattingContextOf(const ContainerBox& formattingContextRoot) const
     255{
     256    ASSERT(formattingContextRoot.establishesFormattingContext());
     257    ASSERT(!isInitialContainingBlock());
     258    auto* ancestor = &containingBlock();
     259    while (ancestor) {
     260        if (ancestor == &formattingContextRoot)
    259261            return true;
    260     }
    261     return false;
    262 }
    263 
    264 bool Box::isContainingBlockDescendantOf(const ContainerBox& ancestorCandidate) const
    265 {
    266     for (auto* ancestor = containingBlock(); ancestor; ancestor = ancestor->containingBlock()) {
    267         if (ancestor == &ancestorCandidate)
    268             return true;
    269     }
     262        if (ancestor->isInitialContainingBlock())
     263            return false;
     264        ancestor = &ancestor->containingBlock();
     265    }
     266    ASSERT_NOT_REACHED();
    270267    return false;
    271268}
  • trunk/Source/WebCore/layout/layouttree/LayoutBox.h

    r256417 r258819  
    9494    bool isFloatingOrOutOfFlowPositioned() const { return isFloatingPositioned() || isOutOfFlowPositioned(); }
    9595
    96     const ContainerBox* containingBlock() const;
     96    const ContainerBox& containingBlock() const;
    9797    const ContainerBox& formattingContextRoot() const;
    9898    const ContainerBox& initialContainingBlock() const;
    9999
    100     bool isDescendantOf(const ContainerBox&) const;
    101     bool isContainingBlockDescendantOf(const ContainerBox&) const;
     100    bool isInFormattingContextOf(const ContainerBox&) const;
    102101
    103102    bool isAnonymous() const { return m_isAnonymous; }
Note: See TracChangeset for help on using the changeset viewer.