[LFC][TFC] Internal table boxes should take collapsed border into account
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 May 2020 15:34:24 +0000 (15:34 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 May 2020 15:34:24 +0000 (15:34 +0000)
https://bugs.webkit.org/show_bug.cgi?id=212135

Source/WebCore:

Reviewed by Antti Koivisto.

Use the collapsed border value to compute the borders for sections, rows and cells.
The collapsed border is propagated to the table box and the adjacent cell boxes.

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

* layout/LayoutUnits.h:
(WebCore::Layout::operator/):
* layout/blockformatting/tablewrapper/TableWrapperBlockFormattingContext.cpp:
(WebCore::Layout::TableWrapperBlockFormattingContext::computeBorderAndPaddingForTableBox):
* layout/tableformatting/TableFormattingContext.cpp:
(WebCore::Layout::TableFormattingContext::setUsedGeometryForRows):
(WebCore::Layout::TableFormattingContext::setUsedGeometryForSections):
(WebCore::Layout::TableFormattingContext::layoutCell):
* layout/tableformatting/TableGrid.h:
(WebCore::Layout::TableGrid::setCollapsedBorder):
(WebCore::Layout::TableGrid::collapsedBorder const):

LayoutTests:

Reviewed by Antti Koivisto.

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

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

LayoutTests/ChangeLog
LayoutTests/fast/layoutformattingcontext/table-simple-border-collapse-expected.html [new file with mode: 0644]
LayoutTests/fast/layoutformattingcontext/table-simple-border-collapse.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/layout/LayoutUnits.h
Source/WebCore/layout/blockformatting/tablewrapper/TableWrapperBlockFormattingContext.cpp
Source/WebCore/layout/tableformatting/TableFormattingContext.cpp
Source/WebCore/layout/tableformatting/TableGrid.h

index 3857898..c4ac8c8 100644 (file)
@@ -1,3 +1,13 @@
+2020-05-20  Alan Kinsley  <zalan@apple.com>
+
+        [LFC][TFC] Internal table boxes should take collapsed border into account
+        https://bugs.webkit.org/show_bug.cgi?id=212135
+
+        Reviewed by Antti Koivisto.
+
+        * fast/layoutformattingcontext/table-simple-border-collapse-expected.html: Added.
+        * fast/layoutformattingcontext/table-simple-border-collapse.html: Added.
+
 2020-05-20  Zan Dobersek  <zdobersek@igalia.com>
 
         Unreviewed WPE gardening. Enabling the remaining unskippable CSS3 tests
diff --git a/LayoutTests/fast/layoutformattingcontext/table-simple-border-collapse-expected.html b/LayoutTests/fast/layoutformattingcontext/table-simple-border-collapse-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-collapse.html b/LayoutTests/fast/layoutformattingcontext/table-simple-border-collapse.html
new file mode 100644 (file)
index 0000000..f452f7d
--- /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: 10px solid green;
+    padding: 0px;
+}
+</style>
+<table><tr><td></td></tr></tbody></table>
index 2f46e19..9e9aa7f 100644 (file)
@@ -1,3 +1,27 @@
+2020-05-20  Zalan Bujtas  <zalan@apple.com>
+
+        [LFC][TFC] Internal table boxes should take collapsed border into account
+        https://bugs.webkit.org/show_bug.cgi?id=212135
+
+        Reviewed by Antti Koivisto.
+
+        Use the collapsed border value to compute the borders for sections, rows and cells.
+        The collapsed border is propagated to the table box and the adjacent cell boxes.  
+
+        Test: fast/layoutformattingcontext/table-simple-border-collapse.html
+
+        * layout/LayoutUnits.h:
+        (WebCore::Layout::operator/):
+        * layout/blockformatting/tablewrapper/TableWrapperBlockFormattingContext.cpp:
+        (WebCore::Layout::TableWrapperBlockFormattingContext::computeBorderAndPaddingForTableBox):
+        * layout/tableformatting/TableFormattingContext.cpp:
+        (WebCore::Layout::TableFormattingContext::setUsedGeometryForRows):
+        (WebCore::Layout::TableFormattingContext::setUsedGeometryForSections):
+        (WebCore::Layout::TableFormattingContext::layoutCell):
+        * layout/tableformatting/TableGrid.h:
+        (WebCore::Layout::TableGrid::setCollapsedBorder):
+        (WebCore::Layout::TableGrid::collapsedBorder const):
+
 2020-05-20  Youenn Fablet  <youenn@apple.com>
 
         [Mac] Use preferedPixelBufferFormat for AVVideoCaptureSource
