[LFC] Do not pass LayoutState& to compute* and layout* functions
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 31 Oct 2018 13:51:56 +0000 (13:51 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 31 Oct 2018 13:51:56 +0000 (13:51 +0000)
https://bugs.webkit.org/show_bug.cgi?id=191100

Reviewed by Antti Koivisto.

Reduce noise by removing LayoutState& parameter where possible.

* layout/FormattingContext.cpp:
(WebCore::Layout::FormattingContext::computeOutOfFlowHorizontalGeometry const):
(WebCore::Layout::FormattingContext::computeOutOfFlowVerticalGeometry const):
(WebCore::Layout::FormattingContext::computeBorderAndPadding const):
(WebCore::Layout::FormattingContext::placeInFlowPositionedChildren const):
(WebCore::Layout::FormattingContext::layoutOutOfFlowDescendants const):
(WebCore::Layout::FormattingContext::validateGeometryConstraintsAfterLayout const):
* layout/FormattingContext.h:
* layout/FormattingContextGeometry.cpp:
(WebCore::Layout::FormattingContext::Geometry::shrinkToFitWidth):
* layout/LayoutFormattingState.cpp:
(WebCore::Layout::LayoutState::layoutFormattingContextSubtree):
* layout/blockformatting/BlockFormattingContext.cpp:
(WebCore::Layout::BlockFormattingContext::layout const):
(WebCore::Layout::BlockFormattingContext::layoutFormattingContextRoot const):
(WebCore::Layout::BlockFormattingContext::computeStaticPosition const):
(WebCore::Layout::BlockFormattingContext::computeEstimatedMarginTop const):
(WebCore::Layout::BlockFormattingContext::computeEstimatedMarginTopForAncestors const):
(WebCore::Layout::BlockFormattingContext::precomputeVerticalPositionForFormattingRootIfNeeded const):
(WebCore::Layout::BlockFormattingContext::computeFloatingPosition const):
(WebCore::Layout::BlockFormattingContext::computePositionToAvoidFloats const):
(WebCore::Layout::BlockFormattingContext::computeVerticalPositionForFloatClear const):
(WebCore::Layout::BlockFormattingContext::computeInFlowPositionedPosition const):
(WebCore::Layout::BlockFormattingContext::computeWidthAndMargin const):
(WebCore::Layout::BlockFormattingContext::computeHeightAndMargin const):
(WebCore::Layout::BlockFormattingContext::instrinsicWidthConstraints const):
* layout/blockformatting/BlockFormattingContext.h:
* layout/inlineformatting/InlineFormattingContext.cpp:
(WebCore::Layout::InlineFormattingContext::layout const):
(WebCore::Layout::InlineFormattingContext::initializeNewLine const):
(WebCore::Layout::InlineFormattingContext::layoutInlineContent const):
(WebCore::Layout::InlineFormattingContext::layoutFormattingContextRoot const):
(WebCore::Layout::InlineFormattingContext::computeWidthAndHeightForInlineBox const):
(WebCore::Layout::InlineFormattingContext::computeFloatPosition const):
(WebCore::Layout::InlineFormattingContext::computeStaticPosition const):
(WebCore::Layout::InlineFormattingContext::computeInFlowPositionedPosition const):
(WebCore::Layout::InlineFormattingContext::instrinsicWidthConstraints const):
* layout/inlineformatting/InlineFormattingContext.h:

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

index 9aa95c2..f811120 100644 (file)
@@ -1,5 +1,53 @@
 2018-10-31  Zalan Bujtas  <zalan@apple.com>
 
+        [LFC] Do not pass LayoutState& to compute* and layout* functions
+        https://bugs.webkit.org/show_bug.cgi?id=191100
+
+        Reviewed by Antti Koivisto.
+
+        Reduce noise by removing LayoutState& parameter where possible.
+
+        * layout/FormattingContext.cpp:
+        (WebCore::Layout::FormattingContext::computeOutOfFlowHorizontalGeometry const):
+        (WebCore::Layout::FormattingContext::computeOutOfFlowVerticalGeometry const):
+        (WebCore::Layout::FormattingContext::computeBorderAndPadding const):
+        (WebCore::Layout::FormattingContext::placeInFlowPositionedChildren const):
+        (WebCore::Layout::FormattingContext::layoutOutOfFlowDescendants const):
+        (WebCore::Layout::FormattingContext::validateGeometryConstraintsAfterLayout const):
+        * layout/FormattingContext.h:
+        * layout/FormattingContextGeometry.cpp:
+        (WebCore::Layout::FormattingContext::Geometry::shrinkToFitWidth):
+        * layout/LayoutFormattingState.cpp:
+        (WebCore::Layout::LayoutState::layoutFormattingContextSubtree):
+        * layout/blockformatting/BlockFormattingContext.cpp:
+        (WebCore::Layout::BlockFormattingContext::layout const):
+        (WebCore::Layout::BlockFormattingContext::layoutFormattingContextRoot const):
+        (WebCore::Layout::BlockFormattingContext::computeStaticPosition const):
+        (WebCore::Layout::BlockFormattingContext::computeEstimatedMarginTop const):
+        (WebCore::Layout::BlockFormattingContext::computeEstimatedMarginTopForAncestors const):
+        (WebCore::Layout::BlockFormattingContext::precomputeVerticalPositionForFormattingRootIfNeeded const):
+        (WebCore::Layout::BlockFormattingContext::computeFloatingPosition const):
+        (WebCore::Layout::BlockFormattingContext::computePositionToAvoidFloats const):
+        (WebCore::Layout::BlockFormattingContext::computeVerticalPositionForFloatClear const):
+        (WebCore::Layout::BlockFormattingContext::computeInFlowPositionedPosition const):
+        (WebCore::Layout::BlockFormattingContext::computeWidthAndMargin const):
+        (WebCore::Layout::BlockFormattingContext::computeHeightAndMargin const):
+        (WebCore::Layout::BlockFormattingContext::instrinsicWidthConstraints const):
+        * layout/blockformatting/BlockFormattingContext.h:
+        * layout/inlineformatting/InlineFormattingContext.cpp:
+        (WebCore::Layout::InlineFormattingContext::layout const):
+        (WebCore::Layout::InlineFormattingContext::initializeNewLine const):
+        (WebCore::Layout::InlineFormattingContext::layoutInlineContent const):
+        (WebCore::Layout::InlineFormattingContext::layoutFormattingContextRoot const):
+        (WebCore::Layout::InlineFormattingContext::computeWidthAndHeightForInlineBox const):
+        (WebCore::Layout::InlineFormattingContext::computeFloatPosition const):
+        (WebCore::Layout::InlineFormattingContext::computeStaticPosition const):
+        (WebCore::Layout::InlineFormattingContext::computeInFlowPositionedPosition const):
+        (WebCore::Layout::InlineFormattingContext::instrinsicWidthConstraints const):
+        * layout/inlineformatting/InlineFormattingContext.h:
+
+2018-10-31  Zalan Bujtas  <zalan@apple.com>
+
         [LFC] FormattingContext class should take FormattingState&
         https://bugs.webkit.org/show_bug.cgi?id=191099
 
index 29f832d..4a33df9 100644 (file)
@@ -63,8 +63,10 @@ LayoutState& FormattingContext::layoutState() const
     return m_formattingState.layoutState();
 }
 
