[LFC][TFC] Preferred width computation should take border collapsing into account
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 May 2020 01:58:33 +0000 (01:58 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 May 2020 01:58:33 +0000 (01:58 +0000)
https://bugs.webkit.org/show_bug.cgi?id=212141

Reviewed by Antti Koivisto.

Source/WebCore:

Test: fast/layoutformattingcontext/table-simple-border-collapse2.html

* layout/tableformatting/TableFormattingContext.cpp:
(WebCore::Layout::TableFormattingContext::computedPreferredWidthForColumns):
* layout/tableformatting/TableFormattingContext.h:
(WebCore::Layout::TableFormattingContext::Geometry::Geometry):
* layout/tableformatting/TableFormattingContextGeometry.cpp:
(WebCore::Layout::TableFormattingContext::Geometry::intrinsicWidthConstraintsForCell):

LayoutTests:

* fast/layoutformattingcontext/table-simple-border-collapse2-expected.html: Added.
* fast/layoutformattingcontext/table-simple-border-collapse2.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261980 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/layoutformattingcontext/table-simple-border-collapse2-expected.html [new file with mode: 0644]
LayoutTests/fast/layoutformattingcontext/table-simple-border-collapse2.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/layout/tableformatting/TableFormattingContext.cpp
Source/WebCore/layout/tableformatting/TableFormattingContext.h
Source/WebCore/layout/tableformatting/TableFormattingContextGeometry.cpp

index 6e03748..0232488 100644 (file)
@@ -1,5 +1,15 @@
 2020-05-20  Zalan Bujtas  <zalan@apple.com>
 
+        [LFC][TFC] Preferred width computation should take border collapsing into account
+        https://bugs.webkit.org/show_bug.cgi?id=212141
+
+        Reviewed by Antti Koivisto.
+
+        * fast/layoutformattingcontext/table-simple-border-collapse2-expected.html: Added.
+        * fast/layoutformattingcontext/table-simple-border-collapse2.html: Added.
+
+2020-05-20  Zalan Bujtas  <zalan@apple.com>
+
         Repaint issues when the login field collapses on music.apple.com
         https://bugs.webkit.org/show_bug.cgi?id=212101
         <rdar://problem/62874369>
diff --git a/LayoutTests/fast/layoutformattingcontext/table-simple-border-collapse2-expected.html b/LayoutTests/fast/layoutformattingcontext/table-simple-border-collapse2-expected.html
new file mode 100644 (file)
index 0000000..2db524a
--- /dev/null
@@ -0,0 +1,9 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ internal:LayoutFormattingContextEnabled=true internal:LayoutFormattingContextIntegrationEnabled=false ] -->
+<style>
+div {
+    height: 10px;
+    width: 10px;
+    border: 20px solid green;
+}
+</style>
+<div></div>
diff --git a/LayoutTests/fast/layoutformattingcontext/table-simple-border-collapse2.html b/LayoutTests/fast/layoutformattingcontext/table-simple-border-collapse2.html
new file mode 100644 (file)
index 0000000..f9fe435
--- /dev/null
@@ -0,0 +1,15 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ internal:LayoutFormattingContextEnabled=true internal:LayoutFormattingContextIntegrationEnabled=false ] -->
+<style>
+table {
+    border-collapse: collapse;
+    border: 20px solid green;
+}
+
+td {
+    width: 10px;
+    height: 10px;
+    border: 1px solid green;
+    padding: 0px;
+}
+</style>
+<table><tr><td></td></tr></tbody></table>
index 40b93e7..29ac19f 100644 (file)
@@ -1,5 +1,21 @@
 2020-05-20  Zalan Bujtas  <zalan@apple.com>
 
+        [LFC][TFC] Preferred width computation should take border collapsing into account
+        https://bugs.webkit.org/show_bug.cgi?id=212141
+
+        Reviewed by Antti Koivisto.
+
+        Test: fast/layoutformattingcontext/table-simple-border-collapse2.html
+
+        * layout/tableformatting/TableFormattingContext.cpp:
+        (WebCore::Layout::TableFormattingContext::computedPreferredWidthForColumns):
+        * layout/tableformatting/TableFormattingContext.h:
+        (WebCore::Layout::TableFormattingContext::Geometry::Geometry):
+        * layout/tableformatting/TableFormattingContextGeometry.cpp:
+        (WebCore::Layout::TableFormattingContext::Geometry::intrinsicWidthConstraintsForCell):
+
+2020-05-20  Zalan Bujtas  <zalan@apple.com>
+
         Repaint issues when the login field collapses on music.apple.com
         https://bugs.webkit.org/show_bug.cgi?id=212101
         <rdar://problem/62874369>
