Title: [248290] trunk/Source/WebCore
Revision
248290
Author
za...@apple.com
Date
2019-08-05 22:20:09 -0700 (Mon, 05 Aug 2019)

Log Message

[LFC] Remove out-of-flow descendants from Container
https://bugs.webkit.org/show_bug.cgi?id=200430
<rdar://problem/53923980>

Reviewed by Antti Koivisto.

The out-of-flow descendant list is the last "formatting context type" bit in the layout tree.
Let's cached them in the FormattingStates instead for now.

* layout/FormattingContext.cpp:
(WebCore::Layout::FormattingContext::layoutOutOfFlowDescendants const):
* layout/FormattingContext.h:
* layout/FormattingState.h:
(WebCore::Layout::FormattingState::addOutOfFlowBox):
(WebCore::Layout::FormattingState::outOfFlowBoxes const):
* layout/LayoutState.cpp:
(WebCore::Layout::LayoutState::layoutFormattingContextSubtree):
(WebCore::Layout::LayoutState::createFormattingStateForFormattingRootIfNeeded):
(WebCore::Layout::LayoutState::run):
* layout/LayoutState.h:
* layout/blockformatting/BlockFormattingContext.cpp:
(WebCore::Layout::BlockFormattingContext::layoutFormattingContextRoot const):
* layout/inlineformatting/InlineFormattingContext.cpp:
(WebCore::Layout::InlineFormattingContext::layoutFormattingContextRoot const):
* layout/layouttree/LayoutBox.h:
* layout/layouttree/LayoutContainer.cpp:
(WebCore::Layout::Container::addOutOfFlowDescendant): Deleted.
* layout/layouttree/LayoutContainer.h:
* layout/layouttree/LayoutTreeBuilder.cpp:
(WebCore::Layout::TreeBuilder::createLayoutTree):
* page/FrameViewLayoutContext.cpp:
(WebCore::layoutUsingFormattingContext):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (248289 => 248290)


--- trunk/Source/WebCore/ChangeLog	2019-08-06 05:04:15 UTC (rev 248289)
+++ trunk/Source/WebCore/ChangeLog	2019-08-06 05:20:09 UTC (rev 248290)
@@ -1,3 +1,38 @@
+2019-08-05  Zalan Bujtas  <za...@apple.com>
+
+        [LFC] Remove out-of-flow descendants from Container
+        https://bugs.webkit.org/show_bug.cgi?id=200430
+        <rdar://problem/53923980>
+
+        Reviewed by Antti Koivisto.
+
+        The out-of-flow descendant list is the last "formatting context type" bit in the layout tree.
+        Let's cached them in the FormattingStates instead for now. 
+
+        * layout/FormattingContext.cpp:
+        (WebCore::Layout::FormattingContext::layoutOutOfFlowDescendants const):
+        * layout/FormattingContext.h:
+        * layout/FormattingState.h:
+        (WebCore::Layout::FormattingState::addOutOfFlowBox):
+        (WebCore::Layout::FormattingState::outOfFlowBoxes const):
+        * layout/LayoutState.cpp:
+        (WebCore::Layout::LayoutState::layoutFormattingContextSubtree):
+        (WebCore::Layout::LayoutState::createFormattingStateForFormattingRootIfNeeded):
+        (WebCore::Layout::LayoutState::run):
+        * layout/LayoutState.h:
+        * layout/blockformatting/BlockFormattingContext.cpp:
+        (WebCore::Layout::BlockFormattingContext::layoutFormattingContextRoot const):
+        * layout/inlineformatting/InlineFormattingContext.cpp:
+        (WebCore::Layout::InlineFormattingContext::layoutFormattingContextRoot const):
+        * layout/layouttree/LayoutBox.h:
+        * layout/layouttree/LayoutContainer.cpp:
+        (WebCore::Layout::Container::addOutOfFlowDescendant): Deleted.
+        * layout/layouttree/LayoutContainer.h:
+        * layout/layouttree/LayoutTreeBuilder.cpp:
+        (WebCore::Layout::TreeBuilder::createLayoutTree):
+        * page/FrameViewLayoutContext.cpp:
+        (WebCore::layoutUsingFormattingContext):
+
 2019-08-05  Devin Rousso  <drou...@apple.com>
 
         Web Inspector: Styles: show @supports CSS groupings

