Title: [239330] trunk/Source/WebCore
Revision
239330
Author
[email protected]
Date
2018-12-18 07:19:21 -0800 (Tue, 18 Dec 2018)

Log Message

[LFC][BFC][MarginCollapsing] Expand marginAfterCollapsesWithParentMarginAfter and marginBeforeCollapsesWithParentMarginBefore collapsing logic
https://bugs.webkit.org/show_bug.cgi?id=192787

Reviewed by Antti Koivisto.

* layout/blockformatting/BlockFormattingContext.h:
* layout/blockformatting/BlockMarginCollapse.cpp:
(WebCore::Layout::hasClearance):
(WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::marginBeforeCollapsesWithParentMarginBefore):
(WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::marginAfterCollapsesWithSiblingMarginBeforeWithClearance):
(WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::marginAfterCollapsesWithParentMarginBefore):
(WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::marginAfterCollapsesWithParentMarginAfter):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (239329 => 239330)


--- trunk/Source/WebCore/ChangeLog	2018-12-18 13:00:36 UTC (rev 239329)
+++ trunk/Source/WebCore/ChangeLog	2018-12-18 15:19:21 UTC (rev 239330)
@@ -1,3 +1,18 @@
+2018-12-18  Zalan Bujtas  <[email protected]>
+
+        [LFC][BFC][MarginCollapsing] Expand marginAfterCollapsesWithParentMarginAfter and marginBeforeCollapsesWithParentMarginBefore collapsing logic
+        https://bugs.webkit.org/show_bug.cgi?id=192787
+
+        Reviewed by Antti Koivisto.
+
+        * layout/blockformatting/BlockFormattingContext.h:
+        * layout/blockformatting/BlockMarginCollapse.cpp:
+        (WebCore::Layout::hasClearance):
+        (WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::marginBeforeCollapsesWithParentMarginBefore):
+        (WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::marginAfterCollapsesWithSiblingMarginBeforeWithClearance):
+        (WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::marginAfterCollapsesWithParentMarginBefore):
+        (WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::marginAfterCollapsesWithParentMarginAfter):
+
 2018-12-17  Fujii Hironori  <[email protected]>
 
         [Win][Clang] Fix compilation warnings WebCore/platform/graphics directory

Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h (239329 => 239330)


--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h	2018-12-18 13:00:36 UTC (rev 239329)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h	2018-12-18 15:19:21 UTC (rev 239330)
@@ -105,6 +105,8 @@
             static bool marginBeforeCollapsesWithParentMarginBefore(const LayoutState&, const Box&);
             static bool marginBeforeCollapsesWithPreviousSibling(const Box&);
             static bool marginAfterCollapsesWithNextSibling(const Box&);
+            static bool marginAfterCollapsesWithSiblingMarginBeforeWithClearance(const Box&);
+            static bool marginAfterCollapsesWithParentMarginBefore(const Box&);
             static bool marginsCollapseThrough(const Box&);
         };
 

Modified: trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp (239329 => 239330)


--- trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp	2018-12-18 13:00:36 UTC (rev 239329)
+++ trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp	2018-12-18 15:19:21 UTC (rev 239330)
@@ -69,6 +69,14 @@
     return hasPadding(layoutBox.style().paddingAfter());
 }
 
+static bool hasClearance(const Box& layoutBox)
+{
+    if (!layoutBox.hasFloatClear())
+        return false;
+    // FIXME
+    return false;
+}
+
 static bool establishesBlockFormattingContext(const Box& layoutBox)
 {
     // WebKit treats the document element renderer as a block formatting context root. It probably only impacts margin collapsing, so let's not do
@@ -179,9 +187,18 @@
 
     ASSERT(layoutBox.isBlockLevelBox());
 
-    if (layoutBox.isFloatingOrOutOfFlowPositioned())
+    // Margins between a floated box and any other box do not collapse.
+    if (layoutBox.isFloatingPositioned())
         return false;
 
+    // Margins of absolutely positioned boxes do not collapse.
+    if (layoutBox.isOutOfFlowPositioned())
+        return false;
+
+    // Margins of inline-block boxes do not collapse.
+    if (layoutBox.isInlineBlockBox())
+        return false;
+
     // Only the first inlflow child collapses with parent.
     if (layoutBox.previousInFlowSibling())
         return false;
@@ -197,6 +214,10 @@
     if (hasPaddingBefore(parent))
         return false;
 
+    // ...and the child has no clearance.
+    if (hasClearance(layoutBox))
+        return false;
+
     if (BlockFormattingContext::Quirks::shouldIgnoreMarginBefore(layoutState, layoutBox))
         return false;
 
@@ -203,39 +224,65 @@
     return true;
 }
 
+bool BlockFormattingContext::Geometry::MarginCollapse::marginAfterCollapsesWithSiblingMarginBeforeWithClearance(const Box&)
+{
+    return false;
+}
+
+bool BlockFormattingContext::Geometry::MarginCollapse::marginAfterCollapsesWithParentMarginBefore(const Box&)
+{
+    return false;
+}
+
 bool BlockFormattingContext::Geometry::MarginCollapse::marginAfterCollapsesWithParentMarginAfter(const Box& layoutBox)
 {
-    // last inflow box to parent.
-    // https://www.w3.org/TR/CSS21/box.html#collapsing-margins
     if (layoutBox.isAnonymous())
         return false;
 
     ASSERT(layoutBox.isBlockLevelBox());
 
-    if (layoutBox.isFloatingOrOutOfFlowPositioned())
+    // Margins between a floated box and any other box do not collapse.
+    if (layoutBox.isFloatingPositioned())
         return false;
 
-    if (marginsCollapseThrough(layoutBox))
+    // Margins of absolutely positioned boxes do not collapse.
+    if (layoutBox.isOutOfFlowPositioned())
         return false;
 
+    // Margins of inline-block boxes do not collapse.
+    if (layoutBox.isInlineBlockBox())
+        return false;
+
     // Only the last inlflow child collapses with parent.
     if (layoutBox.nextInFlowSibling())
         return false;
 
     auto& parent = *layoutBox.parent();
-    // Margins of elements that establish new block formatting contexts do not collapse with their in-flow children
+    // Margins of elements that establish new block formatting contexts do not collapse with their in-flow children.
     if (establishesBlockFormattingContext(parent))
         return false;
 
-    if (hasBorderBefore(parent))
+    // The bottom margin of an in-flow block box with a 'height' of 'auto' collapses with its last in-flow block-level child's bottom margin, if:
+    if (!parent.style().height().isAuto())
         return false;
 
+    // the box has no bottom padding, and
     if (hasPaddingBefore(parent))
         return false;
 
-    if (!parent.style().height().isAuto())
+    // the box has no bottom border, and
+    if (hasBorderBefore(parent))
         return false;
 
+    // the child's bottom margin neither collapses with a top margin that has clearance...
+    if (marginAfterCollapsesWithSiblingMarginBeforeWithClearance(layoutBox))
+        return false;
+
+    // nor (if the box's min-height is non-zero) with the box's top margin.
+    auto computedMinHeight = parent.style().logicalMinHeight();
+    if (!computedMinHeight.isAuto() && computedMinHeight.value() && marginAfterCollapsesWithParentMarginBefore(layoutBox))
+        return false;
+
     return true;
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to