Title: [254927] trunk/Source/WebCore
Revision
254927
Author
[email protected]
Date
2020-01-22 09:07:27 -0800 (Wed, 22 Jan 2020)

Log Message

[LFC] Do not create a FormattingContext unless there's content to layout.
https://bugs.webkit.org/show_bug.cgi?id=206570
<rdar://problem/58785735>

Reviewed by Antti Koivisto.

We still construct "no-op" FormattingContexts through the computeIntrinsicWidth* codepath (see webkit.org/b/206581).

* layout/FormattingContext.cpp:
(WebCore::Layout::FormattingContext::FormattingContext):
(WebCore::Layout::FormattingContext::layoutOutOfFlowContent):
* layout/blockformatting/BlockFormattingContext.cpp:
(WebCore::Layout::BlockFormattingContext::layoutInFlowContent):
* layout/inlineformatting/InlineFormattingContext.cpp:
(WebCore::Layout::InlineFormattingContext::layoutInFlowContent):
(WebCore::Layout::InlineFormattingContext::layoutFormattingContextRoot):
* layout/tableformatting/TableFormattingContext.cpp:
(WebCore::Layout::TableFormattingContext::layoutTableCellBox):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (254926 => 254927)


--- trunk/Source/WebCore/ChangeLog	2020-01-22 17:06:32 UTC (rev 254926)
+++ trunk/Source/WebCore/ChangeLog	2020-01-22 17:07:27 UTC (rev 254927)
@@ -1,3 +1,24 @@
+2020-01-22  Zalan Bujtas  <[email protected]>
+
+        [LFC] Do not create a FormattingContext unless there's content to layout.
+        https://bugs.webkit.org/show_bug.cgi?id=206570
+        <rdar://problem/58785735>
+
+        Reviewed by Antti Koivisto.
+
+        We still construct "no-op" FormattingContexts through the computeIntrinsicWidth* codepath (see webkit.org/b/206581).
+
+        * layout/FormattingContext.cpp:
+        (WebCore::Layout::FormattingContext::FormattingContext):
+        (WebCore::Layout::FormattingContext::layoutOutOfFlowContent):
+        * layout/blockformatting/BlockFormattingContext.cpp:
+        (WebCore::Layout::BlockFormattingContext::layoutInFlowContent):
+        * layout/inlineformatting/InlineFormattingContext.cpp:
+        (WebCore::Layout::InlineFormattingContext::layoutInFlowContent):
+        (WebCore::Layout::InlineFormattingContext::layoutFormattingContextRoot):
+        * layout/tableformatting/TableFormattingContext.cpp:
+        (WebCore::Layout::TableFormattingContext::layoutTableCellBox):
+
 2020-01-22  Antti Koivisto  <[email protected]>
 
         [LFC][Integration] Disable integration to see performance impact

Modified: trunk/Source/WebCore/layout/FormattingContext.cpp (254926 => 254927)


--- trunk/Source/WebCore/layout/FormattingContext.cpp	2020-01-22 17:06:32 UTC (rev 254926)
+++ trunk/Source/WebCore/layout/FormattingContext.cpp	2020-01-22 17:07:27 UTC (rev 254927)
@@ -163,15 +163,17 @@
         auto& outOfFlowRootDisplayBox = geometryForBox(*outOfFlowBox);
         computeBorderAndPadding(*outOfFlowBox, Geometry::horizontalConstraintsForInFlow(outOfFlowRootDisplayBox));
         computeOutOfFlowHorizontalGeometry(*outOfFlowBox, horizontalConstraints);
-        if (is<Container>(*outOfFlowBox)) {
-            auto& outOfFlowRootContainer = downcast<Container>(*outOfFlowBox);
-            auto formattingContext = LayoutContext::createFormattingContext(outOfFlowRootContainer, layoutState());
+        if (!is<Container>(*outOfFlowBox) || !downcast<Container>(*outOfFlowBox).hasChild()) {
+            computeOutOfFlowVerticalGeometry(*outOfFlowBox, horizontalConstraints, verticalConstraints);
+            continue;
+        }
+
+        auto& outOfFlowRootContainer = downcast<Container>(*outOfFlowBox);
+        auto formattingContext = LayoutContext::createFormattingContext(outOfFlowRootContainer, layoutState());
+        if (outOfFlowRootContainer.hasInFlowOrFloatingChild())
             formattingContext->layoutInFlowContent(invalidationState, Geometry::horizontalConstraintsForInFlow(outOfFlowRootDisplayBox), Geometry::verticalConstraintsForInFlow(outOfFlowRootDisplayBox));
-            computeOutOfFlowVerticalGeometry(outOfFlowRootContainer, horizontalConstraints, verticalConstraints);
-
-            formattingContext->layoutOutOfFlowContent(invalidationState, Geometry::horizontalConstraintsForInFlow(outOfFlowRootDisplayBox), Geometry::verticalConstraintsForInFlow(outOfFlowRootDisplayBox));
-        } else
-            computeOutOfFlowVerticalGeometry(*outOfFlowBox, horizontalConstraints, verticalConstraints);
+        computeOutOfFlowVerticalGeometry(outOfFlowRootContainer, horizontalConstraints, verticalConstraints);
+        formattingContext->layoutOutOfFlowContent(invalidationState, Geometry::horizontalConstraintsForInFlow(outOfFlowRootDisplayBox), Geometry::verticalConstraintsForInFlow(outOfFlowRootDisplayBox));
     }
     LOG_WITH_STREAM(FormattingContextLayout, stream << "End: layout out-of-flow content -> context: " << &layoutState() << " root: " << &root());
 }

Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp (254926 => 254927)


