[LFC] The *FormattingState class should provide the *FormattingContext.
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 31 Oct 2018 13:43:03 +0000 (13:43 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 31 Oct 2018 13:43:03 +0000 (13:43 +0000)
https://bugs.webkit.org/show_bug.cgi?id=191089

Reviewed by Antti Koivisto.

BlockFormattingState provides the BlockFormattingContext object, while InlineFormattingState provides the InlineFormattingContext.

* layout/FormattingContext.cpp:
(WebCore::Layout::FormattingContext::layoutOutOfFlowDescendants const):
* layout/FormattingState.h:
* layout/LayoutFormattingState.cpp:
(WebCore::Layout::LayoutState::layoutFormattingContextSubtree):
(WebCore::Layout::LayoutState::formattingContext const): Deleted.
* layout/LayoutFormattingState.h:
* layout/blockformatting/BlockFormattingContext.cpp:
(WebCore::Layout::BlockFormattingContext::layoutFormattingContextRoot const):
(WebCore::Layout::BlockFormattingContext::instrinsicWidthConstraints const):
* layout/blockformatting/BlockFormattingState.cpp:
(WebCore::Layout::BlockFormattingState::formattingContext const):
* layout/blockformatting/BlockFormattingState.h:
* layout/inlineformatting/InlineFormattingContext.cpp:
(WebCore::Layout::InlineFormattingContext::layoutFormattingContextRoot const):
* layout/inlineformatting/InlineFormattingState.cpp:
(WebCore::Layout::InlineFormattingState::formattingContext const):
* layout/inlineformatting/InlineFormattingState.h:

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

Source/WebCore/ChangeLog
Source/WebCore/layout/FormattingContext.cpp
Source/WebCore/layout/FormattingState.h
Source/WebCore/layout/LayoutFormattingState.cpp
Source/WebCore/layout/LayoutFormattingState.h
Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp
Source/WebCore/layout/blockformatting/BlockFormattingState.cpp
Source/WebCore/layout/blockformatting/BlockFormattingState.h
Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp
Source/WebCore/layout/inlineformatting/InlineFormattingState.cpp
Source/WebCore/layout/inlineformatting/InlineFormattingState.h

index c257f72..ff6fc5b 100644 (file)
@@ -1,5 +1,33 @@
 2018-10-31  Zalan Bujtas  <zalan@apple.com>
 
+        [LFC] The *FormattingState class should provide the *FormattingContext.
+        https://bugs.webkit.org/show_bug.cgi?id=191089
+
+        Reviewed by Antti Koivisto.
+
+        BlockFormattingState provides the BlockFormattingContext object, while InlineFormattingState provides the InlineFormattingContext.
+
+        * layout/FormattingContext.cpp:
+        (WebCore::Layout::FormattingContext::layoutOutOfFlowDescendants const):
+        * layout/FormattingState.h:
+        * layout/LayoutFormattingState.cpp:
+        (WebCore::Layout::LayoutState::layoutFormattingContextSubtree):
+        (WebCore::Layout::LayoutState::formattingContext const): Deleted.
+        * layout/LayoutFormattingState.h:
+        * layout/blockformatting/BlockFormattingContext.cpp:
+        (WebCore::Layout::BlockFormattingContext::layoutFormattingContextRoot const):
+        (WebCore::Layout::BlockFormattingContext::instrinsicWidthConstraints const):
+        * layout/blockformatting/BlockFormattingState.cpp:
+        (WebCore::Layout::BlockFormattingState::formattingContext const):
+        * layout/blockformatting/BlockFormattingState.h:
+        * layout/inlineformatting/InlineFormattingContext.cpp:
+        (WebCore::Layout::InlineFormattingContext::layoutFormattingContextRoot const):
+        * layout/inlineformatting/InlineFormattingState.cpp:
+        (WebCore::Layout::InlineFormattingState::formattingContext const):
+        * layout/inlineformatting/InlineFormattingState.h:
+
+2018-10-31  Zalan Bujtas  <zalan@apple.com>
+
         [LFC] Rename LayoutContext to LayoutState
         https://bugs.webkit.org/show_bug.cgi?id=191080
 
index 3f01e05..ac1652f 100644 (file)
@@ -29,6 +29,7 @@
 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)
 
 #include "DisplayBox.h"
+#include "FormattingState.h"
 #include "LayoutBox.h"
 #include "LayoutContainer.h"
 #include "LayoutDescendantIterator.h"
@@ -147,13 +148,12 @@ void FormattingContext::layoutOutOfFlowDescendants(LayoutState& layoutState, con
         auto& layoutBox = *outOfFlowBox;
 
         ASSERT(layoutBox.establishesFormattingContext());
-        auto formattingContext = layoutState.formattingContext(layoutBox);
 
         computeBorderAndPadding(layoutState, layoutBox);
         computeOutOfFlowHorizontalGeometry(layoutState, layoutBox);
 
         auto& formattingState = layoutState.createFormattingStateForFormattingRootIfNeeded(layoutBox);
-        formattingContext->layout(layoutState, formattingState);
+        formattingState.formattingContext(layoutBox)->layout(layoutState, formattingState);
 
         computeOutOfFlowVerticalGeometry(layoutState, layoutBox);
         layoutOutOfFlowDescendants(layoutState, layoutBox);
index 0a39723..1073f7f 100644 (file)
@@ -46,6 +46,8 @@ class FormattingState {
 public:
     virtual ~FormattingState();
 
+    virtual std::unique_ptr<FormattingContext>formattingContext(const Box& formattingContextRoot) const = 0;
+
     FloatingState& floatingState() const { return m_floatingState; }
 
     void markNeedsLayout(const Box&, StyleDiff);
index 5fa0186..d7ca48a 100644 (file)
@@ -81,8 +81,8 @@ void LayoutState::updateLayout()
 void LayoutState::layoutFormattingContextSubtree(const Box& layoutRoot)
 {
     RELEASE_ASSERT(layoutRoot.establishesFormattingContext());
-    auto formattingContext = this->formattingContext(layoutRoot);
     auto& formattingState = createFormattingStateForFormattingRootIfNeeded(layoutRoot);
+    auto formattingContext = formattingState.formattingContext(layoutRoot);
     formattingContext->layout(*this, formattingState);
     formattingContext->layoutOutOfFlowDescendants(*this, layoutRoot);
 }
@@ -156,18 +156,6 @@ FormattingState& LayoutState::createFormattingStateForFormattingRootIfNeeded(con
     CRASH();
 }
 
-std::unique_ptr<FormattingContext> LayoutState::formattingContext(const Box& formattingContextRoot) const
-{
-    if (formattingContextRoot.establishesInlineFormattingContext())
-        return std::make_unique<InlineFormattingContext>(formattingContextRoot);
-
-    if (formattingContextRoot.establishesBlockFormattingContext())
-        return std::make_unique<BlockFormattingContext>(formattingContextRoot);
-
-    ASSERT_NOT_IMPLEMENTED_YET();
-    return nullptr;
-}
-
 }
 }
 
