[LFC] Pass in const LayoutContext& to geometry methods when possible
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 Sep 2018 01:42:10 +0000 (01:42 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 Sep 2018 01:42:10 +0000 (01:42 +0000)
https://bugs.webkit.org/show_bug.cgi?id=189331

Reviewed by Antti Koivisto.

Only layout and layout-like methods (intrinsic width computation -> shrink to fit -> out-of-flow/floating boxes) should take a
non-const LayoutContext&. Other geometry functions should not mutate the the context.

* layout/FormattingContext.cpp:
(WebCore::Layout::FormattingContext::computeOutOfFlowVerticalGeometry const):
(WebCore::Layout::FormattingContext::computeBorderAndPadding const):
(WebCore::Layout::FormattingContext::placeInFlowPositionedChildren const):
(WebCore::Layout::FormattingContext::layoutOutOfFlowDescendants const):
* layout/FormattingContext.h:
(WebCore::Layout::FormattingContext::Geometry::inlineReplacedWidthAndMargin):
* layout/FormattingContextGeometry.cpp:
(WebCore::Layout::contentHeightForFormattingContextRoot):
(WebCore::Layout::FormattingContext::Geometry::outOfFlowNonReplacedVerticalGeometry):
(WebCore::Layout::FormattingContext::Geometry::outOfFlowReplacedVerticalGeometry):
(WebCore::Layout::FormattingContext::Geometry::outOfFlowReplacedHorizontalGeometry):
(WebCore::Layout::FormattingContext::Geometry::complicatedCases):
(WebCore::Layout::FormattingContext::Geometry::floatingReplacedHeightAndMargin):
(WebCore::Layout::FormattingContext::Geometry::floatingReplacedWidthAndMargin):
(WebCore::Layout::FormattingContext::Geometry::outOfFlowVerticalGeometry):
(WebCore::Layout::FormattingContext::Geometry::floatingHeightAndMargin):
(WebCore::Layout::FormattingContext::Geometry::inlineReplacedHeightAndMargin):
(WebCore::Layout::FormattingContext::Geometry::inlineReplacedWidthAndMargin):
(WebCore::Layout::FormattingContext::Geometry::computedBorder):
(WebCore::Layout::FormattingContext::Geometry::computedPadding):
* layout/LayoutContext.cpp:
(WebCore::Layout::LayoutContext::layoutFormattingContextSubtree):
(WebCore::Layout::LayoutContext::establishedFormattingState const):
(WebCore::Layout::LayoutContext::createFormattingStateForFormattingRootIfNeeded):
(WebCore::Layout::LayoutContext::formattingContext const):
(WebCore::Layout::LayoutContext::establishedFormattingState): Deleted.
(WebCore::Layout::LayoutContext::formattingContext): Deleted.
* layout/LayoutContext.h:
* layout/blockformatting/BlockFormattingContext.cpp:
(WebCore::Layout::BlockFormattingContext::layoutFormattingContextRoot const):
(WebCore::Layout::BlockFormattingContext::computeStaticPosition const):
(WebCore::Layout::BlockFormattingContext::computeEstimatedMarginTop const):
(WebCore::Layout::BlockFormattingContext::computeEstimatedMarginTopForAncestors const):
(WebCore::Layout::BlockFormattingContext::computeFloatingPosition const):
(WebCore::Layout::BlockFormattingContext::computePositionToAvoidFloats const):
(WebCore::Layout::BlockFormattingContext::computeVerticalPositionForFloatClear const):
(WebCore::Layout::BlockFormattingContext::computeInFlowPositionedPosition const):
(WebCore::Layout::BlockFormattingContext::computeHeightAndMargin const):
(WebCore::Layout::BlockFormattingContext::instrinsicWidthConstraints const):
* layout/blockformatting/BlockFormattingContext.h:
* layout/blockformatting/BlockFormattingContextGeometry.cpp:
(WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedHeightAndMargin):
(WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedWidthAndMargin):
(WebCore::Layout::BlockFormattingContext::Geometry::inFlowReplacedWidthAndMargin):
(WebCore::Layout::BlockFormattingContext::Geometry::staticPosition):
(WebCore::Layout::BlockFormattingContext::Geometry::inFlowPositionedPosition):
(WebCore::Layout::BlockFormattingContext::Geometry::inFlowHeightAndMargin):
(WebCore::Layout::BlockFormattingContext::Geometry::inFlowWidthAndMargin):
(WebCore::Layout::BlockFormattingContext::Geometry::instrinsicWidthConstraints):
* layout/inlineformatting/InlineFormattingContext.cpp:
(WebCore::Layout::InlineFormattingContext::computeStaticPosition const):
(WebCore::Layout::InlineFormattingContext::computeInFlowPositionedPosition const):
* layout/inlineformatting/InlineFormattingContext.h:

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

index 99072ac..d6415ce 100644 (file)
@@ -1,3 +1,68 @@
+2018-09-05  Zalan Bujtas  <zalan@apple.com>
+
+        [LFC] Pass in const LayoutContext& to geometry methods when possible
+        https://bugs.webkit.org/show_bug.cgi?id=189331
+
+        Reviewed by Antti Koivisto.
+
+        Only layout and layout-like methods (intrinsic width computation -> shrink to fit -> out-of-flow/floating boxes) should take a
+        non-const LayoutContext&. Other geometry functions should not mutate the the context.
+
+        * layout/FormattingContext.cpp:
+        (WebCore::Layout::FormattingContext::computeOutOfFlowVerticalGeometry const):
+        (WebCore::Layout::FormattingContext::computeBorderAndPadding const):
+        (WebCore::Layout::FormattingContext::placeInFlowPositionedChildren const):
+        (WebCore::Layout::FormattingContext::layoutOutOfFlowDescendants const):
+        * layout/FormattingContext.h:
+        (WebCore::Layout::FormattingContext::Geometry::inlineReplacedWidthAndMargin):
+        * layout/FormattingContextGeometry.cpp:
+        (WebCore::Layout::contentHeightForFormattingContextRoot):
+        (WebCore::Layout::FormattingContext::Geometry::outOfFlowNonReplacedVerticalGeometry):
+        (WebCore::Layout::FormattingContext::Geometry::outOfFlowReplacedVerticalGeometry):
+        (WebCore::Layout::FormattingContext::Geometry::outOfFlowReplacedHorizontalGeometry):
+        (WebCore::Layout::FormattingContext::Geometry::complicatedCases):
+        (WebCore::Layout::FormattingContext::Geometry::floatingReplacedHeightAndMargin):
+        (WebCore::Layout::FormattingContext::Geometry::floatingReplacedWidthAndMargin):
+        (WebCore::Layout::FormattingContext::Geometry::outOfFlowVerticalGeometry):
+        (WebCore::Layout::FormattingContext::Geometry::floatingHeightAndMargin):
+        (WebCore::Layout::FormattingContext::Geometry::inlineReplacedHeightAndMargin):
+        (WebCore::Layout::FormattingContext::Geometry::inlineReplacedWidthAndMargin):
+        (WebCore::Layout::FormattingContext::Geometry::computedBorder):
+        (WebCore::Layout::FormattingContext::Geometry::computedPadding):
+        * layout/LayoutContext.cpp:
+        (WebCore::Layout::LayoutContext::layoutFormattingContextSubtree):
+        (WebCore::Layout::LayoutContext::establishedFormattingState const):
+        (WebCore::Layout::LayoutContext::createFormattingStateForFormattingRootIfNeeded):
+        (WebCore::Layout::LayoutContext::formattingContext const):
+        (WebCore::Layout::LayoutContext::establishedFormattingState): Deleted.
+        (WebCore::Layout::LayoutContext::formattingContext): Deleted.
+        * layout/LayoutContext.h:
+        * layout/blockformatting/BlockFormattingContext.cpp:
+        (WebCore::Layout::BlockFormattingContext::layoutFormattingContextRoot const):
+        (WebCore::Layout::BlockFormattingContext::computeStaticPosition const):
+        (WebCore::Layout::BlockFormattingContext::computeEstimatedMarginTop const):
+        (WebCore::Layout::BlockFormattingContext::computeEstimatedMarginTopForAncestors const):
+        (WebCore::Layout::BlockFormattingContext::computeFloatingPosition const):
+        (WebCore::Layout::BlockFormattingContext::computePositionToAvoidFloats const):
+        (WebCore::Layout::BlockFormattingContext::computeVerticalPositionForFloatClear const):
+        (WebCore::Layout::BlockFormattingContext::computeInFlowPositionedPosition const):
+        (WebCore::Layout::BlockFormattingContext::computeHeightAndMargin const):
+        (WebCore::Layout::BlockFormattingContext::instrinsicWidthConstraints const):
+        * layout/blockformatting/BlockFormattingContext.h:
+        * layout/blockformatting/BlockFormattingContextGeometry.cpp:
+        (WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedHeightAndMargin):
+        (WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedWidthAndMargin):
+        (WebCore::Layout::BlockFormattingContext::Geometry::inFlowReplacedWidthAndMargin):
+        (WebCore::Layout::BlockFormattingContext::Geometry::staticPosition):
+        (WebCore::Layout::BlockFormattingContext::Geometry::inFlowPositionedPosition):
+        (WebCore::Layout::BlockFormattingContext::Geometry::inFlowHeightAndMargin):
+        (WebCore::Layout::BlockFormattingContext::Geometry::inFlowWidthAndMargin):
+        (WebCore::Layout::BlockFormattingContext::Geometry::instrinsicWidthConstraints):
+        * layout/inlineformatting/InlineFormattingContext.cpp:
+        (WebCore::Layout::InlineFormattingContext::computeStaticPosition const):
+        (WebCore::Layout::InlineFormattingContext::computeInFlowPositionedPosition const):
+        * layout/inlineformatting/InlineFormattingContext.h:
+
 2018-09-05  Youenn Fablet  <youenn@apple.com>
 
         Expose RTCRtpSender.setParameters
index 1ab6f71..32c2d06 100644 (file)
@@ -62,7 +62,7 @@ void FormattingContext::computeOutOfFlowHorizontalGeometry(LayoutContext& layout
     displayBox.setHorizontalNonComputedMargin(horizontalGeometry.widthAndMargin.nonComputedMargin);
 }
 
-void FormattingContext::computeOutOfFlowVerticalGeometry(LayoutContext& layoutContext, const Box& layoutBox) const
+void FormattingContext::computeOutOfFlowVerticalGeometry(const LayoutContext& layoutContext, const Box& layoutBox) const
 {
     auto verticalGeometry = Geometry::outOfFlowVerticalGeometry(layoutContext, layoutBox);
 
@@ -74,14 +74,14 @@ void FormattingContext::computeOutOfFlowVerticalGeometry(LayoutContext& layoutCo
     displayBox.setVerticalNonCollapsedMargin(verticalGeometry.heightAndMargin.margin);
 }
 
-void FormattingContext::computeBorderAndPadding(LayoutContext& layoutContext, const Box& layoutBox) const
+void FormattingContext::computeBorderAndPadding(const LayoutContext& layoutContext, const Box& layoutBox) const
 {
     auto& displayBox = layoutContext.displayBoxForLayoutBox(layoutBox);
     displayBox.setBorder(Geometry::computedBorder(layoutContext, layoutBox));
     displayBox.setPadding(Geometry::computedPadding(layoutContext, layoutBox));
 }
 
-void FormattingContext::placeInFlowPositionedChildren(LayoutContext& layoutContext, const Container& container) const
+void FormattingContext::placeInFlowPositionedChildren(const LayoutContext& layoutContext, 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())
@@ -120,7 +120,8 @@ void FormattingContext::layoutOutOfFlowDescendants(LayoutContext& layoutContext,
         computeBorderAndPadding(layoutContext, layoutBox);
         computeOutOfFlowHorizontalGeometry(layoutContext, layoutBox);
 
-        formattingContext->layout(layoutContext, layoutContext.establishedFormattingState(layoutBox));
+        auto& formattingState = layoutContext.createFormattingStateForFormattingRootIfNeeded(layoutBox);
+        formattingContext->layout(layoutContext, formattingState);
 
         computeOutOfFlowVerticalGeometry(layoutContext, layoutBox);
         layoutOutOfFlowDescendants(layoutContext, layoutBox);
index 114a431..e85bf2f 100644 (file)
@@ -68,12 +68,12 @@ protected:
 
     const Box& root() const { return *m_root; }
 
-    virtual void computeStaticPosition(LayoutContext&, const Box&) const = 0;
-    virtual void computeInFlowPositionedPosition(LayoutContext&, const Box&) const = 0;
+    virtual void computeStaticPosition(const LayoutContext&, const Box&) const = 0;
+    virtual void computeInFlowPositionedPosition(const LayoutContext&, const Box&) const = 0;
 
-    void computeBorderAndPadding(LayoutContext&, const Box&) const;
+    void computeBorderAndPadding(const LayoutContext&, const Box&) const;
 
-    void placeInFlowPositionedChildren(LayoutContext&, const Container&) const;
+    void placeInFlowPositionedChildren(const LayoutContext&, const Container&) const;
 
 #ifndef NDEBUG
     virtual void validateGeometryConstraintsAfterLayout(const LayoutContext&) const;
@@ -82,20 +82,20 @@ protected:
     // This class implements generic positioning and sizing.
     class Geometry {
     public:
-        static VerticalGeometry outOfFlowVerticalGeometry(LayoutContext&, const Box&);
+        static VerticalGeometry outOfFlowVerticalGeometry(const LayoutContext&, const Box&);
         static HorizontalGeometry outOfFlowHorizontalGeometry(LayoutContext&, const FormattingContext&, const Box&);
 
-        static HeightAndMargin floatingHeightAndMargin(LayoutContext&, const Box&);
+        static HeightAndMargin floatingHeightAndMargin(const LayoutContext&, const Box&);
         static WidthAndMargin floatingWidthAndMargin(LayoutContext&, const FormattingContext&, const Box&);
 
-        static HeightAndMargin inlineReplacedHeightAndMargin(LayoutContext&, const Box&);
-        static WidthAndMargin inlineReplacedWidthAndMargin(LayoutContext&, const Box&, std::optional<LayoutUnit> precomputedMarginLeft = { },
+        static HeightAndMargin inlineReplacedHeightAndMargin(const LayoutContext&, const Box&);
+        static WidthAndMargin inlineReplacedWidthAndMargin(const LayoutContext&, const Box&, std::optional<LayoutUnit> precomputedMarginLeft = { },
             std::optional<LayoutUnit> precomputedMarginRight = { });
 
-        static HeightAndMargin complicatedCases(LayoutContext&, const Box&);
+        static HeightAndMargin complicatedCases(const LayoutContext&, const Box&);
 
-        static Edges computedBorder(LayoutContext&, const Box&);
-        static std::optional<Edges> computedPadding(LayoutContext&, const Box&);
+        static Edges computedBorder(const LayoutContext&, const Box&);
+        static std::optional<Edges> computedPadding(const LayoutContext&, const Box&);
 
         static HorizontalEdges computedNonCollapsedHorizontalMarginValue(const LayoutContext&, const Box&);
         static VerticalEdges computedNonCollapsedVerticalMarginValue(const LayoutContext&, const Box&);
@@ -104,14 +104,14 @@ protected:
         static std::optional<LayoutUnit> fixedValue(const Length& geometryProperty);
 
     private:
-        static VerticalGeometry outOfFlowReplacedVerticalGeometry(LayoutContext&, const Box&);
-        static HorizontalGeometry outOfFlowReplacedHorizontalGeometry(LayoutContext&, const Box&);
+        static VerticalGeometry outOfFlowReplacedVerticalGeometry(const LayoutContext&, const Box&);
+        static HorizontalGeometry outOfFlowReplacedHorizontalGeometry(const LayoutContext&, const Box&);
 
-        static VerticalGeometry outOfFlowNonReplacedVerticalGeometry(LayoutContext&, const Box&);
+        static VerticalGeometry outOfFlowNonReplacedVerticalGeometry(const LayoutContext&, const Box&);
         static HorizontalGeometry outOfFlowNonReplacedHorizontalGeometry(LayoutContext&, const FormattingContext&, const Box&);
 
-        static HeightAndMargin floatingReplacedHeightAndMargin(LayoutContext&, const Box&);
-        static WidthAndMargin floatingReplacedWidthAndMargin(LayoutContext&, const Box&);
+        static HeightAndMargin floatingReplacedHeightAndMargin(const LayoutContext&, const Box&);
+        static WidthAndMargin floatingReplacedWidthAndMargin(const LayoutContext&, const Box&);
 
         static WidthAndMargin floatingNonReplacedWidthAndMargin(LayoutContext&, const FormattingContext&, const Box&);
 
@@ -119,7 +119,7 @@ protected:
     };
 
 private:
-    void computeOutOfFlowVerticalGeometry(LayoutContext&, const Box&) const;
+    void computeOutOfFlowVerticalGeometry(const LayoutContext&, const Box&) const;
     void computeOutOfFlowHorizontalGeometry(LayoutContext&, const Box&) const;
 
     WeakPtr<Box> m_root;
index 77d9241..2b0dc14 100644 (file)
@@ -34,7 +34,7 @@
 namespace WebCore {
 namespace Layout {
 
-static LayoutUnit contentHeightForFormattingContextRoot(LayoutContext& layoutContext, const Box& layoutBox)
+static LayoutUnit contentHeightForFormattingContextRoot(const LayoutContext& layoutContext, const Box& layoutBox)
 {
     ASSERT(layoutBox.style().logicalHeight().isAuto() && (layoutBox.establishesFormattingContext() || layoutBox.isDocumentBox()));
 
@@ -158,7 +158,7 @@ LayoutUnit FormattingContext::Geometry::shrinkToFitWidth(LayoutContext& layoutCo
     return std::min(std::max(instrinsicWidthConstraints.minimum, availableWidth), instrinsicWidthConstraints.maximum);
 }
 
-VerticalGeometry FormattingContext::Geometry::outOfFlowNonReplacedVerticalGeometry(LayoutContext& layoutContext, const Box& layoutBox)
+VerticalGeometry FormattingContext::Geometry::outOfFlowNonReplacedVerticalGeometry(const LayoutContext& layoutContext, const Box& layoutBox)
 {
     ASSERT(layoutBox.isOutOfFlowPositioned() && !layoutBox.replaced());
 
@@ -420,7 +420,7 @@ HorizontalGeometry FormattingContext::Geometry::outOfFlowNonReplacedHorizontalGe
     return { *left, *right, { *width, { *marginLeft, *marginRight }, { nonComputedMarginLeft, nonComputedMarginRight } } };
 }
 
-VerticalGeometry FormattingContext::Geometry::outOfFlowReplacedVerticalGeometry(LayoutContext& layoutContext, const Box& layoutBox)
+VerticalGeometry FormattingContext::Geometry::outOfFlowReplacedVerticalGeometry(const LayoutContext& layoutContext, const Box& layoutBox)
 {
     ASSERT(layoutBox.isOutOfFlowPositioned() && layoutBox.replaced());
 
@@ -489,7 +489,7 @@ VerticalGeometry FormattingContext::Geometry::outOfFlowReplacedVerticalGeometry(
     return { *top, *bottom, { height, { *marginTop, *marginBottom }, { } } };
 }
 
-HorizontalGeometry FormattingContext::Geometry::outOfFlowReplacedHorizontalGeometry(LayoutContext& layoutContext, const Box& layoutBox)
+HorizontalGeometry FormattingContext::Geometry::outOfFlowReplacedHorizontalGeometry(const LayoutContext& layoutContext, const Box& layoutBox)
 {
     ASSERT(layoutBox.isOutOfFlowPositioned() && layoutBox.replaced());
 
@@ -587,7 +587,7 @@ HorizontalGeometry FormattingContext::Geometry::outOfFlowReplacedHorizontalGeome
     return { *left, *right, { width, { *marginLeft, *marginRight }, { nonComputedMarginLeft, nonComputedMarginRight } } };
 }
 
-HeightAndMargin FormattingContext::Geometry::complicatedCases(LayoutContext& layoutContext, const Box& layoutBox)
+HeightAndMargin FormattingContext::Geometry::complicatedCases(const LayoutContext& layoutContext, const Box& layoutBox)
 {
     ASSERT(!layoutBox.replaced());
     // TODO: Use complicated-case for document renderer for now (see BlockFormattingContext::Geometry::inFlowHeightAndMargin).
@@ -653,7 +653,7 @@ WidthAndMargin FormattingContext::Geometry::floatingNonReplacedWidthAndMargin(La
     return WidthAndMargin { *width, margin, margin };
 }
 
-HeightAndMargin FormattingContext::Geometry::floatingReplacedHeightAndMargin(LayoutContext& layoutContext, const Box& layoutBox)
+HeightAndMargin FormattingContext::Geometry::floatingReplacedHeightAndMargin(const LayoutContext& layoutContext, const Box& layoutBox)
 {
     ASSERT(layoutBox.isFloatingPositioned() && layoutBox.replaced());
 
@@ -663,7 +663,7 @@ HeightAndMargin FormattingContext::Geometry::floatingReplacedHeightAndMargin(Lay
     return inlineReplacedHeightAndMargin(layoutContext, layoutBox);
 }
 
-WidthAndMargin FormattingContext::Geometry::floatingReplacedWidthAndMargin(LayoutContext& layoutContext, const Box& layoutBox)
+WidthAndMargin FormattingContext::Geometry::floatingReplacedWidthAndMargin(const LayoutContext& layoutContext, const Box& layoutBox)
 {
     ASSERT(layoutBox.isFloatingPositioned() && layoutBox.replaced());
 
@@ -677,7 +677,7 @@ WidthAndMargin FormattingContext::Geometry::floatingReplacedWidthAndMargin(Layou
     return inlineReplacedWidthAndMargin(layoutContext, layoutBox, margin.left, margin.right);
 }
 
-VerticalGeometry FormattingContext::Geometry::outOfFlowVerticalGeometry(LayoutContext& layoutContext, const Box& layoutBox)
+VerticalGeometry FormattingContext::Geometry::outOfFlowVerticalGeometry(const LayoutContext& layoutContext, const Box& layoutBox)
 {
     ASSERT(layoutBox.isOutOfFlowPositioned());
 
@@ -695,7 +695,7 @@ HorizontalGeometry FormattingContext::Geometry::outOfFlowHorizontalGeometry(Layo
     return outOfFlowReplacedHorizontalGeometry(layoutContext, layoutBox);
 }
 
-HeightAndMargin FormattingContext::Geometry::floatingHeightAndMargin(LayoutContext& layoutContext, const Box& layoutBox)
+HeightAndMargin FormattingContext::Geometry::floatingHeightAndMargin(const LayoutContext& layoutContext, const Box& layoutBox)
 {
     ASSERT(layoutBox.isFloatingPositioned());
 
@@ -713,7 +713,7 @@ WidthAndMargin FormattingContext::Geometry::floatingWidthAndMargin(LayoutContext
     return floatingReplacedWidthAndMargin(layoutContext, layoutBox);
 }
 
-HeightAndMargin FormattingContext::Geometry::inlineReplacedHeightAndMargin(LayoutContext& layoutContext, const Box& layoutBox)
+HeightAndMargin FormattingContext::Geometry::inlineReplacedHeightAndMargin(const LayoutContext& layoutContext, const Box& layoutBox)
 {
     ASSERT((layoutBox.isOutOfFlowPositioned() || layoutBox.isFloatingPositioned() || layoutBox.isInFlow()) && layoutBox.replaced());
 
@@ -762,7 +762,7 @@ HeightAndMargin FormattingContext::Geometry::inlineReplacedHeightAndMargin(Layou
     return { *height, margin, { } };
 }
 
-WidthAndMargin FormattingContext::Geometry::inlineReplacedWidthAndMargin(LayoutContext& layoutContext, const Box& layoutBox,
+WidthAndMargin FormattingContext::Geometry::inlineReplacedWidthAndMargin(const LayoutContext& layoutContext, const Box& layoutBox,
     std::optional<LayoutUnit> precomputedMarginLeft, std::optional<LayoutUnit> precomputedMarginRight)
 {
     ASSERT((layoutBox.isOutOfFlowPositioned() || layoutBox.isFloatingPositioned() || layoutBox.isInFlow()) && layoutBox.replaced());
@@ -843,7 +843,7 @@ WidthAndMargin FormattingContext::Geometry::inlineReplacedWidthAndMargin(LayoutC
     return { *width, { marginLeft, marginRight }, { nonComputedMarginLeft, nonComputedMarginRight } };
 }
 
-Edges FormattingContext::Geometry::computedBorder(LayoutContext&, const Box& layoutBox)
+Edges FormattingContext::Geometry::computedBorder(const LayoutContext&, const Box& layoutBox)
 {
     auto& style = layoutBox.style();
     LOG_WITH_STREAM(FormattingContextLayout, stream << "[Border] -> layoutBox: " << &layoutBox);
@@ -853,7 +853,7 @@ Edges FormattingContext::Geometry::computedBorder(LayoutContext&, const Box& lay
     };
 }
 
-std::optional<Edges> FormattingContext::Geometry::computedPadding(LayoutContext& layoutContext, const Box& layoutBox)
+std::optional<Edges> FormattingContext::Geometry::computedPadding(const LayoutContext& layoutContext, const Box& layoutBox)
 {
     if (!layoutBox.isPaddingApplicable())
         return std::nullopt;
index 07398c9..fe6785e 100644 (file)
@@ -82,7 +82,8 @@ void LayoutContext::layoutFormattingContextSubtree(const Box& layoutRoot)
 {
     RELEASE_ASSERT(layoutRoot.establishesFormattingContext());
     auto formattingContext = this->formattingContext(layoutRoot);
-    formattingContext->layout(*this, establishedFormattingState(layoutRoot));
+    auto& formattingState = createFormattingStateForFormattingRootIfNeeded(layoutRoot);
+    formattingContext->layout(*this, formattingState);
     formattingContext->layoutOutOfFlowDescendants(*this, layoutRoot);
 }
 
@@ -118,8 +119,17 @@ FormattingState& LayoutContext::formattingStateForBox(const Box& layoutBox) cons
     return *m_formattingStates.get(&root);
 }
 
-FormattingState& LayoutContext::establishedFormattingState(const Box& formattingRoot)
+FormattingState& LayoutContext::establishedFormattingState(const Box& formattingRoot) const
 {
+    ASSERT(formattingRoot.establishesFormattingContext());
+    RELEASE_ASSERT(m_formattingStates.contains(&formattingRoot));
+    return *m_formattingStates.get(&formattingRoot);
+}
+
+FormattingState& LayoutContext::createFormattingStateForFormattingRootIfNeeded(const Box& formattingRoot)
+{
+    ASSERT(formattingRoot.establishesFormattingContext());
+
     if (formattingRoot.establishesInlineFormattingContext()) {
         return *m_formattingStates.ensure(&formattingRoot, [&] {
 
@@ -142,10 +152,11 @@ FormattingState& LayoutContext::establishedFormattingState(const Box& formatting
             return std::make_unique<BlockFormattingState>(FloatingState::create(*this, formattingRoot), *this);
         }).iterator->value;
     }
+
     CRASH();
 }
 
-std::unique_ptr<FormattingContext> LayoutContext::formattingContext(const Box& formattingContextRoot)
+std::unique_ptr<FormattingContext> LayoutContext::formattingContext(const Box& formattingContextRoot) const
 {
     if (formattingContextRoot.establishesBlockFormattingContext())
         return std::make_unique<BlockFormattingContext>(formattingContextRoot);
index 37b77b4..cadf61f 100644 (file)
@@ -75,10 +75,11 @@ public:
     void markNeedsUpdate(const Box&, OptionSet<UpdateType>);
     bool needsUpdate(const Box&) const;
 
-    std::unique_ptr<FormattingContext> formattingContext(const Box& formattingContextRoot);
+    std::unique_ptr<FormattingContext> formattingContext(const Box& formattingContextRoot) const;
 
     FormattingState& formattingStateForBox(const Box&) const;
-    FormattingState& establishedFormattingState(const Box& formattingRoot);
+    FormattingState& establishedFormattingState(const Box& formattingRoot) const;
+    FormattingState& createFormattingStateForFormattingRootIfNeeded(const Box& formattingRoot);
 
     Display::Box& displayBoxForLayoutBox(const Box& layoutBox) const;
 
index bb1089c..d28b9f7 100644 (file)
@@ -134,7 +134,8 @@ void BlockFormattingContext::layoutFormattingContextRoot(LayoutContext& layoutCo
 
     // Swich over to the new formatting context (the one that the root creates).
     auto formattingContext = layoutContext.formattingContext(layoutBox);
-    formattingContext->layout(layoutContext, layoutContext.establishedFormattingState(layoutBox));
+    auto& formattingState = layoutContext.createFormattingStateForFormattingRootIfNeeded(layoutBox);
+    formattingContext->layout(layoutContext, formattingState);
 
     // Come back and finalize the root's geometry.
     LOG_WITH_STREAM(FormattingContextLayout, stream << "[Compute] -> [Height][Margin] -> for layoutBox(" << &layoutBox << ")");
@@ -152,12 +153,12 @@ void BlockFormattingContext::layoutFormattingContextRoot(LayoutContext& layoutCo
     formattingContext->layoutOutOfFlowDescendants(layoutContext, layoutBox);
 }
 
-void BlockFormattingContext::computeStaticPosition(LayoutContext& layoutContext, const Box& layoutBox) const
+void BlockFormattingContext::computeStaticPosition(const LayoutContext& layoutContext, const Box& layoutBox) const
 {
     layoutContext.displayBoxForLayoutBox(layoutBox).setTopLeft(Geometry::staticPosition(layoutContext, layoutBox));
 }
 
-void BlockFormattingContext::computeEstimatedMarginTop(LayoutContext& layoutContext, const Box& layoutBox) const
+void BlockFormattingContext::computeEstimatedMarginTop(const LayoutContext& layoutContext, const Box& layoutBox) const
 {
     auto estimatedMarginTop = Geometry::estimatedMarginTop(layoutContext, layoutBox);
 
@@ -166,7 +167,7 @@ void BlockFormattingContext::computeEstimatedMarginTop(LayoutContext& layoutCont
     displayBox.moveVertically(estimatedMarginTop);
 }
 
-void BlockFormattingContext::computeEstimatedMarginTopForAncestors(LayoutContext& layoutContext, const Box& layoutBox) const
+void BlockFormattingContext::computeEstimatedMarginTopForAncestors(const LayoutContext& layoutContext, 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());
@@ -191,7 +192,7 @@ void BlockFormattingContext::computeEstimatedMarginTopForAncestors(LayoutContext
     }
 }
 
-void BlockFormattingContext::computeFloatingPosition(LayoutContext& layoutContext, FloatingContext& floatingContext, const Box& layoutBox) const
+void BlockFormattingContext::computeFloatingPosition(const LayoutContext& layoutContext, FloatingContext& floatingContext, const Box& layoutBox) const
 {
     ASSERT(layoutBox.isFloatingPositioned());
     auto& displayBox = layoutContext.displayBoxForLayoutBox(layoutBox);
@@ -207,7 +208,7 @@ void BlockFormattingContext::computeFloatingPosition(LayoutContext& layoutContex
     floatingContext.floatingState().append(layoutBox);
 }
 
-void BlockFormattingContext::computePositionToAvoidFloats(LayoutContext& layoutContext, FloatingContext& floatingContext, const Box& layoutBox) const
+void BlockFormattingContext::computePositionToAvoidFloats(const LayoutContext& layoutContext, FloatingContext& floatingContext, const Box& layoutBox) const
 {
     // Formatting context roots avoid floats.
     ASSERT(layoutBox.establishesBlockFormattingContext());
@@ -222,7 +223,7 @@ void BlockFormattingContext::computePositionToAvoidFloats(LayoutContext& layoutC
         layoutContext.displayBoxForLayoutBox(layoutBox).setTopLeft(*adjustedPosition);
 }
 
-void BlockFormattingContext::computeVerticalPositionForFloatClear(LayoutContext& layoutContext, const FloatingContext& floatingContext, const Box& layoutBox) const
+void BlockFormattingContext::computeVerticalPositionForFloatClear(const LayoutContext& layoutContext, const FloatingContext& floatingContext, const Box& layoutBox) const
 {
     ASSERT(layoutBox.hasFloatClear());
     if (floatingContext.floatingState().isEmpty())
@@ -233,7 +234,7 @@ void BlockFormattingContext::computeVerticalPositionForFloatClear(LayoutContext&
         layoutContext.displayBoxForLayoutBox(layoutBox).setTop(*verticalPositionWithClearance);
 }
 
-void BlockFormattingContext::computeInFlowPositionedPosition(LayoutContext& layoutContext, const Box& layoutBox) const
+void BlockFormattingContext::computeInFlowPositionedPosition(const LayoutContext& layoutContext, const Box& layoutBox) const
 {
     layoutContext.displayBoxForLayoutBox(layoutBox).setTopLeft(Geometry::inFlowPositionedPosition(layoutContext, layoutBox));
 }
@@ -256,7 +257,7 @@ void BlockFormattingContext::computeWidthAndMargin(LayoutContext& layoutContext,
     displayBox.setHorizontalNonComputedMargin(widthAndMargin.nonComputedMargin);
 }
 
-void BlockFormattingContext::computeHeightAndMargin(LayoutContext& layoutContext, const Box& layoutBox) const
+void BlockFormattingContext::computeHeightAndMargin(const LayoutContext& layoutContext, const Box& layoutBox) const
 {
     HeightAndMargin heightAndMargin;
     std::optional<LayoutUnit> marginTopOffset;
@@ -308,7 +309,7 @@ FormattingContext::InstrinsicWidthConstraints BlockFormattingContext::instrinsic
     if (auto* firstChild = downcast<Container>(layoutBox).firstInFlowOrFloatingChild())
         queue.append(firstChild);
 
-    auto& formattingStateForChildren = layoutBox.establishesFormattingContext() ? layoutContext.establishedFormattingState(layoutBox) : formattingState;
+    auto& formattingStateForChildren = layoutBox.establishesFormattingContext() ? layoutContext.createFormattingStateForFormattingRootIfNeeded(layoutBox) : formattingState;
     while (!queue.isEmpty()) {
         while (true) {
             auto& childBox = *queue.last(); 
index 9892561..8d54216 100644 (file)
@@ -53,30 +53,30 @@ private:
     void layoutFormattingContextRoot(LayoutContext&, FloatingContext&, FormattingState&, const Box&) const;
 
     void computeWidthAndMargin(LayoutContext&, const Box&) const;
-    void computeHeightAndMargin(LayoutContext&, const Box&) const;
+    void computeHeightAndMargin(const LayoutContext&, const Box&) const;
 
-    void computeStaticPosition(LayoutContext&, const Box&) const override;
-    void computeFloatingPosition(LayoutContext&, FloatingContext&, const Box&) const;
-    void computePositionToAvoidFloats(LayoutContext&, FloatingContext&, const Box&) const;
-    void computeVerticalPositionForFloatClear(LayoutContext&, const FloatingContext&, const Box&) const;
+    void computeStaticPosition(const LayoutContext&, const Box&) const override;
+    void computeFloatingPosition(const LayoutContext&, FloatingContext&, const Box&) const;
+    void computePositionToAvoidFloats(const LayoutContext&, FloatingContext&, const Box&) const;
+    void computeVerticalPositionForFloatClear(const LayoutContext&, const FloatingContext&, const Box&) const;
 
-    void computeInFlowPositionedPosition(LayoutContext&, const Box&) const override;
-    void computeEstimatedMarginTop(LayoutContext&, const Box&) const;
-    void computeEstimatedMarginTopForAncestors(LayoutContext&, const Box&) const;
+    void computeInFlowPositionedPosition(const LayoutContext&, const Box&) const override;
+    void computeEstimatedMarginTop(const LayoutContext&, const Box&) const;
+    void computeEstimatedMarginTopForAncestors(const LayoutContext&, const Box&) const;
 
     InstrinsicWidthConstraints instrinsicWidthConstraints(LayoutContext&, const Box&) const override;
 
     // This class implements positioning and sizing for boxes participating in a block formatting context.
     class Geometry : public FormattingContext::Geometry {
     public:
-        static HeightAndMargin inFlowHeightAndMargin(LayoutContext&, const Box&);
-        static WidthAndMargin inFlowWidthAndMargin(LayoutContext&, const Box&);
+        static HeightAndMargin inFlowHeightAndMargin(const LayoutContext&, const Box&);
+        static WidthAndMargin inFlowWidthAndMargin(const LayoutContext&, const Box&);
 
-        static Position staticPosition(LayoutContext&, const Box&);
-        static Position inFlowPositionedPosition(LayoutContext&, const Box&);
+        static Position staticPosition(const LayoutContext&, const Box&);
+        static Position inFlowPositionedPosition(const LayoutContext&, const Box&);
 
         static bool instrinsicWidthConstraintsNeedChildrenWidth(const Box&);
-        static InstrinsicWidthConstraints instrinsicWidthConstraints(LayoutContext&, const Box&);
+        static InstrinsicWidthConstraints instrinsicWidthConstraints(const LayoutContext&, const Box&);
 
         static LayoutUnit estimatedMarginTop(const LayoutContext&, const Box&);
 
@@ -101,9 +101,9 @@ private:
             static LayoutUnit nonCollapsedMarginTop(const LayoutContext&, const Box&);
         };
 
-        static HeightAndMargin inFlowNonReplacedHeightAndMargin(LayoutContext&, const Box&);
-        static WidthAndMargin inFlowNonReplacedWidthAndMargin(LayoutContext&, const Box&, std::optional<LayoutUnit> precomputedWidth = std::nullopt);
-        static WidthAndMargin inFlowReplacedWidthAndMargin(LayoutContext&, const Box&);
+        static HeightAndMargin inFlowNonReplacedHeightAndMargin(const LayoutContext&, const Box&);
+        static WidthAndMargin inFlowNonReplacedWidthAndMargin(const LayoutContext&, const Box&, std::optional<LayoutUnit> precomputedWidth = std::nullopt);
+        static WidthAndMargin inFlowReplacedWidthAndMargin(const LayoutContext&, const Box&);
         static Position staticPositionForOutOfFlowPositioned(const LayoutContext&, const Box&);
     };
 };
index 5442036..ae36d1c 100644 (file)
@@ -77,7 +77,7 @@ static WidthAndMargin stretchWidthToInitialContainingBlock(WidthAndMargin widthA
     return widthAndMargin;
 }
 
-HeightAndMargin BlockFormattingContext::Geometry::inFlowNonReplacedHeightAndMargin(LayoutContext& layoutContext, const Box& layoutBox)
+HeightAndMargin BlockFormattingContext::Geometry::inFlowNonReplacedHeightAndMargin(const LayoutContext& layoutContext, const Box& layoutBox)
 {
     ASSERT(layoutBox.isInFlow() && !layoutBox.replaced());
     ASSERT(layoutBox.isOverflowVisible());
@@ -151,7 +151,7 @@ HeightAndMargin BlockFormattingContext::Geometry::inFlowNonReplacedHeightAndMarg
     return heightAndMargin;
 }
 
-WidthAndMargin BlockFormattingContext::Geometry::inFlowNonReplacedWidthAndMargin(LayoutContext& layoutContext, const Box& layoutBox,
+WidthAndMargin BlockFormattingContext::Geometry::inFlowNonReplacedWidthAndMargin(const LayoutContext& layoutContext, const Box& layoutBox,
     std::optional<LayoutUnit> precomputedWidth)
 {
     ASSERT(layoutBox.isInFlow() && !layoutBox.replaced());
@@ -252,7 +252,7 @@ WidthAndMargin BlockFormattingContext::Geometry::inFlowNonReplacedWidthAndMargin
     return widthAndMargin;
 }
 
-WidthAndMargin BlockFormattingContext::Geometry::inFlowReplacedWidthAndMargin(LayoutContext& layoutContext, const Box& layoutBox)
+WidthAndMargin BlockFormattingContext::Geometry::inFlowReplacedWidthAndMargin(const LayoutContext& layoutContext, const Box& layoutBox)
 {
     ASSERT(layoutBox.isInFlow() && layoutBox.replaced());
 
@@ -270,7 +270,7 @@ WidthAndMargin BlockFormattingContext::Geometry::inFlowReplacedWidthAndMargin(La
     return { width, nonReplacedWidthAndMargin.margin, nonReplacedWidthAndMargin.nonComputedMargin };
 }
 
-Position BlockFormattingContext::Geometry::staticPosition(LayoutContext& layoutContext, const Box& layoutBox)
+Position BlockFormattingContext::Geometry::staticPosition(const LayoutContext& layoutContext, const Box& layoutBox)
 {
     // https://www.w3.org/TR/CSS22/visuren.html#block-formatting
     // In a block formatting context, boxes are laid out one after the other, vertically, beginning at the top of a containing block.
@@ -291,7 +291,7 @@ Position BlockFormattingContext::Geometry::staticPosition(LayoutContext& layoutC
     return { left, top };
 }
 
-Position BlockFormattingContext::Geometry::inFlowPositionedPosition(LayoutContext& layoutContext, const Box& layoutBox)
+Position BlockFormattingContext::Geometry::inFlowPositionedPosition(const LayoutContext& layoutContext, const Box& layoutBox)
 {
     ASSERT(layoutBox.isInFlowPositioned());
 
@@ -368,7 +368,7 @@ Position BlockFormattingContext::Geometry::inFlowPositionedPosition(LayoutContex
     return { newLeftPosition, newTopPosition };
 }
 
-HeightAndMargin BlockFormattingContext::Geometry::inFlowHeightAndMargin(LayoutContext& layoutContext, const Box& layoutBox)
+HeightAndMargin BlockFormattingContext::Geometry::inFlowHeightAndMargin(const LayoutContext& layoutContext, const Box& layoutBox)
 {
     ASSERT(layoutBox.isInFlow());
 
@@ -397,7 +397,7 @@ HeightAndMargin BlockFormattingContext::Geometry::inFlowHeightAndMargin(LayoutCo
     return heightAndMargin;
 }
 
-WidthAndMargin BlockFormattingContext::Geometry::inFlowWidthAndMargin(LayoutContext& layoutContext, const Box& layoutBox)
+WidthAndMargin BlockFormattingContext::Geometry::inFlowWidthAndMargin(const LayoutContext& layoutContext, const Box& layoutBox)
 {
     ASSERT(layoutBox.isInFlow());
 
@@ -413,7 +413,7 @@ bool BlockFormattingContext::Geometry::instrinsicWidthConstraintsNeedChildrenWid
     return layoutBox.style().width().isAuto();
 }
 
-FormattingContext::InstrinsicWidthConstraints BlockFormattingContext::Geometry::instrinsicWidthConstraints(LayoutContext& layoutContext, const Box& layoutBox)
+FormattingContext::InstrinsicWidthConstraints BlockFormattingContext::Geometry::instrinsicWidthConstraints(const LayoutContext& layoutContext, const Box& layoutBox)
 {
     auto& style = layoutBox.style();
     if (auto width = fixedValue(style.logicalWidth()))
index 9e26b75..a5bf1ad 100644 (file)
@@ -102,11 +102,11 @@ void InlineFormattingContext::layout(LayoutContext& layoutContext, FormattingSta
     LOG_WITH_STREAM(FormattingContextLayout, stream << "[End] -> inline formatting context -> layout context(" << &layoutContext << ") formatting root(" << &root() << ")");
 }
 
-void InlineFormattingContext::computeStaticPosition(LayoutContext&, const Box&) const
+void InlineFormattingContext::computeStaticPosition(const LayoutContext&, const Box&) const
 {
 }
 
-void InlineFormattingContext::computeInFlowPositionedPosition(LayoutContext&, const Box&) const
+void InlineFormattingContext::computeInFlowPositionedPosition(const LayoutContext&, const Box&) const
 {
 }
 
index 0266df3..324d9d5 100644 (file)
@@ -46,8 +46,8 @@ public:
     void layout(LayoutContext&, FormattingState&) const override;
 
 private:
-    void computeStaticPosition(LayoutContext&, const Box&) const override;
-    void computeInFlowPositionedPosition(LayoutContext&, const Box&) const override;
+    void computeStaticPosition(const LayoutContext&, const Box&) const override;
+    void computeInFlowPositionedPosition(const LayoutContext&, const Box&) const override;
 
     InstrinsicWidthConstraints instrinsicWidthConstraints(LayoutContext&, const Box&) const override;
 };