Changeset 254927 in webkit


Ignore:
Timestamp:
Jan 22, 2020 9:07:27 AM (4 years ago)
Author:
Alan Bujtas
Message:

[LFC] Do not create a FormattingContext unless there's content to layout.
https://bugs.webkit.org/show_bug.cgi?id=206570
<rdar://problem/58785735>

Reviewed by Antti Koivisto.

We still construct "no-op" FormattingContexts through the computeIntrinsicWidth* codepath (see webkit.org/b/206581).

  • layout/FormattingContext.cpp:

(WebCore::Layout::FormattingContext::FormattingContext):
(WebCore::Layout::FormattingContext::layoutOutOfFlowContent):

  • layout/blockformatting/BlockFormattingContext.cpp:

(WebCore::Layout::BlockFormattingContext::layoutInFlowContent):

  • layout/inlineformatting/InlineFormattingContext.cpp:

(WebCore::Layout::InlineFormattingContext::layoutInFlowContent):
(WebCore::Layout::InlineFormattingContext::layoutFormattingContextRoot):

  • layout/tableformatting/TableFormattingContext.cpp:

(WebCore::Layout::TableFormattingContext::layoutTableCellBox):

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r254923 r254927  
     12020-01-22  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC] Do not create a FormattingContext unless there's content to layout.
     4        https://bugs.webkit.org/show_bug.cgi?id=206570
     5        <rdar://problem/58785735>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        We still construct "no-op" FormattingContexts through the computeIntrinsicWidth* codepath (see webkit.org/b/206581).
     10
     11        * layout/FormattingContext.cpp:
     12        (WebCore::Layout::FormattingContext::FormattingContext):
     13        (WebCore::Layout::FormattingContext::layoutOutOfFlowContent):
     14        * layout/blockformatting/BlockFormattingContext.cpp:
     15        (WebCore::Layout::BlockFormattingContext::layoutInFlowContent):
     16        * layout/inlineformatting/InlineFormattingContext.cpp:
     17        (WebCore::Layout::InlineFormattingContext::layoutInFlowContent):
     18        (WebCore::Layout::InlineFormattingContext::layoutFormattingContextRoot):
     19        * layout/tableformatting/TableFormattingContext.cpp:
     20        (WebCore::Layout::TableFormattingContext::layoutTableCellBox):
     21
    1222020-01-22  Antti Koivisto  <antti@apple.com>
    223
  • trunk/Source/WebCore/layout/FormattingContext.cpp

    r254407 r254927  
    164164        computeBorderAndPadding(*outOfFlowBox, Geometry::horizontalConstraintsForInFlow(outOfFlowRootDisplayBox));
    165165        computeOutOfFlowHorizontalGeometry(*outOfFlowBox, horizontalConstraints);
    166         if (is<Container>(*outOfFlowBox)) {
    167             auto& outOfFlowRootContainer = downcast<Container>(*outOfFlowBox);
    168             auto formattingContext = LayoutContext::createFormattingContext(outOfFlowRootContainer, layoutState());
     166        if (!is<Container>(*outOfFlowBox) || !downcast<Container>(*outOfFlowBox).hasChild()) {
     167            computeOutOfFlowVerticalGeometry(*outOfFlowBox, horizontalConstraints, verticalConstraints);
     168            continue;
     169        }
     170
     171        auto& outOfFlowRootContainer = downcast<Container>(*outOfFlowBox);
     172        auto formattingContext = LayoutContext::createFormattingContext(outOfFlowRootContainer, layoutState());
     173        if (outOfFlowRootContainer.hasInFlowOrFloatingChild())
    169174            formattingContext->layoutInFlowContent(invalidationState, Geometry::horizontalConstraintsForInFlow(outOfFlowRootDisplayBox), Geometry::verticalConstraintsForInFlow(outOfFlowRootDisplayBox));
    170             computeOutOfFlowVerticalGeometry(outOfFlowRootContainer, horizontalConstraints, verticalConstraints);
    171 
    172             formattingContext->layoutOutOfFlowContent(invalidationState, Geometry::horizontalConstraintsForInFlow(outOfFlowRootDisplayBox), Geometry::verticalConstraintsForInFlow(outOfFlowRootDisplayBox));
    173         } else
    174             computeOutOfFlowVerticalGeometry(*outOfFlowBox, horizontalConstraints, verticalConstraints);
     175        computeOutOfFlowVerticalGeometry(outOfFlowRootContainer, horizontalConstraints, verticalConstraints);
     176        formattingContext->layoutOutOfFlowContent(invalidationState, Geometry::horizontalConstraintsForInFlow(outOfFlowRootDisplayBox), Geometry::verticalConstraintsForInFlow(outOfFlowRootDisplayBox));
    175177    }
    176178    LOG_WITH_STREAM(FormattingContextLayout, stream << "End: layout out-of-flow content -> context: " << &layoutState() << " root: " << &root());
  • trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp

    r254922 r254927  
    6060    LOG_WITH_STREAM(FormattingContextLayout, stream << "[Start] -> block formatting context -> formatting root(" << &root() << ")");
    6161    auto& formattingRoot = root();
     62    ASSERT(formattingRoot.hasInFlowOrFloatingChild());
    6263    auto floatingContext = FloatingContext { formattingRoot, *this, formattingState().floatingState() };
    6364
     
    149150            if (layoutBox.establishesFormattingContext()) {
    150151                // Now that we computed the root's height, we can layout the out-of-flow descendants.
    151                 if (is<Container>(layoutBox)) {
     152                if (is<Container>(layoutBox) && downcast<Container>(layoutBox).hasChild()) {
    152153                    auto& rootDisplayBox = geometryForBox(layoutBox);
    153154                    auto horizontalConstraintsForOutOfFlow =  Geometry::horizontalConstraintsForOutOfFlow(rootDisplayBox);
  • trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp

    r254837 r254927  
    6969void InlineFormattingContext::layoutInFlowContent(InvalidationState& invalidationState, const HorizontalConstraints& horizontalConstraints, const VerticalConstraints& verticalConstraints)
    7070{
    71     if (!root().hasInFlowOrFloatingChild())
    72         return;
     71    LOG_WITH_STREAM(FormattingContextLayout, stream << "[Start] -> inline formatting context -> formatting root(" << &root() << ")");
     72    ASSERT(root().hasInFlowOrFloatingChild());
    7373
    7474    invalidateFormattingState(invalidationState);
    75     LOG_WITH_STREAM(FormattingContextLayout, stream << "[Start] -> inline formatting context -> formatting root(" << &root() << ")");
    7675    auto* layoutBox = root().firstInFlowOrFloatingChild();
    7776    // 1. Visit each inline box and partially compute their geometry (margins, paddings and borders).
     
    136135    computeBorderAndPadding(formattingContextRoot, horizontalConstraints);
    137136    computeWidthAndMargin(formattingContextRoot, horizontalConstraints);
     137    if (!is<Container>(formattingContextRoot) || !downcast<Container>(formattingContextRoot).hasChild()) {
     138        computeHeightAndMargin(formattingContextRoot, horizontalConstraints);
     139        return;
     140    }
    138141    // Swich over to the new formatting context (the one that the root creates).
    139     if (is<Container>(formattingContextRoot)) {
    140         auto& rootContainer = downcast<Container>(formattingContextRoot);
    141         auto formattingContext = LayoutContext::createFormattingContext(rootContainer, layoutState());
     142    auto& rootContainer = downcast<Container>(formattingContextRoot);
     143    auto formattingContext = LayoutContext::createFormattingContext(rootContainer, layoutState());
     144    if (rootContainer.hasInFlowOrFloatingChild())
    142145        formattingContext->layoutInFlowContent(invalidationState, horizontalConstraints, verticalConstraints);
    143         // Come back and finalize the root's height and margin.
    144         computeHeightAndMargin(rootContainer, horizontalConstraints);
    145         // Now that we computed the root's height, we can go back and layout the out-of-flow content.
     146    // Come back and finalize the root's height and margin.
     147    computeHeightAndMargin(rootContainer, horizontalConstraints);
     148    // Now that we computed the root's height, we can go back and layout the out-of-flow content.
     149    if (rootContainer.hasChild()) {
    146150        auto& rootContainerDisplayBox = geometryForBox(rootContainer);
    147151        auto horizontalConstraintsForOutOfFlow = Geometry::horizontalConstraintsForOutOfFlow(rootContainerDisplayBox);
    148152        auto verticalConstraintsForOutOfFlow = Geometry::verticalConstraintsForOutOfFlow(rootContainerDisplayBox);
    149153        formattingContext->layoutOutOfFlowContent(invalidationState, horizontalConstraintsForOutOfFlow, verticalConstraintsForOutOfFlow);
    150     } else
    151         computeHeightAndMargin(formattingContextRoot, horizontalConstraints);
     154    }
    152155}
    153156
  • trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp

    r254666 r254927  
    112112
    113113    ASSERT(cellLayoutBox.establishesBlockFormattingContext());
    114     if (is<Container>(cellLayoutBox))
     114    if (is<Container>(cellLayoutBox) && downcast<Container>(cellLayoutBox).hasInFlowOrFloatingChild())
    115115        LayoutContext::createFormattingContext(downcast<Container>(cellLayoutBox), layoutState())->layoutInFlowContent(invalidationState, Geometry::horizontalConstraintsForInFlow(cellDisplayBox), Geometry::verticalConstraintsForInFlow(cellDisplayBox));
    116116    cellDisplayBox.setVerticalMargin({ { }, { } });
Note: See TracChangeset for help on using the changeset viewer.