-void FormattingContext::computeOutOfFlowHorizontalGeometry(LayoutState& layoutState, const Box& layoutBox) const
+void FormattingContext::computeOutOfFlowHorizontalGeometry(const Box& layoutBox) const
 {
+    auto& layoutState = this->layoutState();
+
     auto compute = [&](std::optional<LayoutUnit> usedWidth) {
         return Geometry::outOfFlowHorizontalGeometry(layoutState, *this, layoutBox, usedWidth);
     };
@@ -91,8 +93,10 @@ void FormattingContext::computeOutOfFlowHorizontalGeometry(LayoutState& layoutSt
     displayBox.setHorizontalNonComputedMargin(horizontalGeometry.widthAndMargin.nonComputedMargin);
 }
 
-void FormattingContext::computeOutOfFlowVerticalGeometry(const LayoutState& layoutState, const Box& layoutBox) const
+void FormattingContext::computeOutOfFlowVerticalGeometry(const Box& layoutBox) const
 {
+    auto& layoutState = this->layoutState();
+
     auto compute = [&](std::optional<LayoutUnit> usedHeight) {
         return Geometry::outOfFlowVerticalGeometry(layoutState, layoutBox, usedHeight);
     };
@@ -118,29 +122,30 @@ void FormattingContext::computeOutOfFlowVerticalGeometry(const LayoutState& layo
     displayBox.setVerticalNonCollapsedMargin(verticalGeometry.heightAndMargin.margin);
 }
 
-void FormattingContext::computeBorderAndPadding(const LayoutState& layoutState, const Box& layoutBox) const
+void FormattingContext::computeBorderAndPadding(const Box& layoutBox) const
 {
+    auto& layoutState = this->layoutState();
     auto& displayBox = layoutState.displayBoxForLayoutBox(layoutBox);
     displayBox.setBorder(Geometry::computedBorder(layoutState, layoutBox));
     displayBox.setPadding(Geometry::computedPadding(layoutState, layoutBox));
 }
 
-void FormattingContext::placeInFlowPositionedChildren(const LayoutState& layoutState, const Container& container) const
+void FormattingContext::placeInFlowPositionedChildren(const Container& container) const
 {
     // If this container also establishes a formatting context, then positioning already has happend in that the formatting context.
     if (container.establishesFormattingContext() && &container != &root())
         return;
 
-    LOG_WITH_STREAM(FormattingContextLayout, stream << "Start: move in-flow positioned children -> context: " << &layoutState << " parent: " << &container);
+    LOG_WITH_STREAM(FormattingContextLayout, stream << "Start: move in-flow positioned children -> parent: " << &container);
     for (auto& layoutBox : childrenOfType<Box>(container)) {
         if (!layoutBox.isInFlowPositioned())
             continue;
-        computeInFlowPositionedPosition(layoutState, layoutBox);
+        computeInFlowPositionedPosition(layoutBox);
     }
-    LOG_WITH_STREAM(FormattingContextLayout, stream << "End: move in-flow positioned children -> context: " << &layoutState << " parent: " << &container);
+    LOG_WITH_STREAM(FormattingContextLayout, stream << "End: move in-flow positioned children -> parent: " << &container);
 }
 
-void FormattingContext::layoutOutOfFlowDescendants(LayoutState& layoutState, const Box& layoutBox) const
+void FormattingContext::layoutOutOfFlowDescendants(const Box& layoutBox) const
 {
     // Initial containing block by definition is a containing block.
     if (!layoutBox.isPositioned() && !layoutBox.isInitialContainingBlock())
@@ -153,6 +158,7 @@ void FormattingContext::layoutOutOfFlowDescendants(LayoutState& layoutState, con
     if (!container.hasChild())
         return;
 
+    auto& layoutState = this->layoutState();
     LOG_WITH_STREAM(FormattingContextLayout, stream << "Start: layout out-of-flow descendants -> context: " << &layoutState << " root: " << &root());
 
     for (auto& outOfFlowBox : container.outOfFlowDescendants()) {
@@ -160,14 +166,13 @@ void FormattingContext::layoutOutOfFlowDescendants(LayoutState& layoutState, con
 
         ASSERT(layoutBox.establishesFormattingContext());
 
-        computeBorderAndPadding(layoutState, layoutBox);
-        computeOutOfFlowHorizontalGeometry(layoutState, layoutBox);
+        computeBorderAndPadding(layoutBox);
+        computeOutOfFlowHorizontalGeometry(layoutBox);
 
-        auto& formattingState = layoutState.createFormattingStateForFormattingRootIfNeeded(layoutBox);
-        formattingState.formattingContext(layoutBox)->layout(layoutState, formattingState);
+        layoutState.createFormattingStateForFormattingRootIfNeeded(layoutBox).formattingContext(layoutBox)->layout();
 
-        computeOutOfFlowVerticalGeometry(layoutState, layoutBox);
-        layoutOutOfFlowDescendants(layoutState, layoutBox);
+        computeOutOfFlowVerticalGeometry(layoutBox);
+        layoutOutOfFlowDescendants(layoutBox);
     }
     LOG_WITH_STREAM(FormattingContextLayout, stream << "End: layout out-of-flow descendants -> context: " << &layoutState << " root: " << &root());
 }
@@ -215,11 +220,12 @@ Position FormattingContext::mapCoordinateToAncestor(const LayoutState& layoutSta
 }
 
 #ifndef NDEBUG
-void FormattingContext::validateGeometryConstraintsAfterLayout(const LayoutState& layoutState) const
+void FormattingContext::validateGeometryConstraintsAfterLayout() const
 {
     if (!is<Container>(root()))
         return;
     auto& formattingContextRoot = downcast<Container>(root());
+    auto& layoutState = this->layoutState();
     // FIXME: add a descendantsOfType<> flavor that stops at nested formatting contexts
     for (auto& layoutBox : descendantsOfType<Box>(formattingContextRoot)) {
         if (&layoutBox.formattingContextRoot() != &formattingContextRoot)
index 49d8926..a23477f 100644 (file)
@@ -49,14 +49,14 @@ public:
     FormattingContext(const Box& formattingContextRoot, FormattingState&);
     virtual ~FormattingContext();
 
-    virtual void layout(LayoutState&, FormattingState&) const = 0;
-    void layoutOutOfFlowDescendants(LayoutState&, const Box&) const;
+    virtual void layout() const = 0;
+    void layoutOutOfFlowDescendants(const Box&) const;
 
     struct InstrinsicWidthConstraints {
         LayoutUnit minimum;
         LayoutUnit maximum;
     };
-    virtual InstrinsicWidthConstraints instrinsicWidthConstraints(LayoutState&, const Box&) const = 0;
+    virtual InstrinsicWidthConstraints instrinsicWidthConstraints(const Box&) const = 0;
 
     static Display::Box mapBoxToAncestor(const LayoutState&, const Box&, const Container& ancestor);
     static Position mapTopLeftToAncestor(const LayoutState&, const Box&, const Container& ancestor);
@@ -69,15 +69,15 @@ protected:
     LayoutState& layoutState() const;
     const Box& root() const { return *m_root; }
 
-    virtual void computeStaticPosition(const LayoutState&, const Box&) const = 0;
-    virtual void computeInFlowPositionedPosition(const LayoutState&, const Box&) const = 0;
+    virtual void computeStaticPosition(const Box&) const = 0;
+    virtual void computeInFlowPositionedPosition(const Box&) const = 0;
 
-    void computeBorderAndPadding(const LayoutState&, const Box&) const;
+    void computeBorderAndPadding(const Box&) const;
 
-    void placeInFlowPositionedChildren(const LayoutState&, const Container&) const;
+    void placeInFlowPositionedChildren(const Container&) const;
 
 #ifndef NDEBUG
-    virtual void validateGeometryConstraintsAfterLayout(const LayoutState&) const;
+    virtual void validateGeometryConstraintsAfterLayout() const;
 #endif
 
     // This class implements generic positioning and sizing.
@@ -123,8 +123,8 @@ protected:
     };
 
 private:
-    void computeOutOfFlowVerticalGeometry(const LayoutState&, const Box&) const;
-    void computeOutOfFlowHorizontalGeometry(LayoutState&, const Box&) const;
+    void computeOutOfFlowVerticalGeometry(const Box&) const;
+    void computeOutOfFlowHorizontalGeometry(const Box&) const;
 
     WeakPtr<const Box> m_root;
     FormattingState& m_formattingState;
index c27f2a2..4cf7dbd 100644 (file)
@@ -210,7 +210,7 @@ LayoutUnit FormattingContext::Geometry::shrinkToFitWidth(LayoutState& layoutStat
 
     // Then the shrink-to-fit width is: min(max(preferred minimum width, available width), preferred width).
     auto availableWidth = layoutState.displayBoxForLayoutBox(*layoutBox.containingBlock()).width();
-    auto instrinsicWidthConstraints = formattingContext.instrinsicWidthConstraints(layoutState, layoutBox);
+    auto instrinsicWidthConstraints = formattingContext.instrinsicWidthConstraints(layoutBox);
     return std::min(std::max(instrinsicWidthConstraints.minimum, availableWidth), instrinsicWidthConstraints.maximum);
 }
 
index d7ca48a..8b4c936 100644 (file)
@@ -83,8 +83,8 @@ void LayoutState::layoutFormattingContextSubtree(const Box& layoutRoot)
     RELEASE_ASSERT(layoutRoot.establishesFormattingContext());
     auto& formattingState = createFormattingStateForFormattingRootIfNeeded(layoutRoot);
     auto formattingContext = formattingState.formattingContext(layoutRoot);
-    formattingContext->layout(*this, formattingState);
-    formattingContext->layoutOutOfFlowDescendants(*this, layoutRoot);
+    formattingContext->layout();
+    formattingContext->layoutOutOfFlowDescendants(layoutRoot);
 }
 
 Display::Box& LayoutState::displayBoxForLayoutBox(const Box& layoutBox) const
index 8cc1ede..3a4f791 100644 (file)
@@ -49,7 +49,7 @@ BlockFormattingContext::BlockFormattingContext(const Box& formattingContextRoot,
 {
 }
 
-void BlockFormattingContext::layout(LayoutState& layoutState, FormattingState& formattingState) const
+void BlockFormattingContext::layout() const
 {
     // 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.
@@ -58,11 +58,11 @@ void BlockFormattingContext::layout(LayoutState& layoutState, FormattingState& f
     if (!is<Container>(root()))
         return;
 
-    LOG_WITH_STREAM(FormattingContextLayout, stream << "[Start] -> block formatting context -> layout context(" << &layoutState << ") formatting root(" << &root() << ")");
+    LOG_WITH_STREAM(FormattingContextLayout, stream << "[Start] -> block formatting context -> formatting root(" << &root() << ")");
 
     auto& formattingRoot = downcast<Container>(root());
     LayoutQueue layoutQueue;
-    FloatingContext floatingContext(formattingState.floatingState());
+    FloatingContext floatingContext(formattingState().floatingState());
     // This is a post-order tree traversal layout.
     // The root container layout is done in the formatting context it lives in, not that one it creates, so let's start with the first child.
     if (auto* firstChild = formattingRoot.firstInFlowOrFloatingChild())
@@ -77,7 +77,7 @@ void BlockFormattingContext::layout(LayoutState& layoutState, FormattingState& f
             auto& layoutBox = *layoutQueue.last();
 
             if (layoutBox.establishesFormattingContext()) {
-                layoutFormattingContextRoot(layoutState, floatingContext, formattingState, layoutBox);
+                layoutFormattingContextRoot(floatingContext, layoutBox);
                 layoutQueue.removeLast();
                 // Since this box is a formatting context root, it takes care of its entire subtree.
                 // Continue with next sibling if exists.
@@ -88,9 +88,9 @@ void BlockFormattingContext::layout(LayoutState& layoutState, FormattingState& f
             }
 
             LOG_WITH_STREAM(FormattingContextLayout, stream << "[Compute] -> [Position][Border][Padding][Width][Margin] -> for layoutBox(" << &layoutBox << ")");
-            computeStaticPosition(layoutState, layoutBox);
-            computeBorderAndPadding(layoutState, layoutBox);
-            computeWidthAndMargin(layoutState, layoutBox);
+            computeStaticPosition(layoutBox);
+            computeBorderAndPadding(layoutBox);
+            computeWidthAndMargin(layoutBox);
             if (!is<Container>(layoutBox) || !downcast<Container>(layoutBox).hasInFlowOrFloatingChild())
                 break;
             layoutQueue.append(downcast<Container>(layoutBox).firstInFlowOrFloatingChild());
@@ -104,15 +104,15 @@ void BlockFormattingContext::layout(LayoutState& layoutState, FormattingState& f
             LOG_WITH_STREAM(FormattingContextLayout, stream << "[Compute] -> [Height][Margin] -> for layoutBox(" << &layoutBox << ")");
             // Formatting root boxes are special-cased and they don't come here.
             ASSERT(!layoutBox.establishesFormattingContext());
-            computeHeightAndMargin(layoutState, layoutBox);
+            computeHeightAndMargin(layoutBox);
             // Finalize position with clearance.
             if (layoutBox.hasFloatClear())
-                computeVerticalPositionForFloatClear(layoutState, floatingContext, layoutBox);
+                computeVerticalPositionForFloatClear(floatingContext, layoutBox);
             if (!is<Container>(layoutBox))
                 continue;
             auto& container = downcast<Container>(layoutBox);
             // Move in-flow positioned children to their final position.
-            placeInFlowPositionedChildren(layoutState, container);
+            placeInFlowPositionedChildren(container);
             if (auto* nextSibling = container.nextInFlowOrFloatingSibling()) {
                 layoutQueue.append(nextSibling);
                 break;
@@ -120,48 +120,49 @@ void BlockFormattingContext::layout(LayoutState& layoutState, FormattingState& f
         }
     }
     // Place the inflow positioned children.
-    placeInFlowPositionedChildren(layoutState, formattingRoot);
-    LOG_WITH_STREAM(FormattingContextLayout, stream << "[End] -> block formatting context -> layout context(" << &layoutState << ") formatting root(" << &root() << ")");
+    placeInFlowPositionedChildren(formattingRoot);
+    LOG_WITH_STREAM(FormattingContextLayout, stream << "[End] -> block formatting context -> formatting root(" << &root() << ")");
 }
 
-void BlockFormattingContext::layoutFormattingContextRoot(LayoutState& layoutState, FloatingContext& floatingContext, FormattingState&, const Box& layoutBox) const
+void BlockFormattingContext::layoutFormattingContextRoot(FloatingContext& floatingContext, const Box& layoutBox) const
 {
     // Start laying out this formatting root in the formatting contenxt it lives in.
     LOG_WITH_STREAM(FormattingContextLayout, stream << "[Compute] -> [Position][Border][Padding][Width][Margin] -> for layoutBox(" << &layoutBox << ")");
-    computeStaticPosition(layoutState, layoutBox);
-    computeBorderAndPadding(layoutState, layoutBox);
-    computeWidthAndMargin(layoutState, layoutBox);
+    computeStaticPosition(layoutBox);
+    computeBorderAndPadding(layoutBox);
+    computeWidthAndMargin(layoutBox);
 
-    precomputeVerticalPositionForFormattingRootIfNeeded(layoutState, layoutBox);
+    precomputeVerticalPositionForFormattingRootIfNeeded(layoutBox);
     // Swich over to the new formatting context (the one that the root creates).
-    auto& formattingState = layoutState.createFormattingStateForFormattingRootIfNeeded(layoutBox);
-    auto formattingContext = formattingState.formattingContext(layoutBox);
-    formattingContext->layout(layoutState, formattingState);
+    auto formattingContext = layoutState().createFormattingStateForFormattingRootIfNeeded(layoutBox).formattingContext(layoutBox);
+    formattingContext->layout();
 
     // Come back and finalize the root's geometry.
     LOG_WITH_STREAM(FormattingContextLayout, stream << "[Compute] -> [Height][Margin] -> for layoutBox(" << &layoutBox << ")");
-    computeHeightAndMargin(layoutState, layoutBox);
+    computeHeightAndMargin(layoutBox);
 
     // Float related final positioning.
     if (layoutBox.isFloatingPositioned()) {
-        computeFloatingPosition(layoutState, floatingContext, layoutBox);
+        computeFloatingPosition(floatingContext, layoutBox);
         floatingContext.floatingState().append(layoutBox);
     } else if (layoutBox.hasFloatClear())
-        computeVerticalPositionForFloatClear(layoutState, floatingContext, layoutBox);
+        computeVerticalPositionForFloatClear(floatingContext, layoutBox);
     else if (layoutBox.establishesBlockFormattingContext())
-        computePositionToAvoidFloats(layoutState, floatingContext, layoutBox);
+        computePositionToAvoidFloats(floatingContext, layoutBox);
 
     // Now that we computed the root's height, we can go back and layout the out-of-flow descedants (if any).
-    formattingContext->layoutOutOfFlowDescendants(layoutState, layoutBox);
+    formattingContext->layoutOutOfFlowDescendants(layoutBox);
 }
 
-void BlockFormattingContext::computeStaticPosition(const LayoutState& layoutState, const Box& layoutBox) const
+void BlockFormattingContext::computeStaticPosition(const Box& layoutBox) const
 {
+    auto& layoutState = this->layoutState();
     layoutState.displayBoxForLayoutBox(layoutBox).setTopLeft(Geometry::staticPosition(layoutState, layoutBox));
 }
 
-void BlockFormattingContext::computeEstimatedMarginTop(const LayoutState& layoutState, const Box& layoutBox) const
+void BlockFormattingContext::computeEstimatedMarginTop(const Box& layoutBox) const
 {
+    auto& layoutState = this->layoutState();
     auto estimatedMarginTop = Geometry::estimatedMarginTop(layoutState, layoutBox);
 
     auto& displayBox = layoutState.displayBoxForLayoutBox(layoutBox);
@@ -169,7 +170,7 @@ void BlockFormattingContext::computeEstimatedMarginTop(const LayoutState& layout
     displayBox.moveVertically(estimatedMarginTop);
 }
 
-void BlockFormattingContext::computeEstimatedMarginTopForAncestors(const LayoutState& layoutState, const Box& layoutBox) const
+void BlockFormattingContext::computeEstimatedMarginTopForAncestors(const Box& layoutBox) const
 {
     // We only need to estimate margin top for float related layout (formatting context roots avoid floats).
     ASSERT(layoutBox.isFloatingPositioned() || layoutBox.hasFloatClear() || layoutBox.establishesBlockFormattingContext() || layoutBox.establishesInlineFormattingContext());
@@ -183,6 +184,7 @@ void BlockFormattingContext::computeEstimatedMarginTopForAncestors(const LayoutS
     // So when we get to the point where we intersect the box with the float to decide if the box needs to move, we don't yet have the final vertical position.
     //
     // 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 margin.
+    auto& layoutState = this->layoutState();
 
     for (auto* ancestor = layoutBox.containingBlock(); ancestor && !ancestor->establishesBlockFormattingContext(); ancestor = ancestor->containingBlock()) {
         auto& displayBox = layoutState.displayBoxForLayoutBox(*ancestor);
@@ -190,24 +192,24 @@ void BlockFormattingContext::computeEstimatedMarginTopForAncestors(const LayoutS
         if (displayBox.estimatedMarginTop())
             return;
 
-        computeEstimatedMarginTop(layoutState, *ancestor);
+        computeEstimatedMarginTop(*ancestor);
     }
 }
 
-void BlockFormattingContext::precomputeVerticalPositionForFormattingRootIfNeeded(const LayoutState& layoutState, const Box& layoutBox) const
+void BlockFormattingContext::precomputeVerticalPositionForFormattingRootIfNeeded(const Box& layoutBox) const
 {
     ASSERT(layoutBox.establishesFormattingContext());
 
     auto avoidsFloats = layoutBox.isFloatingPositioned() || layoutBox.establishesBlockFormattingContext() || layoutBox.hasFloatClear();
     if (avoidsFloats)
-        computeEstimatedMarginTopForAncestors(layoutState, layoutBox);
+        computeEstimatedMarginTopForAncestors(layoutBox);
 
     // If the inline formatting root is also the root for the floats (happens when the root box also establishes a block formatting context)
     // the floats are in the coordinate system of this root. No need to find the final vertical position.
     auto inlineContextInheritsFloats = layoutBox.establishesInlineFormattingContext() && !layoutBox.establishesBlockFormattingContext();
     if (inlineContextInheritsFloats) {
-        computeEstimatedMarginTop(layoutState, layoutBox);
-        computeEstimatedMarginTopForAncestors(layoutState, layoutBox);
+        computeEstimatedMarginTop(layoutBox);
+        computeEstimatedMarginTopForAncestors(layoutBox);
     }
 }
 
@@ -223,8 +225,9 @@ static bool hasPrecomputedMarginTop(const LayoutState& layoutState, const Box& l
 }
 #endif
 
-void BlockFormattingContext::computeFloatingPosition(const LayoutState& layoutState, const FloatingContext& floatingContext, const Box& layoutBox) const
+void BlockFormattingContext::computeFloatingPosition(const FloatingContext& floatingContext, const Box& layoutBox) const
 {
+    auto& layoutState = this->layoutState();
     ASSERT(layoutBox.isFloatingPositioned());
     ASSERT(hasPrecomputedMarginTop(layoutState, layoutBox));
 
@@ -239,8 +242,9 @@ void BlockFormattingContext::computeFloatingPosition(const LayoutState& layoutSt
     displayBox.setTopLeft(floatingContext.positionForFloat(layoutBox));
 }
 
-void BlockFormattingContext::computePositionToAvoidFloats(const LayoutState& layoutState, const FloatingContext& floatingContext, const Box& layoutBox) const
+void BlockFormattingContext::computePositionToAvoidFloats(const FloatingContext& floatingContext, const Box& layoutBox) const
 {
+    auto& layoutState = this->layoutState();
     // Formatting context roots avoid floats.
     ASSERT(layoutBox.establishesBlockFormattingContext());
     ASSERT(!layoutBox.isFloatingPositioned());
@@ -254,28 +258,32 @@ void BlockFormattingContext::computePositionToAvoidFloats(const LayoutState& lay
         layoutState.displayBoxForLayoutBox(layoutBox).setTopLeft(*adjustedPosition);
 }
 
-void BlockFormattingContext::computeVerticalPositionForFloatClear(const LayoutState& layoutState, const FloatingContext& floatingContext, const Box& layoutBox) const
+void BlockFormattingContext::computeVerticalPositionForFloatClear(const FloatingContext& floatingContext, const Box& layoutBox) const
 {
     ASSERT(layoutBox.hasFloatClear());
     if (floatingContext.floatingState().isEmpty())
         return;
 
+    auto& layoutState = this->layoutState();
     // For formatting roots, we already precomputed final position.
     if (!layoutBox.establishesFormattingContext())
-        computeEstimatedMarginTopForAncestors(layoutState, layoutBox);
+        computeEstimatedMarginTopForAncestors(layoutBox);
     ASSERT(hasPrecomputedMarginTop(layoutState, layoutBox));
 
     if (auto verticalPositionWithClearance = floatingContext.verticalPositionWithClearance(layoutBox))
         layoutState.displayBoxForLayoutBox(layoutBox).setTop(*verticalPositionWithClearance);
 }
 
-void BlockFormattingContext::computeInFlowPositionedPosition(const LayoutState& layoutState, const Box& layoutBox) const
+void BlockFormattingContext::computeInFlowPositionedPosition(const Box& layoutBox) const
 {
+    auto& layoutState = this->layoutState();
     layoutState.displayBoxForLayoutBox(layoutBox).setTopLeft(Geometry::inFlowPositionedPosition(layoutState, layoutBox));
 }
 
-void BlockFormattingContext::computeWidthAndMargin(LayoutState& layoutState, const Box& layoutBox) const
+void BlockFormattingContext::computeWidthAndMargin(const Box& layoutBox) const
 {
+    auto& layoutState = this->layoutState();
+
     auto compute = [&](std::optional<LayoutUnit> usedWidth) -> WidthAndMargin {
 
         if (layoutBox.isInFlow())
@@ -310,8 +318,10 @@ void BlockFormattingContext::computeWidthAndMargin(LayoutState& layoutState, con
     displayBox.setHorizontalNonComputedMargin(widthAndMargin.nonComputedMargin);
 }
 
-void BlockFormattingContext::computeHeightAndMargin(const LayoutState& layoutState, const Box& layoutBox) const
+void BlockFormattingContext::computeHeightAndMargin(const Box& layoutBox) const
 {
+    auto& layoutState = this->layoutState();
+
     auto compute = [&](std::optional<LayoutUnit> usedHeight) -> HeightAndMargin {
 
         if (layoutBox.isInFlow())
@@ -347,8 +357,9 @@ void BlockFormattingContext::computeHeightAndMargin(const LayoutState& layoutSta
         displayBox.moveVertically(heightAndMargin.collapsedMargin.value_or(heightAndMargin.margin).top);
 }
 
-FormattingContext::InstrinsicWidthConstraints BlockFormattingContext::instrinsicWidthConstraints(LayoutState& layoutState, const Box& layoutBox) const
+FormattingContext::InstrinsicWidthConstraints BlockFormattingContext::instrinsicWidthConstraints(const Box& layoutBox) const
 {
+    auto& layoutState = this->layoutState();
     auto& formattingState = layoutState.formattingStateForBox(layoutBox);
     ASSERT(formattingState.isBlockFormattingState());
     if (auto instrinsicWidthConstraints = formattingState.instrinsicWidthConstraints(layoutBox))
@@ -383,7 +394,7 @@ FormattingContext::InstrinsicWidthConstraints BlockFormattingContext::instrinsic
                 instrinsicWidthConstraints = Geometry::instrinsicWidthConstraints(layoutState, childBox);
             // Is it a formatting context root?
             if (!instrinsicWidthConstraints && childBox.establishesFormattingContext())
-                instrinsicWidthConstraints = formattingStateForChildren.formattingContext(childBox)->instrinsicWidthConstraints(layoutState, childBox);
+                instrinsicWidthConstraints = formattingStateForChildren.formattingContext(childBox)->instrinsicWidthConstraints(childBox);
             // Go to the next sibling (and skip the descendants) if this box's min/max width is computed.
             if (instrinsicWidthConstraints) {
                 formattingStateForChildren.setInstrinsicWidthConstraints(childBox, *instrinsicWidthConstraints); 
index 8c0426a..c767ba4 100644 (file)
@@ -47,26 +47,26 @@ class BlockFormattingContext : public FormattingContext {
 public:
     BlockFormattingContext(const Box& formattingContextRoot, FormattingState& formattingState);
 
-    void layout(LayoutState&, FormattingState&) const override;
+    void layout() const override;
 
 private:
-    void layoutFormattingContextRoot(LayoutState&, FloatingContext&, FormattingState&, const Box&) const;
+    void layoutFormattingContextRoot(FloatingContext&, const Box&) const;
 
-    void computeWidthAndMargin(LayoutState&, const Box&) const;
-    void computeHeightAndMargin(const LayoutState&, const Box&) const;
+    void computeWidthAndMargin(const Box&) const;
+    void computeHeightAndMargin(const Box&) const;
 
-    void computeStaticPosition(const LayoutState&, const Box&) const override;
-    void computeFloatingPosition(const LayoutState&, const FloatingContext&, const Box&) const;
-    void computePositionToAvoidFloats(const LayoutState&, const FloatingContext&, const Box&) const;
-    void computeVerticalPositionForFloatClear(const LayoutState&, const FloatingContext&, const Box&) const;
+    void computeStaticPosition(const Box&) const override;
+    void computeFloatingPosition(const FloatingContext&, const Box&) const;
+    void computePositionToAvoidFloats(const FloatingContext&, const Box&) const;
+    void computeVerticalPositionForFloatClear(const FloatingContext&, const Box&) const;
 
-    void computeInFlowPositionedPosition(const LayoutState&, const Box&) const override;
-    void computeEstimatedMarginTopForAncestors(const LayoutState&, const Box&) const;
-    void computeEstimatedMarginTop(const LayoutState&, const Box&) const;
+    void computeInFlowPositionedPosition(const Box&) const override;
+    void computeEstimatedMarginTopForAncestors(const Box&) const;
+    void computeEstimatedMarginTop(const Box&) const;
 
-    void precomputeVerticalPositionForFormattingRootIfNeeded(const LayoutState&, const Box&) const;
+    void precomputeVerticalPositionForFormattingRootIfNeeded(const Box&) const;
 
-    InstrinsicWidthConstraints instrinsicWidthConstraints(LayoutState&, const Box&) const override;
+    InstrinsicWidthConstraints instrinsicWidthConstraints(const Box&) const override;
 
     // This class implements positioning and sizing for boxes participating in a block formatting context.
     class Geometry : public FormattingContext::Geometry {
index 7bc0eed..ed02c36 100644 (file)
@@ -51,14 +51,14 @@ InlineFormattingContext::InlineFormattingContext(const Box& formattingContextRoo
 {
 }
 
-void InlineFormattingContext::layout(LayoutState& layoutState, FormattingState& formattingState) const
+void InlineFormattingContext::layout() const
 {
     if (!is<Container>(root()))
         return;
 
-    LOG_WITH_STREAM(FormattingContextLayout, stream << "[Start] -> inline formatting context -> layout context(" << &layoutState << ") formatting root(" << &root() << ")");
+    LOG_WITH_STREAM(FormattingContextLayout, stream << "[Start] -> inline formatting context -> formatting root(" << &root() << ")");
 
-    auto& inlineFormattingState = downcast<InlineFormattingState>(formattingState);
+    auto& inlineFormattingState = downcast<InlineFormattingState>(formattingState());
     InlineRunProvider inlineRunProvider(inlineFormattingState);
     auto& formattingRoot = downcast<Container>(root());
     auto* layoutBox = formattingRoot.firstInFlowOrFloatingChild();
@@ -66,7 +66,7 @@ void InlineFormattingContext::layout(LayoutState& layoutState, FormattingState&
     while (layoutBox) {
 
         if (layoutBox->establishesFormattingContext()) {
-            layoutFormattingContextRoot(layoutState, *layoutBox);
+            layoutFormattingContextRoot(*layoutBox);
             // Formatting context roots take care of their entire subtree. Continue with next sibling.
             inlineRunProvider.append(*layoutBox);
             layoutBox = layoutBox->nextInFlowOrFloatingSibling();
@@ -80,7 +80,7 @@ void InlineFormattingContext::layout(LayoutState& layoutState, FormattingState&
         }
 
         inlineRunProvider.append(*layoutBox);
-        computeWidthAndHeightForInlineBox(layoutState, *layoutBox);
+        computeWidthAndHeightForInlineBox(*layoutBox);
 
         for (; layoutBox; layoutBox = layoutBox->parent()) {
             if (layoutBox == &formattingRoot) {
@@ -95,9 +95,9 @@ void InlineFormattingContext::layout(LayoutState& layoutState, FormattingState&
         ASSERT(!layoutBox || layoutBox->isDescendantOf(formattingRoot));
     }
 
-    layoutInlineContent(layoutState, inlineFormattingState, inlineRunProvider);
+    layoutInlineContent(inlineRunProvider);
 
-    LOG_WITH_STREAM(FormattingContextLayout, stream << "[End] -> inline formatting context -> layout context(" << &layoutState << ") formatting root(" << &root() << ")");
+    LOG_WITH_STREAM(FormattingContextLayout, stream << "[End] -> inline formatting context -> formatting root(" << &root() << ")");
 }
 
 static bool isTrimmableContent(const InlineLineBreaker::Run& run)
@@ -105,17 +105,17 @@ static bool isTrimmableContent(const InlineLineBreaker::Run& run)
     return run.content.isWhitespace() && run.content.style().collapseWhiteSpace();
 }
 
-void InlineFormattingContext::initializeNewLine(const LayoutState& layoutState, InlineFormattingState& inlineFormattingState, Line& line) const
+void InlineFormattingContext::initializeNewLine(Line& line) const
 {
     auto& formattingRoot = downcast<Container>(root());
-    auto& formattingRootDisplayBox = layoutState.displayBoxForLayoutBox(formattingRoot);
+    auto& formattingRootDisplayBox = layoutState().displayBoxForLayoutBox(formattingRoot);
 
     auto lineLogicalLeft = formattingRootDisplayBox.contentBoxLeft();
     auto lineLogicalTop = line.isFirstLine() ? formattingRootDisplayBox.contentBoxTop() : line.logicalBottom();
     auto availableWidth = formattingRootDisplayBox.contentBoxWidth();
 
     // Check for intruding floats and adjust logical left/available width for this line accordingly.
-    auto& floatingState = inlineFormattingState.floatingState();
+    auto& floatingState = formattingState().floatingState();
     if (!floatingState.isEmpty()) {
         auto floatConstraints = floatingState.constraints(lineLogicalTop, formattingRoot);
         // Check if these constraints actually put limitation on the line.
@@ -148,12 +148,14 @@ void InlineFormattingContext::initializeNewLine(const LayoutState& layoutState,
     line.init(logicalRect);
 }
 
-void InlineFormattingContext::layoutInlineContent(const LayoutState& layoutState, InlineFormattingState& inlineFormattingState, const InlineRunProvider& inlineRunProvider) const
+void InlineFormattingContext::layoutInlineContent(const InlineRunProvider& inlineRunProvider) const
 {
+    auto& layoutState = this->layoutState();
+    auto& inlineFormattingState = downcast<InlineFormattingState>(formattingState());
     auto floatingContext = FloatingContext { inlineFormattingState.floatingState() };
 
     Line line(inlineFormattingState, root());
-    initializeNewLine(layoutState, inlineFormattingState, line);
+    initializeNewLine(line);
 
     InlineLineBreaker lineBreaker(layoutState, inlineFormattingState.inlineContent(), inlineRunProvider.runs());
     while (auto run = lineBreaker.nextRun(line.contentLogicalRight(), line.availableWidth(), !line.hasContent())) {
@@ -164,7 +166,7 @@ void InlineFormattingContext::layoutInlineContent(const LayoutState& layoutState
         // Position float and adjust the runs on line.
         if (run->content.isFloat()) {
             auto& floatBox = run->content.inlineItem().layoutBox();
-            computeFloatPosition(layoutState, floatingContext, line, floatBox);
+            computeFloatPosition(floatingContext, line, floatBox);
             inlineFormattingState.floatingState().append(floatBox);
 
             auto floatBoxWidth = layoutState.displayBoxForLayoutBox(floatBox).width();
@@ -188,7 +190,7 @@ void InlineFormattingContext::layoutInlineContent(const LayoutState& layoutState
                 // Previous run ended up being at the line end. Adjust the line accordingly.
                 if (!line.isClosed())
                     line.close(Line::LastLine::No);
-                initializeNewLine(layoutState, inlineFormattingState, line);
+                initializeNewLine(line);
             }
          }
 
@@ -202,8 +204,10 @@ void InlineFormattingContext::layoutInlineContent(const LayoutState& layoutState
     line.close(Line::LastLine::Yes);
 }
 
-void InlineFormattingContext::layoutFormattingContextRoot(LayoutState& layoutState, const Box& layoutBox) const
+void InlineFormattingContext::layoutFormattingContextRoot(const Box& layoutBox) const
 {
+    auto& layoutState = this->layoutState();
+
     ASSERT(layoutBox.isFloatingPositioned() || layoutBox.isInlineBlockBox());
     auto& displayBox = layoutState.displayBoxForLayoutBox(layoutBox);
 
@@ -237,18 +241,17 @@ void InlineFormattingContext::layoutFormattingContextRoot(LayoutState& layoutSta
         displayBox.setVerticalMargin(heightAndMargin.collapsedMargin.value_or(heightAndMargin.margin));
     };
 
-    computeBorderAndPadding(layoutState, layoutBox);
+    computeBorderAndPadding(layoutBox);
     computeWidthAndMargin();
 
     // Swich over to the new formatting context (the one that the root creates).
-    auto& formattingState = layoutState.createFormattingStateForFormattingRootIfNeeded(layoutBox);
-    formattingState.formattingContext(layoutBox)->layout(layoutState, formattingState);
+    layoutState.createFormattingStateForFormattingRootIfNeeded(layoutBox).formattingContext(layoutBox)->layout();
 
     // Come back and finalize the root's height and margin.
     computeHeightAndMargin();
 }
 
-void InlineFormattingContext::computeWidthAndHeightForInlineBox(LayoutState& layoutState, const Box& layoutBox) const
+void InlineFormattingContext::computeWidthAndHeightForInlineBox(const Box& layoutBox) const
 {
     ASSERT(!layoutBox.isContainer());
     ASSERT(!layoutBox.establishesFormattingContext());
@@ -259,9 +262,10 @@ void InlineFormattingContext::computeWidthAndHeightForInlineBox(LayoutState& lay
         return;
     }
 
+    auto& layoutState = this->layoutState();
     // This is pretty much only for replaced inline boxes atm.
     ASSERT(layoutBox.replaced());
-    computeBorderAndPadding(layoutState, layoutBox);
+    computeBorderAndPadding(layoutBox);
 
     auto widthAndMargin = Geometry::inlineReplacedWidthAndMargin(layoutState, layoutBox);
     auto heightAndMargin = Geometry::inlineReplacedHeightAndMargin(layoutState, layoutBox);
@@ -276,8 +280,9 @@ void InlineFormattingContext::computeWidthAndHeightForInlineBox(LayoutState& lay
     displayBox.setVerticalMargin(heightAndMargin.collapsedMargin.value_or(heightAndMargin.margin));
 }
 
-void InlineFormattingContext::computeFloatPosition(const LayoutState& layoutState, const FloatingContext& floatingContext, Line& line, const Box& floatBox) const
+void InlineFormattingContext::computeFloatPosition(const FloatingContext& floatingContext, Line& line, const Box& floatBox) const
 {
+    auto& layoutState = this->layoutState();
     ASSERT(layoutState.hasDisplayBox(floatBox));
     auto& displayBox = layoutState.displayBoxForLayoutBox(floatBox);
 
@@ -287,15 +292,15 @@ void InlineFormattingContext::computeFloatPosition(const LayoutState& layoutStat
     displayBox.setTopLeft(floatingContext.positionForFloat(floatBox));
 }
 
-void InlineFormattingContext::computeStaticPosition(const LayoutState&, const Box&) const
+void InlineFormattingContext::computeStaticPosition(const Box&) const
 {
 }
 
-void InlineFormattingContext::computeInFlowPositionedPosition(const LayoutState&, const Box&) const
+void InlineFormattingContext::computeInFlowPositionedPosition(const Box&) const
 {
 }
 
-FormattingContext::InstrinsicWidthConstraints InlineFormattingContext::instrinsicWidthConstraints(LayoutState&, const Box&) const
+FormattingContext::InstrinsicWidthConstraints InlineFormattingContext::instrinsicWidthConstraints(const Box&) const
 {
     return { };
 }
index 184dd24..6d8c8c6 100644 (file)
@@ -45,7 +45,7 @@ class InlineFormattingContext : public FormattingContext {
 public:
     InlineFormattingContext(const Box& formattingContextRoot, FormattingState&);
 
-    void layout(LayoutState&, FormattingState&) const override;
+    void layout() const override;
 
 private:
     class Line {
@@ -102,16 +102,16 @@ private:
         static WidthAndMargin inlineBlockWidthAndMargin(const LayoutState&, const Box&);
     };
 
-    void layoutInlineContent(const LayoutState&, InlineFormattingState&, const InlineRunProvider&) const;
-    void initializeNewLine(const LayoutState&, InlineFormattingState&, Line&) const;
+    void layoutInlineContent(const InlineRunProvider&) const;
+    void initializeNewLine(Line&) const;
 
-    void layoutFormattingContextRoot(LayoutState&, const Box&) const;
-    void computeWidthAndHeightForInlineBox(LayoutState&, const Box&) const;
-    void computeFloatPosition(const LayoutState&, const FloatingContext&, Line&, const Box&) const;
-    void computeStaticPosition(const LayoutState&, const Box&) const override;
-    void computeInFlowPositionedPosition(const LayoutState&, const Box&) const override;
+    void layoutFormattingContextRoot(const Box&) const;
+    void computeWidthAndHeightForInlineBox(const Box&) const;
+    void computeFloatPosition(const FloatingContext&, Line&, const Box&) const;
+    void computeStaticPosition(const Box&) const override;
+    void computeInFlowPositionedPosition(const Box&) const override;
 
-    InstrinsicWidthConstraints instrinsicWidthConstraints(LayoutState&, const Box&) const override;
+    InstrinsicWidthConstraints instrinsicWidthConstraints(const Box&) const override;
 };
 
 }