[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 c4f2b67..7a6d28b 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 51a92b4..9855bad 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 87f39d7..e86cff9 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 be0f314..8fa0d43 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 7821e7b..e34c009 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 386b85c..938dd2b 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 15c8415..15007d6 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 397a97d..d37e181 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 969b85a..f12e7e7 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 f781853..244d825 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 2b37ba2..5485bda 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 05f1d82..7d1b764 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 1bbe266..6026060 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 8d73ec5..930a885 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 f0ef9e1..ed9bcda 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();
 };
 
 }