Title: [263902] trunk
Revision
263902
Author
[email protected]
Date
2020-07-03 11:32:41 -0700 (Fri, 03 Jul 2020)

Log Message

[LFC][TFC][Quirk] Inflow child box quirk vertical margins should collapse with table cell.
https://bugs.webkit.org/show_bug.cgi?id=213926

Reviewed by Antti Koivisto.

Source/WebCore:

The BFC rootd (table cell box in this case) nornally do not collapse their margins with the first/last inflow child.
However in quirks mode, cell boxes collapse their (non-existing)margins with inflow quirk margins.

<table><tr><td><p>text content</td></tr></table> <- <p> box's top position is at 0px in quirks mode, while at 16px (1em) in strict mode.

This patch ensures that we collapse the quirk margins and take them into account when computing the cell's content height.

Test: fast/layoutformattingcontext/table-quirk-vertical-margin-simple.html

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* layout/blockformatting/BlockFormattingContext.cpp:
(WebCore::Layout::BlockFormattingContext::computeHeightAndMargin):
* layout/blockformatting/BlockFormattingContext.h:
* layout/blockformatting/BlockFormattingContextQuirks.cpp:
(WebCore::Layout::BlockFormattingContext::Quirks::shouldCollapseMarginBeforeWithParentMarginBefore const):
(WebCore::Layout::BlockFormattingContext::Quirks::shouldCollapseMarginAfterWithParentMarginAfter const):
* layout/blockformatting/BlockMarginCollapse.cpp:
(WebCore::Layout::BlockFormattingContext::MarginCollapse::marginBeforeCollapsesWithParentMarginBefore const):
(WebCore::Layout::BlockFormattingContext::MarginCollapse::marginAfterCollapsesWithParentMarginAfter const):
(WebCore::Layout::BlockFormattingContext::MarginCollapse::collapsedVerticalValues):
* layout/tableformatting/TableFormattingContext.h:
(WebCore::Layout::TableFormattingContext::Quirks::Quirks):
* layout/tableformatting/TableFormattingContextGeometry.cpp:
(WebCore::Layout::TableFormattingContext::Geometry::cellHeigh const):
* layout/tableformatting/TableFormattingContextQuirks.cpp: Added.
(WebCore::Layout::TableFormattingContext::Quirks::shouldIgnoreChildContentVerticalMargin const):

LayoutTests:

* fast/layoutformattingcontext/table-quirk-vertical-margin-simple-expected.html: Added.
* fast/layoutformattingcontext/table-quirk-vertical-margin-simple.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (263901 => 263902)


--- trunk/LayoutTests/ChangeLog	2020-07-03 16:55:41 UTC (rev 263901)
+++ trunk/LayoutTests/ChangeLog	2020-07-03 18:32:41 UTC (rev 263902)
@@ -1,3 +1,13 @@
+2020-07-03  Zalan Bujtas  <[email protected]>
+
+        [LFC][TFC][Quirk] Inflow child box quirk vertical margins should collapse with table cell.
+        https://bugs.webkit.org/show_bug.cgi?id=213926
+
+        Reviewed by Antti Koivisto.
+
+        * fast/layoutformattingcontext/table-quirk-vertical-margin-simple-expected.html: Added.
+        * fast/layoutformattingcontext/table-quirk-vertical-margin-simple.html: Added.
+
 2020-07-03  Youenn Fablet  <[email protected]>
 
         Support MediaRecorder.onstart

Added: trunk/LayoutTests/fast/layoutformattingcontext/table-quirk-vertical-margin-simple-expected.html (0 => 263902)


--- trunk/LayoutTests/fast/layoutformattingcontext/table-quirk-vertical-margin-simple-expected.html	                        (rev 0)
+++ trunk/LayoutTests/fast/layoutformattingcontext/table-quirk-vertical-margin-simple-expected.html	2020-07-03 18:32:41 UTC (rev 263902)
@@ -0,0 +1,18 @@
+<!DOCTYPE html><!-- webkit-test-runner [ internal:LayoutFormattingContextEnabled=true internal:LayoutFormattingContextIntegrationEnabled=false ] -->
+<style>
+.first {
+    width: 100px;
+    height: 200px;
+    background-color: green;
+}
+
+.second {
+    width: 100px;
+    height: 60px;
+    background-color: blue;
+    position: relative;
+    top: -80px;
+}
+</style>
+<div class=first></div>
+<div class=second></div>
\ No newline at end of file