index 2a8b2e7..a4c0037 100644 (file)
@@ -321,7 +321,7 @@ FormattingContext::IntrinsicWidthConstraints TableFormattingContext::computedPre
 
         auto intrinsicWidth = formattingState.intrinsicWidthConstraintsForBox(cellBox);
         if (!intrinsicWidth) {
-            intrinsicWidth = geometry().intrinsicWidthConstraintsForCell(cellBox);
+            intrinsicWidth = geometry().intrinsicWidthConstraintsForCell(*cell);
             formattingState.setIntrinsicWidthConstraintsForBox(cellBox, *intrinsicWidth);
         }
         // Spanner cells put their intrinsic widths on the initial slots.
index 833329d..bf5d2df 100644 (file)
@@ -67,16 +67,17 @@ private:
     public:
         LayoutUnit cellHeigh(const ContainerBox&) const;
         Optional<LayoutUnit> computedColumnWidth(const ContainerBox& columnBox) const;
-        FormattingContext::IntrinsicWidthConstraints intrinsicWidthConstraintsForCell(const ContainerBox& cellBox);
+        FormattingContext::IntrinsicWidthConstraints intrinsicWidthConstraintsForCell(const TableGrid::Cell&);
         InlineLayoutUnit usedBaselineForCell(const ContainerBox& cellBox);
 
     private:
         friend class TableFormattingContext;
-        Geometry(const TableFormattingContext&);
+        Geometry(const TableFormattingContext&, const TableGrid&);
 
         const TableFormattingContext& formattingContext() const { return downcast<TableFormattingContext>(FormattingContext::Geometry::formattingContext()); }
+        const TableGrid& m_grid;
     };
-    TableFormattingContext::Geometry geometry() const { return Geometry(*this); }
+    TableFormattingContext::Geometry geometry() const { return Geometry(*this, formattingState().tableGrid()); }
     TableFormattingContext::TableLayout tableLayout() const { return TableLayout(*this, formattingState().tableGrid()); }
 
     IntrinsicWidthConstraints computedIntrinsicWidthConstraints() override;
@@ -92,8 +93,9 @@ private:
     TableFormattingState& formattingState() { return downcast<TableFormattingState>(FormattingContext::formattingState()); }
 };
 
-inline TableFormattingContext::Geometry::Geometry(const TableFormattingContext& tableFormattingContext)
+inline TableFormattingContext::Geometry::Geometry(const TableFormattingContext& tableFormattingContext, const TableGrid& grid)
     : FormattingContext::Geometry(tableFormattingContext)
+    , m_grid(grid)
 {
 }
 
index d2ccfe9..9b7a16b 100644 (file)
@@ -55,16 +55,22 @@ Optional<LayoutUnit> TableFormattingContext::Geometry::computedColumnWidth(const
     return columnBox.columnWidth();
 }
 
-FormattingContext::IntrinsicWidthConstraints TableFormattingContext::Geometry::intrinsicWidthConstraintsForCell(const ContainerBox& cellBox)
+FormattingContext::IntrinsicWidthConstraints TableFormattingContext::Geometry::intrinsicWidthConstraintsForCell(const TableGrid::Cell& cell)
 {
-    auto fixedMarginBorderAndPadding = [&] {
-        auto& style = cellBox.style();
-        return fixedValue(style.marginStart()).valueOr(0)
-            + LayoutUnit { style.borderLeftWidth() }
-            + fixedValue(style.paddingLeft()).valueOr(0)
-            + fixedValue(style.paddingRight()).valueOr(0)
-            + LayoutUnit { style.borderRightWidth() }
-            + fixedValue(style.marginEnd()).valueOr(0);
+    auto& cellBox = cell.box();
+    auto& style = cellBox.style();
+
+    auto computedHorizontalBorder = [&] {
+        auto leftBorderWidth = LayoutUnit { style.borderLeftWidth() };
+        auto rightBorderWidth = LayoutUnit { style.borderRightWidth() };
+        if (auto collapsedBorder = m_grid.collapsedBorder()) {
+            auto cellPosition = cell.position();
+            if (!cellPosition.column)
+                leftBorderWidth = collapsedBorder->horizontal.left / 2;
+            if (cellPosition.column == m_grid.columns().size() - 1)
+                rightBorderWidth = collapsedBorder->horizontal.right / 2;
+        }
+        return leftBorderWidth + rightBorderWidth;
     };
 
     auto computedIntrinsicWidthConstraints = [&] {
@@ -79,7 +85,12 @@ FormattingContext::IntrinsicWidthConstraints TableFormattingContext::Geometry::i
     };
     // FIXME Check for box-sizing: border-box;
     auto intrinsicWidthConstraints = constrainByMinMaxWidth(cellBox, computedIntrinsicWidthConstraints());
-    intrinsicWidthConstraints.expand(fixedMarginBorderAndPadding());
+    // Expand with border
+    intrinsicWidthConstraints.expand(computedHorizontalBorder());
+    // padding
+    intrinsicWidthConstraints.expand(fixedValue(style.paddingLeft()).valueOr(0) + fixedValue(style.paddingRight()).valueOr(0));
+    // and margin
+    intrinsicWidthConstraints.expand(fixedValue(style.marginStart()).valueOr(0) + fixedValue(style.marginEnd()).valueOr(0));
     return intrinsicWidthConstraints;
 }