Title: [239900] trunk/Source/WebCore
Revision
239900
Author
[email protected]
Date
2019-01-12 08:56:55 -0800 (Sat, 12 Jan 2019)

Log Message

[LFC] Move formatting context creation from FormattingState to LayoutState
https://bugs.webkit.org/show_bug.cgi?id=193381

Reviewed by Antti Koivisto.

layoutState().createFormattingStateForFormattingRootIfNeeded(root).createFormattingContext(root) is not only mouthful
but also feels unintuitive. Use layoutState().createFormattingContext(root) instead.

* layout/FormattingContext.cpp:
(WebCore::Layout::FormattingContext::FormattingContext):
(WebCore::Layout::FormattingContext::~FormattingContext):
(WebCore::Layout::FormattingContext::layoutOutOfFlowDescendants const):
* layout/FormattingContextGeometry.cpp:
(WebCore::Layout::FormattingContext::Geometry::shrinkToFitWidth):
* layout/FormattingState.h:
* layout/LayoutState.cpp:
(WebCore::Layout::LayoutState::layoutFormattingContextSubtree):
(WebCore::Layout::LayoutState::createFormattingContext):
* layout/LayoutState.h:
(WebCore::Layout::LayoutState::deregisterFormattingContext):
(WebCore::Layout::LayoutState::registerFormattingContext):
* layout/blockformatting/BlockFormattingContext.cpp:
(WebCore::Layout::BlockFormattingContext::layoutFormattingContextRoot const):
(WebCore::Layout::BlockFormattingContext::instrinsicWidthConstraints const):
* layout/blockformatting/BlockFormattingState.cpp:
(WebCore::Layout::BlockFormattingState::createFormattingContext): Deleted.
* layout/blockformatting/BlockFormattingState.h:
* layout/inlineformatting/InlineFormattingContext.cpp:
(WebCore::Layout::InlineFormattingContext::layoutFormattingContextRoot const):
* layout/inlineformatting/InlineFormattingState.cpp:
(WebCore::Layout::InlineFormattingState::createFormattingContext): Deleted.
* layout/inlineformatting/InlineFormattingState.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (239899 => 239900)


--- trunk/Source/WebCore/ChangeLog	2019-01-12 15:30:55 UTC (rev 239899)
+++ trunk/Source/WebCore/ChangeLog	2019-01-12 16:56:55 UTC (rev 239900)
@@ -1,5 +1,40 @@
 2019-01-12  Zalan Bujtas  <[email protected]>
 
+        [LFC] Move formatting context creation from FormattingState to LayoutState
+        https://bugs.webkit.org/show_bug.cgi?id=193381
+
+        Reviewed by Antti Koivisto.
+
+        layoutState().createFormattingStateForFormattingRootIfNeeded(root).createFormattingContext(root) is not only mouthful
+        but also feels unintuitive. Use layoutState().createFormattingContext(root) instead.
+
+        * layout/FormattingContext.cpp:
+        (WebCore::Layout::FormattingContext::FormattingContext):
+        (WebCore::Layout::FormattingContext::~FormattingContext):
+        (WebCore::Layout::FormattingContext::layoutOutOfFlowDescendants const):
+        * layout/FormattingContextGeometry.cpp:
+        (WebCore::Layout::FormattingContext::Geometry::shrinkToFitWidth):
+        * layout/FormattingState.h:
+        * layout/LayoutState.cpp:
+        (WebCore::Layout::LayoutState::layoutFormattingContextSubtree):
+        (WebCore::Layout::LayoutState::createFormattingContext):
+        * layout/LayoutState.h:
+        (WebCore::Layout::LayoutState::deregisterFormattingContext):
+        (WebCore::Layout::LayoutState::registerFormattingContext):
+        * layout/blockformatting/BlockFormattingContext.cpp:
+        (WebCore::Layout::BlockFormattingContext::layoutFormattingContextRoot const):
+        (WebCore::Layout::BlockFormattingContext::instrinsicWidthConstraints const):
+        * layout/blockformatting/BlockFormattingState.cpp:
+        (WebCore::Layout::BlockFormattingState::createFormattingContext): Deleted.
+        * layout/blockformatting/BlockFormattingState.h:
+        * layout/inlineformatting/InlineFormattingContext.cpp:
+        (WebCore::Layout::InlineFormattingContext::layoutFormattingContextRoot const):
+        * layout/inlineformatting/InlineFormattingState.cpp:
+        (WebCore::Layout::InlineFormattingState::createFormattingContext): Deleted.
+        * layout/inlineformatting/InlineFormattingState.h:
+
+2019-01-12  Zalan Bujtas  <[email protected]>
+
         [LFC][BFC][MarginCollapsing] Move estimatedMarginBefore flag from state/display box to BlockFormattingContext
         https://bugs.webkit.org/show_bug.cgi?id=193375
 

