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

Reviewed by Antti Koivisto.

Horizontal and vertical out-of-flow constraints are always computed and used in pairs.

* layout/FormattingContext.cpp:
(WebCore::Layout::FormattingContext::computeOutOfFlowHorizontalGeometry):
(WebCore::Layout::FormattingContext::computeOutOfFlowVerticalGeometry):
(WebCore::Layout::FormattingContext::layoutOutOfFlowContent):
* layout/FormattingContext.h:
* layout/FormattingContextGeometry.cpp:
(WebCore::Layout::FormattingContext::Geometry::constraintsForOutOfFlowContent):
(WebCore::Layout::FormattingContext::Geometry::horizontalConstraintsForOutOfFlow): Deleted.
(WebCore::Layout::FormattingContext::Geometry::verticalConstraintsForOutOfFlow): Deleted.
* layout/LayoutContext.cpp:
(WebCore::Layout::LayoutContext::layoutFormattingContextSubtree):
* layout/LayoutUnits.h:
* layout/blockformatting/BlockFormattingContext.cpp:
(WebCore::Layout::BlockFormattingContext::layoutInFlowContent):
* layout/inlineformatting/InlineFormattingContext.cpp:
(WebCore::Layout::InlineFormattingContext::layoutInFlowContent):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@260827 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/LayoutContext.cpp
Source/WebCore/layout/LayoutUnits.h
Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp
Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp

index 52e6161..072009a 100644 (file)
@@ -1,5 +1,31 @@
 2020-04-28  Zalan Bujtas  <zalan@apple.com>
 
+        [LFC] Introduce FormattingContext::ConstraintsForOutOfFlowContent
+        https://bugs.webkit.org/show_bug.cgi?id=211125
+
+        Reviewed by Antti Koivisto.
+
+        Horizontal and vertical out-of-flow constraints are always computed and used in pairs.
+
+        * layout/FormattingContext.cpp:
+        (WebCore::Layout::FormattingContext::computeOutOfFlowHorizontalGeometry):
+        (WebCore::Layout::FormattingContext::computeOutOfFlowVerticalGeometry):
+        (WebCore::Layout::FormattingContext::layoutOutOfFlowContent):
+        * layout/FormattingContext.h:
+        * layout/FormattingContextGeometry.cpp:
+        (WebCore::Layout::FormattingContext::Geometry::constraintsForOutOfFlowContent):
+        (WebCore::Layout::FormattingContext::Geometry::horizontalConstraintsForOutOfFlow): Deleted.
+        (WebCore::Layout::FormattingContext::Geometry::verticalConstraintsForOutOfFlow): Deleted.
+        * layout/LayoutContext.cpp:
+        (WebCore::Layout::LayoutContext::layoutFormattingContextSubtree):
+        * layout/LayoutUnits.h:
+        * layout/blockformatting/BlockFormattingContext.cpp:
+        (WebCore::Layout::BlockFormattingContext::layoutInFlowContent):
+        * layout/inlineformatting/InlineFormattingContext.cpp:
+        (WebCore::Layout::InlineFormattingContext::layoutInFlowContent):
+
+2020-04-28  Zalan Bujtas  <zalan@apple.com>
+
         [LFC] Introduce FormattingContext::ConstraintsForInFlowContent
         https://bugs.webkit.org/show_bug.cgi?id=211113
 
index fe64fe3..11d8f0e 100644 (file)
@@ -69,14 +69,14 @@ LayoutState& FormattingContext::layoutState() const
     return m_formattingState.layoutState();
 }
 
