[LFC] Implement LayoutContexet::layout() and its dependencies.
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 25 Apr 2018 22:54:01 +0000 (22:54 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 25 Apr 2018 22:54:01 +0000 (22:54 +0000)
https://bugs.webkit.org/show_bug.cgi?id=184951

Reviewed by Antti Koivisto.

* layout/FormattingContext.cpp:
(WebCore::Layout::FormattingContext::FormattingContext):
(WebCore::Layout::FormattingContext::~FormattingContext):
(WebCore::Layout::FormattingContext::computeStaticPosition):
(WebCore::Layout::FormattingContext::computeInFlowPositionedPosition):
(WebCore::Layout::FormattingContext::computeOutOfFlowPosition):
(WebCore::Layout::FormattingContext::computeWidth):
(WebCore::Layout::FormattingContext::computeHeight):
(WebCore::Layout::FormattingContext::marginTop):
(WebCore::Layout::FormattingContext::marginLeft):
(WebCore::Layout::FormattingContext::marginBottom):
(WebCore::Layout::FormattingContext::marginRight):
* layout/FormattingContext.h:
* layout/FormattingState.cpp:
(WebCore::Layout::FormattingState::FormattingState):
* layout/FormattingState.h:
* layout/LayoutContext.cpp:
(WebCore::Layout::LayoutContext::LayoutContext):
(WebCore::Layout::LayoutContext::updateLayout):
(WebCore::Layout::LayoutContext::formattingState):
(WebCore::Layout::LayoutContext::formattingContext):
* layout/LayoutContext.h:
* layout/blockformatting/BlockFormattingContext.cpp:
(WebCore::Layout::BlockFormattingContext::BlockFormattingContext):
(WebCore::Layout::BlockFormattingContext::layout):
(WebCore::Layout::BlockFormattingContext::formattingState const):
(WebCore::Layout::BlockFormattingContext::computeStaticPosition):
(WebCore::Layout::BlockFormattingContext::computeWidth):
(WebCore::Layout::BlockFormattingContext::computeHeight):
(WebCore::Layout::BlockFormattingContext::marginTop):
(WebCore::Layout::BlockFormattingContext::marginBottom):
* layout/blockformatting/BlockFormattingContext.h:
* layout/blockformatting/BlockFormattingState.cpp:
(WebCore::Layout::BlockFormattingState::BlockFormattingState):
* layout/blockformatting/BlockFormattingState.h:
* layout/inlineformatting/InlineFormattingContext.cpp:
(WebCore::Layout::InlineFormattingContext::InlineFormattingContext):
(WebCore::Layout::InlineFormattingContext::layout):
(WebCore::Layout::InlineFormattingContext::formattingState const):
* layout/inlineformatting/InlineFormattingContext.h:
* layout/inlineformatting/InlineFormattingState.cpp:
(WebCore::Layout::InlineFormattingState::InlineFormattingState):
* layout/inlineformatting/InlineFormattingState.h:

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

15 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/LayoutContext.cpp
Source/WebCore/layout/LayoutContext.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 c4f2b67b22f7006fc73a1e4654b2b84c00a29d2e..7a6d28b8cc1ea407daaf981ef340836edb6f1d07 100644 (file)
@@ -1,3 +1,54 @@
+2018-04-25  Zalan Bujtas  <zalan@apple.com>
+
+        [LFC] Implement LayoutContexet::layout() and its dependencies.
+        https://bugs.webkit.org/show_bug.cgi?id=184951
+
+        Reviewed by Antti Koivisto.
+
+        * layout/FormattingContext.cpp:
+        (WebCore::Layout::FormattingContext::FormattingContext):
+        (WebCore::Layout::FormattingContext::~FormattingContext):
+        (WebCore::Layout::FormattingContext::computeStaticPosition):
+        (WebCore::Layout::FormattingContext::computeInFlowPositionedPosition):
+        (WebCore::Layout::FormattingContext::computeOutOfFlowPosition):
+        (WebCore::Layout::FormattingContext::computeWidth):
+        (WebCore::Layout::FormattingContext::computeHeight):
+        (WebCore::Layout::FormattingContext::marginTop):
+        (WebCore::Layout::FormattingContext::marginLeft):
+        (WebCore::Layout::FormattingContext::marginBottom):
+        (WebCore::Layout::FormattingContext::marginRight):
+        * layout/FormattingContext.h:
+        * layout/FormattingState.cpp:
+        (WebCore::Layout::FormattingState::FormattingState):
+        * layout/FormattingState.h:
+        * layout/LayoutContext.cpp:
+        (WebCore::Layout::LayoutContext::LayoutContext):
+        (WebCore::Layout::LayoutContext::updateLayout):
+        (WebCore::Layout::LayoutContext::formattingState):
+        (WebCore::Layout::LayoutContext::formattingContext):
+        * layout/LayoutContext.h:
+        * layout/blockformatting/BlockFormattingContext.cpp:
+        (WebCore::Layout::BlockFormattingContext::BlockFormattingContext):
+        (WebCore::Layout::BlockFormattingContext::layout):
+        (WebCore::Layout::BlockFormattingContext::formattingState const):
+        (WebCore::Layout::BlockFormattingContext::computeStaticPosition):
+        (WebCore::Layout::BlockFormattingContext::computeWidth):
+        (WebCore::Layout::BlockFormattingContext::computeHeight):
+        (WebCore::Layout::BlockFormattingContext::marginTop):
+        (WebCore::Layout::BlockFormattingContext::marginBottom):
+        * layout/blockformatting/BlockFormattingContext.h:
+        * layout/blockformatting/BlockFormattingState.cpp:
+        (WebCore::Layout::BlockFormattingState::BlockFormattingState):
+        * layout/blockformatting/BlockFormattingState.h:
+        * layout/inlineformatting/InlineFormattingContext.cpp:
+        (WebCore::Layout::InlineFormattingContext::InlineFormattingContext):
+        (WebCore::Layout::InlineFormattingContext::layout):
+        (WebCore::Layout::InlineFormattingContext::formattingState const):
+        * layout/inlineformatting/InlineFormattingContext.h:
+        * layout/inlineformatting/InlineFormattingState.cpp:
+        (WebCore::Layout::InlineFormattingState::InlineFormattingState):
+        * layout/inlineformatting/InlineFormattingState.h:
+
 2018-04-25  Mark Lam  <mark.lam@apple.com>
 
         Push the definition of PtrTag down to the WTF layer.
index 51a92b47aeb86a5ac06d280bb4c0b8816b25571d..9855bad4295e7a9b5c8bdf5f2c87d3f41b14d4ec 100644 (file)
 
 #include "config.h"
 #include "FormattingContext.h"
+
+#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
+
+#include <wtf/IsoMallocInlines.h>
+
+namespace WebCore {
+namespace Layout {
+
+WTF_MAKE_ISO_ALLOCATED_IMPL(FormattingContext);
+
+FormattingContext::FormattingContext(Box& formattingContextRoot)
+    : m_root(makeWeakPtr(formattingContextRoot))
+{
+}
+
+FormattingContext::~FormattingContext()
+{
+}
+
+void FormattingContext::computeStaticPosition(const Box&) const
+{
+}
+
+void FormattingContext::computeInFlowPositionedPosition(const Box&) const
+{
+}
+
+void FormattingContext::computeOutOfFlowPosition(const Box&) const
+{
+}
+
+void FormattingContext::computeWidth(const Box&) const
+{
+}
+
+void FormattingContext::computeHeight(const Box&) const
+{
+}
+
+LayoutUnit FormattingContext::marginTop(const Box&) const
+{
+    return 0;
+}
+
+LayoutUnit FormattingContext::marginLeft(const Box&) const
+{
+    return 0;
+}
+
+LayoutUnit FormattingContext::marginBottom(const Box&) const
+{
+    return 0;
+}
+
+LayoutUnit FormattingContext::marginRight(const Box&) const
+{
+    return 0;
+}
+
+}
+}
+#endif
index 87f39d74fccb4adf81ffb45e997eab9c2bf343be..e86cff92d2775a3057774837b294f04ee7f81d51 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "LayoutUnit.h"
 #include <wtf/IsoMalloc.h>
+#include <wtf/WeakPtr.h>
 
 namespace WebCore {
 
@@ -40,25 +41,29 @@ class Box;
 class FormattingContext {
     WTF_MAKE_ISO_ALLOCATED(FormattingContext);
 public:
-    FormattingContext(FormattingState&);
+    FormattingContext(Box& formattingContextRoot);
     virtual ~FormattingContext();
 
-    virtual void layout();
+    virtual void layout(FormattingState&) = 0;
+    virtual std::unique_ptr<FormattingState> formattingState() const = 0;
 
-    FormattingState& formattingState() const;
+    const Box& root() const { return *m_root; }
 
 protected:
-    virtual void computeStaticPosition(const Box&);
-    virtual void computeInFlowPositionedPosition(const Box&);
-    virtual void computeOutOfFlowPosition(const Box&);
+    virtual void computeStaticPosition(const Box&) const;
+    virtual void computeInFlowPositionedPosition(const Box&) const;
+    virtual void computeOutOfFlowPosition(const Box&) const;
 
-    virtual void computeWidth(const Box&);
-    virtual void computeHeight(const Box&);
+    virtual void computeWidth(const Box&) const;
+    virtual void computeHeight(const Box&) const;
 
-    virtual LayoutUnit marginTop(const Box&);
-    virtual LayoutUnit marginLeft(const Box&);
-    virtual LayoutUnit marginBottom(const Box&);
-    virtual LayoutUnit marginRight(const Box&);
+    virtual LayoutUnit marginTop(const Box&) const;
+    virtual LayoutUnit marginLeft(const Box&) const;
+    virtual LayoutUnit marginBottom(const Box&) const;
+    virtual LayoutUnit marginRight(const Box&) const;
+
+private:
+    WeakPtr<Box> m_root;
 };
 
 }
index be0f314194bd94c65fb4f4d50b69923c57a59188..8fa0d438ccf7c53096a38db4c44afc12e410c93f 100644 (file)
 
 #include "config.h"
 #include "FormattingState.h"
+
+#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
+
+#include <wtf/IsoMallocInlines.h>
+
+namespace WebCore {
+namespace Layout {
+
+WTF_MAKE_ISO_ALLOCATED_IMPL(FormattingState);
+
+FormattingState::FormattingState()
+{
+}
+
+}
+}
+#endif
index 7821e7b19c64046599e6787fa20d4f4fda5e43ad..e34c009c3c0631f42baa5b6f2f61c705efba219d 100644 (file)
@@ -34,18 +34,14 @@ namespace WebCore {
 namespace Layout {
 
 class Box;
-class Container;
 class FloatingState;
-class LayoutState;
 class StyleDiff;
 
 class FormattingState {
     WTF_MAKE_ISO_ALLOCATED(FormattingState);
 public:
-    FormattingState(Container& formattingRoot, LayoutState&);
+    FormattingState();
 
-    Container& formattingRoot() const;
-    LayoutState& layoutState() const;
     FloatingState& floatingState();
 
     void markNeedsLayout(const Box&, StyleDiff);
index 386b85c9511446e75218f191f37a6d251dcfb56d..938dd2b085dce73fefb960dd2d911f2e52a35791 100644 (file)
 
 #include "config.h"
 #include "LayoutContext.h"
+
+#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
+
+#include "BlockFormattingContext.h"
+#include "BlockFormattingState.h"
+#include "InlineFormattingContext.h"
+#include "InlineFormattingState.h"
+#include "LayoutBox.h"
+#include <wtf/IsoMallocInlines.h>
+
+namespace WebCore {
+namespace Layout {
+
+WTF_MAKE_ISO_ALLOCATED_IMPL(LayoutContext);
+
+LayoutContext::LayoutContext(Box& root)
+    : m_root(makeWeakPtr(root))
+{
+}
+
+void LayoutContext::updateLayout()
+{
+    auto context = formattingContext(*m_root);
+    auto state = formattingState(*context);
+    context->layout(state);
+}
+
+FormattingState& LayoutContext::formattingState(const FormattingContext& context)
+{
+    return *m_formattingStates.ensure(&context.root(), [&context] {
+        return context.formattingState();
+    }).iterator->value;
+}
+
+std::unique_ptr<FormattingContext> LayoutContext::formattingContext(Box& formattingContextRoot)
+{
+    if (formattingContextRoot.establishesBlockFormattingContext())
+        return std::make_unique<BlockFormattingContext>(formattingContextRoot);
+
+    if (formattingContextRoot.establishesInlineFormattingContext())
+        return std::make_unique<InlineFormattingContext>(formattingContextRoot);
+
+    ASSERT_NOT_REACHED();
+    return nullptr;
+}
+
+}
+}
+
+#endif
index 15c84158c5e735922a57d2af1edc9dbf30d1dd93..15007d60a621aa64a0aa9ab4b3d3885f6945a5de 100644 (file)
@@ -27,6 +27,7 @@
 
 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)
 
+#include "LayoutBox.h"
 #include <wtf/IsoMalloc.h>
 
 namespace WebCore {
@@ -37,8 +38,6 @@ class Box;
 
 namespace Layout {
 
-class Box;
-class Container;
 class FormattingContext;
 class FormattingState;
 class StyleDiff;
@@ -51,20 +50,22 @@ class StyleDiff;
 class LayoutContext {
     WTF_MAKE_ISO_ALLOCATED(LayoutContext);
 public:
-    LayoutContext(const Container& rootContainer);
-
-    void layout();
+    LayoutContext(Box& root);
 
-    Container& rootContainer() const;
-    FormattingContext& formattingContext(const Container& formattingRoot) const;
-    FormattingState& establishedFormattingState(const Container& formattingRoot);
-    FormattingState& formattingState(const Box&);
+    void updateLayout();
 
     void addDisplayBox(const Box&, Display::Box&);
     Display::Box* displayBox(const Box&) const;
 
     void markNeedsLayout(const Box&, StyleDiff);
     bool needsLayout(const Box&) const;
+
+private:
+    FormattingState& formattingState(const FormattingContext&);
+    std::unique_ptr<FormattingContext> formattingContext(Box& formattingContextRoot);
+
+    WeakPtr<Box> m_root;
+    HashMap<const Box*, std::unique_ptr<FormattingState>> m_formattingStates;
 };
 
 }
index 397a97d5e93058bdb2b3e848b62a7e03a93c8a9d..d37e1814bbede6d7737dbd0115fccd75f61d1ced 100644 (file)
 
 #include "config.h"
 #include "BlockFormattingContext.h"
+
+#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
+
+#include "BlockFormattingState.h"
+#include <wtf/IsoMallocInlines.h>
+
+namespace WebCore {
+namespace Layout {
+
+WTF_MAKE_ISO_ALLOCATED_IMPL(BlockFormattingContext);
+
+BlockFormattingContext::BlockFormattingContext(Box& formattingContextRoot)
+    : FormattingContext(formattingContextRoot)
+{
+}
+
+void BlockFormattingContext::layout(FormattingState&)
+{
+}
+
+std::unique_ptr<FormattingState> BlockFormattingContext::formattingState() const
+{
+    return std::make_unique<BlockFormattingState>();
+}
+
+void BlockFormattingContext::computeStaticPosition(const Box&) const
+{
+}
+
+void BlockFormattingContext::computeWidth(const Box&) const
+{
+}
+
+void BlockFormattingContext::computeHeight(const Box&) const
+{
+}
+
+LayoutUnit BlockFormattingContext::marginTop(const Box&) const
+{
+    return 0;
+}
+
+LayoutUnit BlockFormattingContext::marginBottom(const Box&) const
+{
+    return 0;
+}
+
+}
+}
+
+#endif
index 969b85a77eb9810c2a480380d3a2e9d9fedd98a9..f12e7e762d53341ea26ccde7a1d81be9c9fdbbfa 100644 (file)
@@ -43,18 +43,19 @@ class Box;
 class BlockFormattingContext : public FormattingContext {
     WTF_MAKE_ISO_ALLOCATED(BlockFormattingContext);
 public:
-    BlockFormattingContext(BlockFormattingState&);
+    BlockFormattingContext(Box& formattingContextRoot);
 
-    void layout() override;
+    void layout(FormattingState&) override;
+    std::unique_ptr<FormattingState> formattingState() const override;
 
 protected:
-    void computeStaticPosition(const Box&) override;
+    void computeStaticPosition(const Box&) const override;
 
-    void computeWidth(const Box&) override;
-    void computeHeight(const Box&) override;
+    void computeWidth(const Box&) const override;
+    void computeHeight(const Box&) const override;
 
-    LayoutUnit marginTop(const Box&) override;
-    LayoutUnit marginBottom(const Box&) override;
+    LayoutUnit marginTop(const Box&) const override;
+    LayoutUnit marginBottom(const Box&) const override;
 };
 
 }
index f781853a3a921da96a2ac8e7ec589837ec34d4a2..244d8254acef7f1c3291de976204af82de57fe2c 100644 (file)
 
 #include "config.h"
 #include "BlockFormattingState.h"
+
+#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
+
+#include <wtf/IsoMallocInlines.h>
+
+namespace WebCore {
+namespace Layout {
+
+WTF_MAKE_ISO_ALLOCATED_IMPL(BlockFormattingState);
+
+BlockFormattingState::BlockFormattingState()
+    : FormattingState()
+{
+}
+
+}
+}
+#endif
index 2b37ba2098753002e6d156005a56c9bea999e5d1..5485bda2f68ddeacc14e28bd5c95f1bc74c5633f 100644 (file)
@@ -34,14 +34,11 @@ namespace WebCore {
 
 namespace Layout {
 
-class Container;
-class LayoutState;
-
 // BlockFormattingState holds the state for a particular block formatting context tree.
 class BlockFormattingState : public FormattingState {
     WTF_MAKE_ISO_ALLOCATED(BlockFormattingState);
 public:
-    BlockFormattingState(Layout::Container& formattingRoot, LayoutState&);
+    BlockFormattingState();
 };
 
 }
index 05f1d82d59f75f15957451183f1b63810754ad47..7d1b76403d9cb43977f35d917bc718d244bb5af6 100644 (file)
 
 #include "config.h"
 #include "InlineFormattingContext.h"
+
+#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
+
+#include "InlineFormattingState.h"
+#include <wtf/IsoMallocInlines.h>
+
+namespace WebCore {
+namespace Layout {
+
+WTF_MAKE_ISO_ALLOCATED_IMPL(InlineFormattingContext);
+
+InlineFormattingContext::InlineFormattingContext(Box& formattingContextRoot)
+    : FormattingContext(formattingContextRoot)
+{
+}
+
+void InlineFormattingContext::layout(FormattingState&)
+{
+}
+
+std::unique_ptr<FormattingState> InlineFormattingContext::formattingState() const
+{
+    return std::make_unique<InlineFormattingState>();
+}
+
+}
+}
+
+#endif
index 1bbe266cbc2a3965473f7ce5c2ed6534f39a9db0..6026060e9ec4e787f230501649a2dbe898d27125 100644 (file)
@@ -41,9 +41,10 @@ class InlineFormattingState;
 class InlineFormattingContext : public FormattingContext {
     WTF_MAKE_ISO_ALLOCATED(InlineFormattingContext);
 public:
-    InlineFormattingContext(InlineFormattingState&);
+    InlineFormattingContext(Box& formattingContextRoot);
 
-    void layout() override;
+    void layout(FormattingState&) override;
+    std::unique_ptr<FormattingState> formattingState() const override;
 };
 
 }
index 8d73ec5af331306d8aa8f611dc5c4be45e99d201..930a88504192b2f75ac52fd6ec1a8c8a26065640 100644 (file)
 
 #include "config.h"
 #include "InlineFormattingState.h"
+
+#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
+
+#include <wtf/IsoMallocInlines.h>
+
+namespace WebCore {
+namespace Layout {
+
+WTF_MAKE_ISO_ALLOCATED_IMPL(InlineFormattingState);
+
+InlineFormattingState::InlineFormattingState()
+    : FormattingState()
+{
+}
+
+}
+}
+#endif
index f0ef9e1c56cd5d198e04b9a3a80d3a2820fbb106..ed9bcdadc7844f17e0e7ea861734d05b31ee55bc 100644 (file)
@@ -34,14 +34,11 @@ namespace WebCore {
 
 namespace Layout {
 
-class Container;
-class LayoutState;
-
 // InlineFormattingState holds the state for a particular inline formatting context tree.
 class InlineFormattingState : public FormattingState {
     WTF_MAKE_ISO_ALLOCATED(InlineFormattingState);
 public:
-    InlineFormattingState(Layout::Container& formattingRoot, LayoutState&);
+    InlineFormattingState();
 };
 
 }