Added: trunk/LayoutTests/fast/layoutformattingcontext/table-quirk-vertical-margin-simple.html (0 => 263902)


--- trunk/LayoutTests/fast/layoutformattingcontext/table-quirk-vertical-margin-simple.html	                        (rev 0)
+++ trunk/LayoutTests/fast/layoutformattingcontext/table-quirk-vertical-margin-simple.html	2020-07-03 18:32:41 UTC (rev 263902)
@@ -0,0 +1,30 @@
+<!-- webkit-test-runner [ internal:LayoutFormattingContextEnabled=true internal:LayoutFormattingContextIntegrationEnabled=false ] -->
+<style>
+table {
+    width: 100px;
+    font-size: 10px;
+    border-spacing: 0px;
+}
+
+p {
+    height: 50px;
+    color: green;
+}
+
+td {
+    padding: 0px;
+    background-color: green;
+}
+
+div {
+    margin-top: 20px;
+    margin-bottom: 20px;
+    background-color: blue;
+    color: blue;
+    width: 100px;
+    height: 60px;
+}
+</style>
+
+<table><tr><td><p>collapse quirk margins</td></tr></table>
+<table><tr><td><p>collapse quirk margins only with the cell<div></div></td></tr></table>

Modified: trunk/Source/WebCore/ChangeLog (263901 => 263902)


--- trunk/Source/WebCore/ChangeLog	2020-07-03 16:55:41 UTC (rev 263901)
+++ trunk/Source/WebCore/ChangeLog	2020-07-03 18:32:41 UTC (rev 263902)
@@ -1,3 +1,38 @@
+2020-07-03  Zalan Bujtas  <[email protected]>
+
+        [LFC][TFC][Quirk] Inflow child box quirk vertical margins should collapse with table cell.
+        https://bugs.webkit.org/show_bug.cgi?id=213926
+
+        Reviewed by Antti Koivisto.
+
+        The BFC rootd (table cell box in this case) nornally do not collapse their margins with the first/last inflow child.
+        However in quirks mode, cell boxes collapse their (non-existing)margins with inflow quirk margins.
+
+        <table><tr><td><p>text content</td></tr></table> <- <p> box's top position is at 0px in quirks mode, while at 16px (1em) in strict mode.
+
+        This patch ensures that we collapse the quirk margins and take them into account when computing the cell's content height.
+
+        Test: fast/layoutformattingcontext/table-quirk-vertical-margin-simple.html
+
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * layout/blockformatting/BlockFormattingContext.cpp:
+        (WebCore::Layout::BlockFormattingContext::computeHeightAndMargin):
+        * layout/blockformatting/BlockFormattingContext.h:
+        * layout/blockformatting/BlockFormattingContextQuirks.cpp:
+        (WebCore::Layout::BlockFormattingContext::Quirks::shouldCollapseMarginBeforeWithParentMarginBefore const):
+        (WebCore::Layout::BlockFormattingContext::Quirks::shouldCollapseMarginAfterWithParentMarginAfter const):
+        * layout/blockformatting/BlockMarginCollapse.cpp:
+        (WebCore::Layout::BlockFormattingContext::MarginCollapse::marginBeforeCollapsesWithParentMarginBefore const):
+        (WebCore::Layout::BlockFormattingContext::MarginCollapse::marginAfterCollapsesWithParentMarginAfter const):
+        (WebCore::Layout::BlockFormattingContext::MarginCollapse::collapsedVerticalValues):
+        * layout/tableformatting/TableFormattingContext.h:
+        (WebCore::Layout::TableFormattingContext::Quirks::Quirks):
+        * layout/tableformatting/TableFormattingContextGeometry.cpp:
+        (WebCore::Layout::TableFormattingContext::Geometry::cellHeigh const):
+        * layout/tableformatting/TableFormattingContextQuirks.cpp: Added.
+        (WebCore::Layout::TableFormattingContext::Quirks::shouldIgnoreChildContentVerticalMargin const):
+
 2020-07-03  Sam Weinig  <[email protected]>
 
         Split color conversion functions out of ColorUtilities.h/cpp into their own file.