Modified: trunk/Source/WebCore/layout/FormattingContext.cpp (239899 => 239900)


--- trunk/Source/WebCore/layout/FormattingContext.cpp	2019-01-12 15:30:55 UTC (rev 239899)
+++ trunk/Source/WebCore/layout/FormattingContext.cpp	2019-01-12 16:56:55 UTC (rev 239900)
@@ -47,10 +47,16 @@
     : m_root(makeWeakPtr(formattingContextRoot))
     , m_formattingState(formattingState)
 {
+#ifndef NDEBUG
+    layoutState().registerFormattingContext(*this);
+#endif
 }
 
 FormattingContext::~FormattingContext()
 {
+#ifndef NDEBUG
+    layoutState().deregisterFormattingContext(*this);
+#endif
 }
 
 FormattingState& FormattingContext::formattingState() const
@@ -154,7 +160,7 @@
         computeBorderAndPadding(layoutBox);
         computeOutOfFlowHorizontalGeometry(layoutBox);
 
-        layoutState.createFormattingStateForFormattingRootIfNeeded(layoutBox).createFormattingContext(layoutBox)->layout();
+        layoutState.createFormattingContext(layoutBox)->layout();
 
         computeOutOfFlowVerticalGeometry(layoutBox);
         layoutOutOfFlowDescendants(layoutBox);

Modified: trunk/Source/WebCore/layout/FormattingContextGeometry.cpp (239899 => 239900)


--- trunk/Source/WebCore/layout/FormattingContextGeometry.cpp	2019-01-12 15:30:55 UTC (rev 239899)
+++ trunk/Source/WebCore/layout/FormattingContextGeometry.cpp	2019-01-12 16:56:55 UTC (rev 239900)
@@ -238,8 +238,7 @@
 
     // Then the shrink-to-fit width is: min(max(preferred minimum width, available width), preferred width).
     auto availableWidth = layoutState.displayBoxForLayoutBox(*formattingRoot.containingBlock()).width();
-    auto& formattingState = layoutState.createFormattingStateForFormattingRootIfNeeded(formattingRoot);
-    auto instrinsicWidthConstraints = formattingState.createFormattingContext(formattingRoot)->instrinsicWidthConstraints();
+    auto instrinsicWidthConstraints = layoutState.createFormattingContext(formattingRoot)->instrinsicWidthConstraints();
     return std::min(std::max(instrinsicWidthConstraints.minimum, availableWidth), instrinsicWidthConstraints.maximum);
 }
 

Modified: trunk/Source/WebCore/layout/FormattingState.h (239899 => 239900)


--- trunk/Source/WebCore/layout/FormattingState.h	2019-01-12 15:30:55 UTC (rev 239899)
+++ trunk/Source/WebCore/layout/FormattingState.h	2019-01-12 16:56:55 UTC (rev 239900)
@@ -46,8 +46,6 @@
 public:
     virtual ~FormattingState();
 
-    virtual std::unique_ptr<FormattingContext> createFormattingContext(const Box& formattingContextRoot) = 0;
-
     FloatingState& floatingState() const { return m_floatingState; }
 
     void markNeedsLayout(const Box&, StyleDiff);

Modified: trunk/Source/WebCore/layout/LayoutState.cpp (239899 => 239900)


--- trunk/Source/WebCore/layout/LayoutState.cpp	2019-01-12 15:30:55 UTC (rev 239899)
+++ trunk/Source/WebCore/layout/LayoutState.cpp	2019-01-12 16:56:55 UTC (rev 239900)
@@ -76,8 +76,7 @@
 void LayoutState::layoutFormattingContextSubtree(const Box& layoutRoot)
 {
     RELEASE_ASSERT(layoutRoot.establishesFormattingContext());
-    auto& formattingState = createFormattingStateForFormattingRootIfNeeded(layoutRoot);
-    auto formattingContext = formattingState.createFormattingContext(layoutRoot);
+    auto formattingContext = createFormattingContext(layoutRoot);
     formattingContext->layout();
     formattingContext->layoutOutOfFlowDescendants(layoutRoot);
 }
