Title: [258480] trunk
Revision
258480
Author
[email protected]
Date
2020-03-15 08:33:24 -0700 (Sun, 15 Mar 2020)

Log Message

[LFC][TFC] Add basic column span support for content box width
https://bugs.webkit.org/show_bug.cgi?id=209120
<rdar://problem/60463424>

Reviewed by Antti Koivisto.

Source/WebCore:

Take the column spanning into account when computing the content width for the table cell.
[content box width = column width(1) + column width(2) + .. + column width(spanning value) + ((spanning value - 1) * horizontal spacing)]

Test: fast/layoutformattingcontext/table-colspan-simple.html

* layout/tableformatting/TableFormattingContext.cpp:
(WebCore::Layout::TableFormattingContext::layoutInFlowContent):
(WebCore::Layout::TableFormattingContext::layoutTableCellBox):
(WebCore::Layout::TableFormattingContext::positionTableCells):
* layout/tableformatting/TableFormattingContext.h:
* layout/tableformatting/TableGrid.cpp:
(WebCore::Layout::TableGrid::appendCell):
* layout/tableformatting/TableGrid.h:
(WebCore::Layout::TableGrid::CellInfo::startColumn const):
(WebCore::Layout::TableGrid::CellInfo::endColumn const):
(WebCore::Layout::TableGrid::CellInfo::startRow const):
(WebCore::Layout::TableGrid::CellInfo::endRow const):
(WebCore::Layout::TableGrid::CellInfo::columnSpan const):
(WebCore::Layout::TableGrid::CellInfo::rowSpan const):

LayoutTests:

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

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (258479 => 258480)


--- trunk/LayoutTests/ChangeLog	2020-03-15 10:51:04 UTC (rev 258479)
+++ trunk/LayoutTests/ChangeLog	2020-03-15 15:33:24 UTC (rev 258480)
@@ -1,3 +1,14 @@
+2020-03-15  Zalan Bujtas  <[email protected]>
+
+        [LFC][TFC] Add basic column span support for content box width
+        https://bugs.webkit.org/show_bug.cgi?id=209120
+        <rdar://problem/60463424>
+
+        Reviewed by Antti Koivisto.
+
+        * fast/layoutformattingcontext/table-colspan-simple-expected.html: Added.
+        * fast/layoutformattingcontext/table-colspan-simple.html: Added.
+
 2020-03-14  Zalan Bujtas  <[email protected]>
 
         [LFC][TFC] Fill in the gaps with anonymous table cell boxes

Added: trunk/LayoutTests/fast/layoutformattingcontext/table-colspan-simple-expected.html (0 => 258480)


--- trunk/LayoutTests/fast/layoutformattingcontext/table-colspan-simple-expected.html	                        (rev 0)
+++ trunk/LayoutTests/fast/layoutformattingcontext/table-colspan-simple-expected.html	2020-03-15 15:33:24 UTC (rev 258480)
@@ -0,0 +1,20 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ internal:LayoutFormattingContextEnabled=true internal:LayoutFormattingContextIntegrationEnabled=false ] -->
+<style>
+body {
+    font-size: 10px;
+    padding: 3px;
+}
+span {
+    margin-right: 4px;
+}
+div {
+    margin-bottom: 4px;
+}
+.spacing {
+    margin-top: 6px;
+}
+</style>
+<div><span>1</span><span>2</span><span>3</span><span>4</span></div>
+<div><span>1</span><span style="margin-left: 9px">2</span></div>
+<div><span>1</span><span style="margin-left: 18px">2</span></div>
+<div>1</div>

Added: trunk/LayoutTests/fast/layoutformattingcontext/table-colspan-simple.html (0 => 258480)


--- trunk/LayoutTests/fast/layoutformattingcontext/table-colspan-simple.html	                        (rev 0)
+++ trunk/LayoutTests/fast/layoutformattingcontext/table-colspan-simple.html	2020-03-15 15:33:24 UTC (rev 258480)
@@ -0,0 +1,12 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ internal:LayoutFormattingContextEnabled=true internal:LayoutFormattingContextIntegrationEnabled=false ] -->
+<style>
+table {
+    font-size: 10px;
+}
+</style>
+<table>
+<tr><td>1</td><td>2</td><td>3</td><td>4</td></tr>
+<tr><td colspan=2>1</td><td colspan=2>2</td></tr>
+<tr><td colspan=3>1</td><td>2</td></tr>
+<tr><td colspan=4>1</td></tr>
+</table>