--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp	2020-01-22 17:06:32 UTC (rev 254926)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp	2020-01-22 17:07:27 UTC (rev 254927)
@@ -59,6 +59,7 @@
     // Vertical margins between adjacent block-level boxes in a block formatting context collapse.
     LOG_WITH_STREAM(FormattingContextLayout, stream << "[Start] -> block formatting context -> formatting root(" << &root() << ")");
     auto& formattingRoot = root();
+    ASSERT(formattingRoot.hasInFlowOrFloatingChild());
     auto floatingContext = FloatingContext { formattingRoot, *this, formattingState().floatingState() };
 
     LayoutQueue layoutQueue;
@@ -148,7 +149,7 @@
 
             if (layoutBox.establishesFormattingContext()) {
                 // Now that we computed the root's height, we can layout the out-of-flow descendants.
-                if (is<Container>(layoutBox)) {
+                if (is<Container>(layoutBox) && downcast<Container>(layoutBox).hasChild()) {
                     auto& rootDisplayBox = geometryForBox(layoutBox);
                     auto horizontalConstraintsForOutOfFlow =  Geometry::horizontalConstraintsForOutOfFlow(rootDisplayBox);
                     auto verticalConstraintsForOutOfFlow = Geometry::verticalConstraintsForOutOfFlow(rootDisplayBox);

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp (254926 => 254927)


--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp	2020-01-22 17:06:32 UTC (rev 254926)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp	2020-01-22 17:07:27 UTC (rev 254927)
@@ -68,11 +68,10 @@
 
 void InlineFormattingContext::layoutInFlowContent(InvalidationState& invalidationState, const HorizontalConstraints& horizontalConstraints, const VerticalConstraints& verticalConstraints)
 {
-    if (!root().hasInFlowOrFloatingChild())
-        return;
+    LOG_WITH_STREAM(FormattingContextLayout, stream << "[Start] -> inline formatting context -> formatting root(" << &root() << ")");
+    ASSERT(root().hasInFlowOrFloatingChild());
 
     invalidateFormattingState(invalidationState);
-    LOG_WITH_STREAM(FormattingContextLayout, stream << "[Start] -> inline formatting context -> formatting root(" << &root() << ")");
     auto* layoutBox = root().firstInFlowOrFloatingChild();
     // 1. Visit each inline box and partially compute their geometry (margins, paddings and borders).
     // 2. Collect the inline items (flatten the the layout tree) and place them on lines in bidirectional order. 
@@ -135,20 +134,24 @@
 
     computeBorderAndPadding(formattingContextRoot, horizontalConstraints);
     computeWidthAndMargin(formattingContextRoot, horizontalConstraints);
+    if (!is<Container>(formattingContextRoot) || !downcast<Container>(formattingContextRoot).hasChild()) {
+        computeHeightAndMargin(formattingContextRoot, horizontalConstraints);
+        return;
+    }
     // Swich over to the new formatting context (the one that the root creates).
-    if (is<Container>(formattingContextRoot)) {
-        auto& rootContainer = downcast<Container>(formattingContextRoot);
-        auto formattingContext = LayoutContext::createFormattingContext(rootContainer, layoutState());
+    auto& rootContainer = downcast<Container>(formattingContextRoot);
+    auto formattingContext = LayoutContext::createFormattingContext(rootContainer, layoutState());
+    if (rootContainer.hasInFlowOrFloatingChild())
         formattingContext->layoutInFlowContent(invalidationState, horizontalConstraints, verticalConstraints);
-        // Come back and finalize the root's height and margin.
-        computeHeightAndMargin(rootContainer, horizontalConstraints);
-        // Now that we computed the root's height, we can go back and layout the out-of-flow content.
+    // Come back and finalize the root's height and margin.
+    computeHeightAndMargin(rootContainer, horizontalConstraints);
+    // Now that we computed the root's height, we can go back and layout the out-of-flow content.
+    if (rootContainer.hasChild()) {
         auto& rootContainerDisplayBox = geometryForBox(rootContainer);
         auto horizontalConstraintsForOutOfFlow = Geometry::horizontalConstraintsForOutOfFlow(rootContainerDisplayBox);
         auto verticalConstraintsForOutOfFlow = Geometry::verticalConstraintsForOutOfFlow(rootContainerDisplayBox);
         formattingContext->layoutOutOfFlowContent(invalidationState, horizontalConstraintsForOutOfFlow, verticalConstraintsForOutOfFlow);
-    } else
-        computeHeightAndMargin(formattingContextRoot, horizontalConstraints);
+    }
 }
 
 void InlineFormattingContext::computeHorizontalAndVerticalGeometry(const Box& layoutBox, const HorizontalConstraints& horizontalConstraints)

Modified: trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp (254926 => 254927)


--- trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp	2020-01-22 17:06:32 UTC (rev 254926)
+++ trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp	2020-01-22 17:07:27 UTC (rev 254927)
@@ -111,7 +111,7 @@
     cellDisplayBox.setContentBoxWidth(column.logicalWidth() - cellDisplayBox.horizontalMarginBorderAndPadding());
 
     ASSERT(cellLayoutBox.establishesBlockFormattingContext());
-    if (is<Container>(cellLayoutBox))
+    if (is<Container>(cellLayoutBox) && downcast<Container>(cellLayoutBox).hasInFlowOrFloatingChild())
         LayoutContext::createFormattingContext(downcast<Container>(cellLayoutBox), layoutState())->layoutInFlowContent(invalidationState, Geometry::horizontalConstraintsForInFlow(cellDisplayBox), Geometry::verticalConstraintsForInFlow(cellDisplayBox));
     cellDisplayBox.setVerticalMargin({ { }, { } });
     cellDisplayBox.setContentBoxHeight(geometry().tableCellHeightAndMargin(cellLayoutBox).contentHeight);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to