Title: [257507] trunk/Source/WebCore
Revision
257507
Author
[email protected]
Date
2020-02-26 13:30:58 -0800 (Wed, 26 Feb 2020)

Log Message

[LFC][BFC][MarginCollapsing] Decouple regular and pre-computed margin collapsing logic
https://bugs.webkit.org/show_bug.cgi?id=208247
<rdar://problem/59808951>

Reviewed by Antti Koivisto.

The pre-computed path is so peculiar it deserves a dedicated file.

This is in preparation for fixing a flaw in the pre-computed logic where we end up
accessing a not-yet-computed horizontal constraint. No change in functionality at this point.

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* layout/blockformatting/BlockFormattingContext.h:
* layout/blockformatting/BlockMarginCollapse.cpp:
(WebCore::Layout::BlockFormattingContext::MarginCollapse::positiveNegativeValues const):
(WebCore::Layout::BlockFormattingContext::MarginCollapse::precomputedMarginBefore): Deleted.
* layout/blockformatting/PrecomputedBlockMarginCollapse.cpp: Added.
(WebCore::Layout::BlockFormattingContext::MarginCollapse::precomputedPositiveNegativeValues const):
(WebCore::Layout::BlockFormattingContext::MarginCollapse::precomputedPositiveNegativeMarginBefore const):
(WebCore::Layout::BlockFormattingContext::MarginCollapse::precomputedMarginBefore):
* layout/integration/LayoutIntegrationBoxTree.cpp:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (257506 => 257507)


--- trunk/Source/WebCore/ChangeLog	2020-02-26 21:21:16 UTC (rev 257506)
+++ trunk/Source/WebCore/ChangeLog	2020-02-26 21:30:58 UTC (rev 257507)
@@ -1,3 +1,28 @@
+2020-02-26  Zalan Bujtas  <[email protected]>
+
+        [LFC][BFC][MarginCollapsing] Decouple regular and pre-computed margin collapsing logic
+        https://bugs.webkit.org/show_bug.cgi?id=208247
+        <rdar://problem/59808951>
+
+        Reviewed by Antti Koivisto.
+
+        The pre-computed path is so peculiar it deserves a dedicated file.
+
+        This is in preparation for fixing a flaw in the pre-computed logic where we end up
+        accessing a not-yet-computed horizontal constraint. No change in functionality at this point.
+
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * layout/blockformatting/BlockFormattingContext.h:
+        * layout/blockformatting/BlockMarginCollapse.cpp:
+        (WebCore::Layout::BlockFormattingContext::MarginCollapse::positiveNegativeValues const):
+        (WebCore::Layout::BlockFormattingContext::MarginCollapse::precomputedMarginBefore): Deleted.
+        * layout/blockformatting/PrecomputedBlockMarginCollapse.cpp: Added.
+        (WebCore::Layout::BlockFormattingContext::MarginCollapse::precomputedPositiveNegativeValues const):
+        (WebCore::Layout::BlockFormattingContext::MarginCollapse::precomputedPositiveNegativeMarginBefore const):
+        (WebCore::Layout::BlockFormattingContext::MarginCollapse::precomputedMarginBefore):
+        * layout/integration/LayoutIntegrationBoxTree.cpp:
+
 2020-02-26  Keith Rollin  <[email protected]>
 
         Add logging to help diagnose redirect issue

Modified: trunk/Source/WebCore/Sources.txt (257506 => 257507)


--- trunk/Source/WebCore/Sources.txt	2020-02-26 21:21:16 UTC (rev 257506)
+++ trunk/Source/WebCore/Sources.txt	2020-02-26 21:30:58 UTC (rev 257507)
@@ -1430,6 +1430,7 @@
 layout/blockformatting/BlockFormattingContextQuirks.cpp
 layout/blockformatting/BlockFormattingState.cpp
 layout/blockformatting/BlockMarginCollapse.cpp
+layout/blockformatting/PrecomputedBlockMarginCollapse.cpp
 layout/displaytree/DisplayBox.cpp
 layout/displaytree/DisplayInlineContent.cpp
 layout/displaytree/DisplayPainter.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (257506 => 257507)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2020-02-26 21:21:16 UTC (rev 257506)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2020-02-26 21:30:58 UTC (rev 257507)