Modified: trunk/Source/WebCore/layout/FormattingContext.cpp (248289 => 248290)


--- trunk/Source/WebCore/layout/FormattingContext.cpp	2019-08-06 05:04:15 UTC (rev 248289)
+++ trunk/Source/WebCore/layout/FormattingContext.cpp	2019-08-06 05:20:09 UTC (rev 248290)
@@ -133,32 +133,23 @@
     displayBox.setPadding(Geometry::computedPadding(layoutBox, *usedValues));
 }
 
-void FormattingContext::layoutOutOfFlowDescendants(const Box& layoutBox) const
+void FormattingContext::layoutOutOfFlowDescendants() const
 {
-    if (!is<Container>(layoutBox))
-        return;
+    LOG_WITH_STREAM(FormattingContextLayout, stream << "Start: layout out-of-flow descendants -> context: " << &layoutState() << " root: " << &root());
 
-    auto& container = downcast<Container>(layoutBox);
-    if (!container.hasChild())
-        return;
+    for (auto& outOfFlowBox : formattingState().outOfFlowBoxes()) {
+        ASSERT(outOfFlowBox->establishesFormattingContext());
 
-    auto& layoutState = this->layoutState();
-    LOG_WITH_STREAM(FormattingContextLayout, stream << "Start: layout out-of-flow descendants -> context: " << &layoutState << " root: " << &root());
+        computeBorderAndPadding(*outOfFlowBox);
+        computeOutOfFlowHorizontalGeometry(*outOfFlowBox);
 
-    for (auto& outOfFlowBox : container.outOfFlowDescendants()) {
-        auto& layoutBox = *outOfFlowBox;
+        auto formattingContext = layoutState().createFormattingContext(*outOfFlowBox);
+        formattingContext->layout();
 
-        ASSERT(layoutBox.establishesFormattingContext());
-
-        computeBorderAndPadding(layoutBox);
-        computeOutOfFlowHorizontalGeometry(layoutBox);
-
-        layoutState.createFormattingContext(layoutBox)->layout();
-
-        computeOutOfFlowVerticalGeometry(layoutBox);
-        layoutOutOfFlowDescendants(layoutBox);
+        computeOutOfFlowVerticalGeometry(*outOfFlowBox);
+        formattingContext->layoutOutOfFlowDescendants();
     }
-    LOG_WITH_STREAM(FormattingContextLayout, stream << "End: layout out-of-flow descendants -> context: " << &layoutState << " root: " << &root());
+    LOG_WITH_STREAM(FormattingContextLayout, stream << "End: layout out-of-flow descendants -> context: " << &layoutState() << " root: " << &root());
 }
 
 static LayoutUnit mapHorizontalPositionToAncestor(const LayoutState& layoutState, LayoutUnit horizontalPosition, const Container& containingBlock, const Container& ancestor)

Modified: trunk/Source/WebCore/layout/FormattingContext.h (248289 => 248290)


--- trunk/Source/WebCore/layout/FormattingContext.h	2019-08-06 05:04:15 UTC (rev 248289)
+++ trunk/Source/WebCore/layout/FormattingContext.h	2019-08-06 05:20:09 UTC (rev 248290)
@@ -50,7 +50,7 @@
     virtual ~FormattingContext();
 
     virtual void layout() const = 0;
-    void layoutOutOfFlowDescendants(const Box&) const;
+    void layoutOutOfFlowDescendants() const;
 
     struct IntrinsicWidthConstraints {
         void expand(LayoutUnit horizontalValue);

Modified: trunk/Source/WebCore/layout/FormattingState.h (248289 => 248290)


--- trunk/Source/WebCore/layout/FormattingState.h	2019-08-06 05:04:15 UTC (rev 248289)
+++ trunk/Source/WebCore/layout/FormattingState.h	2019-08-06 05:20:09 UTC (rev 248290)
@@ -33,6 +33,7 @@
 #include "LayoutState.h"
 #include "LayoutUnit.h"
 #include <wtf/IsoMalloc.h>
+#include <wtf/WeakPtr.h>
 
 namespace WebCore {
 
@@ -64,6 +65,12 @@
 
     LayoutState& layoutState() const { return m_layoutState; }
 
+    // Since we layout the out-of-flow boxes at the end of the formatting context layout, it's okay to store them in the formatting state -as opposed to the containing block level.
+    using OutOfFlowBoxList = Vector<WeakPtr<const Box>>;
+    void addOutOfFlowBox(const Box& outOfFlowBox) { m_outOfFlowBoxes.append(makeWeakPtr(outOfFlowBox)); }
+    void removeOutOfFlowBox(const Box&);
+    const OutOfFlowBoxList& outOfFlowBoxes() const { return m_outOfFlowBoxes; }
+
 protected:
     enum class Type { Block, Inline, Table };
     FormattingState(Ref<FloatingState>&&, Type, LayoutState&);
@@ -73,6 +80,8 @@
     Ref<FloatingState> m_floatingState;
     HashMap<const Box*, FormattingContext::IntrinsicWidthConstraints> m_intrinsicWidthConstraintsForBoxes;
     Optional<FormattingContext::IntrinsicWidthConstraints> m_intrinsicWidthConstraints;
+    // FIXME: This needs WeakListHashSet
+    OutOfFlowBoxList m_outOfFlowBoxes;
     Type m_type;
 };
 

Modified: trunk/Source/WebCore/layout/LayoutState.cpp (248289 => 248290)


--- trunk/Source/WebCore/layout/LayoutState.cpp	2019-08-06 05:04:15 UTC (rev 248289)
+++ trunk/Source/WebCore/layout/LayoutState.cpp	2019-08-06 05:20:09 UTC (rev 248290)
@@ -38,6 +38,8 @@
 #include "Invalidation.h"
 #include "LayoutBox.h"
 #include "LayoutContainer.h"
+#include "LayoutTreeBuilder.h"
+#include "RenderView.h"
 #include "TableFormattingContext.h"
 #include "TableFormattingState.h"
 #include <wtf/IsoMallocInlines.h>
@@ -80,7 +82,7 @@
     RELEASE_ASSERT(layoutRoot.establishesFormattingContext());
     auto formattingContext = createFormattingContext(layoutRoot);
     formattingContext->layout();
-    formattingContext->layoutOutOfFlowDescendants(layoutRoot);
+    formattingContext->layoutOutOfFlowDescendants();
 }
 
 Display::Box& LayoutState::displayBoxForLayoutBox(const Box& layoutBox) const
@@ -137,7 +139,9 @@
 
             // 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 and use its floating state.
-            return std::make_unique<InlineFormattingState>(formattingStateForBox(formattingRoot).floatingState(), *this);
+            auto& parentFormattingState = createFormattingStateForFormattingRootIfNeeded(formattingRoot.formattingContextRoot()); 
+            auto& parentFloatingState = parentFormattingState.floatingState();
+            return std::make_unique<InlineFormattingState>(parentFloatingState, *this);
         }).iterator->value;
     }
 