-void FormattingContext::computeOutOfFlowHorizontalGeometry(const Box& layoutBox, const HorizontalConstraints& horizontalConstraints, const VerticalConstraints& verticalConstraints)
+void FormattingContext::computeOutOfFlowHorizontalGeometry(const Box& layoutBox, const ConstraintsForOutOfFlowContent& constraints)
 {
     ASSERT(layoutBox.isOutOfFlowPositioned());
     auto compute = [&](Optional<LayoutUnit> usedWidth) {
-        return geometry().outOfFlowHorizontalGeometry(layoutBox, horizontalConstraints, verticalConstraints, { usedWidth, { } });
+        return geometry().outOfFlowHorizontalGeometry(layoutBox, constraints.horizontal, constraints.vertical, { usedWidth, { } });
     };
 
-    auto containingBlockWidth = horizontalConstraints.logicalWidth;
+    auto containingBlockWidth = constraints.horizontal.logicalWidth;
     auto horizontalGeometry = compute({ });
     if (auto maxWidth = geometry().computedMaxWidth(layoutBox, containingBlockWidth)) {
         auto maxHorizontalGeometry = compute(maxWidth);
@@ -97,14 +97,14 @@ void FormattingContext::computeOutOfFlowHorizontalGeometry(const Box& layoutBox,
     displayBox.setHorizontalComputedMargin(horizontalGeometry.contentWidthAndMargin.computedMargin);
 }
 
-void FormattingContext::computeOutOfFlowVerticalGeometry(const Box& layoutBox, const HorizontalConstraints& horizontalConstraints, const VerticalConstraints& verticalConstraints)
+void FormattingContext::computeOutOfFlowVerticalGeometry(const Box& layoutBox, const ConstraintsForOutOfFlowContent& constraints)
 {
     ASSERT(layoutBox.isOutOfFlowPositioned());
     auto compute = [&](Optional<LayoutUnit> usedHeight) {
-        return geometry().outOfFlowVerticalGeometry(layoutBox, horizontalConstraints, verticalConstraints, { usedHeight });
+        return geometry().outOfFlowVerticalGeometry(layoutBox, constraints.horizontal, constraints.vertical, { usedHeight });
     };
 
-    auto containingBlockHeight = *verticalConstraints.logicalHeight;
+    auto containingBlockHeight = *constraints.vertical.logicalHeight;
     auto verticalGeometry = compute({ });
     if (auto maxHeight = geometry().computedMaxHeight(layoutBox, containingBlockHeight)) {
         auto maxVerticalGeometry = compute(maxHeight);
@@ -133,24 +133,15 @@ void FormattingContext::computeBorderAndPadding(const Box& layoutBox, const Hori
     displayBox.setPadding(geometry().computedPadding(layoutBox, horizontalConstraint.logicalWidth));
 }
 
-void FormattingContext::layoutOutOfFlowContent(InvalidationState& invalidationState, const OutOfFlowHorizontalConstraints& rootHorizontalConstraints, const VerticalConstraints& rootVerticalConstraints)
+void FormattingContext::layoutOutOfFlowContent(InvalidationState& invalidationState, const ConstraintsForOutOfFlowContent& constraints)
 {
     LOG_WITH_STREAM(FormattingContextLayout, stream << "Start: layout out-of-flow content -> context: " << &layoutState() << " root: " << &root());
 
     collectOutOfFlowDescendantsIfNeeded();
 
-    auto horizontalConstraintsForLayoutBox = [&] (const auto& outOfFlowBox) {
+    auto constraintsForLayoutBox = [&] (const auto& outOfFlowBox) {
         auto& containingBlock = outOfFlowBox.containingBlock();
-        if (&containingBlock == &root())
-            return rootHorizontalConstraints;
-        return Geometry::horizontalConstraintsForOutOfFlow(geometryForBox(containingBlock));
-    };
-
-    auto verticalConstraintsForLayoutBox = [&] (const auto& outOfFlowBox) {
-        auto& containingBlock = outOfFlowBox.containingBlock();
-        if (&containingBlock == &root())
-            return rootVerticalConstraints;
-        return Geometry::verticalConstraintsForOutOfFlow(geometryForBox(containingBlock));
+        return &containingBlock == &root() ? constraints : Geometry::constraintsForOutOfFlowContent(geometryForBox(containingBlock));
     };
 
     for (auto& outOfFlowBox : formattingState().outOfFlowBoxes()) {
@@ -158,13 +149,11 @@ void FormattingContext::layoutOutOfFlowContent(InvalidationState& invalidationSt
         if (!invalidationState.needsLayout(*outOfFlowBox))
             continue;
 
-        auto outOfFlowHorizontalConstraints = horizontalConstraintsForLayoutBox(*outOfFlowBox);
-        auto horizontalConstraintsForBorderAndPadding = HorizontalConstraints { outOfFlowHorizontalConstraints.value.logicalLeft, outOfFlowHorizontalConstraints.borderAndPaddingSpecificWidth };
+        auto containingBlockConstraints = constraintsForLayoutBox(*outOfFlowBox);
+        auto horizontalConstraintsForBorderAndPadding = HorizontalConstraints { containingBlockConstraints.horizontal.logicalLeft, containingBlockConstraints.borderAndPaddingConstraints };
         computeBorderAndPadding(*outOfFlowBox, horizontalConstraintsForBorderAndPadding);
 
-        auto horizontalConstraints = outOfFlowHorizontalConstraints.value;
-        auto verticalConstraints = verticalConstraintsForLayoutBox(*outOfFlowBox);
-        computeOutOfFlowHorizontalGeometry(*outOfFlowBox, horizontalConstraints, verticalConstraints);
+        computeOutOfFlowHorizontalGeometry(*outOfFlowBox, containingBlockConstraints);
         if (is<ContainerBox>(*outOfFlowBox)) {
             auto& containerBox = downcast<ContainerBox>(*outOfFlowBox);
             auto& containerDisplayBox = geometryForBox(containerBox);
@@ -173,15 +162,13 @@ void FormattingContext::layoutOutOfFlowContent(InvalidationState& invalidationSt
                 auto formattingContext = LayoutContext::createFormattingContext(containerBox, layoutState());
                 formattingContext->layoutInFlowContent(invalidationState, Geometry::constraintsForInFlowContent(containerDisplayBox));
             }
-            computeOutOfFlowVerticalGeometry(containerBox, horizontalConstraints, verticalConstraints);
+            computeOutOfFlowVerticalGeometry(containerBox, containingBlockConstraints);
             if (containerBox.hasChild()) {
-                auto horizontalConstraintsForOutOfFlowContent =  Geometry::horizontalConstraintsForOutOfFlow(containerDisplayBox);
-                auto verticalConstraintsForOutOfFlowContent = Geometry::verticalConstraintsForOutOfFlow(containerDisplayBox);
                 auto formattingContext = LayoutContext::createFormattingContext(containerBox, layoutState());
-                formattingContext->layoutOutOfFlowContent(invalidationState, horizontalConstraintsForOutOfFlowContent, verticalConstraintsForOutOfFlowContent);
+                formattingContext->layoutOutOfFlowContent(invalidationState, Geometry::constraintsForOutOfFlowContent(containerDisplayBox));
             }
         } else
-            computeOutOfFlowVerticalGeometry(*outOfFlowBox, horizontalConstraints, verticalConstraints);
+            computeOutOfFlowVerticalGeometry(*outOfFlowBox, containingBlockConstraints);
     }
     LOG_WITH_STREAM(FormattingContextLayout, stream << "End: layout out-of-flow content -> context: " << &layoutState() << " root: " << &root());
 }
index 2f848af..c818079 100644 (file)
@@ -70,7 +70,14 @@ public:
         VerticalConstraints vertical;
     };
     virtual void layoutInFlowContent(InvalidationState&, const ConstraintsForInFlowContent&) = 0;
-    void layoutOutOfFlowContent(InvalidationState&, const OutOfFlowHorizontalConstraints&, const VerticalConstraints&);
+
+    struct ConstraintsForOutOfFlowContent {
+        HorizontalConstraints horizontal;
+        VerticalConstraints vertical;
+        // Borders and paddings are resolved against the containing block's content box as if the box was an in-flow box.
+        LayoutUnit borderAndPaddingConstraints;
+    };
+    void layoutOutOfFlowContent(InvalidationState&, const ConstraintsForOutOfFlowContent&);
 
     struct IntrinsicWidthConstraints {
         void expand(LayoutUnit horizontalValue);
@@ -150,9 +157,8 @@ protected:
 
         LayoutUnit contentHeightForFormattingContextRoot(const Box&) const;
 
-        static OutOfFlowHorizontalConstraints horizontalConstraintsForOutOfFlow(const Display::Box& containingBlockGeometry);
-        static VerticalConstraints verticalConstraintsForOutOfFlow(const Display::Box& containingBlockGeometry);
-        static FormattingContext::ConstraintsForInFlowContent constraintsForInFlowContent(const Display::Box& containingBlockGeometry);
+        static ConstraintsForOutOfFlowContent constraintsForOutOfFlowContent(const Display::Box& containingBlockGeometry);
+        static ConstraintsForInFlowContent constraintsForInFlowContent(const Display::Box& containingBlockGeometry);
 
     protected:
         friend class FormattingContext;
@@ -204,8 +210,8 @@ protected:
 
 private:
     void collectOutOfFlowDescendantsIfNeeded();
-    void computeOutOfFlowVerticalGeometry(const Box&, const HorizontalConstraints&, const VerticalConstraints&);
-    void computeOutOfFlowHorizontalGeometry(const Box&, const HorizontalConstraints&, const VerticalConstraints&);
+    void computeOutOfFlowVerticalGeometry(const Box&, const ConstraintsForOutOfFlowContent&);
+    void computeOutOfFlowHorizontalGeometry(const Box&, const ConstraintsForOutOfFlowContent&);
 
     WeakPtr<const ContainerBox> m_root;
     FormattingState& m_formattingState;
index 37b0c00..ce1d575 100644 (file)
@@ -1098,18 +1098,14 @@ FormattingContext::IntrinsicWidthConstraints FormattingContext::Geometry::constr
     return intrinsicWidth;
 }
 
-OutOfFlowHorizontalConstraints FormattingContext::Geometry::horizontalConstraintsForOutOfFlow(const Display::Box& containingBlockGeometry)
+FormattingContext::ConstraintsForOutOfFlowContent FormattingContext::Geometry::constraintsForOutOfFlowContent(const Display::Box& containingBlockGeometry)
 {
-    return OutOfFlowHorizontalConstraints {
-        HorizontalConstraints { containingBlockGeometry.paddingBoxLeft(), containingBlockGeometry.paddingBoxWidth() },
+    return {
+        { containingBlockGeometry.paddingBoxLeft(), containingBlockGeometry.paddingBoxWidth() },
+        { containingBlockGeometry.paddingBoxTop(), containingBlockGeometry.paddingBoxHeight() },
         containingBlockGeometry.contentBoxWidth() };
 }
 
-VerticalConstraints FormattingContext::Geometry::verticalConstraintsForOutOfFlow(const Display::Box& containingBlockGeometry)
-{
-    return VerticalConstraints { containingBlockGeometry.paddingBoxTop(), containingBlockGeometry.paddingBoxHeight() };
-}
-
 FormattingContext::ConstraintsForInFlowContent FormattingContext::Geometry::constraintsForInFlowContent(const Display::Box& containingBlockGeometry)
 {
     return { { containingBlockGeometry.contentBoxLeft(), containingBlockGeometry.contentBoxWidth() }, { containingBlockGeometry.contentBoxTop(), { } } };
index ee8ddbd..284c624 100644 (file)
@@ -107,9 +107,9 @@ void LayoutContext::layoutFormattingContextSubtree(const ContainerBox& formattin
     // It constructs an FC for descendant boxes and runs layout on them. The formattingContextRoot is laid out in the FC in which it lives (parent formatting context).
     // It also means that the formattingContextRoot has to have a valid/clean geometry at this point.
     {
-        auto horizontalConstraints = OutOfFlowHorizontalConstraints { HorizontalConstraints { displayBox.paddingBoxLeft(), displayBox.paddingBoxWidth() }, displayBox.contentBoxWidth() };
-        auto verticalConstraints = VerticalConstraints { displayBox.paddingBoxTop(), displayBox.paddingBoxHeight() };
-        formattingContext->layoutOutOfFlowContent(invalidationState, horizontalConstraints, verticalConstraints);
+        auto constraints = FormattingContext::ConstraintsForOutOfFlowContent { { displayBox.paddingBoxLeft(), displayBox.paddingBoxWidth() },
+            { displayBox.paddingBoxTop(), displayBox.paddingBoxHeight() }, displayBox.contentBoxWidth() };
+        formattingContext->layoutOutOfFlowContent(invalidationState, constraints);
     }
 }
 
index 909324d..6260f8c 100644 (file)
@@ -161,12 +161,6 @@ struct HorizontalConstraints {
     LayoutUnit logicalWidth;
 };
 
-struct OutOfFlowHorizontalConstraints {
-    HorizontalConstraints value;
-    // Borders and paddings are resolved against the containing block's content box as if the box was an in-flow box.
-    LayoutUnit borderAndPaddingSpecificWidth;
-};
-
 struct VerticalConstraints {
     LayoutUnit logicalTop;
     Optional<LayoutUnit> logicalHeight;
index 822bf92..6677c9b 100644 (file)
@@ -152,10 +152,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);
-                    auto& rootDisplayBox = geometryForBox(containerBox);
-                    auto horizontalConstraintsForOutOfFlowContent =  Geometry::horizontalConstraintsForOutOfFlow(rootDisplayBox);
-                    auto verticalConstraintsForOutOfFlowContent = Geometry::verticalConstraintsForOutOfFlow(rootDisplayBox);
-                    LayoutContext::createFormattingContext(containerBox, layoutState())->layoutOutOfFlowContent(invalidationState, horizontalConstraintsForOutOfFlowContent, verticalConstraintsForOutOfFlowContent);
+                    LayoutContext::createFormattingContext(containerBox, layoutState())->layoutOutOfFlowContent(invalidationState, Geometry::constraintsForOutOfFlowContent(geometryForBox(containerBox)));
                 }
             }
             // Resolve final positions.
index 6a83e16..fa5d24a 100644 (file)
@@ -103,10 +103,8 @@ void InlineFormattingContext::layoutInFlowContent(InvalidationState& invalidatio
                 }
                 computeHeightAndMargin(containerBox, constraints.horizontal);
                 if (containerBox.hasChild()) {
-                    auto horizontalConstraintsForOutOfFlow = Geometry::horizontalConstraintsForOutOfFlow(formattingRootDisplayBox);
-                    auto verticalConstraintsForOutOfFlow = Geometry::verticalConstraintsForOutOfFlow(formattingRootDisplayBox);
                     auto formattingContext = LayoutContext::createFormattingContext(containerBox, layoutState());
-                    formattingContext->layoutOutOfFlowContent(invalidationState, horizontalConstraintsForOutOfFlow, verticalConstraintsForOutOfFlow);
+                    formattingContext->layoutOutOfFlowContent(invalidationState, Geometry::constraintsForOutOfFlowContent(formattingRootDisplayBox));
                 }
             } else {
                 // Replaced and other type of leaf atomic inline boxes.