[LFC] FormattingContext::constraintsForInFlow/OutOfFlowContent should take const...
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 Apr 2020 16:06:32 +0000 (16:06 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 Apr 2020 16:06:32 +0000 (16:06 +0000)
https://bugs.webkit.org/show_bug.cgi?id=211161

Reviewed by Antti Koivisto.

Leaf boxes should not need to compute constraints (as by definition they don't have in/out-of-flow descendants).

* layout/FormattingContext.cpp:
(WebCore::Layout::FormattingContext::layoutOutOfFlowContent):
* layout/FormattingContext.h:
* layout/FormattingContextGeometry.cpp:
(WebCore::Layout::FormattingContext::Geometry::constraintsForOutOfFlowContent):
(WebCore::Layout::FormattingContext::Geometry::constraintsForInFlowContent):
* layout/FormattingContextQuirks.cpp:
(WebCore::Layout::FormattingContext::Quirks::heightValueOfNearestContainingBlockWithFixedHeight):
* layout/blockformatting/BlockFormattingContext.cpp:
(WebCore::Layout::BlockFormattingContext::layoutInFlowContent):
(WebCore::Layout::BlockFormattingContext::precomputeVerticalPositionForBoxAndAncestors):
* layout/blockformatting/BlockFormattingContextQuirks.cpp:
(WebCore::Layout::BlockFormattingContext::Quirks::stretchedInFlowHeight):
* layout/blockformatting/PrecomputedBlockMarginCollapse.cpp:
(WebCore::Layout::BlockFormattingContext::MarginCollapse::precomputedPositiveNegativeValues const):
* layout/inlineformatting/InlineFormattingContext.cpp:
(WebCore::Layout::InlineFormattingContext::layoutInFlowContent):
* layout/tableformatting/TableFormattingContext.cpp:
(WebCore::Layout::TableFormattingContext::layoutCell):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@260898 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/layout/FormattingContext.cpp
Source/WebCore/layout/FormattingContext.h
Source/WebCore/layout/FormattingContextGeometry.cpp
Source/WebCore/layout/FormattingContextQuirks.cpp
Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp
Source/WebCore/layout/blockformatting/BlockFormattingContextQuirks.cpp
Source/WebCore/layout/blockformatting/PrecomputedBlockMarginCollapse.cpp
Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp
Source/WebCore/layout/tableformatting/TableFormattingContext.cpp

index ba53a35..97c7892 100644 (file)
@@ -1,3 +1,32 @@
+2020-04-29  Zalan Bujtas  <zalan@apple.com>
+
+        [LFC] FormattingContext::constraintsForInFlow/OutOfFlowContent should take const ContainerBox&
+        https://bugs.webkit.org/show_bug.cgi?id=211161
+
+        Reviewed by Antti Koivisto.
+
+        Leaf boxes should not need to compute constraints (as by definition they don't have in/out-of-flow descendants).
+
+        * layout/FormattingContext.cpp:
+        (WebCore::Layout::FormattingContext::layoutOutOfFlowContent):
+        * layout/FormattingContext.h:
+        * layout/FormattingContextGeometry.cpp:
+        (WebCore::Layout::FormattingContext::Geometry::constraintsForOutOfFlowContent):
+        (WebCore::Layout::FormattingContext::Geometry::constraintsForInFlowContent):
+        * layout/FormattingContextQuirks.cpp:
+        (WebCore::Layout::FormattingContext::Quirks::heightValueOfNearestContainingBlockWithFixedHeight):
+        * layout/blockformatting/BlockFormattingContext.cpp:
+        (WebCore::Layout::BlockFormattingContext::layoutInFlowContent):
+        (WebCore::Layout::BlockFormattingContext::precomputeVerticalPositionForBoxAndAncestors):
+        * layout/blockformatting/BlockFormattingContextQuirks.cpp:
+        (WebCore::Layout::BlockFormattingContext::Quirks::stretchedInFlowHeight):
+        * layout/blockformatting/PrecomputedBlockMarginCollapse.cpp:
+        (WebCore::Layout::BlockFormattingContext::MarginCollapse::precomputedPositiveNegativeValues const):
+        * layout/inlineformatting/InlineFormattingContext.cpp:
+        (WebCore::Layout::InlineFormattingContext::layoutInFlowContent):
+        * layout/tableformatting/TableFormattingContext.cpp:
+        (WebCore::Layout::TableFormattingContext::layoutCell):
+
 2020-04-29  Joonghun Park  <jh718.park@samsung.com>
 
         Unreviewed. Remove no longer used variable and the build warning below.
index 11d8f0e..fe6496b 100644 (file)
@@ -141,7 +141,7 @@ void FormattingContext::layoutOutOfFlowContent(InvalidationState& invalidationSt
 
     auto constraintsForLayoutBox = [&] (const auto& outOfFlowBox) {
         auto& containingBlock = outOfFlowBox.containingBlock();
-        return &containingBlock == &root() ? constraints : Geometry::constraintsForOutOfFlowContent(geometryForBox(containingBlock));
+        return &containingBlock == &root() ? constraints : geometry().constraintsForOutOfFlowContent(containingBlock);
     };
 
     for (auto& outOfFlowBox : formattingState().outOfFlowBoxes()) {
@@ -154,19 +154,14 @@ void FormattingContext::layoutOutOfFlowContent(InvalidationState& invalidationSt
         computeBorderAndPadding(*outOfFlowBox, horizontalConstraintsForBorderAndPadding);
 
         computeOutOfFlowHorizontalGeometry(*outOfFlowBox, containingBlockConstraints);
-        if (is<ContainerBox>(*outOfFlowBox)) {
+        auto outOfFlowBoxHasContent = is<ContainerBox>(*outOfFlowBox) && downcast<ContainerBox>(*outOfFlowBox).hasChild();
+        if (outOfFlowBoxHasContent) {
             auto& containerBox = downcast<ContainerBox>(*outOfFlowBox);
-            auto& containerDisplayBox = geometryForBox(containerBox);
-
-            if (containerBox.hasInFlowOrFloatingChild()) {
-                auto formattingContext = LayoutContext::createFormattingContext(containerBox, layoutState());
-                formattingContext->layoutInFlowContent(invalidationState, Geometry::constraintsForInFlowContent(containerDisplayBox));
-            }
+            auto formattingContext = LayoutContext::createFormattingContext(containerBox, layoutState());
+            if (containerBox.hasInFlowOrFloatingChild())
+                formattingContext->layoutInFlowContent(invalidationState, geometry().constraintsForInFlowContent(containerBox));
             computeOutOfFlowVerticalGeometry(containerBox, containingBlockConstraints);
-            if (containerBox.hasChild()) {
-                auto formattingContext = LayoutContext::createFormattingContext(containerBox, layoutState());
-                formattingContext->layoutOutOfFlowContent(invalidationState, Geometry::constraintsForOutOfFlowContent(containerDisplayBox));
-            }
+            formattingContext->layoutOutOfFlowContent(invalidationState, geometry().constraintsForOutOfFlowContent(containerBox));
         } else
             computeOutOfFlowVerticalGeometry(*outOfFlowBox, containingBlockConstraints);
     }
index c818079..58975ce 100644 (file)
@@ -157,8 +157,8 @@ protected:
 
         LayoutUnit contentHeightForFormattingContextRoot(const Box&) const;
 
-        static ConstraintsForOutOfFlowContent constraintsForOutOfFlowContent(const Display::Box& containingBlockGeometry);
-        static ConstraintsForInFlowContent constraintsForInFlowContent(const Display::Box& containingBlockGeometry);
+        ConstraintsForOutOfFlowContent constraintsForOutOfFlowContent(const ContainerBox&);
+        ConstraintsForInFlowContent constraintsForInFlowContent(const ContainerBox&, Optional<EscapeReason> = WTF::nullopt);
 
     protected:
         friend class FormattingContext;
index ce1d575..2464b13 100644 (file)
@@ -1098,17 +1098,19 @@ FormattingContext::IntrinsicWidthConstraints FormattingContext::Geometry::constr
     return intrinsicWidth;
 }
 
-FormattingContext::ConstraintsForOutOfFlowContent FormattingContext::Geometry::constraintsForOutOfFlowContent(const Display::Box& containingBlockGeometry)
+FormattingContext::ConstraintsForOutOfFlowContent FormattingContext::Geometry::constraintsForOutOfFlowContent(const ContainerBox& containerBox)
 {
+    auto& boxGeometry = formattingContext().geometryForBox(containerBox);
     return {
-        { containingBlockGeometry.paddingBoxLeft(), containingBlockGeometry.paddingBoxWidth() },
-        { containingBlockGeometry.paddingBoxTop(), containingBlockGeometry.paddingBoxHeight() },
-        containingBlockGeometry.contentBoxWidth() };
+        { boxGeometry.paddingBoxLeft(), boxGeometry.paddingBoxWidth() },
+        { boxGeometry.paddingBoxTop(), boxGeometry.paddingBoxHeight() },
+        boxGeometry.contentBoxWidth() };
 }
 
-FormattingContext::ConstraintsForInFlowContent FormattingContext::Geometry::constraintsForInFlowContent(const Display::Box& containingBlockGeometry)
+FormattingContext::ConstraintsForInFlowContent FormattingContext::Geometry::constraintsForInFlowContent(const ContainerBox& containerBox, Optional<EscapeReason> escapeReason)
 {
-    return { { containingBlockGeometry.contentBoxLeft(), containingBlockGeometry.contentBoxWidth() }, { containingBlockGeometry.contentBoxTop(), { } } };
+    auto& boxGeometry = formattingContext().geometryForBox(containerBox, escapeReason);
+    return { { boxGeometry.contentBoxLeft(), boxGeometry.contentBoxWidth() }, { boxGeometry.contentBoxTop(), { } } };
 }
 
 }
index 8ebae29..146375a 100644 (file)
@@ -50,11 +50,12 @@ LayoutUnit FormattingContext::Quirks::heightValueOfNearestContainingBlockWithFix
         // If the only fixed value box we find is the ICB, then ignore the body and the document (vertical) margin, padding and border. So much quirkiness.
         // -and it's totally insane because now we freely travel across formatting context boundaries and computed margins are nonexistent.
         if (containingBlock->isBodyBox() || containingBlock->isDocumentBox()) {
-            auto& boxGeometry = formattingContext.geometryForBox(*containingBlock, FormattingContext::EscapeReason::FindFixedHeightAncestorQuirk);
 
-            auto& containingBlockDisplayBox = formattingContext.geometryForBox(containingBlock->containingBlock(), FormattingContext::EscapeReason::FindFixedHeightAncestorQuirk);
-            auto horizontalConstraints = Geometry::constraintsForInFlowContent(containingBlockDisplayBox).horizontal;
-            auto verticalMargin = formattingContext.geometry().computedVerticalMargin(*containingBlock, horizontalConstraints);
+            auto geometry = formattingContext.geometry();
+            auto horizontalConstraints = geometry.constraintsForInFlowContent(containingBlock->containingBlock(), FormattingContext::EscapeReason::FindFixedHeightAncestorQuirk).horizontal;
+            auto verticalMargin = geometry.computedVerticalMargin(*containingBlock, horizontalConstraints);
+
+            auto& boxGeometry = formattingContext.geometryForBox(*containingBlock, FormattingContext::EscapeReason::FindFixedHeightAncestorQuirk);
             auto verticalPadding = boxGeometry.paddingTop().valueOr(0) + boxGeometry.paddingBottom().valueOr(0);
             auto verticalBorder = boxGeometry.borderTop() + boxGeometry.borderBottom();
             bodyAndDocumentVerticalMarginPaddingAndBorder += verticalMargin.before.valueOr(0) + verticalMargin.after.valueOr(0) + verticalPadding + verticalBorder;
index 6677c9b..4bddd5a 100644 (file)
@@ -93,9 +93,7 @@ void BlockFormattingContext::layoutInFlowContent(InvalidationState& invalidation
 
     auto constraintsForLayoutBox = [&] (const auto& layoutBox) {
         auto& containingBlock = layoutBox.containingBlock();
-        if (&containingBlock == &formattingRoot)
-            return constraints;
-        return Geometry::constraintsForInFlowContent(geometryForBox(containingBlock));
+        return &containingBlock == &formattingRoot ? constraints : geometry().constraintsForInFlowContent(containingBlock);
     };
 
     // This is a post-order tree traversal layout.
@@ -113,7 +111,6 @@ void BlockFormattingContext::layoutInFlowContent(InvalidationState& invalidation
 
             computeBorderAndPadding(layoutBox, containingBlockConstraints.horizontal);
             computeStaticVerticalPosition(layoutBox, containingBlockConstraints.vertical);
-
             computeWidthAndMargin(floatingContext, layoutBox, { constraints, containingBlockConstraints });
             computeStaticHorizontalPosition(layoutBox, containingBlockConstraints.horizontal);
 
@@ -131,7 +128,7 @@ void BlockFormattingContext::layoutInFlowContent(InvalidationState& invalidation
                         }
                     }
                     // Layout the inflow descendants of this formatting context root.
-                    LayoutContext::createFormattingContext(containerBox, layoutState())->layoutInFlowContent(invalidationState, Geometry::constraintsForInFlowContent(geometryForBox(containerBox)));
+                    LayoutContext::createFormattingContext(containerBox, layoutState())->layoutInFlowContent(invalidationState, geometry().constraintsForInFlowContent(containerBox));
                 }
                 break;
             }
@@ -152,7 +149,7 @@ void BlockFormattingContext::layoutInFlowContent(InvalidationState& invalidation
                 // Now that we computed the root's height, we can layout the out-of-flow descendants.
                 if (is<ContainerBox>(layoutBox) && downcast<ContainerBox>(layoutBox).hasChild()) {
                     auto& containerBox = downcast<ContainerBox>(layoutBox);
-                    LayoutContext::createFormattingContext(containerBox, layoutState())->layoutOutOfFlowContent(invalidationState, Geometry::constraintsForOutOfFlowContent(geometryForBox(containerBox)));
+                    LayoutContext::createFormattingContext(containerBox, layoutState())->layoutOutOfFlowContent(invalidationState, geometry().constraintsForOutOfFlowContent(containerBox));
                 }
             }
             // Resolve final positions.
@@ -257,7 +254,7 @@ void BlockFormattingContext::precomputeVerticalPositionForBoxAndAncestors(const
     for (auto* ancestor = &layoutBox; ancestor && ancestor != &root(); ancestor = &ancestor->containingBlock()) {
         auto constraintsForAncestor = [&] {
             auto& containingBlock = ancestor->containingBlock();
-            return &containingBlock == &root() ? constraintsPair.formattingContextRoot : Geometry::constraintsForInFlowContent(geometryForBox(containingBlock));
+            return &containingBlock == &root() ? constraintsPair.formattingContextRoot : geometry().constraintsForInFlowContent(containingBlock);
         }();
 
         auto computedVerticalMargin = geometry().computedVerticalMargin(*ancestor, constraintsForAncestor.horizontal);
index dcf8725..e6dc2ee 100644 (file)
@@ -73,7 +73,8 @@ LayoutUnit BlockFormattingContext::Quirks::stretchedInFlowHeight(const Box& layo
 
     // 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).
     ASSERT(layoutBox.isBodyBox());
-    auto& initialContainingBlockGeometry = formattingContext.geometryForBox(layoutBox.initialContainingBlock(), EscapeReason::BodyStrechesToViewportQuirk);
+    auto& initialContainingBlock = layoutBox.initialContainingBlock();
+    auto& initialContainingBlockGeometry = formattingContext.geometryForBox(initialContainingBlock, EscapeReason::BodyStrechesToViewportQuirk);
     // Start the content height with the ICB.
     auto bodyBoxContentHeight = initialContainingBlockGeometry.contentBoxHeight();
     // Body box's own border and padding shrink the content height.
@@ -91,7 +92,8 @@ LayoutUnit BlockFormattingContext::Quirks::stretchedInFlowHeight(const Box& layo
     bodyBoxContentHeight -= documentBoxGeometry.verticalBorder() + documentBoxGeometry.verticalPadding().valueOr(0);
     // However the non-in-flow document box's vertical margins are ignored. They don't affect the body box's content height.
     if (documentBox.isInFlow()) {
-        auto precomputeDocumentBoxVerticalMargin = formattingContext.geometry().computedVerticalMargin(documentBox, Geometry::constraintsForInFlowContent(initialContainingBlockGeometry).horizontal);
+        auto geometry = formattingContext.geometry();
+        auto precomputeDocumentBoxVerticalMargin = geometry.computedVerticalMargin(documentBox, geometry.constraintsForInFlowContent(initialContainingBlock, EscapeReason::BodyStrechesToViewportQuirk).horizontal);
         bodyBoxContentHeight -= precomputeDocumentBoxVerticalMargin.before.valueOr(0) + precomputeDocumentBoxVerticalMargin.after.valueOr(0);
     }
     return std::max(contentHeightAndMargin.contentHeight,  bodyBoxContentHeight);
index 4c7887e..a58c5f6 100644 (file)
@@ -44,8 +44,9 @@ PositiveAndNegativeVerticalMargin::Values BlockFormattingContext::MarginCollapse
     if (blockFormattingState.hasPositiveAndNegativeVerticalMargin(layoutBox))
         return blockFormattingState.positiveAndNegativeVerticalMargin(layoutBox).before;
 
-    auto horizontalConstraints = Geometry::constraintsForInFlowContent(formattingContext().geometryForBox(layoutBox.containingBlock())).horizontal;
-    auto computedVerticalMargin = formattingContext().geometry().computedVerticalMargin(layoutBox, horizontalConstraints);
+    auto geometry = formattingContext().geometry();
+    auto horizontalConstraints = geometry.constraintsForInFlowContent(layoutBox.containingBlock()).horizontal;
+    auto computedVerticalMargin = geometry.computedVerticalMargin(layoutBox, horizontalConstraints);
     auto nonCollapsedMargin = UsedVerticalMargin::NonCollapsedValues { computedVerticalMargin.before.valueOr(0), computedVerticalMargin.after.valueOr(0) };
     return precomputedPositiveNegativeMarginBefore(layoutBox, nonCollapsedMargin);
 }
index fa5d24a..b81a137 100644 (file)
@@ -92,20 +92,18 @@ void InlineFormattingContext::layoutInFlowContent(InvalidationState& invalidatio
             // Inline-blocks, inline-tables and replaced elements (img, video) can be sized but not yet positioned.
             if (is<ContainerBox>(layoutBox) && layoutBox->establishesFormattingContext()) {
                 ASSERT(layoutBox->isInlineBlockBox() || layoutBox->isInlineTableBox() || layoutBox->isFloatingPositioned());
-                auto& containerBox = downcast<ContainerBox>(*layoutBox);
-                computeBorderAndPadding(containerBox, constraints.horizontal);
-                computeWidthAndMargin(containerBox, constraints.horizontal);
-
-                auto& formattingRootDisplayBox = geometryForBox(containerBox);
-                if (containerBox.hasInFlowOrFloatingChild()) {
-                    auto formattingContext = LayoutContext::createFormattingContext(containerBox, layoutState());
-                    formattingContext->layoutInFlowContent(invalidationState, Geometry::constraintsForInFlowContent(formattingRootDisplayBox));
-                }
-                computeHeightAndMargin(containerBox, constraints.horizontal);
-                if (containerBox.hasChild()) {
-                    auto formattingContext = LayoutContext::createFormattingContext(containerBox, layoutState());
-                    formattingContext->layoutOutOfFlowContent(invalidationState, Geometry::constraintsForOutOfFlowContent(formattingRootDisplayBox));
-                }
+                auto& formattingRoot = downcast<ContainerBox>(*layoutBox);
+                computeBorderAndPadding(formattingRoot, constraints.horizontal);
+                computeWidthAndMargin(formattingRoot, constraints.horizontal);
+
+                if (formattingRoot.hasChild()) {
+                    auto formattingContext = LayoutContext::createFormattingContext(formattingRoot, layoutState());
+                    if (formattingRoot.hasInFlowOrFloatingChild())
+                        formattingContext->layoutInFlowContent(invalidationState, geometry().constraintsForInFlowContent(formattingRoot));
+                    computeHeightAndMargin(formattingRoot, constraints.horizontal);
+                    formattingContext->layoutOutOfFlowContent(invalidationState, geometry().constraintsForOutOfFlowContent(formattingRoot));
+                } else
+                    computeHeightAndMargin(formattingRoot, constraints.horizontal);
             } else {
                 // Replaced and other type of leaf atomic inline boxes.
                 computeBorderAndPadding(*layoutBox, constraints.horizontal);
index 988f5ed..f249348 100644 (file)
@@ -177,7 +177,7 @@ void TableFormattingContext::layoutCell(const TableGrid::Cell& cell, LayoutUnit
 
     if (cellBox.hasInFlowOrFloatingChild()) {
         auto invalidationState = InvalidationState { };
-        auto constraintsForCellContent = Geometry::constraintsForInFlowContent(cellDisplayBox);
+        auto constraintsForCellContent = geometry().constraintsForInFlowContent(cellBox);
         constraintsForCellContent.vertical.logicalHeight = usedCellHeight;
         LayoutContext::createFormattingContext(cellBox, layoutState())->layoutInFlowContent(invalidationState, constraintsForCellContent);
     }