@@ -182,7 +186,32 @@
     CRASH();
 }
 
+void LayoutState::run(const RenderView& renderView)
+{
+    auto initialContainingBlock = TreeBuilder::createLayoutTree(renderView);
+    auto layoutState = LayoutState(*initialContainingBlock);
+    // Not efficient, but this is temporary anyway.
+    // Collect the out-of-flow descendants at the formatting root level (as opposed to at the containing block level, though they might be the same).
+    for (auto& descendant : descendantsOfType<Box>(*initialContainingBlock)) {
+        if (!descendant.isOutOfFlowPositioned())
+            continue;
+        auto& formattingState = layoutState.createFormattingStateForFormattingRootIfNeeded(descendant.formattingContextRoot());
+        formattingState.addOutOfFlowBox(descendant);
+    }
+    auto quirksMode = [&] {
+        auto& document = renderView.document();
+        if (document.inLimitedQuirksMode())
+            return QuirksMode::Limited;
+        if (document.inQuirksMode())
+            return QuirksMode::Yes;
+        return QuirksMode::No;
+    };
+    layoutState.setQuirksMode(quirksMode());
+    layoutState.updateLayout();
+    layoutState.verifyAndOutputMismatchingLayoutTree(renderView);
 }
+
 }
+}
 
 #endif

Modified: trunk/Source/WebCore/layout/LayoutState.h (248289 => 248290)


