[LFC] Add FormattingContext::layoutOutOfFlowDescendants implementation
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 8 May 2018 05:26:39 +0000 (05:26 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 8 May 2018 05:26:39 +0000 (05:26 +0000)
https://bugs.webkit.org/show_bug.cgi?id=185377

Reviewed by Antti Koivisto.

Also, remove FormattingContext's m_layoutContext member and pass it in to ::layout() instead.
In theory LayoutContext is needed only during ::layout() call.

* layout/FormattingContext.cpp:
(WebCore::Layout::FormattingContext::layoutOutOfFlowDescendants const):
* layout/FormattingContext.h:
(WebCore::Layout::FormattingContext::layoutContext const):
* layout/LayoutContext.cpp:
(WebCore::Layout::LayoutContext::updateLayout):
* layout/blockformatting/BlockFormattingContext.cpp:
(WebCore::Layout::BlockFormattingContext::layout const):
* layout/blockformatting/BlockFormattingContext.h:
* layout/inlineformatting/InlineFormattingContext.cpp:
(WebCore::Layout::InlineFormattingContext::layout const):
* layout/inlineformatting/InlineFormattingContext.h:

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

Source/WebCore/ChangeLog
Source/WebCore/layout/FormattingContext.cpp
Source/WebCore/layout/FormattingContext.h
Source/WebCore/layout/LayoutContext.cpp
Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp
Source/WebCore/layout/blockformatting/BlockFormattingContext.h
Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp
Source/WebCore/layout/inlineformatting/InlineFormattingContext.h

index fa619a3..9978f96 100644 (file)
@@ -1,3 +1,26 @@
+2018-05-07  Zalan Bujtas  <zalan@apple.com>
+
+        [LFC] Add FormattingContext::layoutOutOfFlowDescendants implementation
+        https://bugs.webkit.org/show_bug.cgi?id=185377
+
+        Reviewed by Antti Koivisto.
+
+        Also, remove FormattingContext's m_layoutContext member and pass it in to ::layout() instead.
+        In theory LayoutContext is needed only during ::layout() call. 
+
+        * layout/FormattingContext.cpp:
+        (WebCore::Layout::FormattingContext::layoutOutOfFlowDescendants const):
+        * layout/FormattingContext.h:
+        (WebCore::Layout::FormattingContext::layoutContext const):
+        * layout/LayoutContext.cpp:
+        (WebCore::Layout::LayoutContext::updateLayout):
+        * layout/blockformatting/BlockFormattingContext.cpp:
+        (WebCore::Layout::BlockFormattingContext::layout const):
+        * layout/blockformatting/BlockFormattingContext.h:
+        * layout/inlineformatting/InlineFormattingContext.cpp:
+        (WebCore::Layout::InlineFormattingContext::layout const):
+        * layout/inlineformatting/InlineFormattingContext.h:
+
 2018-05-07  Daniel Bates  <dabates@apple.com>
 
         Check X-Frame-Options and CSP frame-ancestors in network process
index 63f1b50..79f61ee 100644 (file)
@@ -29,6 +29,8 @@
 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)
 
 #include "LayoutBox.h"