index 4674b61..d43b889 100644 (file)
@@ -75,8 +75,6 @@ public:
     void markNeedsUpdate(const Box&, OptionSet<UpdateType>);
     bool needsUpdate(const Box&) const;
 
-    std::unique_ptr<FormattingContext> formattingContext(const Box& formattingContextRoot) const;
-
     FormattingState& formattingStateForBox(const Box&) const;
     FormattingState& establishedFormattingState(const Box& formattingRoot) const;
     FormattingState& createFormattingStateForFormattingRootIfNeeded(const Box& formattingRoot);
index 7ec2467..5ae6b68 100644 (file)
@@ -134,8 +134,8 @@ void BlockFormattingContext::layoutFormattingContextRoot(LayoutState& layoutStat
 
     precomputeVerticalPositionForFormattingRootIfNeeded(layoutState, layoutBox);
     // Swich over to the new formatting context (the one that the root creates).
-    auto formattingContext = layoutState.formattingContext(layoutBox);
     auto& formattingState = layoutState.createFormattingStateForFormattingRootIfNeeded(layoutBox);
+    auto formattingContext = formattingState.formattingContext(layoutBox);
     formattingContext->layout(layoutState, formattingState);
 
     // Come back and finalize the root's geometry.
@@ -383,7 +383,7 @@ FormattingContext::InstrinsicWidthConstraints BlockFormattingContext::instrinsic
                 instrinsicWidthConstraints = Geometry::instrinsicWidthConstraints(layoutState, childBox);
             // Is it a formatting context root?
             if (!instrinsicWidthConstraints && childBox.establishesFormattingContext())
-                instrinsicWidthConstraints = layoutState.formattingContext(childBox)->instrinsicWidthConstraints(layoutState, childBox);
+                instrinsicWidthConstraints = formattingStateForChildren.formattingContext(childBox)->instrinsicWidthConstraints(layoutState, 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 0d2491e..3a544c4 100644 (file)
@@ -46,6 +46,12 @@ BlockFormattingState::~BlockFormattingState()
 {
 }
 
+std::unique_ptr<FormattingContext> BlockFormattingState::formattingContext(const Box& formattingContextRoot) const
+{
+    ASSERT(formattingContextRoot.establishesBlockFormattingContext());
+    return std::make_unique<BlockFormattingContext>(formattingContextRoot);
+}
+
 }
 }
 #endif
index b46b8c9..8cd8b45 100644 (file)
@@ -40,6 +40,8 @@ class BlockFormattingState : public FormattingState {
 public:
     BlockFormattingState(Ref<FloatingState>&&, const LayoutState&);
     virtual ~BlockFormattingState();
+
+    std::unique_ptr<FormattingContext> formattingContext(const Box& formattingContextRoot) const override;
 };
 
 }
index 5a86220..b2925e8 100644 (file)
@@ -241,7 +241,8 @@ void InlineFormattingContext::layoutFormattingContextRoot(LayoutState& layoutSta
     computeWidthAndMargin();
 
     // Swich over to the new formatting context (the one that the root creates).
-    layoutState.formattingContext(layoutBox)->layout(layoutState, layoutState.createFormattingStateForFormattingRootIfNeeded(layoutBox));
+    auto& formattingState = layoutState.createFormattingStateForFormattingRootIfNeeded(layoutBox);
+    formattingState.formattingContext(layoutBox)->layout(layoutState, formattingState);
 
     // Come back and finalize the root's height and margin.
     computeHeightAndMargin();
index 984bc6c..437d948 100644 (file)
@@ -44,6 +44,12 @@ InlineFormattingState::~InlineFormattingState()
 {
 }
 
+std::unique_ptr<FormattingContext> InlineFormattingState::formattingContext(const Box& formattingContextRoot) const
+{
+    ASSERT(formattingContextRoot.establishesInlineFormattingContext());
+    return std::make_unique<InlineFormattingContext>(formattingContextRoot);
+}
+
 }
 }
 #endif
index cfdf406..302b0dd 100644 (file)
@@ -42,6 +42,8 @@ public:
     InlineFormattingState(Ref<FloatingState>&&, const LayoutState&);
     virtual ~InlineFormattingState();
 
+    std::unique_ptr<FormattingContext> formattingContext(const Box& formattingContextRoot) const override;
+
     InlineContent& inlineContent() { return m_inlineContent; }
     // Temp
     InlineRuns& inlineRuns() { return m_inlineRuns; }