--- trunk/Source/WebCore/layout/LayoutState.h	2019-08-06 05:04:15 UTC (rev 248289)
+++ trunk/Source/WebCore/layout/LayoutState.h	2019-08-06 05:20:09 UTC (rev 248290)
@@ -27,6 +27,7 @@
 
 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)
 
+#include "LayoutContainer.h"
 #include <wtf/HashMap.h>
 #include <wtf/HashSet.h>
 #include <wtf/IsoMalloc.h>
@@ -47,7 +48,6 @@
 
 enum class StyleDiff;
 class Box;
-class Container;
 class FormattingContext;
 class FormattingState;
 
@@ -62,6 +62,9 @@
 public:
     LayoutState(const Container& initialContainingBlock);
 
+    // FIXME: This is a temporary entry point for LFC layout.
+    static void run(const RenderView&);
+
     void updateLayout();
     void styleChanged(const Box&, StyleDiff);
     enum class QuirksMode { No, Limited, Yes };

Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp (248289 => 248290)


--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp	2019-08-06 05:04:15 UTC (rev 248289)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp	2019-08-06 05:20:09 UTC (rev 248290)
@@ -172,6 +172,8 @@
     // Come back and finalize the root's geometry.
     LOG_WITH_STREAM(FormattingContextLayout, stream << "[Compute] -> [Height][Margin] -> for layoutBox(" << &layoutBox << ")");
     computeHeightAndMargin(layoutBox);
+    // Now that we computed the root's height, we can go back and layout the out-of-flow descedants (if any).
+    formattingContext->layoutOutOfFlowDescendants();
 
     // Float related final positioning.
     if (layoutBox.isFloatingPositioned()) {
@@ -179,9 +181,6 @@
         floatingContext.floatingState().append(layoutBox);
     } else if (layoutBox.establishesBlockFormattingContext())
         computePositionToAvoidFloats(floatingContext, layoutBox);
-
-    // Now that we computed the root's height, we can go back and layout the out-of-flow descedants (if any).
-    formattingContext->layoutOutOfFlowDescendants(layoutBox);
 }
 
 void BlockFormattingContext::placeInFlowPositionedChildren(const Box& layoutBox) const

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp (248289 => 248290)


--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp	2019-08-06 05:04:15 UTC (rev 248289)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp	2019-08-06 05:20:09 UTC (rev 248290)
@@ -249,7 +249,7 @@
     // Come back and finalize the root's height and margin.
     computeHeightAndMargin(root);
     // Now that we computed the root's height, we can go back and layout the out-of-flow descedants (if any).
-    formattingContext->layoutOutOfFlowDescendants(root);
+    formattingContext->layoutOutOfFlowDescendants();
 }
 
 void InlineFormattingContext::computeWidthAndHeightForReplacedInlineBox(const Box& layoutBox, UsedHorizontalValues usedValues) const

Modified: trunk/Source/WebCore/layout/layouttree/LayoutBox.h (248289 => 248290)


--- trunk/Source/WebCore/layout/layouttree/LayoutBox.h	2019-08-06 05:04:15 UTC (rev 248289)
+++ trunk/Source/WebCore/layout/layouttree/LayoutBox.h	2019-08-06 05:20:09 UTC (rev 248290)
@@ -97,7 +97,7 @@
     bool isFloatingOrOutOfFlowPositioned() const { return isFloatingPositioned() || isOutOfFlowPositioned(); }
 
     const Container* containingBlock() const;
-    virtual const Container& formattingContextRoot() const;
+    const Container& formattingContextRoot() const;
     const Container& initialContainingBlock() const;
 
     bool isDescendantOf(const Container&) const;

Modified: trunk/Source/WebCore/layout/layouttree/LayoutContainer.cpp (248289 => 248290)


--- trunk/Source/WebCore/layout/layouttree/LayoutContainer.cpp	2019-08-06 05:04:15 UTC (rev 248289)
+++ trunk/Source/WebCore/layout/layouttree/LayoutContainer.cpp	2019-08-06 05:20:09 UTC (rev 248290)
@@ -91,14 +91,6 @@
     m_lastChild = &childBox;
 }
 
