[LFC] FormattingContext class should take FormattingState&
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 31 Oct 2018 13:50:05 +0000 (13:50 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 31 Oct 2018 13:50:05 +0000 (13:50 +0000)
https://bugs.webkit.org/show_bug.cgi?id=191099

Reviewed by Antti Koivisto.

This is in preparation for not passing LayoutState& into every layout functions.
FormattingContext has FormattingState now and LayoutState can be acquired through FormattingState.
LayoutState <- FormattingState <- FormattingContext

* layout/FormattingContext.cpp:
(WebCore::Layout::FormattingContext::FormattingContext):
(WebCore::Layout::FormattingContext::formattingState const):
(WebCore::Layout::FormattingContext::layoutState const):
* layout/FormattingContext.h:
* layout/FormattingState.cpp:
(WebCore::Layout::FormattingState::FormattingState):
* layout/FormattingState.h:
(WebCore::Layout::FormattingState::layoutState const):
* layout/LayoutFormattingState.h:
* layout/blockformatting/BlockFormattingContext.cpp:
(WebCore::Layout::BlockFormattingContext::BlockFormattingContext):
* layout/blockformatting/BlockFormattingContext.h:
* layout/blockformatting/BlockFormattingState.cpp:
(WebCore::Layout::BlockFormattingState::BlockFormattingState):
(WebCore::Layout::BlockFormattingState::formattingContext):
(WebCore::Layout::BlockFormattingState::formattingContext const): Deleted.
* layout/blockformatting/BlockFormattingState.h:
* layout/inlineformatting/InlineFormattingContext.cpp:
(WebCore::Layout::InlineFormattingContext::InlineFormattingContext):
* layout/inlineformatting/InlineFormattingContext.h:
* layout/inlineformatting/InlineFormattingState.cpp:
(WebCore::Layout::InlineFormattingState::InlineFormattingState):
(WebCore::Layout::InlineFormattingState::formattingContext):
(WebCore::Layout::InlineFormattingState::formattingContext const): Deleted.
* layout/inlineformatting/InlineFormattingState.h:

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

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

index ff6fc5b..9aa95c2 100644 (file)
@@ -1,5 +1,43 @@
 2018-10-31  Zalan Bujtas  <zalan@apple.com>
 
+        [LFC] FormattingContext class should take FormattingState&
+        https://bugs.webkit.org/show_bug.cgi?id=191099
+
+        Reviewed by Antti Koivisto.
+
+        This is in preparation for not passing LayoutState& into every layout functions.
+        FormattingContext has FormattingState now and LayoutState can be acquired through FormattingState.
+        LayoutState <- FormattingState <- FormattingContext
+
+        * layout/FormattingContext.cpp:
+        (WebCore::Layout::FormattingContext::FormattingContext):
+        (WebCore::Layout::FormattingContext::formattingState const):
+        (WebCore::Layout::FormattingContext::layoutState const):
+        * layout/FormattingContext.h:
+        * layout/FormattingState.cpp:
+        (WebCore::Layout::FormattingState::FormattingState):
+        * layout/FormattingState.h:
+        (WebCore::Layout::FormattingState::layoutState const):
+        * layout/LayoutFormattingState.h:
+        * layout/blockformatting/BlockFormattingContext.cpp:
+        (WebCore::Layout::BlockFormattingContext::BlockFormattingContext):
+        * layout/blockformatting/BlockFormattingContext.h:
+        * layout/blockformatting/BlockFormattingState.cpp:
+        (WebCore::Layout::BlockFormattingState::BlockFormattingState):
+        (WebCore::Layout::BlockFormattingState::formattingContext):
+        (WebCore::Layout::BlockFormattingState::formattingContext const): Deleted.
+        * layout/blockformatting/BlockFormattingState.h:
+        * layout/inlineformatting/InlineFormattingContext.cpp:
+        (WebCore::Layout::InlineFormattingContext::InlineFormattingContext):
+        * layout/inlineformatting/InlineFormattingContext.h:
+        * layout/inlineformatting/InlineFormattingState.cpp:
+        (WebCore::Layout::InlineFormattingState::InlineFormattingState):
+        (WebCore::Layout::InlineFormattingState::formattingContext):
+        (WebCore::Layout::InlineFormattingState::formattingContext const): Deleted.
+        * layout/inlineformatting/InlineFormattingState.h:
+
+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
 
index ac1652f..29f832d 100644 (file)
@@ -43,8 +43,9 @@ namespace Layout {
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(FormattingContext);
 
-FormattingContext::FormattingContext(const Box& formattingContextRoot)
+FormattingContext::FormattingContext(const Box& formattingContextRoot, FormattingState& formattingState)
     : m_root(makeWeakPtr(formattingContextRoot))
+    , m_formattingState(formattingState)
 {
 }
 
@@ -52,6 +53,16 @@ FormattingContext::~FormattingContext()
 {
 }
 
+FormattingState& FormattingContext::formattingState() const
+{
+    return m_formattingState;
+}
+
+LayoutState& FormattingContext::layoutState() const
+{
+    return m_formattingState.layoutState();
+}
+
 void FormattingContext::computeOutOfFlowHorizontalGeometry(LayoutState& layoutState, const Box& layoutBox) const
 {
     auto compute = [&](std::optional<LayoutUnit> usedWidth) {
index 4195c93..49d8926 100644 (file)
@@ -28,7 +28,6 @@
 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)
 
 #include "DisplayBox.h"
-#include "FloatingState.h"
 #include <wtf/IsoMalloc.h>
 #include <wtf/WeakPtr.h>
 
@@ -47,7 +46,7 @@ class LayoutState;
 class FormattingContext {
     WTF_MAKE_ISO_ALLOCATED(FormattingContext);
 public:
-    FormattingContext(const Box& formattingContextRoot);
+    FormattingContext(const Box& formattingContextRoot, FormattingState&);
     virtual ~FormattingContext();
 
     virtual void layout(LayoutState&, FormattingState&) const = 0;
@@ -66,6 +65,8 @@ public:
 protected:
     using LayoutQueue = Vector<const Box*>;
 
+    FormattingState& formattingState() const;
+    LayoutState& layoutState() const;
     const Box& root() const { return *m_root; }
 
     virtual void computeStaticPosition(const LayoutState&, const Box&) const = 0;
@@ -126,6 +127,7 @@ private:
     void computeOutOfFlowHorizontalGeometry(LayoutState&, const Box&) const;
 
     WeakPtr<const Box> m_root;
+    FormattingState& m_formattingState;
 };
 
 }
index 0cd0acb..2178165 100644 (file)
@@ -35,7 +35,7 @@ namespace Layout {
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(FormattingState);
 
-FormattingState::FormattingState(Ref<FloatingState>&& floatingState, Type type, const LayoutState& layoutState)
+FormattingState::FormattingState(Ref<FloatingState>&& floatingState, Type type, LayoutState& layoutState)
     : m_layoutState(layoutState)
     , m_floatingState(WTFMove(floatingState))
     , m_type(type)
index 1073f7f..90283e0 100644 (file)
@@ -46,7 +46,7 @@ class FormattingState {
 public:
     virtual ~FormattingState();
 
-    virtual std::unique_ptr<FormattingContext>formattingContext(const Box& formattingContextRoot) const = 0;
+    virtual std::unique_ptr<FormattingContext>formattingContext(const Box& formattingContextRoot) = 0;
 
     FloatingState& floatingState() const { return m_floatingState; }
 
@@ -60,13 +60,14 @@ public:
     bool isBlockFormattingState() const { return m_type == Type::Block; }
     bool isInlineFormattingState() const { return m_type == Type::Inline; }
 
+    LayoutState& layoutState() const { return m_layoutState; }
+
 protected:
     enum class Type { Block, Inline };
-    FormattingState(Ref<FloatingState>&&, Type, const LayoutState&);
-
-    const LayoutState& m_layoutState;
+    FormattingState(Ref<FloatingState>&&, Type, LayoutState&);
 
 private:
+    LayoutState& m_layoutState;
     Ref<FloatingState> m_floatingState;
     HashMap<const Box*, FormattingContext::InstrinsicWidthConstraints> m_instrinsicWidthConstraints;
     Type m_type;
index d43b889..e203e67 100644 (file)
@@ -27,7 +27,6 @@
 
 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)
 
-#include "FormattingContext.h"
 #include <wtf/HashMap.h>
 #include <wtf/HashSet.h>
 #include <wtf/IsoMalloc.h>
index 5ae6b68..8cc1ede 100644 (file)
@@ -44,8 +44,8 @@ namespace Layout {
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(BlockFormattingContext);
 
-BlockFormattingContext::BlockFormattingContext(const Box& formattingContextRoot)
-    : FormattingContext(formattingContextRoot)
+BlockFormattingContext::BlockFormattingContext(const Box& formattingContextRoot, FormattingState& formattingState)
+    : FormattingContext(formattingContextRoot, formattingState)
 {
 }
 
index 9bd35ec..8c0426a 100644 (file)
@@ -45,7 +45,7 @@ class FloatingContext;
 class BlockFormattingContext : public FormattingContext {
     WTF_MAKE_ISO_ALLOCATED(BlockFormattingContext);
 public:
-    BlockFormattingContext(const Box& formattingContextRoot);
+    BlockFormattingContext(const Box& formattingContextRoot, FormattingState& formattingState);
 
     void layout(LayoutState&, FormattingState&) const override;
 
index 3a544c4..8c30077 100644 (file)
@@ -37,7 +37,7 @@ namespace Layout {
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(BlockFormattingState);
 
-BlockFormattingState::BlockFormattingState(Ref<FloatingState>&& floatingState, const LayoutState& layoutState)
+BlockFormattingState::BlockFormattingState(Ref<FloatingState>&& floatingState, LayoutState& layoutState)
     : FormattingState(WTFMove(floatingState), Type::Block, layoutState)
 {
 }
@@ -46,10 +46,10 @@ BlockFormattingState::~BlockFormattingState()
 {
 }
 
-std::unique_ptr<FormattingContext> BlockFormattingState::formattingContext(const Box& formattingContextRoot) const
+std::unique_ptr<FormattingContext> BlockFormattingState::formattingContext(const Box& formattingContextRoot)
 {
     ASSERT(formattingContextRoot.establishesBlockFormattingContext());
-    return std::make_unique<BlockFormattingContext>(formattingContextRoot);
+    return std::make_unique<BlockFormattingContext>(formattingContextRoot, *this);
 }
 
 }
index 8cd8b45..16b8595 100644 (file)
@@ -38,10 +38,10 @@ namespace Layout {
 class BlockFormattingState : public FormattingState {
     WTF_MAKE_ISO_ALLOCATED(BlockFormattingState);
 public:
-    BlockFormattingState(Ref<FloatingState>&&, const LayoutState&);
+    BlockFormattingState(Ref<FloatingState>&&, LayoutState&);
     virtual ~BlockFormattingState();
 
-    std::unique_ptr<FormattingContext> formattingContext(const Box& formattingContextRoot) const override;
+    std::unique_ptr<FormattingContext> formattingContext(const Box& formattingContextRoot) override;
 };
 
 }
index b2925e8..7bc0eed 100644 (file)
@@ -46,8 +46,8 @@ namespace Layout {
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(InlineFormattingContext);
 
-InlineFormattingContext::InlineFormattingContext(const Box& formattingContextRoot)
-    : FormattingContext(formattingContextRoot)
+InlineFormattingContext::InlineFormattingContext(const Box& formattingContextRoot, FormattingState& formattingState)
+    : FormattingContext(formattingContextRoot, formattingState)
 {
 }
 
index 429734f..184dd24 100644 (file)
@@ -43,7 +43,7 @@ class InlineRunProvider;
 class InlineFormattingContext : public FormattingContext {
     WTF_MAKE_ISO_ALLOCATED(InlineFormattingContext);
 public:
-    InlineFormattingContext(const Box& formattingContextRoot);
+    InlineFormattingContext(const Box& formattingContextRoot, FormattingState&);
 
     void layout(LayoutState&, FormattingState&) const override;
 
index 437d948..ff010c8 100644 (file)
@@ -35,7 +35,7 @@ namespace Layout {
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(InlineFormattingState);
 
-InlineFormattingState::InlineFormattingState(Ref<FloatingState>&& floatingState, const LayoutState& layoutState)
+InlineFormattingState::InlineFormattingState(Ref<FloatingState>&& floatingState, LayoutState& layoutState)
     : FormattingState(WTFMove(floatingState), Type::Inline, layoutState)
 {
 }
@@ -44,10 +44,10 @@ InlineFormattingState::~InlineFormattingState()
 {
 }
 
-std::unique_ptr<FormattingContext> InlineFormattingState::formattingContext(const Box& formattingContextRoot) const
+std::unique_ptr<FormattingContext> InlineFormattingState::formattingContext(const Box& formattingContextRoot)
 {
     ASSERT(formattingContextRoot.establishesInlineFormattingContext());
-    return std::make_unique<InlineFormattingContext>(formattingContextRoot);
+    return std::make_unique<InlineFormattingContext>(formattingContextRoot, this);
 }
 
 }
index 302b0dd..a753597 100644 (file)
@@ -39,10 +39,10 @@ namespace Layout {
 class InlineFormattingState : public FormattingState {
     WTF_MAKE_ISO_ALLOCATED(InlineFormattingState);
 public:
-    InlineFormattingState(Ref<FloatingState>&&, const LayoutState&);
+    InlineFormattingState(Ref<FloatingState>&&, LayoutState&);
     virtual ~InlineFormattingState();
 
-    std::unique_ptr<FormattingContext> formattingContext(const Box& formattingContextRoot) const override;
+    std::unique_ptr<FormattingContext> formattingContext(const Box& formattingContextRoot) override;
 
     InlineContent& inlineContent() { return m_inlineContent; }
     // Temp