Modified: trunk/Source/WebCore/ChangeLog (258479 => 258480)


--- trunk/Source/WebCore/ChangeLog	2020-03-15 10:51:04 UTC (rev 258479)
+++ trunk/Source/WebCore/ChangeLog	2020-03-15 15:33:24 UTC (rev 258480)
@@ -1,3 +1,31 @@
+2020-03-15  Zalan Bujtas  <[email protected]>
+
+        [LFC][TFC] Add basic column span support for content box width
+        https://bugs.webkit.org/show_bug.cgi?id=209120
+        <rdar://problem/60463424>
+
+        Reviewed by Antti Koivisto.
+
+        Take the column spanning into account when computing the content width for the table cell.
+        [content box width = column width(1) + column width(2) + .. + column width(spanning value) + ((spanning value - 1) * horizontal spacing)]
+
+        Test: fast/layoutformattingcontext/table-colspan-simple.html
+
+        * layout/tableformatting/TableFormattingContext.cpp:
+        (WebCore::Layout::TableFormattingContext::layoutInFlowContent):
+        (WebCore::Layout::TableFormattingContext::layoutTableCellBox):
+        (WebCore::Layout::TableFormattingContext::positionTableCells):
+        * layout/tableformatting/TableFormattingContext.h:
+        * layout/tableformatting/TableGrid.cpp:
+        (WebCore::Layout::TableGrid::appendCell):
+        * layout/tableformatting/TableGrid.h:
+        (WebCore::Layout::TableGrid::CellInfo::startColumn const):
+        (WebCore::Layout::TableGrid::CellInfo::endColumn const):
+        (WebCore::Layout::TableGrid::CellInfo::startRow const):
+        (WebCore::Layout::TableGrid::CellInfo::endRow const):
+        (WebCore::Layout::TableGrid::CellInfo::columnSpan const):
+        (WebCore::Layout::TableGrid::CellInfo::rowSpan const):
+
 2020-03-15  Yusuke Suzuki  <[email protected]>
 
         Should not use variable-length-array (VLA)

Modified: trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp (258479 => 258480)


--- trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp	2020-03-15 10:51:04 UTC (rev 258479)
+++ trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp	2020-03-15 15:33:24 UTC (rev 258480)
@@ -76,14 +76,13 @@
     }
 
     // 2. Layout each table cell (and compute row height as well).
-    auto& columnList = columnsContext.columns();
     auto& cellList = grid.cells();
     ASSERT(!cellList.isEmpty());
     for (auto& cell : cellList) {
         auto& cellLayoutBox = cell->tableCellBox;
-        layoutTableCellBox(cellLayoutBox, columnList.at(cell->position.x()), invalidationState, horizontalConstraints);
+        layoutTableCellBox(*cell, invalidationState, horizontalConstraints);
         // FIXME: Add support for column and row spanning and this requires a 2 pass layout.
-        auto& row = grid.rows().at(cell->position.y());
+        auto& row = grid.rows().at(cell->startRow());
         row.setLogicalHeight(std::max(row.logicalHeight(), geometryForBox(cellLayoutBox).marginBoxHeight()));
     }
     // This is after the second pass when cell heights are fully computed.
@@ -99,8 +98,9 @@
     setComputedGeometryForRows();
 }
 