@@ -151,7 +150,21 @@
     CRASH();
 }
 
+std::unique_ptr<FormattingContext> LayoutState::createFormattingContext(const Box& formattingContextRoot)
+{
+    ASSERT(formattingContextRoot.establishesFormattingContext());
+    if (formattingContextRoot.establishesInlineFormattingContext())
+        return std::make_unique<InlineFormattingContext>(formattingContextRoot, createFormattingStateForFormattingRootIfNeeded(formattingContextRoot));
+
+    if (formattingContextRoot.establishesBlockFormattingContext()) {
+        ASSERT(formattingContextRoot.establishesBlockFormattingContextOnly());
+        return std::make_unique<BlockFormattingContext>(formattingContextRoot, createFormattingStateForFormattingRootIfNeeded(formattingContextRoot));
+    }
+
+    CRASH();
 }
+
 }
+}
 
 #endif

Modified: trunk/Source/WebCore/layout/LayoutState.h (239899 => 239900)


--- trunk/Source/WebCore/layout/LayoutState.h	2019-01-12 15:30:55 UTC (rev 239899)
+++ trunk/Source/WebCore/layout/LayoutState.h	2019-01-12 16:56:55 UTC (rev 239900)
@@ -47,6 +47,7 @@
 enum class StyleDiff;
 class Box;
 class Container;
+class FormattingContext;
 class FormattingState;
 
 // LayoutState is the entry point for layout. It takes the initial containing block which acts as the root of the layout context.
@@ -78,6 +79,12 @@
     bool hasFormattingState(const Box& formattingRoot) const { return m_formattingStates.contains(&formattingRoot); }
     FormattingState& createFormattingStateForFormattingRootIfNeeded(const Box& formattingRoot);
 
+    std::unique_ptr<FormattingContext> createFormattingContext(const Box& formattingContextRoot);
+#ifndef NDEBUG
+    void registerFormattingContext(const FormattingContext&);
+    void deregisterFormattingContext(const FormattingContext& formattingContext) { m_formattingContextList.remove(&formattingContext); }
+#endif
+
     Display::Box& displayBoxForLayoutBox(const Box& layoutBox) const;
     bool hasDisplayBox(const Box& layoutBox) const { return m_layoutToDisplayBox.contains(&layoutBox); }
 
@@ -92,10 +99,22 @@
     WeakPtr<const Container> m_initialContainingBlock;
     HashSet<const Container*> m_formattingContextRootListForLayout;
     HashMap<const Box*, std::unique_ptr<FormattingState>> m_formattingStates;
+#ifndef NDEBUG
+    HashSet<const FormattingContext*> m_formattingContextList;
+#endif
     mutable HashMap<const Box*, std::unique_ptr<Display::Box>> m_layoutToDisplayBox;
     bool m_inQuirksMode { false };
 };
 
+#ifndef NDEBUG
+inline void LayoutState::registerFormattingContext(const FormattingContext& formattingContext)
+{
+    // Multiple formatting contexts of the same root within a layout frame indicates defective layout logic.
+    ASSERT(!m_formattingContextList.contains(&formattingContext));
+    m_formattingContextList.add(&formattingContext);
 }
+#endif
+
 }
+}
 #endif

Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp (239899 => 239900)


--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp	2019-01-12 15:30:55 UTC (rev 239899)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp	2019-01-12 16:56:55 UTC (rev 239900)
@@ -134,7 +134,7 @@
 
     precomputeVerticalPositionForFormattingRootIfNeeded(layoutBox);
     // Swich over to the new formatting context (the one that the root creates).
-    auto formattingContext = layoutState().createFormattingStateForFormattingRootIfNeeded(layoutBox).createFormattingContext(layoutBox);
+    auto formattingContext = layoutState().createFormattingContext(layoutBox);
     formattingContext->layout();
 
     // Come back and finalize the root's geometry.
