[LFC] Introduce FormattingContext::ConstraintsForInFlowContent
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Apr 2020 14:44:42 +0000 (14:44 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Apr 2020 14:44:42 +0000 (14:44 +0000)
https://bugs.webkit.org/show_bug.cgi?id=211113

Reviewed by Antti Koivisto.

This makes the layoutInFlowContent() related code look simpler.

* layout/FormattingContext.cpp:
(WebCore::Layout::FormattingContext::layoutOutOfFlowContent):
* layout/FormattingContext.h:
* layout/LayoutContext.cpp:
(WebCore::Layout::LayoutContext::layoutFormattingContextSubtree):
* layout/blockformatting/BlockFormattingContext.cpp:
(WebCore::Layout::BlockFormattingContext::layoutInFlowContent):
* layout/blockformatting/BlockFormattingContext.h:
* layout/inlineformatting/InlineFormattingContext.cpp:
(WebCore::Layout::InlineFormattingContext::layoutInFlowContent):
(WebCore::Layout::InlineFormattingContext::lineLayout):
* layout/inlineformatting/InlineFormattingContext.h:
* layout/integration/LayoutIntegrationLineLayout.cpp:
(WebCore::LayoutIntegration::LineLayout::layout):
* layout/tableformatting/TableFormattingContext.cpp:
(WebCore::Layout::TableFormattingContext::layoutInFlowContent):
(WebCore::Layout::TableFormattingContext::layoutCell):
* layout/tableformatting/TableFormattingContext.h:

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

15 files changed:
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/LayoutContext.cpp
Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp
Source/WebCore/layout/blockformatting/BlockFormattingContext.h
Source/WebCore/layout/blockformatting/BlockFormattingContextQuirks.cpp
Source/WebCore/layout/blockformatting/PrecomputedBlockMarginCollapse.cpp
Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp
Source/WebCore/layout/inlineformatting/InlineFormattingContext.h
Source/WebCore/layout/integration/LayoutIntegrationLineLayout.cpp
Source/WebCore/layout/tableformatting/TableFormattingContext.cpp
Source/WebCore/layout/tableformatting/TableFormattingContext.h

index 22a5674..52e6161 100644 (file)
@@ -1,3 +1,31 @@
+2020-04-28  Zalan Bujtas  <zalan@apple.com>
+
+        [LFC] Introduce FormattingContext::ConstraintsForInFlowContent
+        https://bugs.webkit.org/show_bug.cgi?id=211113
+
+        Reviewed by Antti Koivisto.
+
+        This makes the layoutInFlowContent() related code look simpler.
+
+        * layout/FormattingContext.cpp:
+        (WebCore::Layout::FormattingContext::layoutOutOfFlowContent):
+        * layout/FormattingContext.h:
+        * layout/LayoutContext.cpp:
+        (WebCore::Layout::LayoutContext::layoutFormattingContextSubtree):
+        * layout/blockformatting/BlockFormattingContext.cpp:
+        (WebCore::Layout::BlockFormattingContext::layoutInFlowContent):
+        * layout/blockformatting/BlockFormattingContext.h:
+        * layout/inlineformatting/InlineFormattingContext.cpp:
+        (WebCore::Layout::InlineFormattingContext::layoutInFlowContent):
+        (WebCore::Layout::InlineFormattingContext::lineLayout):
+        * layout/inlineformatting/InlineFormattingContext.h:
+        * layout/integration/LayoutIntegrationLineLayout.cpp:
+        (WebCore::LayoutIntegration::LineLayout::layout):
+        * layout/tableformatting/TableFormattingContext.cpp:
+        (WebCore::Layout::TableFormattingContext::layoutInFlowContent):
+        (WebCore::Layout::TableFormattingContext::layoutCell):
+        * layout/tableformatting/TableFormattingContext.h:
+
 2020-04-28  Philippe Normand  <pnormand@igalia.com>
 
         media/track/track-load-error-readyState.html passes only when accompanied by some other tests
index 45bb458..fe64fe3 100644 (file)
@@ -170,10 +170,8 @@ void FormattingContext::layoutOutOfFlowContent(InvalidationState& invalidationSt
             auto& containerDisplayBox = geometryForBox(containerBox);
 
             if (containerBox.hasInFlowOrFloatingChild()) {
-                auto horizontalConstraintsForInFlowContent = Geometry::horizontalConstraintsForInFlow(containerDisplayBox);
-                auto verticalConstraintsForInFlowContent = Geometry::verticalConstraintsForInFlow(containerDisplayBox);
                 auto formattingContext = LayoutContext::createFormattingContext(containerBox, layoutState());
-                formattingContext->layoutInFlowContent(invalidationState, horizontalConstraintsForInFlowContent, verticalConstraintsForInFlowContent);
+                formattingContext->layoutInFlowContent(invalidationState, Geometry::constraintsForInFlowContent(containerDisplayBox));
             }
             computeOutOfFlowVerticalGeometry(containerBox, horizontalConstraints, verticalConstraints);
             if (containerBox.hasChild()) {
index 18a5340..2f848af 100644 (file)
@@ -65,7 +65,11 @@ public:
     FormattingContext(const ContainerBox& formattingContextRoot, FormattingState&);
     virtual ~FormattingContext();
 
-    virtual void layoutInFlowContent(InvalidationState&, const HorizontalConstraints&, const VerticalConstraints&) = 0;
+    struct ConstraintsForInFlowContent {
+        HorizontalConstraints horizontal;
+        VerticalConstraints vertical;
+    };
+    virtual void layoutInFlowContent(InvalidationState&, const ConstraintsForInFlowContent&) = 0;
     void layoutOutOfFlowContent(InvalidationState&, const OutOfFlowHorizontalConstraints&, const VerticalConstraints&);
 
     struct IntrinsicWidthConstraints {
@@ -148,8 +152,7 @@ protected:
 
         static OutOfFlowHorizontalConstraints horizontalConstraintsForOutOfFlow(const Display::Box& containingBlockGeometry);
         static VerticalConstraints verticalConstraintsForOutOfFlow(const Display::Box& containingBlockGeometry);
-        static HorizontalConstraints horizontalConstraintsForInFlow(const Display::Box& containingBlockGeometry);
-        static VerticalConstraints verticalConstraintsForInFlow(const Display::Box& containingBlockGeometry);
+        static FormattingContext::ConstraintsForInFlowContent constraintsForInFlowContent(const Display::Box& containingBlockGeometry);
 
     protected:
         friend class FormattingContext;
index fb284a9..37b0c00 100644 (file)
@@ -1110,14 +1110,9 @@ VerticalConstraints FormattingContext::Geometry::verticalConstraintsForOutOfFlow
     return VerticalConstraints { containingBlockGeometry.paddingBoxTop(), containingBlockGeometry.paddingBoxHeight() };
 }
 
-HorizontalConstraints FormattingContext::Geometry::horizontalConstraintsForInFlow(const Display::Box& containingBlockGeometry)
+FormattingContext::ConstraintsForInFlowContent FormattingContext::Geometry::constraintsForInFlowContent(const Display::Box& containingBlockGeometry)
 {
-    return HorizontalConstraints { containingBlockGeometry.contentBoxLeft(), containingBlockGeometry.contentBoxWidth() };
-}
-
-VerticalConstraints FormattingContext::Geometry::verticalConstraintsForInFlow(const Display::Box& containingBlockGeometry)
-{
-    return VerticalConstraints { containingBlockGeometry.contentBoxTop(), { } };
+    return { { containingBlockGeometry.contentBoxLeft(), containingBlockGeometry.contentBoxWidth() }, { containingBlockGeometry.contentBoxTop(), { } } };
 }
 
 }
index 2d18893..8ebae29 100644 (file)
@@ -53,7 +53,7 @@ LayoutUnit FormattingContext::Quirks::heightValueOfNearestContainingBlockWithFix
             auto& boxGeometry = formattingContext.geometryForBox(*containingBlock, FormattingContext::EscapeReason::FindFixedHeightAncestorQuirk);
 
             auto& containingBlockDisplayBox = formattingContext.geometryForBox(containingBlock->containingBlock(), FormattingContext::EscapeReason::FindFixedHeightAncestorQuirk);
-            auto horizontalConstraints = Geometry::horizontalConstraintsForInFlow(containingBlockDisplayBox);
+            auto horizontalConstraints = Geometry::constraintsForInFlowContent(containingBlockDisplayBox).horizontal;
             auto verticalMargin = formattingContext.geometry().computedVerticalMargin(*containingBlock, horizontalConstraints);
             auto verticalPadding = boxGeometry.paddingTop().valueOr(0) + boxGeometry.paddingBottom().valueOr(0);
             auto verticalBorder = boxGeometry.borderTop() + boxGeometry.borderBottom();
index bea7910..ee8ddbd 100644 (file)
@@ -99,9 +99,8 @@ void LayoutContext::layoutFormattingContextSubtree(const ContainerBox& formattin
     auto& displayBox = layoutState().displayBoxForLayoutBox(formattingContextRoot);
 
     if (formattingContextRoot.hasInFlowOrFloatingChild()) {
-        auto horizontalConstraints = HorizontalConstraints { displayBox.contentBoxLeft(), displayBox.contentBoxWidth() };
-        auto verticalConstraints = VerticalConstraints { displayBox.contentBoxTop(), { } };
-        formattingContext->layoutInFlowContent(invalidationState, horizontalConstraints, verticalConstraints);
+        auto constraintsForInFlowContent = FormattingContext::ConstraintsForInFlowContent { { displayBox.contentBoxLeft(), displayBox.contentBoxWidth() }, { displayBox.contentBoxTop(), { } } };
+        formattingContext->layoutInFlowContent(invalidationState, constraintsForInFlowContent);
     }
 
     // FIXME: layoutFormattingContextSubtree() does not perform layout on the root, rather it lays out the root's content.
index 260d224..822bf92 100644 (file)
@@ -52,7 +52,7 @@ BlockFormattingContext::BlockFormattingContext(const ContainerBox& formattingCon
 {
 }
 
-void BlockFormattingContext::layoutInFlowContent(InvalidationState& invalidationState, const HorizontalConstraints& rootHorizontalConstraints, const VerticalConstraints& rootVerticalConstraints)
+void BlockFormattingContext::layoutInFlowContent(InvalidationState& invalidationState, const ConstraintsForInFlowContent& constraints)
 {
     // 9.4.1 Block formatting contexts
     // In a block formatting context, boxes are laid out one after the other, vertically, beginning at the top of a containing block.
@@ -91,18 +91,11 @@ void BlockFormattingContext::layoutInFlowContent(InvalidationState& invalidation
         return false;
     };
 
-    auto horizontalConstraintsForLayoutBox = [&] (const auto& layoutBox) {
+    auto constraintsForLayoutBox = [&] (const auto& layoutBox) {
         auto& containingBlock = layoutBox.containingBlock();
         if (&containingBlock == &formattingRoot)
-            return rootHorizontalConstraints;
-        return Geometry::horizontalConstraintsForInFlow(geometryForBox(containingBlock));
-    };
-
-    auto verticalConstraintsForLayoutBox = [&] (const auto& layoutBox) {
-        auto& containingBlock = layoutBox.containingBlock();
-        if (&containingBlock == &formattingRoot)
-            return rootVerticalConstraints;
-        return Geometry::verticalConstraintsForInFlow(geometryForBox(containingBlock));
+            return constraints;
+        return Geometry::constraintsForInFlowContent(geometryForBox(containingBlock));
     };
 
     // This is a post-order tree traversal layout.
@@ -116,23 +109,20 @@ void BlockFormattingContext::layoutInFlowContent(InvalidationState& invalidation
         // Traverse down on the descendants and compute width/static position until we find a leaf node.
         while (true) {
             auto& layoutBox = *layoutQueue.last();
-            auto horizontalConstraints = horizontalConstraintsForLayoutBox(layoutBox);
-            auto verticalConstraints = verticalConstraintsForLayoutBox(layoutBox);
+            auto containingBlockConstraints = constraintsForLayoutBox(layoutBox);
 
-            computeBorderAndPadding(layoutBox, horizontalConstraints);
-            computeStaticVerticalPosition(layoutBox, verticalConstraints);
+            computeBorderAndPadding(layoutBox, containingBlockConstraints.horizontal);
+            computeStaticVerticalPosition(layoutBox, containingBlockConstraints.vertical);
 
-            auto horizontalConstraintsPair = ConstraintsPair<HorizontalConstraints> { rootHorizontalConstraints, horizontalConstraints };
-            auto verticalConstraintsPair = ConstraintsPair<VerticalConstraints> { rootVerticalConstraints, verticalConstraints };
-            computeWidthAndMargin(floatingContext, layoutBox, horizontalConstraintsPair, verticalConstraintsPair);
-            computeStaticHorizontalPosition(layoutBox, horizontalConstraints);
+            computeWidthAndMargin(floatingContext, layoutBox, { constraints, containingBlockConstraints });
+            computeStaticHorizontalPosition(layoutBox, containingBlockConstraints.horizontal);
 
             if (layoutBox.establishesFormattingContext()) {
                 if (is<ContainerBox>(layoutBox) && downcast<ContainerBox>(layoutBox).hasInFlowOrFloatingChild()) {
                     auto& containerBox = downcast<ContainerBox>(layoutBox);
                     if (containerBox.establishesInlineFormattingContext()) {
                         // IFCs inherit floats from parent FCs. We need final vertical position to find intruding floats.
-                        precomputeVerticalPositionForBoxAndAncestors(containerBox, horizontalConstraintsPair, verticalConstraintsPair);
+                        precomputeVerticalPositionForBoxAndAncestors(containerBox, { constraints, containingBlockConstraints });
                         if (containerBox.hasFloatClear()) {
                             // Roots with clear set are special because they both inherit floats but avoid them the same time. 
                             // If we just let the root sit at the pre-computed static vertical position, we might find unrelated
@@ -140,11 +130,8 @@ void BlockFormattingContext::layoutInFlowContent(InvalidationState& invalidation
                             computeVerticalPositionForFloatClear(floatingContext, containerBox);
                         }
                     }
-                    auto& rootDisplayBox = geometryForBox(containerBox);
-                    auto horizontalConstraintsForInFlowContent = Geometry::horizontalConstraintsForInFlow(rootDisplayBox);
-                    auto verticalConstraintsForInFlowContent = Geometry::verticalConstraintsForInFlow(rootDisplayBox);
                     // Layout the inflow descendants of this formatting context root.
-                    LayoutContext::createFormattingContext(containerBox, layoutState())->layoutInFlowContent(invalidationState, horizontalConstraintsForInFlowContent, verticalConstraintsForInFlowContent);
+                    LayoutContext::createFormattingContext(containerBox, layoutState())->layoutInFlowContent(invalidationState, Geometry::constraintsForInFlowContent(geometryForBox(containerBox)));
                 }
                 break;
             }
@@ -155,11 +142,10 @@ void BlockFormattingContext::layoutInFlowContent(InvalidationState& invalidation
         // Climb back on the ancestors and compute height/final position.
         while (!layoutQueue.isEmpty()) {
             auto& layoutBox = *layoutQueue.takeLast();
-            auto horizontalConstraints = horizontalConstraintsForLayoutBox(layoutBox);
-            auto verticalConstraints = verticalConstraintsForLayoutBox(layoutBox);
+            auto containingBlockConstraints = constraintsForLayoutBox(layoutBox);
 
             // All inflow descendants (if there are any) are laid out by now. Let's compute the box's height.
-            computeHeightAndMargin(layoutBox, horizontalConstraints, verticalConstraints);
+            computeHeightAndMargin(layoutBox, containingBlockConstraints);
 
             auto establishesFormattingContext = layoutBox.establishesFormattingContext(); 
             if (establishesFormattingContext) {
@@ -174,25 +160,23 @@ void BlockFormattingContext::layoutInFlowContent(InvalidationState& invalidation
             }
             // Resolve final positions.
             if (layoutBox.isFloatAvoider()) {
-                auto horizontalConstraintsPair = ConstraintsPair<HorizontalConstraints> { rootHorizontalConstraints, horizontalConstraints };
-                auto verticalConstraintsPair = ConstraintsPair<VerticalConstraints> { rootVerticalConstraints, verticalConstraints };
-                computePositionToAvoidFloats(floatingContext, layoutBox, horizontalConstraintsPair, verticalConstraintsPair);
+                computePositionToAvoidFloats(floatingContext, layoutBox, { constraints, containingBlockConstraints });
                 if (layoutBox.isFloatingPositioned())
                     floatingContext.append(layoutBox);
             }
             if (!establishesFormattingContext && is<ContainerBox>(layoutBox))
-                placeInFlowPositionedChildren(downcast<ContainerBox>(layoutBox), horizontalConstraints);
+                placeInFlowPositionedChildren(downcast<ContainerBox>(layoutBox), containingBlockConstraints.horizontal);
 
             if (appendNextToLayoutQueue(layoutBox, LayoutDirection::Sibling))
                 break;
         }
     }
     // Place the inflow positioned children.
-    placeInFlowPositionedChildren(formattingRoot, rootHorizontalConstraints);
+    placeInFlowPositionedChildren(formattingRoot, constraints.horizontal);
     LOG_WITH_STREAM(FormattingContextLayout, stream << "[End] -> block formatting context -> formatting root(" << &root() << ")");
 }
 
-Optional<LayoutUnit> BlockFormattingContext::usedAvailableWidthForFloatAvoider(const FloatingContext& floatingContext, const Box& layoutBox, const ConstraintsPair<HorizontalConstraints>& horizontalConstraints, const ConstraintsPair<VerticalConstraints>& verticalConstraints)
+Optional<LayoutUnit> BlockFormattingContext::usedAvailableWidthForFloatAvoider(const FloatingContext& floatingContext, const Box& layoutBox, const ConstraintsPair& constraintsPair)
 {
     // Normally the available width for an in-flow block level box is the width of the containing block's content box.
     // However (and can't find it anywhere in the spec) non-floating positioned float avoider block level boxes are constrained by existing floats.
@@ -206,7 +190,7 @@ Optional<LayoutUnit> BlockFormattingContext::usedAvailableWidthForFloatAvoider(c
 
     ASSERT(layoutBox.establishesFormattingContext());
     // Vertical static position is not computed yet for this formatting context root, so let's just pre-compute it for now.
-    precomputeVerticalPositionForBoxAndAncestors(layoutBox, horizontalConstraints, verticalConstraints);
+    precomputeVerticalPositionForBoxAndAncestors(layoutBox, constraintsPair);
 
     auto mapLogicalTopToFormattingContextRoot = [&] {
         auto& formattingContextRoot = root();
@@ -223,12 +207,12 @@ Optional<LayoutUnit> BlockFormattingContext::usedAvailableWidthForFloatAvoider(c
     if (!constraints.left && !constraints.right)
         return { };
     // Shrink the available space if the floats are actually intruding at this vertical position.
-    auto availableWidth = horizontalConstraints.containingBlock.logicalWidth;
+    auto availableWidth = constraintsPair.containingBlock.horizontal.logicalWidth;
     if (constraints.left)
         availableWidth -= constraints.left->x;
     if (constraints.right) {
         // FIXME: Map the logicalRight to the root's coordinate system.
-        availableWidth -= std::max(0_lu, horizontalConstraints.containingBlock.logicalRight() - constraints.right->x);
+        availableWidth -= std::max(0_lu, constraintsPair.containingBlock.horizontal.logicalRight() - constraints.right->x);
     }
     return availableWidth;
 }
@@ -255,13 +239,13 @@ void BlockFormattingContext::computeStaticHorizontalPosition(const Box& layoutBo
     formattingState().displayBox(layoutBox).setLeft(geometry().staticHorizontalPosition(layoutBox, horizontalConstraints));
 }
 
-void BlockFormattingContext::precomputeVerticalPositionForAncestors(const Box& layoutBox, const ConstraintsPair<HorizontalConstraints>& horizontalConstraints, const ConstraintsPair<VerticalConstraints>& verticalConstraints)
+void BlockFormattingContext::precomputeVerticalPositionForAncestors(const Box& layoutBox, const ConstraintsPair& constraintsPair)
 {
     ASSERT(layoutBox.isFloatAvoider());
-    precomputeVerticalPositionForBoxAndAncestors(layoutBox.containingBlock(), horizontalConstraints, verticalConstraints);
+    precomputeVerticalPositionForBoxAndAncestors(layoutBox.containingBlock(), constraintsPair);
 }
 
-void BlockFormattingContext::precomputeVerticalPositionForBoxAndAncestors(const Box& layoutBox, const ConstraintsPair<HorizontalConstraints>& horizontalConstraints, const ConstraintsPair<VerticalConstraints>& verticalConstraints)
+void BlockFormattingContext::precomputeVerticalPositionForBoxAndAncestors(const Box& layoutBox, const ConstraintsPair& constraintsPair)
 {
     // In order to figure out whether a box should avoid a float, we need to know the final positions of both (ignore relative positioning for now).
     // In block formatting context the final position for a normal flow box includes
@@ -274,16 +258,12 @@ void BlockFormattingContext::precomputeVerticalPositionForBoxAndAncestors(const
     // 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.
     // FIXME: we currently don't account for the "clear" property when computing the final position for an ancestor.
     for (auto* ancestor = &layoutBox; ancestor && ancestor != &root(); ancestor = &ancestor->containingBlock()) {
-        auto horizontalConstraintsForAncestor = [&] {
-            auto& containingBlock = ancestor->containingBlock();
-            return &containingBlock == &root() ? horizontalConstraints.root : Geometry::horizontalConstraintsForInFlow(geometryForBox(containingBlock));
-        };
-        auto verticalConstraintsForAncestor = [&] {
+        auto constraintsForAncestor = [&] {
             auto& containingBlock = ancestor->containingBlock();
-            return &containingBlock == &root() ? verticalConstraints.root : Geometry::verticalConstraintsForInFlow(geometryForBox(containingBlock));
-        };
+            return &containingBlock == &root() ? constraintsPair.formattingContextRoot : Geometry::constraintsForInFlowContent(geometryForBox(containingBlock));
+        }();
 
-        auto computedVerticalMargin = geometry().computedVerticalMargin(*ancestor, horizontalConstraintsForAncestor());
+        auto computedVerticalMargin = geometry().computedVerticalMargin(*ancestor, constraintsForAncestor.horizontal);
         auto usedNonCollapsedMargin = UsedVerticalMargin::NonCollapsedValues { computedVerticalMargin.before.valueOr(0), computedVerticalMargin.after.valueOr(0) };
         auto precomputedMarginBefore = marginCollapse().precomputedMarginBefore(*ancestor, usedNonCollapsedMargin);
         formattingState().setPositiveAndNegativeVerticalMargin(*ancestor, { precomputedMarginBefore.positiveAndNegativeMarginBefore, { } });
@@ -293,7 +273,7 @@ void BlockFormattingContext::precomputeVerticalPositionForBoxAndAncestors(const
         auto collapsedValues = UsedVerticalMargin::CollapsedValues { precomputedMarginBefore.collapsedValue, { }, false };
         auto verticalMargin = UsedVerticalMargin { nonCollapsedValues, collapsedValues };
         displayBox.setVerticalMargin(verticalMargin);
-        displayBox.setTop(verticalPositionWithMargin(*ancestor, verticalMargin, verticalConstraintsForAncestor()));
+        displayBox.setTop(verticalPositionWithMargin(*ancestor, verticalMargin, constraintsForAncestor.vertical));
 #if ASSERT_ENABLED
         setPrecomputedMarginBefore(*ancestor, precomputedMarginBefore);
         displayBox.setHasPrecomputedMarginBefore();
@@ -301,7 +281,7 @@ void BlockFormattingContext::precomputeVerticalPositionForBoxAndAncestors(const
     }
 }
 
-void BlockFormattingContext::computePositionToAvoidFloats(const FloatingContext& floatingContext, const Box& layoutBox, const ConstraintsPair<HorizontalConstraints>& horizontalConstraints, const ConstraintsPair<VerticalConstraints>& verticalConstraints)
+void BlockFormattingContext::computePositionToAvoidFloats(const FloatingContext& floatingContext, const Box& layoutBox, const ConstraintsPair& constraintsPair)
 {
     ASSERT(layoutBox.isFloatAvoider());
     // In order to position a float avoider we need to know its vertical position relative to its formatting context root (and not just its containing block),
@@ -309,14 +289,14 @@ void BlockFormattingContext::computePositionToAvoidFloats(const FloatingContext&
     // to a different set of containing blocks (but they all descendants of the BFC root).
     // However according to the BFC rules, at this point of the layout flow we don't yet have computed vertical positions for the ancestors.
     if (layoutBox.isFloatingPositioned()) {
-        precomputeVerticalPositionForAncestors(layoutBox, horizontalConstraints, verticalConstraints);
-        formattingState().displayBox(layoutBox).setTopLeft(floatingContext.positionForFloat(layoutBox, horizontalConstraints.containingBlock));
+        precomputeVerticalPositionForAncestors(layoutBox, constraintsPair);
+        formattingState().displayBox(layoutBox).setTopLeft(floatingContext.positionForFloat(layoutBox, constraintsPair.containingBlock.horizontal));
         return;
     }
     // Non-float positioned float avoiders (formatting context roots and clear boxes) should be fine unless there are floats in this context.
     if (floatingContext.isEmpty())
         return;
-    precomputeVerticalPositionForAncestors(layoutBox, horizontalConstraints, verticalConstraints);
+    precomputeVerticalPositionForAncestors(layoutBox, constraintsPair);
     if (layoutBox.hasFloatClear())
         return computeVerticalPositionForFloatClear(floatingContext, layoutBox);
 
@@ -344,9 +324,9 @@ void BlockFormattingContext::computeVerticalPositionForFloatClear(const Floating
     // FIXME: Reset the margin values on the ancestors/previous siblings now that the float avoider with clearance does not margin collapse anymore.
 }
 
-void BlockFormattingContext::computeWidthAndMargin(const FloatingContext& floatingContext, const Box& layoutBox, const ConstraintsPair<HorizontalConstraints>& horizontalConstraintsPair, const ConstraintsPair<VerticalConstraints>& verticalConstraintsPair)
+void BlockFormattingContext::computeWidthAndMargin(const FloatingContext& floatingContext, const Box& layoutBox, const ConstraintsPair& constraintsPair)
 {
-    auto& horizontalConstraints = horizontalConstraintsPair.containingBlock
+    auto& horizontalConstraints = constraintsPair.containingBlock.horizontal
     auto compute = [&](Optional<LayoutUnit> usedWidth) -> ContentWidthAndMargin {
         if (layoutBox.isFloatingPositioned())
             return geometry().floatingWidthAndMargin(layoutBox, horizontalConstraints, { usedWidth, { } });
@@ -354,7 +334,7 @@ void BlockFormattingContext::computeWidthAndMargin(const FloatingContext& floati
         if (layoutBox.isFloatAvoider()) {
             auto availableWidth = horizontalConstraints.logicalWidth;
             if (layoutBox.style().logicalWidth().isAuto())
-                availableWidth = usedAvailableWidthForFloatAvoider(floatingContext, layoutBox, horizontalConstraintsPair, verticalConstraintsPair).valueOr(availableWidth);
+                availableWidth = usedAvailableWidthForFloatAvoider(floatingContext, layoutBox, constraintsPair).valueOr(availableWidth);
             return geometry().inFlowWidthAndMargin(layoutBox, { horizontalConstraints.logicalLeft, availableWidth }, { usedWidth, { } });
         }
 
@@ -385,14 +365,14 @@ void BlockFormattingContext::computeWidthAndMargin(const FloatingContext& floati
     displayBox.setHorizontalComputedMargin(contentWidthAndMargin.computedMargin);
 }
 
-void BlockFormattingContext::computeHeightAndMargin(const Box& layoutBox, const HorizontalConstraints& horizontalConstraints, const VerticalConstraints& verticalConstraints)
+void BlockFormattingContext::computeHeightAndMargin(const Box& layoutBox, const ConstraintsForInFlowContent& constraints)
 {
     auto compute = [&](Optional<LayoutUnit> usedHeight) -> ContentHeightAndMargin {
         if (layoutBox.isInFlow())
-            return geometry().inFlowHeightAndMargin(layoutBox, horizontalConstraints, { usedHeight });
+            return geometry().inFlowHeightAndMargin(layoutBox, constraints.horizontal, { usedHeight });
 
         if (layoutBox.isFloatingPositioned())
-            return geometry().floatingHeightAndMargin(layoutBox, horizontalConstraints, { usedHeight });
+            return geometry().floatingHeightAndMargin(layoutBox, constraints.horizontal, { usedHeight });
 
         ASSERT_NOT_REACHED();
         return { };
@@ -449,7 +429,7 @@ void BlockFormattingContext::computeHeightAndMargin(const Box& layoutBox, const
     }
 #endif
     auto& displayBox = formattingState().displayBox(layoutBox);
-    displayBox.setTop(verticalPositionWithMargin(layoutBox, verticalMargin, verticalConstraints));
+    displayBox.setTop(verticalPositionWithMargin(layoutBox, verticalMargin, constraints.vertical));
     displayBox.setContentBoxHeight(contentHeightAndMargin.contentHeight);
     displayBox.setVerticalMargin(verticalMargin);
     // Adjust the previous sibling's margin bottom now that this box's vertical margin is computed.
index 1b183b2..fa3ea02 100644 (file)
@@ -48,27 +48,26 @@ class BlockFormattingContext final : public FormattingContext {
 public:
     BlockFormattingContext(const ContainerBox& formattingContextRoot, BlockFormattingState&);
 
-    void layoutInFlowContent(InvalidationState&, const HorizontalConstraints&, const VerticalConstraints&) override;
+    void layoutInFlowContent(InvalidationState&, const ConstraintsForInFlowContent&) override;
 
 private:
 
-    template<typename T>
     struct ConstraintsPair {
-        const T root;
-        const T containingBlock;
+        const ConstraintsForInFlowContent formattingContextRoot;
+        const ConstraintsForInFlowContent containingBlock;
     };
     void placeInFlowPositionedChildren(const ContainerBox&, const HorizontalConstraints&);
 
-    void computeWidthAndMargin(const FloatingContext&, const Box&, const ConstraintsPair<HorizontalConstraints>&, const ConstraintsPair<VerticalConstraints>&);
-    void computeHeightAndMargin(const Box&, const HorizontalConstraints&, const VerticalConstraints&);
+    void computeWidthAndMargin(const FloatingContext&, const Box&, const ConstraintsPair&);
+    void computeHeightAndMargin(const Box&, const ConstraintsForInFlowContent&);
 
     void computeStaticHorizontalPosition(const Box&, const HorizontalConstraints&);
     void computeStaticVerticalPosition(const Box&, const VerticalConstraints&);
-    void computePositionToAvoidFloats(const FloatingContext&, const Box&, const ConstraintsPair<HorizontalConstraints>&, const ConstraintsPair<VerticalConstraints>&);
+    void computePositionToAvoidFloats(const FloatingContext&, const Box&, const ConstraintsPair&);
     void computeVerticalPositionForFloatClear(const FloatingContext&, const Box&);
 
-    void precomputeVerticalPositionForAncestors(const Box&, const ConstraintsPair<HorizontalConstraints>&, const ConstraintsPair<VerticalConstraints>&);
-    void precomputeVerticalPositionForBoxAndAncestors(const Box&, const ConstraintsPair<HorizontalConstraints>&, const ConstraintsPair<VerticalConstraints>&);
+    void precomputeVerticalPositionForAncestors(const Box&, const ConstraintsPair&);
+    void precomputeVerticalPositionForBoxAndAncestors(const Box&, const ConstraintsPair&);
 
     IntrinsicWidthConstraints computedIntrinsicWidthConstraints() override;
     LayoutUnit verticalPositionWithMargin(const Box&, const UsedVerticalMargin&, const VerticalConstraints&) const;
@@ -167,7 +166,7 @@ private:
     };
     BlockFormattingContext::Quirks quirks() const { return Quirks(*this); }
 
-    Optional<LayoutUnit> usedAvailableWidthForFloatAvoider(const FloatingContext&, const Box&, const ConstraintsPair<HorizontalConstraints>&, const ConstraintsPair<VerticalConstraints>&);
+    Optional<LayoutUnit> usedAvailableWidthForFloatAvoider(const FloatingContext&, const Box&, const ConstraintsPair&);
 
     const BlockFormattingState& formattingState() const { return downcast<BlockFormattingState>(FormattingContext::formattingState()); }
     BlockFormattingState& formattingState() { return downcast<BlockFormattingState>(FormattingContext::formattingState()); }
index ebfbb1f..dcf8725 100644 (file)
@@ -91,7 +91,7 @@ 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::horizontalConstraintsForInFlow(initialContainingBlockGeometry));
+        auto precomputeDocumentBoxVerticalMargin = formattingContext.geometry().computedVerticalMargin(documentBox, Geometry::constraintsForInFlowContent(initialContainingBlockGeometry).horizontal);
         bodyBoxContentHeight -= precomputeDocumentBoxVerticalMargin.before.valueOr(0) + precomputeDocumentBoxVerticalMargin.after.valueOr(0);
     }
     return std::max(contentHeightAndMargin.contentHeight,  bodyBoxContentHeight);
index 1f2ab73..4c7887e 100644 (file)
@@ -44,7 +44,7 @@ PositiveAndNegativeVerticalMargin::Values BlockFormattingContext::MarginCollapse
     if (blockFormattingState.hasPositiveAndNegativeVerticalMargin(layoutBox))
         return blockFormattingState.positiveAndNegativeVerticalMargin(layoutBox).before;
 
-    auto horizontalConstraints = Geometry::horizontalConstraintsForInFlow(formattingContext().geometryForBox(layoutBox.containingBlock()));
+    auto horizontalConstraints = Geometry::constraintsForInFlowContent(formattingContext().geometryForBox(layoutBox.containingBlock())).horizontal;
     auto computedVerticalMargin = formattingContext().geometry().computedVerticalMargin(layoutBox, horizontalConstraints);
     auto nonCollapsedMargin = UsedVerticalMargin::NonCollapsedValues { computedVerticalMargin.before.valueOr(0), computedVerticalMargin.after.valueOr(0) };
     return precomputedPositiveNegativeMarginBefore(layoutBox, nonCollapsedMargin);
index 9c4d92d..6a83e16 100644 (file)
@@ -76,7 +76,7 @@ static inline const Box* nextInlineLevelBoxToLayout(const Box& layoutBox, const
     return nullptr;
 }
 
-void InlineFormattingContext::layoutInFlowContent(InvalidationState& invalidationState, const HorizontalConstraints& horizontalConstraints, const VerticalConstraints& verticalConstraints)
+void InlineFormattingContext::layoutInFlowContent(InvalidationState& invalidationState, const ConstraintsForInFlowContent& constraints)
 {
     LOG_WITH_STREAM(FormattingContextLayout, stream << "[Start] -> inline formatting context -> formatting root(" << &root() << ")");
     ASSERT(root().hasInFlowOrFloatingChild());
@@ -93,35 +93,33 @@ void InlineFormattingContext::layoutInFlowContent(InvalidationState& invalidatio
             if (is<ContainerBox>(layoutBox) && layoutBox->establishesFormattingContext()) {
                 ASSERT(layoutBox->isInlineBlockBox() || layoutBox->isInlineTableBox() || layoutBox->isFloatingPositioned());
                 auto& containerBox = downcast<ContainerBox>(*layoutBox);
-                computeBorderAndPadding(containerBox, horizontalConstraints);
-                computeWidthAndMargin(containerBox, horizontalConstraints);
+                computeBorderAndPadding(containerBox, constraints.horizontal);
+                computeWidthAndMargin(containerBox, constraints.horizontal);
 
-                auto& rootDisplayBox = geometryForBox(containerBox);
+                auto& formattingRootDisplayBox = geometryForBox(containerBox);
                 if (containerBox.hasInFlowOrFloatingChild()) {
-                    auto horizontalConstraintsForInFlowContent = Geometry::horizontalConstraintsForInFlow(rootDisplayBox);
-                    auto verticalConstraintsForInFlowContent = Geometry::verticalConstraintsForInFlow(rootDisplayBox);
                     auto formattingContext = LayoutContext::createFormattingContext(containerBox, layoutState());
-                    formattingContext->layoutInFlowContent(invalidationState, horizontalConstraintsForInFlowContent, verticalConstraintsForInFlowContent);
+                    formattingContext->layoutInFlowContent(invalidationState, Geometry::constraintsForInFlowContent(formattingRootDisplayBox));
                 }
-                computeHeightAndMargin(containerBox, horizontalConstraints);
+                computeHeightAndMargin(containerBox, constraints.horizontal);
                 if (containerBox.hasChild()) {
-                    auto horizontalConstraintsForOutOfFlow = Geometry::horizontalConstraintsForOutOfFlow(rootDisplayBox);
-                    auto verticalConstraintsForOutOfFlow = Geometry::verticalConstraintsForOutOfFlow(rootDisplayBox);
+                    auto horizontalConstraintsForOutOfFlow = Geometry::horizontalConstraintsForOutOfFlow(formattingRootDisplayBox);
+                    auto verticalConstraintsForOutOfFlow = Geometry::verticalConstraintsForOutOfFlow(formattingRootDisplayBox);
                     auto formattingContext = LayoutContext::createFormattingContext(containerBox, layoutState());
                     formattingContext->layoutOutOfFlowContent(invalidationState, horizontalConstraintsForOutOfFlow, verticalConstraintsForOutOfFlow);
                 }
             } else {
                 // Replaced and other type of leaf atomic inline boxes.
-                computeBorderAndPadding(*layoutBox, horizontalConstraints);
-                computeWidthAndMargin(*layoutBox, horizontalConstraints);
-                computeHeightAndMargin(*layoutBox, horizontalConstraints);
+                computeBorderAndPadding(*layoutBox, constraints.horizontal);
+                computeWidthAndMargin(*layoutBox, constraints.horizontal);
+                computeHeightAndMargin(*layoutBox, constraints.horizontal);
             }
         } else if (layoutBox->isInlineBox()) {
             // Text wrapper boxes (anonymous inline level boxes) and <br>s don't generate display boxes (only display runs).
             if (!layoutBox->isInlineTextBox() && !layoutBox->isLineBreakBox()) {
                 // Inline boxes (<span>) can't get sized/positioned yet. At this point we can only compute their margins, borders and paddings.
-                computeBorderAndPadding(*layoutBox, horizontalConstraints);
-                computeHorizontalMargin(*layoutBox, horizontalConstraints);
+                computeBorderAndPadding(*layoutBox, constraints.horizontal);
+                computeHorizontalMargin(*layoutBox, constraints.horizontal);
                 formattingState().displayBox(*layoutBox).setVerticalMargin({ { }, { } });
             }
         } else
@@ -133,13 +131,13 @@ void InlineFormattingContext::layoutInFlowContent(InvalidationState& invalidatio
     collectInlineContentIfNeeded();
 
     auto& inlineItems = formattingState().inlineItems();
-    lineLayout(inlineItems, { 0, inlineItems.size() }, horizontalConstraints, verticalConstraints);
+    lineLayout(inlineItems, { 0, inlineItems.size() }, constraints);
     LOG_WITH_STREAM(FormattingContextLayout, stream << "[End] -> inline formatting context -> formatting root(" << &root() << ")");
 }
 
-void InlineFormattingContext::lineLayout(InlineItems& inlineItems, LineLayoutContext::InlineItemRange layoutRange, const HorizontalConstraints& horizontalConstraints, const VerticalConstraints& verticalConstraints)
+void InlineFormattingContext::lineLayout(InlineItems& inlineItems, LineLayoutContext::InlineItemRange layoutRange, const ConstraintsForInFlowContent& constraints)
 {
-    auto lineLogicalTop = verticalConstraints.logicalTop;
+    auto lineLogicalTop = constraints.vertical.logicalTop;
     struct PreviousLineEnd {
         unsigned runIndex;
         Optional<unsigned> overflowContentLength;
@@ -149,9 +147,9 @@ void InlineFormattingContext::lineLayout(InlineItems& inlineItems, LineLayoutCon
     auto lineLayoutContext = LineLayoutContext { *this, root(), inlineItems };
 
     while (!layoutRange.isEmpty()) {
-        lineBuilder.initialize(constraintsForLine(horizontalConstraints, lineLogicalTop));
+        lineBuilder.initialize(constraintsForLine(constraints.horizontal, lineLogicalTop));
         auto lineContent = lineLayoutContext.layoutLine(lineBuilder, layoutRange, previousLineEnd ? previousLineEnd->overflowContentLength : WTF::nullopt);
-        setDisplayBoxesForLine(lineContent, horizontalConstraints);
+        setDisplayBoxesForLine(lineContent, constraints.horizontal);
 
         if (lineContent.trailingInlineItemIndex) {
             lineLogicalTop = lineContent.lineBox.logicalBottom();
index 88b9920..bc19b2f 100644 (file)
@@ -43,7 +43,7 @@ class InlineFormattingContext final : public FormattingContext {
     WTF_MAKE_ISO_ALLOCATED(InlineFormattingContext);
 public:
     InlineFormattingContext(const ContainerBox& formattingContextRoot, InlineFormattingState&);
-    void layoutInFlowContent(InvalidationState&, const HorizontalConstraints&, const VerticalConstraints&) override;
+    void layoutInFlowContent(InvalidationState&, const ConstraintsForInFlowContent&) override;
 
 private:
     IntrinsicWidthConstraints computedIntrinsicWidthConstraints() override;
@@ -77,7 +77,7 @@ private:
     };
     InlineFormattingContext::Geometry geometry() const { return Geometry(*this); }
 
-    void lineLayout(InlineItems&, LineLayoutContext::InlineItemRange, const HorizontalConstraints&, const VerticalConstraints&);
+    void lineLayout(InlineItems&, LineLayoutContext::InlineItemRange, const ConstraintsForInFlowContent&);
 
     void computeIntrinsicWidthForFormattingRoot(const Box&);
     InlineLayoutUnit computedIntrinsicWidthForConstraint(InlineLayoutUnit availableWidth) const;
index 82e89d3..a1808c4 100644 (file)
@@ -110,7 +110,7 @@ void LineLayout::layout()
     auto horizontalConstraints = Layout::HorizontalConstraints { m_flow.borderAndPaddingStart(), m_flow.contentSize().width() };
     auto verticalConstraints = Layout::VerticalConstraints { m_flow.borderAndPaddingBefore(), { } };
 
-    inlineFormattingContext.layoutInFlowContent(invalidationState, horizontalConstraints, verticalConstraints);
+    inlineFormattingContext.layoutInFlowContent(invalidationState, { horizontalConstraints, verticalConstraints });
     m_inlineFormattingState.shrinkDisplayInlineContent();
 }
 
index d6bdb35..988f5ed 100644 (file)
@@ -48,17 +48,19 @@ TableFormattingContext::TableFormattingContext(const ContainerBox& formattingCon
 {
 }
 
-void TableFormattingContext::layoutInFlowContent(InvalidationState&, const HorizontalConstraints& horizontalConstraints, const VerticalConstraints& verticalConstraints)
+void TableFormattingContext::layoutInFlowContent(InvalidationState&, const ConstraintsForInFlowContent& constraints)
 {
+    auto availableHorizontalSpace = constraints.horizontal.logicalWidth;
+    auto availableVerticalSpace = constraints.vertical.logicalHeight;
     // 1. Compute width and height for the grid.
-    computeAndDistributeExtraHorizontalSpace(horizontalConstraints.logicalWidth);
-    computeAndDistributeExtraVerticalSpace(horizontalConstraints.logicalWidth, verticalConstraints.logicalHeight);
+    computeAndDistributeExtraHorizontalSpace(availableHorizontalSpace);
+    computeAndDistributeExtraVerticalSpace(availableHorizontalSpace, availableVerticalSpace);
     // 2. Finalize cells.
-    setUsedGeometryForCells(horizontalConstraints.logicalWidth);
+    setUsedGeometryForCells(availableHorizontalSpace);
     // 3. Finalize rows.
-    setUsedGeometryForRows(horizontalConstraints.logicalWidth);
+    setUsedGeometryForRows(availableHorizontalSpace);
     // 4. Finalize sections.
-    setUsedGeometryForSections(horizontalConstraints.logicalWidth);
+    setUsedGeometryForSections(availableHorizontalSpace);
 }
 
 void TableFormattingContext::setUsedGeometryForCells(LayoutUnit availableHorizontalSpace)
@@ -174,10 +176,10 @@ void TableFormattingContext::layoutCell(const TableGrid::Cell& cell, LayoutUnit
     cellDisplayBox.setContentBoxWidth(availableSpaceForContent);
 
     if (cellBox.hasInFlowOrFloatingChild()) {
-        auto horizontalConstraintsForCellContent = Geometry::horizontalConstraintsForInFlow(cellDisplayBox);
-        auto verticalConstraintsForCellContent = VerticalConstraints { cellDisplayBox.contentBoxTop(), usedCellHeight };
         auto invalidationState = InvalidationState { };
-        LayoutContext::createFormattingContext(cellBox, layoutState())->layoutInFlowContent(invalidationState, horizontalConstraintsForCellContent, verticalConstraintsForCellContent);
+        auto constraintsForCellContent = Geometry::constraintsForInFlowContent(cellDisplayBox);
+        constraintsForCellContent.vertical.logicalHeight = usedCellHeight;
+        LayoutContext::createFormattingContext(cellBox, layoutState())->layoutInFlowContent(invalidationState, constraintsForCellContent);
     }
     cellDisplayBox.setContentBoxHeight(geometry().cellHeigh(cellBox));
 }
index 9c6a0a7..72dbc37 100644 (file)
@@ -42,7 +42,7 @@ class TableFormattingContext final : public FormattingContext {
     WTF_MAKE_ISO_ALLOCATED(TableFormattingContext);
 public:
     TableFormattingContext(const ContainerBox& formattingContextRoot, TableFormattingState&);
-    void layoutInFlowContent(InvalidationState&, const HorizontalConstraints&, const VerticalConstraints&) override;
+    void layoutInFlowContent(InvalidationState&, const ConstraintsForInFlowContent&) override;
 
 private:
     class Geometry : public FormattingContext::Geometry {