Modified: trunk/Source/WebCore/Sources.txt (263901 => 263902)


--- trunk/Source/WebCore/Sources.txt	2020-07-03 16:55:41 UTC (rev 263901)
+++ trunk/Source/WebCore/Sources.txt	2020-07-03 18:32:41 UTC (rev 263902)
@@ -1526,6 +1526,7 @@
 layout/layouttree/LayoutTreeBuilder.cpp
 layout/tableformatting/TableFormattingContext.cpp
 layout/tableformatting/TableFormattingContextGeometry.cpp
+layout/tableformatting/TableFormattingContextQuirks.cpp
 layout/tableformatting/TableFormattingState.cpp
 layout/tableformatting/TableGrid.cpp
 layout/tableformatting/TableLayout.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (263901 => 263902)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2020-07-03 16:55:41 UTC (rev 263901)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2020-07-03 18:32:41 UTC (rev 263902)
@@ -9497,6 +9497,7 @@
 		6FB47E612277425A00C7BCB0 /* DisplayLineBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DisplayLineBox.h; sourceTree = "<group>"; };
 		6FB5E212221F2447003989CF /* ContentChangeObserver.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ContentChangeObserver.h; sourceTree = "<group>"; };
 		6FBB860520B464B600DAD938 /* FormattingContextGeometry.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = FormattingContextGeometry.cpp; sourceTree = "<group>"; };
+		6FC53AEB24AF7A8E006059FE /* TableFormattingContextQuirks.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TableFormattingContextQuirks.cpp; sourceTree = "<group>"; };
 		6FC5CA9222E3599300B13E11 /* TableFormattingState.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TableFormattingState.cpp; sourceTree = "<group>"; };
 		6FC5CA9422E3599400B13E11 /* TableFormattingContext.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TableFormattingContext.cpp; sourceTree = "<group>"; };
 		6FC5CA9522E3599400B13E11 /* TableFormattingContext.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TableFormattingContext.h; sourceTree = "<group>"; };
@@ -21406,6 +21407,7 @@
 				6FC5CA9422E3599400B13E11 /* TableFormattingContext.cpp */,
 				6FC5CA9522E3599400B13E11 /* TableFormattingContext.h */,
 				11D19C2E23159BAE008F24D3 /* TableFormattingContextGeometry.cpp */,
+				6FC53AEB24AF7A8E006059FE /* TableFormattingContextQuirks.cpp */,
 				6FC5CA9222E3599300B13E11 /* TableFormattingState.cpp */,
 				6FC5CA9622E3599500B13E11 /* TableFormattingState.h */,
 				6F5B7EAA2300A79E0067D9C3 /* TableGrid.cpp */,

Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp (263901 => 263902)


--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp	2020-07-03 16:55:41 UTC (rev 263901)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp	2020-07-03 18:32:41 UTC (rev 263902)
@@ -363,7 +363,7 @@
     }
 
     // 1. Compute collapsed margins.
-    // 2. Adjust vertical position using the collapsed values
+    // 2. Adjust vertical position using the collapsed values.
     // 3. Adjust previous in-flow sibling margin after using this margin.
     auto marginCollapse = this->marginCollapse();
     auto collapsedAndPositiveNegativeValues = marginCollapse.collapsedVerticalValues(layoutBox, contentHeightAndMargin.nonCollapsedMargin);

Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h (263901 => 263902)


--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h	2020-07-03 16:55:41 UTC (rev 263901)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h	2020-07-03 18:32:41 UTC (rev 263902)
@@ -155,8 +155,8 @@
         LayoutUnit stretchedInFlowHeight(const Box&, ContentHeightAndMargin);
 
         bool shouldIgnoreCollapsedQuirkMargin(const Box&) const;
-        bool shouldIgnoreMarginBefore(const Box&) const;
-        bool shouldIgnoreMarginAfter(const Box&) const;
+        bool shouldCollapseMarginBeforeWithParentMarginBefore(const Box&) const;
+        bool shouldCollapseMarginAfterWithParentMarginAfter(const Box&) const;
 
         const BlockFormattingContext& formattingContext() const { return downcast<BlockFormattingContext>(FormattingContext::Quirks::formattingContext()); }
         BlockFormattingContext::Geometry geometry() const { return formattingContext().geometry(); }

Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextQuirks.cpp (263901 => 263902)