-void Container::addOutOfFlowDescendant(const Box& outOfFlowBox)
-{
-    // Since we layout the out-of-flow boxes at the end of the formatting context layout,
-    // it's okay to store them at the formatting context root level -as opposed to the containing block level.
-    ASSERT(establishesFormattingContext());
-    m_outOfFlowDescendants.append(makeWeakPtr(outOfFlowBox));
 }
-
 }
-}
 #endif

Modified: trunk/Source/WebCore/layout/layouttree/LayoutContainer.h (248289 => 248290)


--- trunk/Source/WebCore/layout/layouttree/LayoutContainer.h	2019-08-06 05:04:15 UTC (rev 248289)
+++ trunk/Source/WebCore/layout/layouttree/LayoutContainer.h	2019-08-06 05:20:09 UTC (rev 248290)
@@ -29,7 +29,6 @@
 
 #include "LayoutBox.h"
 #include <wtf/IsoMalloc.h>
-#include <wtf/WeakPtr.h>
 
 namespace WebCore {
 
@@ -53,16 +52,12 @@
     bool hasInFlowChild() const { return firstInFlowChild(); }
     bool hasInFlowOrFloatingChild() const { return firstInFlowOrFloatingChild(); }
 
-    const Vector<WeakPtr<const Box>>& outOfFlowDescendants() const { return m_outOfFlowDescendants; }
-
     void setFirstChild(Box&);
     void setLastChild(Box&);
-    void addOutOfFlowDescendant(const Box&);
 
 private:
     Box* m_firstChild { nullptr };
     Box* m_lastChild { nullptr };
-    Vector<WeakPtr<const Box>> m_outOfFlowDescendants;
 };
 
 }

Modified: trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp (248289 => 248290)


--- trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp	2019-08-06 05:04:15 UTC (rev 248289)
+++ trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp	2019-08-06 05:20:09 UTC (rev 248290)
@@ -75,15 +75,6 @@
 
     std::unique_ptr<Container> initialContainingBlock(new Container(WTF::nullopt, WTFMove(style)));
     TreeBuilder::createSubTree(renderView, *initialContainingBlock);
-
-    // Not efficient, but this is temporary anyway.
-    // Collect the out-of-flow descendants at the formatting root level (as opposed to at the containing block level, though they might be the same).
-    for (auto& descendant : descendantsOfType<Box>(*initialContainingBlock)) {
-        if (!descendant.isOutOfFlowPositioned())
-            continue;
-        const_cast<Container&>(descendant.formattingContextRoot()).addOutOfFlowDescendant(descendant);
-    }
-
     return initialContainingBlock;
 }
 

Modified: trunk/Source/WebCore/page/FrameViewLayoutContext.cpp (248289 => 248290)


--- trunk/Source/WebCore/page/FrameViewLayoutContext.cpp	2019-08-06 05:04:15 UTC (rev 248289)
+++ trunk/Source/WebCore/page/FrameViewLayoutContext.cpp	2019-08-06 05:20:09 UTC (rev 248290)
@@ -39,12 +39,8 @@
 #include "RuntimeEnabledFeatures.h"
 #include "ScriptDisallowedScope.h"
 #include "Settings.h"
-
 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)
-#include "FormattingState.h"
-#include "LayoutContainer.h"
 #include "LayoutState.h"
-#include "LayoutTreeBuilder.h"
 #endif
 
 #include <wtf/SetForScope.h>
@@ -58,16 +54,7 @@
 {
     if (!RuntimeEnabledFeatures::sharedFeatures().layoutFormattingContextEnabled())
         return;
-    auto initialContainingBlock = Layout::TreeBuilder::createLayoutTree(renderView);
-    auto layoutState = std::make_unique<Layout::LayoutState>(*initialContainingBlock);
-    auto quirksMode = Layout::LayoutState::QuirksMode::No;
-    if (renderView.document().inLimitedQuirksMode())
-        quirksMode = Layout::LayoutState::QuirksMode::Limited;
-    else if (renderView.document().inQuirksMode())
-        quirksMode = Layout::LayoutState::QuirksMode::Yes;
-    layoutState->setQuirksMode(quirksMode);
-    layoutState->updateLayout();
-    layoutState->verifyAndOutputMismatchingLayoutTree(renderView);
+    Layout::LayoutState::run(renderView);
 } 
 #endif
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to