@@ -436,7 +436,7 @@
                 if (!Geometry::instrinsicWidthConstraintsNeedChildrenWidth(childBox))
                     instrinsicWidthConstraints = Geometry::instrinsicWidthConstraints(layoutState, childBox);
                 else if (childBox.establishesFormattingContext())
-                    instrinsicWidthConstraints = layoutState.createFormattingStateForFormattingRootIfNeeded(childBox).createFormattingContext(childBox)->instrinsicWidthConstraints();
+                    instrinsicWidthConstraints = layoutState.createFormattingContext(childBox)->instrinsicWidthConstraints();
                 formattingState.setInstrinsicWidthConstraints(childBox, instrinsicWidthConstraints);
 
                 queue.removeLast();

Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingState.cpp (239899 => 239900)


--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingState.cpp	2019-01-12 15:30:55 UTC (rev 239899)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingState.cpp	2019-01-12 16:56:55 UTC (rev 239900)
@@ -46,12 +46,6 @@
 {
 }
 
-std::unique_ptr<FormattingContext> BlockFormattingState::createFormattingContext(const Box& formattingContextRoot)
-{
-    ASSERT(formattingContextRoot.establishesBlockFormattingContext());
-    return std::make_unique<BlockFormattingContext>(formattingContextRoot, *this);
 }
-
 }
-}
 #endif

Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingState.h (239899 => 239900)


--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingState.h	2019-01-12 15:30:55 UTC (rev 239899)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingState.h	2019-01-12 16:56:55 UTC (rev 239900)
@@ -41,8 +41,6 @@
     BlockFormattingState(Ref<FloatingState>&&, LayoutState&);
     virtual ~BlockFormattingState();
 
-    std::unique_ptr<FormattingContext> createFormattingContext(const Box& formattingContextRoot) override;
-
     void setPositiveAndNegativeVerticalMargin(const Box& layoutBox, PositiveAndNegativeVerticalMargin verticalMargin) { m_positiveAndNegativeVerticalMargin.set(&layoutBox, verticalMargin); }
     bool hasPositiveAndNegativeVerticalMargin(const Box& layoutBox) const { return m_positiveAndNegativeVerticalMargin.contains(&layoutBox); }
     PositiveAndNegativeVerticalMargin positiveAndNegativeVerticalMargin(const Box& layoutBox) const { return m_positiveAndNegativeVerticalMargin.get(&layoutBox); }

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp (239899 => 239900)


--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp	2019-01-12 15:30:55 UTC (rev 239899)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp	2019-01-12 16:56:55 UTC (rev 239900)
@@ -375,7 +375,7 @@
     computeBorderAndPadding(root);
     computeWidthAndMargin(root);
     // Swich over to the new formatting context (the one that the root creates).
-    auto formattingContext = layoutState().createFormattingStateForFormattingRootIfNeeded(root).createFormattingContext(root);
+    auto formattingContext = layoutState().createFormattingContext(root);
     formattingContext->layout();
     // Come back and finalize the root's height and margin.
     computeHeightAndMargin(root);

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingState.cpp (239899 => 239900)


--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingState.cpp	2019-01-12 15:30:55 UTC (rev 239899)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingState.cpp	2019-01-12 16:56:55 UTC (rev 239900)
@@ -44,12 +44,6 @@
 {
 }
 
-std::unique_ptr<FormattingContext> InlineFormattingState::createFormattingContext(const Box& formattingContextRoot)
-{
-    ASSERT(formattingContextRoot.establishesInlineFormattingContext());
-    return std::make_unique<InlineFormattingContext>(formattingContextRoot, *this);
 }
-
 }
-}
 #endif

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingState.h (239899 => 239900)


--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingState.h	2019-01-12 15:30:55 UTC (rev 239899)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingState.h	2019-01-12 16:56:55 UTC (rev 239900)
@@ -43,8 +43,6 @@
     InlineFormattingState(Ref<FloatingState>&&, LayoutState&);
     virtual ~InlineFormattingState();
 
-    std::unique_ptr<FormattingContext> createFormattingContext(const Box& formattingContextRoot) override;
-
     InlineContent& inlineContent() { return m_inlineContent; }
     InlineItem* lastInlineItem() const { return m_inlineContent.isEmpty() ? nullptr : m_inlineContent.last().get(); }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to