+#include "LayoutContainer.h"
+#include "LayoutContext.h"
 #include <wtf/IsoMallocInlines.h>
 
 namespace WebCore {
@@ -36,9 +38,8 @@ namespace Layout {
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(FormattingContext);
 
-FormattingContext::FormattingContext(const Box& formattingContextRoot, LayoutContext& layoutContext)
+FormattingContext::FormattingContext(const Box& formattingContextRoot)
     : m_root(makeWeakPtr(const_cast<Box&>(formattingContextRoot)))
-    , m_layoutContext(layoutContext)
 {
 }
 
@@ -46,7 +47,7 @@ FormattingContext::~FormattingContext()
 {
 }
 
-void FormattingContext::computeStaticPosition(const Box&, Display::Box&) const
+void FormattingContext::computeStaticPosition(LayoutContext&, const Box&, Display::Box&) const
 {
 }
 
@@ -116,8 +117,23 @@ void FormattingContext::placeInFlowPositionedChildren(const Container&) const
 {
 }
 
-void FormattingContext::layoutOutOfFlowDescendants() const
+void FormattingContext::layoutOutOfFlowDescendants(LayoutContext& layoutContext) const
 {
+    if (!is<Container>(m_root.get()))
+        return;
+    for (auto& outOfFlowBox : downcast<Container>(*m_root).outOfFlowDescendants()) {
+        auto& layoutBox = *outOfFlowBox;
+        auto& displayBox = layoutContext.createDisplayBox(layoutBox);
+
+        computeOutOfFlowPosition(layoutBox, displayBox);
+        computeOutOfFlowWidth(layoutBox, displayBox);
+
+        ASSERT(layoutBox.establishesFormattingContext());
+        auto formattingContext = layoutContext.formattingContext(layoutBox);
+        formattingContext->layout(layoutContext, layoutContext.establishedFormattingState(layoutBox, *formattingContext));
+
+        computeOutOfFlowHeight(layoutBox, displayBox);
+    }
 }
 
 }
index 5379ebd..6f4dfe5 100644 (file)
@@ -48,12 +48,12 @@ class LayoutContext;
 class FormattingContext {
     WTF_MAKE_ISO_ALLOCATED(FormattingContext);
 public:
-    FormattingContext(const Box& formattingContextRoot, LayoutContext&);
+    FormattingContext(const Box& formattingContextRoot);
     virtual ~FormattingContext();
 
     virtual void layout(LayoutContext&, FormattingState&) const = 0;
     virtual std::unique_ptr<FormattingState> createFormattingState(Ref<FloatingState>&&) const = 0;
-    virtual Ref<FloatingState> createOrFindFloatingState() const = 0;
+    virtual Ref<FloatingState> createOrFindFloatingState(LayoutContext&) const = 0;
 
 protected:
     struct LayoutPair {
@@ -63,9 +63,8 @@ protected:
     using LayoutQueue = Vector<std::unique_ptr<LayoutPair>>;
 
     const Box& root() const { return *m_root; }
-    const LayoutContext& layoutContext() const { return m_layoutContext; }
 
-    virtual void computeStaticPosition(const Box&, Display::Box&) const;
+    virtual void computeStaticPosition(LayoutContext&, const Box&, Display::Box&) const;
     virtual void computeInFlowPositionedPosition(const Box&, Display::Box&) const;
     virtual void computeOutOfFlowPosition(const Box&, Display::Box&) const;
 
@@ -86,11 +85,10 @@ protected:
     virtual LayoutUnit marginRight(const Box&) const;
 
     void placeInFlowPositionedChildren(const Container&) const;
-    void layoutOutOfFlowDescendants() const;
+    void layoutOutOfFlowDescendants(LayoutContext&s) const;
 
 private:
     WeakPtr<Box> m_root;
-    LayoutContext& m_layoutContext;
 };
 
 }
index 6089494..658f8cb 100644 (file)
@@ -98,17 +98,17 @@ FormattingState& LayoutContext::formattingStateForBox(const Box& layoutBox) cons
 FormattingState& LayoutContext::establishedFormattingState(const Box& formattingContextRoot, const FormattingContext& context)
 {
     return *m_formattingStates.ensure(&formattingContextRoot, [this, &context] {
-        return context.createFormattingState(context.createOrFindFloatingState());
+        return context.createFormattingState(context.createOrFindFloatingState(*this));
     }).iterator->value;
 }
 
 std::unique_ptr<FormattingContext> LayoutContext::formattingContext(const Box& formattingContextRoot)
 {
     if (formattingContextRoot.establishesBlockFormattingContext())
-        return std::make_unique<BlockFormattingContext>(formattingContextRoot, *this);
+        return std::make_unique<BlockFormattingContext>(formattingContextRoot);
 
     if (formattingContextRoot.establishesInlineFormattingContext())
-        return std::make_unique<InlineFormattingContext>(formattingContextRoot, *this);
+        return std::make_unique<InlineFormattingContext>(formattingContextRoot);
 
     ASSERT_NOT_REACHED();
     return nullptr;
index 464c0b0..d93360d 100644 (file)
@@ -42,8 +42,8 @@ namespace Layout {
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(BlockFormattingContext);
 
-BlockFormattingContext::BlockFormattingContext(const Box& formattingContextRoot, LayoutContext& layoutContext)
-    : FormattingContext(formattingContextRoot, layoutContext)
+BlockFormattingContext::BlockFormattingContext(const Box& formattingContextRoot)
+    : FormattingContext(formattingContextRoot)
 {
 }
 
@@ -74,7 +74,7 @@ void BlockFormattingContext::layout(LayoutContext& layoutContext, FormattingStat
             auto& displayBox = layoutPair.displayBox;
             
             computeWidth(layoutBox, displayBox);
-            computeStaticPosition(layoutBox, layoutPair.displayBox);
+            computeStaticPosition(layoutContext, layoutBox, layoutPair.displayBox);
             if (layoutBox.establishesFormattingContext()) {
                 auto formattingContext = layoutContext.formattingContext(layoutBox);
                 formattingContext->layout(layoutContext, layoutContext.establishedFormattingState(layoutBox, *formattingContext));
@@ -110,7 +110,7 @@ void BlockFormattingContext::layout(LayoutContext& layoutContext, FormattingStat
     // Place the inflow positioned children.
     placeInFlowPositionedChildren(formattingRoot);
     // And take care of out-of-flow boxes as the final step.
-    layoutOutOfFlowDescendants();
+    layoutOutOfFlowDescendants(layoutContext);
 }
 
 std::unique_ptr<FormattingState> BlockFormattingContext::createFormattingState(Ref<FloatingState>&& floatingState) const
@@ -118,25 +118,25 @@ std::unique_ptr<FormattingState> BlockFormattingContext::createFormattingState(R
     return std::make_unique<BlockFormattingState>(WTFMove(floatingState));
 }
 
-Ref<FloatingState> BlockFormattingContext::createOrFindFloatingState() const
+Ref<FloatingState> BlockFormattingContext::createOrFindFloatingState(LayoutContext&) const
 {
     // Block formatting context always establishes a new floating state.
     return FloatingState::create();
 }
 
-void BlockFormattingContext::computeStaticPosition(const Box& layoutBox, Display::Box& displayBox) const
+void BlockFormattingContext::computeStaticPosition(LayoutContext& layoutContext, const Box& layoutBox, Display::Box& displayBox) const
 {
     // 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.
     // The vertical distance between two sibling boxes is determined by the 'margin' properties.
     // Vertical margins between adjacent block-level boxes in a block formatting context collapse.
     // In a block formatting context, each box's left outer edge touches the left edge of the containing block (for right-to-left formatting, right edges touch).
-    auto containingBlockContentBox = layoutContext().displayBoxForLayoutBox(*layoutBox.containingBlock())->contentBox();
+    auto containingBlockContentBox = layoutContext.displayBoxForLayoutBox(*layoutBox.containingBlock())->contentBox();
     // Start from the top of the container's content box.
     auto top = containingBlockContentBox.y();
     auto left = containingBlockContentBox.x();
     if (auto* previousInFlowSibling = layoutBox.previousInFlowSibling())
-        top = layoutContext().displayBoxForLayoutBox(*previousInFlowSibling)->bottom() + marginBottom(*previousInFlowSibling);
+        top = layoutContext.displayBoxForLayoutBox(*previousInFlowSibling)->bottom() + marginBottom(*previousInFlowSibling);
     LayoutPoint topLeft = { top, left };
     topLeft.moveBy({ marginLeft(layoutBox), marginTop(layoutBox) });
     displayBox.setTopLeft(topLeft);
index 03cff35..691c469 100644 (file)
@@ -43,14 +43,14 @@ class Box;
 class BlockFormattingContext : public FormattingContext {
     WTF_MAKE_ISO_ALLOCATED(BlockFormattingContext);
 public:
-    BlockFormattingContext(const Box& formattingContextRoot, LayoutContext&);
+    BlockFormattingContext(const Box& formattingContextRoot);
 
     void layout(LayoutContext&, FormattingState&) const override;
     std::unique_ptr<FormattingState> createFormattingState(Ref<FloatingState>&&) const override;
-    Ref<FloatingState> createOrFindFloatingState() const override;
+    Ref<FloatingState> createOrFindFloatingState(LayoutContext&) const override;
 
 protected:
-    void computeStaticPosition(const Box&, Display::Box&) const override;
+    void computeStaticPosition(LayoutContext&, const Box&, Display::Box&) const override;
     void computeInFlowWidth(const Box&, Display::Box&) const override;
     void computeInFlowHeight(const Box&, Display::Box&) const override;
 
index f934f68..49c73e8 100644 (file)
@@ -39,8 +39,8 @@ namespace Layout {
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(InlineFormattingContext);
 
-InlineFormattingContext::InlineFormattingContext(const Box& formattingContextRoot, LayoutContext& layoutContext)
-    : FormattingContext(formattingContextRoot, layoutContext)
+InlineFormattingContext::InlineFormattingContext(const Box& formattingContextRoot)
+    : FormattingContext(formattingContextRoot)
 {
 }
 
@@ -53,7 +53,7 @@ std::unique_ptr<FormattingState> InlineFormattingContext::createFormattingState(
     return std::make_unique<InlineFormattingState>(WTFMove(floatingState));
 }
 
-Ref<FloatingState> InlineFormattingContext::createOrFindFloatingState() const
+Ref<FloatingState> InlineFormattingContext::createOrFindFloatingState(LayoutContext& layoutContext) const
 {
     // If the block container box that initiates this inline formatting context also establishes a block context, the floats outside of the formatting root
     // should not interfere with the content inside.
@@ -62,7 +62,7 @@ Ref<FloatingState> InlineFormattingContext::createOrFindFloatingState() const
         return FloatingState::create();
     // Otherwise, the formatting context inherits the floats from the parent formatting context.
     // Find the formatting state in which this formatting root lives, not the one it creates (this) and use its floating state.
-    auto& formattingState = layoutContext().formattingStateForBox(root());
+    auto& formattingState = layoutContext.formattingStateForBox(root());
     return formattingState.floatingState();
 }
 
index 9760b8d..3b1f258 100644 (file)
@@ -41,11 +41,11 @@ class InlineFormattingState;
 class InlineFormattingContext : public FormattingContext {
     WTF_MAKE_ISO_ALLOCATED(InlineFormattingContext);
 public:
-    InlineFormattingContext(const Box& formattingContextRoot, LayoutContext&);
+    InlineFormattingContext(const Box& formattingContextRoot);
 
     void layout(LayoutContext&, FormattingState&) const override;
     std::unique_ptr<FormattingState> createFormattingState(Ref<FloatingState>&&) const override;
-    Ref<FloatingState> createOrFindFloatingState() const override;
+    Ref<FloatingState> createOrFindFloatingState(LayoutContext&) const override;
 
 private:
     void computeInFlowWidth(const Box&, Display::Box&) const override;