index 6260f8c..58c096d 100644 (file)
@@ -131,6 +131,11 @@ struct Edges {
     VerticalEdges vertical;
 };
 
+inline Edges operator/(const Edges& edge, size_t value)
+{
+    return { { edge.horizontal.left / value, edge.horizontal.right / value }, { edge.vertical.top / value, edge.vertical.bottom / value } };
+}
+
 struct ContentWidthAndMargin {
     LayoutUnit contentWidth;
     UsedHorizontalMargin usedMargin;
index 0fc1b3d..08122f7 100644 (file)
@@ -110,10 +110,11 @@ void TableWrapperBlockFormattingContext::computeBorderAndPaddingForTableBox(cons
             topBorder = std::max(topBorder, geometry().computedBorder(boxInFirstRox).vertical.top);
             bottomBorder = std::max(bottomBorder, geometry().computedBorder(boxInLastRow).vertical.bottom);
         }
-        auto collapsedBorder = Edges { { leftBorder / 2, rightBorder / 2 }, { topBorder / 2, bottomBorder / 2 } };
+        auto collapsedBorder = Edges { { leftBorder, rightBorder }, { topBorder, bottomBorder } };
+        grid.setCollapsedBorder(collapsedBorder);
 
         auto& displayBox = formattingState().displayBox(tableBox);
-        displayBox.setBorder(collapsedBorder);
+        displayBox.setBorder(collapsedBorder / 2);
         displayBox.setPadding(geometry().computedPadding(tableBox, horizontalConstraints.logicalWidth));
         return;
     }