--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextQuirks.cpp	2020-07-03 16:55:41 UTC (rev 263901)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextQuirks.cpp	2020-07-03 18:32:41 UTC (rev 263902)
@@ -104,7 +104,17 @@
     return layoutState().inQuirksMode() && isQuirkContainer(layoutBox);
 }
 
+bool BlockFormattingContext::Quirks::shouldCollapseMarginBeforeWithParentMarginBefore(const Box& layoutBox) const
+{
+    return layoutState().inQuirksMode() && layoutBox.style().hasMarginBeforeQuirk() && isQuirkContainer(layoutBox.containingBlock());
 }
+
+bool BlockFormattingContext::Quirks::shouldCollapseMarginAfterWithParentMarginAfter(const Box& layoutBox) const
+{
+    return layoutState().inQuirksMode() && layoutBox.style().hasMarginAfterQuirk() && isQuirkContainer(layoutBox.containingBlock());
 }
 
+}
+}
+
 #endif

Modified: trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp (263901 => 263902)


--- trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp	2020-07-03 16:55:41 UTC (rev 263901)
+++ trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp	2020-07-03 18:32:41 UTC (rev 263902)
@@ -116,6 +116,9 @@
     // https://www.w3.org/TR/CSS21/box.html#collapsing-margins
     ASSERT(layoutBox.isBlockLevelBox());
 
+    if (formattingContext().quirks().shouldCollapseMarginBeforeWithParentMarginBefore(layoutBox))
+        return true;
+
     // Margins between a floated box and any other box do not collapse.
     if (layoutBox.isFloatingPositioned())
         return false;
@@ -251,6 +254,9 @@
 {
     ASSERT(layoutBox.isBlockLevelBox());
 
+    if (formattingContext().quirks().shouldCollapseMarginAfterWithParentMarginAfter(layoutBox))
+        return true;
+
     // Margins between a floated box and any other box do not collapse.
     if (layoutBox.isFloatingPositioned())
         return false;
@@ -592,7 +598,9 @@
         return { { marginValue(positiveAndNegativeVerticalMargin.before), marginValue(positiveAndNegativeVerticalMargin.after), marginsCollapseThrough }, positiveAndNegativeVerticalMargin };
     if (hasCollapsedMarginBefore)
         return { { marginValue(positiveAndNegativeVerticalMargin.before), { }, false }, positiveAndNegativeVerticalMargin };
-    return { { { }, marginValue(positiveAndNegativeVerticalMargin.after), false }, positiveAndNegativeVerticalMargin };
+    if (hasCollapsedMarginAfter)
+        return { { { }, marginValue(positiveAndNegativeVerticalMargin.after), false }, positiveAndNegativeVerticalMargin };
+    return { { { }, { }, false }, positiveAndNegativeVerticalMargin };
 }
 
 }

Modified: trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.h (263901 => 263902)


--- trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.h	2020-07-03 16:55:41 UTC (rev 263901)
+++ trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.h	2020-07-03 18:32:41 UTC (rev 263902)
@@ -79,6 +79,18 @@
         const TableGrid& m_grid;
     };
     TableFormattingContext::Geometry geometry() const { return Geometry(*this, formattingState().tableGrid()); }
+
+    class Quirks : public FormattingContext::Quirks {
+    public:
+        Quirks(const TableFormattingContext&);
+
+        bool shouldIgnoreChildContentVerticalMargin(const ContainerBox&) const;
+
+        const TableFormattingContext& formattingContext() const { return downcast<TableFormattingContext>(FormattingContext::Quirks::formattingContext()); }
+        TableFormattingContext::Geometry geometry() const { return formattingContext().geometry(); }
+    };
+    TableFormattingContext::Quirks quirks() const { return Quirks(*this); }
+
     TableFormattingContext::TableLayout tableLayout() const { return TableLayout(*this, formattingState().tableGrid()); }
 
     IntrinsicWidthConstraints computedIntrinsicWidthConstraints() override;
@@ -100,8 +112,13 @@
 {
 }
 