@@ -9327,6 +9327,7 @@
 		6F995A2E1A70833700A735F4 /* JSWebGLTransformFeedback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSWebGLTransformFeedback.h; sourceTree = "<group>"; };
 		6F995A2F1A70833700A735F4 /* JSWebGLVertexArrayObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSWebGLVertexArrayObject.cpp; sourceTree = "<group>"; };
 		6F995A301A70833700A735F4 /* JSWebGLVertexArrayObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSWebGLVertexArrayObject.h; sourceTree = "<group>"; };
+		6FAE16BA2406DE7E00A48414 /* PrecomputedBlockMarginCollapse.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = PrecomputedBlockMarginCollapse.cpp; sourceTree = "<group>"; };
 		6FB11B5921783FCF00E2A574 /* TextUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextUtil.h; sourceTree = "<group>"; };
 		6FB11B5B21783FCF00E2A574 /* TextUtil.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextUtil.cpp; sourceTree = "<group>"; };
 		6FB22E30230097E300C20866 /* TableGrid.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TableGrid.h; sourceTree = "<group>"; };
@@ -16767,6 +16768,7 @@
 				115CFA79208B8D9D001E6991 /* BlockFormattingState.cpp */,
 				115CFA78208B8D9D001E6991 /* BlockFormattingState.h */,
 				115CFA89208B921A001E6991 /* BlockMarginCollapse.cpp */,
+				6FAE16BA2406DE7E00A48414 /* PrecomputedBlockMarginCollapse.cpp */,
 			);
 			path = blockformatting;
 			sourceTree = "<group>";

Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h (257506 => 257507)


--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h	2020-02-26 21:21:16 UTC (rev 257506)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h	2020-02-26 21:30:58 UTC (rev 257507)
@@ -130,6 +130,10 @@
         PositiveAndNegativeVerticalMargin::Values positiveNegativeValues(const Box&, MarginType) const;
         PositiveAndNegativeVerticalMargin::Values positiveNegativeMarginBefore(const Box&, UsedVerticalMargin::NonCollapsedValues) const;
         PositiveAndNegativeVerticalMargin::Values positiveNegativeMarginAfter(const Box&, UsedVerticalMargin::NonCollapsedValues) const;
+
+        PositiveAndNegativeVerticalMargin::Values precomputedPositiveNegativeMarginBefore(const Box&, UsedVerticalMargin::NonCollapsedValues) const;
+        PositiveAndNegativeVerticalMargin::Values precomputedPositiveNegativeValues(const Box&, MarginType) const;
+
         bool hasClearance(const Box&) const;
 
         LayoutState& layoutState() { return m_blockFormattingContext.layoutState(); }

Modified: trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp (257506 => 257507)


--- trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp	2020-02-26 21:21:16 UTC (rev 257506)
+++ trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp	2020-02-26 21:30:58 UTC (rev 257507)
@@ -507,19 +507,12 @@
 
 PositiveAndNegativeVerticalMargin::Values BlockFormattingContext::MarginCollapse::positiveNegativeValues(const Box& layoutBox, MarginType marginType) const
 {
-    auto& layoutState = this->layoutState();
-    auto& blockFormattingState = downcast<BlockFormattingState>(layoutState.formattingStateForBox(layoutBox));
-    if (blockFormattingState.hasPositiveAndNegativeVerticalMargin(layoutBox)) {
-        auto positiveAndNegativeVerticalMargin = blockFormattingState.positiveAndNegativeVerticalMargin(layoutBox);
-        return marginType == MarginType::Before ? positiveAndNegativeVerticalMargin.before : positiveAndNegativeVerticalMargin.after; 
-    }
-    // This is the pre-computed path. We don't yet have positive/negative margin computed.
-    auto computedVerticalMargin = formattingContext().geometry().computedVerticalMargin(layoutBox, Geometry::horizontalConstraintsForInFlow(formattingContext().geometryForBox(*layoutBox.containingBlock())));
-    auto nonCollapsedMargin = UsedVerticalMargin::NonCollapsedValues { computedVerticalMargin.before.valueOr(0), computedVerticalMargin.after.valueOr(0) }; 
-
-    if (marginType == MarginType::Before)
-        return positiveNegativeMarginBefore(layoutBox, nonCollapsedMargin);
-    return positiveNegativeMarginAfter(layoutBox, nonCollapsedMargin);
+    auto& blockFormattingState = downcast<BlockFormattingState>(layoutState().formattingStateForBox(layoutBox));
+    // By the time we get here in BFC layout to gather positive and negative margin values for a either a previous sibling or a child box,
+    // we mush have computed and cached those valued.
+    ASSERT(blockFormattingState.hasPositiveAndNegativeVerticalMargin(layoutBox));
+    auto positiveAndNegativeVerticalMargin = blockFormattingState.positiveAndNegativeVerticalMargin(layoutBox);
+    return marginType == MarginType::Before ? positiveAndNegativeVerticalMargin.before : positiveAndNegativeVerticalMargin.after; 
 }
 
 PositiveAndNegativeVerticalMargin::Values BlockFormattingContext::MarginCollapse::positiveNegativeMarginBefore(const Box& layoutBox, UsedVerticalMargin::NonCollapsedValues nonCollapsedValues) const