index ff97cbc..2a8b2e7 100644 (file)
@@ -115,10 +115,25 @@ void TableFormattingContext::setUsedGeometryForRows(LayoutUnit availableHorizont
 
     auto rowWidth = grid.columns().logicalWidth() + 2 * grid.horizontalSpacing();
     auto rowLogicalTop = grid.verticalSpacing();
-    for (auto& row : rows) {
+    for (size_t rowIndex = 0; rowIndex < rows.size(); ++rowIndex) {
+        auto& row = rows[rowIndex];
         auto& rowBox = row.box();
         auto& rowDisplayBox = formattingState().displayBox(rowBox);
-        computeBorderAndPadding(rowBox, HorizontalConstraints { { }, availableHorizontalSpace });
+
+        auto computedRowBorder = [&] {
+            auto border = geometry().computedBorder(rowBox);
+            if (!grid.collapsedBorder())
+                return border;
+            // Border collapsing delegates borders to table/cells.
+            border.horizontal = { };
+            if (!rowIndex)
+                border.vertical.top = { };
+            if (rowIndex == rows.size() - 1)
+                border.vertical.bottom = { };
+            return border;
+        }();
+        rowDisplayBox.setBorder(computedRowBorder);
+        rowDisplayBox.setPadding(geometry().computedPadding(rowBox, availableHorizontalSpace));
         // Internal table elements do not have margins.
         rowDisplayBox.setHorizontalMargin({ });
         rowDisplayBox.setHorizontalComputedMargin({ });
@@ -158,7 +173,9 @@ void TableFormattingContext::setUsedGeometryForSections(const ConstraintsForInFl
     auto logicalTop = constraints.vertical.logicalTop;
     for (auto& section : childrenOfType<ContainerBox>(root())) {
         auto& sectionDisplayBox = formattingState().displayBox(section);
-        computeBorderAndPadding(section, HorizontalConstraints { { }, constraints.horizontal.logicalWidth });
+        // FIXME: Multiple sections can have their own borders.
+        sectionDisplayBox.setBorder(grid.collapsedBorder() ? Edges(): geometry().computedBorder(section));
+        sectionDisplayBox.setPadding(geometry().computedPadding(section, constraints.horizontal.logicalWidth));
         // Internal table elements do not have margins.
         sectionDisplayBox.setHorizontalMargin({ });
         sectionDisplayBox.setHorizontalComputedMargin({ });
@@ -178,17 +195,34 @@ void TableFormattingContext::layoutCell(const TableGrid::Cell& cell, LayoutUnit
 {
     ASSERT(cell.box().establishesBlockFormattingContext());
 
+    auto& grid = formattingState().tableGrid();
     auto& cellBox = cell.box();
     auto& cellDisplayBox = formattingState().displayBox(cellBox);
 
-    computeBorderAndPadding(cellBox, HorizontalConstraints { { }, availableHorizontalSpace });
+    auto computedCellBorder = [&] {
+        auto border = geometry().computedBorder(cellBox);
+        auto collapsedBorder = grid.collapsedBorder();
+        if (!collapsedBorder)
+            return border;
+        auto cellPosition = cell.position();
+        if (!cellPosition.column)
+            border.horizontal.left = collapsedBorder->horizontal.left / 2;
+        if (cellPosition.column == grid.columns().size() - 1)
+            border.horizontal.right = collapsedBorder->horizontal.right / 2;
+        if (!cellPosition.row)
+            border.vertical.top = collapsedBorder->vertical.top / 2;
+        if (cellPosition.row == grid.rows().size() - 1)
+            border.vertical.bottom = collapsedBorder->vertical.bottom / 2;
+        return border;
+    }();
+    cellDisplayBox.setBorder(computedCellBorder);
+    cellDisplayBox.setPadding(geometry().computedPadding(cellBox, availableHorizontalSpace));
     // Internal table elements do not have margins.
     cellDisplayBox.setHorizontalMargin({ });
     cellDisplayBox.setHorizontalComputedMargin({ });
     cellDisplayBox.setVerticalMargin({ { }, { } });
 
     auto availableSpaceForContent = [&] {
-        auto& grid = formattingState().tableGrid();
         auto& columnList = grid.columns().list();
         auto logicalWidth = LayoutUnit { };
         for (auto columnIndex = cell.startColumn(); columnIndex < cell.endColumn(); ++columnIndex)
index 16249b7..c3da373 100644 (file)
@@ -55,6 +55,9 @@ public:
     void setVerticalSpacing(LayoutUnit verticalSpacing) { m_verticalSpacing = verticalSpacing; }
     LayoutUnit verticalSpacing() const { return m_verticalSpacing; }
 
+    void setCollapsedBorder(const Edges& collapsedBorder) { m_collapsedBorder = collapsedBorder; }
+    Optional<Edges> collapsedBorder() const { return m_collapsedBorder; }
+
     void setWidthConstraints(FormattingContext::IntrinsicWidthConstraints intrinsicWidthConstraints) { m_intrinsicWidthConstraints = intrinsicWidthConstraints; }
     Optional<FormattingContext::IntrinsicWidthConstraints> widthConstraints() const { return m_intrinsicWidthConstraints; }
 
@@ -228,6 +231,7 @@ private:
     LayoutUnit m_horizontalSpacing;
     LayoutUnit m_verticalSpacing;
     Optional<FormattingContext::IntrinsicWidthConstraints> m_intrinsicWidthConstraints;
+    Optional<Edges> m_collapsedBorder;
 };
 
 }