+inline TableFormattingContext::Quirks::Quirks(const TableFormattingContext& tableFormattingContext)
+    : FormattingContext::Quirks(tableFormattingContext)
+{
 }
+
 }
+}
 
 SPECIALIZE_TYPE_TRAITS_LAYOUT_FORMATTING_CONTEXT(TableFormattingContext, isTableFormattingContext())
 

Modified: trunk/Source/WebCore/layout/tableformatting/TableFormattingContextGeometry.cpp (263901 => 263902)


--- trunk/Source/WebCore/layout/tableformatting/TableFormattingContextGeometry.cpp	2020-07-03 16:55:41 UTC (rev 263901)
+++ trunk/Source/WebCore/layout/tableformatting/TableFormattingContextGeometry.cpp	2020-07-03 18:32:41 UTC (rev 263902)
@@ -41,7 +41,21 @@
 LayoutUnit TableFormattingContext::Geometry::cellHeigh(const ContainerBox& cellBox) const
 {
     ASSERT(cellBox.isInFlow());
-    return std::max(computedHeight(cellBox).valueOr(0_lu), contentHeightForFormattingContextRoot(cellBox));
+    auto contentHeight = LayoutUnit { };
+    if (formattingContext().quirks().shouldIgnoreChildContentVerticalMargin(cellBox)) {
+        ASSERT(cellBox.firstInFlowChild());
+        auto formattingContext = this->formattingContext();
+        auto& firstInFlowChild = *cellBox.firstInFlowChild();
+        auto& lastInFlowChild = *cellBox.lastInFlowChild();
+        auto& firstInFlowChildGeometry = formattingContext.geometryForBox(firstInFlowChild, EscapeReason::NeedsGeometryFromEstablishedFormattingContext);
+        auto& lastInFlowChildGeometry = formattingContext.geometryForBox(lastInFlowChild, EscapeReason::NeedsGeometryFromEstablishedFormattingContext);
+
+        auto top = firstInFlowChild.style().hasMarginBeforeQuirk() ? firstInFlowChildGeometry.top() : firstInFlowChildGeometry.rectWithMargin().top();
+        auto bottom = lastInFlowChild.style().hasMarginAfterQuirk() ? lastInFlowChildGeometry.bottom() : lastInFlowChildGeometry.rectWithMargin().bottom();
+        contentHeight = bottom - top;
+    } else
+        contentHeight = contentHeightForFormattingContextRoot(cellBox);
+    return std::max(computedHeight(cellBox).valueOr(0_lu), contentHeight);
 }
 
 Edges TableFormattingContext::Geometry::computedCellBorder(const TableGrid::Cell& cell) const

Added: trunk/Source/WebCore/layout/tableformatting/TableFormattingContextQuirks.cpp (0 => 263902)


--- trunk/Source/WebCore/layout/tableformatting/TableFormattingContextQuirks.cpp	                        (rev 0)
+++ trunk/Source/WebCore/layout/tableformatting/TableFormattingContextQuirks.cpp	2020-07-03 18:32:41 UTC (rev 263902)
@@ -0,0 +1,57 @@
+/*
+ * 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 "TableFormattingContext.h"
+
+#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
+
+#include "LayoutBox.h"
+#include "LayoutContainerBox.h"
+#include "LayoutState.h"
+
+namespace WebCore {
+namespace Layout {
+
+bool TableFormattingContext::Quirks::shouldIgnoreChildContentVerticalMargin(const ContainerBox& cellBox) const
+{
+    // Normally BFC root content height takes the margin box of the child content as vertical margins don't collapse with BFC roots,
+    // but table cell boxes do collapse their (non-existing) margins with child quirk margins (so much quirk), so here we check
+    // if the content height should include margins or not.
+    // e.g <table><tr><td><p>text content</td></tr></table> <- <p>'s quirk margin collapses with the <td> so its content
+    // height should not include vertical margins.
+    if (!layoutState().inQuirksMode())
+        return false;
+    if (cellBox.establishesInlineFormattingContext())
+        return false;
+    if (!cellBox.hasInFlowChild())
+        return false;
+    return cellBox.firstInFlowChild()->style().hasMarginBeforeQuirk() || cellBox.lastInFlowChild()->style().hasMarginAfterQuirk();
+}
+
+}
+}
+
+#endif
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to