-void TableFormattingContext::layoutTableCellBox(const Box& cellLayoutBox, const TableGrid::Column& column, InvalidationState& invalidationState, const HorizontalConstraints& horizontalConstraints)
+void TableFormattingContext::layoutTableCellBox(const TableGrid::CellInfo& cell, InvalidationState& invalidationState, const HorizontalConstraints& horizontalConstraints)
 {
+    auto& cellLayoutBox = cell.tableCellBox;
     computeBorderAndPadding(cellLayoutBox, horizontalConstraints);
     // Margins do not apply to internal table elements.
     auto& cellDisplayBox = formattingState().displayBox(cellLayoutBox);
@@ -108,7 +108,17 @@
     cellDisplayBox.setHorizontalComputedMargin({ });
     // Don't know the actual position yet.
     cellDisplayBox.setTopLeft({ });
-    cellDisplayBox.setContentBoxWidth(column.logicalWidth() - cellDisplayBox.horizontalMarginBorderAndPadding());
+    auto contentWidth = [&] {
+        auto& grid = formattingState().tableGrid();
+        auto& columnList = grid.columnsContext().columns();
+        auto logicalWidth = LayoutUnit { };
+        for (auto columnIndex = cell.startColumn(); columnIndex < cell.endColumn(); ++columnIndex)
+            logicalWidth += columnList.at(columnIndex).logicalWidth();
+        // No column spacing when spanning.
+        logicalWidth += (cell.columnSpan() - 1) * grid.horizontalSpacing();
+        return logicalWidth - cellDisplayBox.horizontalMarginBorderAndPadding();
+    }();
+    cellDisplayBox.setContentBoxWidth(contentWidth);
 
     ASSERT(cellLayoutBox.establishesBlockFormattingContext());
     if (is<ContainerBox>(cellLayoutBox) && downcast<ContainerBox>(cellLayoutBox).hasInFlowOrFloatingChild()) {
@@ -130,8 +140,8 @@
     auto& columnList = grid.columnsContext().columns();
     for (auto& cell : grid.cells()) {
         auto& cellDisplayBox = formattingState().displayBox(cell->tableCellBox);
-        cellDisplayBox.setTop(rowList.at(cell->position.y()).logicalTop());
-        cellDisplayBox.setLeft(columnList.at(cell->position.x()).logicalLeft());
+        cellDisplayBox.setTop(rowList.at(cell->startRow()).logicalTop());
+        cellDisplayBox.setLeft(columnList.at(cell->startColumn()).logicalLeft());
     }
 }
 

Modified: trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.h (258479 => 258480)


--- trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.h	2020-03-15 10:51:04 UTC (rev 258479)
+++ trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.h	2020-03-15 15:33:24 UTC (rev 258480)
@@ -59,7 +59,7 @@
     TableFormattingContext::Geometry geometry() const { return Geometry(*this); }
 
     IntrinsicWidthConstraints computedIntrinsicWidthConstraints() override;
-    void layoutTableCellBox(const Box& cellLayoutBox, const TableGrid::Column&, InvalidationState&, const HorizontalConstraints&);
+    void layoutTableCellBox(const TableGrid::CellInfo&, InvalidationState&, const HorizontalConstraints&);
     void positionTableCells();
     void setComputedGeometryForRows();
     void setComputedGeometryForSections();

Modified: trunk/Source/WebCore/layout/tableformatting/TableGrid.cpp (258479 => 258480)


--- trunk/Source/WebCore/layout/tableformatting/TableGrid.cpp	2020-03-15 10:51:04 UTC (rev 258479)
+++ trunk/Source/WebCore/layout/tableformatting/TableGrid.cpp	2020-03-15 15:33:24 UTC (rev 258480)
@@ -142,11 +142,11 @@
             initialSlotPosition.move(1, 0);
         }
     }
-    auto cellInfo = makeUnique<CellInfo>(tableCellBox, initialSlotPosition, CellSize { rowSpan, columnSpan });
+    auto cellInfo = makeUnique<CellInfo>(tableCellBox, initialSlotPosition, CellSize { columnSpan, rowSpan });
     // Row and column spanners create additional slots.
     for (int row = 1; row <= rowSpan; ++row) {
         for (int column = 1; column <= columnSpan; ++column) {
-            auto position = SlotPosition { initialSlotPosition.x() + row - 1, initialSlotPosition.y() + column - 1 };
+            auto position = SlotPosition { initialSlotPosition.x() + column - 1, initialSlotPosition.y() + row - 1 };
             ASSERT(!m_slotMap.contains(position));
             m_slotMap.add(position, makeUnique<SlotInfo>(*cellInfo));
         }

Modified: trunk/Source/WebCore/layout/tableformatting/TableGrid.h (258479 => 258480)


--- trunk/Source/WebCore/layout/tableformatting/TableGrid.h	2020-03-15 10:51:04 UTC (rev 258479)
+++ trunk/Source/WebCore/layout/tableformatting/TableGrid.h	2020-03-15 15:33:24 UTC (rev 258480)
@@ -62,6 +62,15 @@
         WTF_MAKE_STRUCT_FAST_ALLOCATED;
         CellInfo(const Box& tableCellBox, SlotPosition, CellSize);
 
+        size_t startColumn() const { return position.x(); }
+        size_t endColumn() const { return position.x() + size.width(); }
+
+        size_t startRow() const { return position.y(); }
+        size_t endRow() const { return position.y() + size.height(); }
+
+        size_t columnSpan() const { return size.width(); }
+        size_t rowSpan() const { return size.height(); }
+
         const Box& tableCellBox;
         SlotPosition position;
         CellSize size;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to