@@ -571,22 +564,6 @@
     return computedPositiveAndNegativeMargin(lastChildCollapsedMarginAfter(), nonCollapsedAfter);
 }
 
-PrecomputedMarginBefore BlockFormattingContext::MarginCollapse::precomputedMarginBefore(const Box& layoutBox, UsedVerticalMargin::NonCollapsedValues usedNonCollapsedMargin)
-{
-    ASSERT(layoutBox.isBlockLevelBox());
-    // Don't pre-compute vertical margins for out of flow boxes.
-    ASSERT(layoutBox.isInFlow() || layoutBox.isFloatingPositioned());
-    ASSERT(!layoutBox.isReplacedBox());
-
-    auto marginsCollapseThrough = this->marginsCollapseThrough(layoutBox);
-    auto positiveNegativeMarginBefore = this->positiveNegativeMarginBefore(layoutBox, usedNonCollapsedMargin);
-
-    auto collapsedMarginBefore = marginValue(!marginsCollapseThrough ? positiveNegativeMarginBefore
-        : computedPositiveAndNegativeMargin(positiveNegativeMarginBefore, positiveNegativeMarginAfter(layoutBox, usedNonCollapsedMargin)));
-
-    return { usedNonCollapsedMargin.before, collapsedMarginBefore, marginsCollapseThrough };
-}
-
 LayoutUnit BlockFormattingContext::MarginCollapse::marginBeforeIgnoringCollapsingThrough(const Box& layoutBox, UsedVerticalMargin::NonCollapsedValues nonCollapsedValues)
 {
     ASSERT(layoutBox.isBlockLevelBox());

Added: trunk/Source/WebCore/layout/blockformatting/PrecomputedBlockMarginCollapse.cpp (0 => 257507)


--- trunk/Source/WebCore/layout/blockformatting/PrecomputedBlockMarginCollapse.cpp	                        (rev 0)
+++ trunk/Source/WebCore/layout/blockformatting/PrecomputedBlockMarginCollapse.cpp	2020-02-26 21:30:58 UTC (rev 257507)
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "BlockFormattingContext.h"
+
+#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
+
+#include "LayoutBox.h"
+#include "LayoutContainerBox.h"
+#include "LayoutUnit.h"
+#include "RenderStyle.h"
+
+namespace WebCore {
+namespace Layout {
+
+PositiveAndNegativeVerticalMargin::Values BlockFormattingContext::MarginCollapse::precomputedPositiveNegativeValues(const Box& layoutBox, MarginType marginType) const
+{
+    auto computedVerticalMargin = formattingContext().geometry().computedVerticalMargin(layoutBox, Geometry::horizontalConstraintsForInFlow(formattingContext().geometryForBox(*layoutBox.containingBlock())));
+    auto nonCollapsedMargin = UsedVerticalMargin::NonCollapsedValues { computedVerticalMargin.before.valueOr(0), computedVerticalMargin.after.valueOr(0) }; 
+
+    if (marginType == MarginType::Before)
+        return positiveNegativeMarginBefore(layoutBox, nonCollapsedMargin);
+    return positiveNegativeMarginAfter(layoutBox, nonCollapsedMargin);
+}
+
+PositiveAndNegativeVerticalMargin::Values BlockFormattingContext::MarginCollapse::precomputedPositiveNegativeMarginBefore(const Box& layoutBox, UsedVerticalMargin::NonCollapsedValues nonCollapsedValues) const
+{
+    auto firstChildCollapsedMarginBefore = [&]() -> PositiveAndNegativeVerticalMargin::Values {
+        if (!marginBeforeCollapsesWithFirstInFlowChildMarginBefore(layoutBox))
+            return { };
+        return precomputedPositiveNegativeValues(*downcast<ContainerBox>(layoutBox).firstInFlowChild(), MarginType::Before);
+    };
+
+    auto previouSiblingCollapsedMarginAfter = [&]() -> PositiveAndNegativeVerticalMargin::Values {
+        if (!marginBeforeCollapsesWithPreviousSiblingMarginAfter(layoutBox))
+            return { };
+        return precomputedPositiveNegativeValues(*layoutBox.previousInFlowSibling(), MarginType::After);
+    };
+
+    // 1. Gather positive and negative margin values from first child if margins are adjoining.
+    // 2. Gather positive and negative margin values from previous inflow sibling if margins are adjoining.
+    // 3. Compute min/max positive and negative collapsed margin values using non-collpased computed margin before.
+    auto collapsedMarginBefore = computedPositiveAndNegativeMargin(firstChildCollapsedMarginBefore(), previouSiblingCollapsedMarginAfter());
+    if (collapsedMarginBefore.isQuirk && formattingContext().quirks().shouldIgnoreCollapsedQuirkMargin(layoutBox))
+        collapsedMarginBefore = { };
+
+    auto nonCollapsedBefore = PositiveAndNegativeVerticalMargin::Values { };
+    if (nonCollapsedValues.before > 0)
+        nonCollapsedBefore = { nonCollapsedValues.before, { }, layoutBox.style().hasMarginBeforeQuirk() };
+    else if (nonCollapsedValues.before < 0)
+        nonCollapsedBefore = { { }, nonCollapsedValues.before, layoutBox.style().hasMarginBeforeQuirk() };
+
+    return computedPositiveAndNegativeMargin(collapsedMarginBefore, nonCollapsedBefore);
+}
+
+PrecomputedMarginBefore BlockFormattingContext::MarginCollapse::precomputedMarginBefore(const Box& layoutBox, UsedVerticalMargin::NonCollapsedValues usedNonCollapsedMargin)
+{
+    ASSERT(layoutBox.isBlockLevelBox());
+    // Don't pre-compute vertical margins for out of flow boxes.
+    ASSERT(layoutBox.isInFlow() || layoutBox.isFloatingPositioned());
+    ASSERT(!layoutBox.isReplacedBox());
+
+    auto marginsCollapseThrough = this->marginsCollapseThrough(layoutBox);
+    auto positiveNegativeMarginBefore = precomputedPositiveNegativeMarginBefore(layoutBox, usedNonCollapsedMargin);
+
+    auto collapsedMarginBefore = marginValue(!marginsCollapseThrough ? positiveNegativeMarginBefore
+        : computedPositiveAndNegativeMargin(positiveNegativeMarginBefore, positiveNegativeMarginAfter(layoutBox, usedNonCollapsedMargin)));
+
+    return { usedNonCollapsedMargin.before, collapsedMarginBefore, marginsCollapseThrough };
+}
+
+}
+}
+#endif

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationBoxTree.cpp (257506 => 257507)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationBoxTree.cpp	2020-02-26 21:21:16 UTC (rev 257506)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationBoxTree.cpp	2020-02-26 21:30:58 UTC (rev 257507)
@@ -28,6 +28,7 @@
 
 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)
 
+#include "LayoutInlineTextBox.h"
 #include "LayoutLineBreakBox.h"
 #include "RenderBlockFlow.h"
 #include "RenderChildIterator.h"
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to