Changeset 258480 in webkit


Ignore:
Timestamp:
Mar 15, 2020 8:33:24 AM (4 years ago)
Author:
Alan Bujtas
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.
Location:
trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r258473 r258480  
     12020-03-15  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][TFC] Add basic column span support for content box width
     4        https://bugs.webkit.org/show_bug.cgi?id=209120
     5        <rdar://problem/60463424>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        * fast/layoutformattingcontext/table-colspan-simple-expected.html: Added.
     10        * fast/layoutformattingcontext/table-colspan-simple.html: Added.
     11
    1122020-03-14  Zalan Bujtas  <zalan@apple.com>
    213
  • trunk/Source/WebCore/ChangeLog

    r258478 r258480  
     12020-03-15  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][TFC] Add basic column span support for content box width
     4        https://bugs.webkit.org/show_bug.cgi?id=209120
     5        <rdar://problem/60463424>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        Take the column spanning into account when computing the content width for the table cell.
     10        [content box width = column width(1) + column width(2) + .. + column width(spanning value) + ((spanning value - 1) * horizontal spacing)]
     11
     12        Test: fast/layoutformattingcontext/table-colspan-simple.html
     13
     14        * layout/tableformatting/TableFormattingContext.cpp:
     15        (WebCore::Layout::TableFormattingContext::layoutInFlowContent):
     16        (WebCore::Layout::TableFormattingContext::layoutTableCellBox):
     17        (WebCore::Layout::TableFormattingContext::positionTableCells):
     18        * layout/tableformatting/TableFormattingContext.h:
     19        * layout/tableformatting/TableGrid.cpp:
     20        (WebCore::Layout::TableGrid::appendCell):
     21        * layout/tableformatting/TableGrid.h:
     22        (WebCore::Layout::TableGrid::CellInfo::startColumn const):
     23        (WebCore::Layout::TableGrid::CellInfo::endColumn const):
     24        (WebCore::Layout::TableGrid::CellInfo::startRow const):
     25        (WebCore::Layout::TableGrid::CellInfo::endRow const):
     26        (WebCore::Layout::TableGrid::CellInfo::columnSpan const):
     27        (WebCore::Layout::TableGrid::CellInfo::rowSpan const):
     28
    1292020-03-15  Yusuke Suzuki  <ysuzuki@apple.com>
    230
  • trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp

    r258137 r258480  
    7777
    7878    // 2. Layout each table cell (and compute row height as well).
    79     auto& columnList = columnsContext.columns();
    8079    auto& cellList = grid.cells();
    8180    ASSERT(!cellList.isEmpty());
    8281    for (auto& cell : cellList) {
    8382        auto& cellLayoutBox = cell->tableCellBox;
    84         layoutTableCellBox(cellLayoutBox, columnList.at(cell->position.x()), invalidationState, horizontalConstraints);
     83        layoutTableCellBox(*cell, invalidationState, horizontalConstraints);
    8584        // FIXME: Add support for column and row spanning and this requires a 2 pass layout.
    86         auto& row = grid.rows().at(cell->position.y());
     85        auto& row = grid.rows().at(cell->startRow());
    8786        row.setLogicalHeight(std::max(row.logicalHeight(), geometryForBox(cellLayoutBox).marginBoxHeight()));
    8887    }
     
    10099}
    101100
    102 void TableFormattingContext::layoutTableCellBox(const Box& cellLayoutBox, const TableGrid::Column& column, InvalidationState& invalidationState, const HorizontalConstraints& horizontalConstraints)
    103 {
     101void TableFormattingContext::layoutTableCellBox(const TableGrid::CellInfo& cell, InvalidationState& invalidationState, const HorizontalConstraints& horizontalConstraints)
     102{
     103    auto& cellLayoutBox = cell.tableCellBox;
    104104    computeBorderAndPadding(cellLayoutBox, horizontalConstraints);
    105105    // Margins do not apply to internal table elements.
     
    109109    // Don't know the actual position yet.
    110110    cellDisplayBox.setTopLeft({ });
    111     cellDisplayBox.setContentBoxWidth(column.logicalWidth() - cellDisplayBox.horizontalMarginBorderAndPadding());
     111    auto contentWidth = [&] {
     112        auto& grid = formattingState().tableGrid();
     113        auto& columnList = grid.columnsContext().columns();
     114        auto logicalWidth = LayoutUnit { };
     115        for (auto columnIndex = cell.startColumn(); columnIndex < cell.endColumn(); ++columnIndex)
     116            logicalWidth += columnList.at(columnIndex).logicalWidth();
     117        // No column spacing when spanning.
     118        logicalWidth += (cell.columnSpan() - 1) * grid.horizontalSpacing();
     119        return logicalWidth - cellDisplayBox.horizontalMarginBorderAndPadding();
     120    }();
     121    cellDisplayBox.setContentBoxWidth(contentWidth);
    112122
    113123    ASSERT(cellLayoutBox.establishesBlockFormattingContext());
     
    131141    for (auto& cell : grid.cells()) {
    132142        auto& cellDisplayBox = formattingState().displayBox(cell->tableCellBox);
    133         cellDisplayBox.setTop(rowList.at(cell->position.y()).logicalTop());
    134         cellDisplayBox.setLeft(columnList.at(cell->position.x()).logicalLeft());
     143        cellDisplayBox.setTop(rowList.at(cell->startRow()).logicalTop());
     144        cellDisplayBox.setLeft(columnList.at(cell->startColumn()).logicalLeft());
    135145    }
    136146}
  • trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.h

    r258137 r258480  
    6060
    6161    IntrinsicWidthConstraints computedIntrinsicWidthConstraints() override;
    62     void layoutTableCellBox(const Box& cellLayoutBox, const TableGrid::Column&, InvalidationState&, const HorizontalConstraints&);
     62    void layoutTableCellBox(const TableGrid::CellInfo&, InvalidationState&, const HorizontalConstraints&);
    6363    void positionTableCells();
    6464    void setComputedGeometryForRows();
  • trunk/Source/WebCore/layout/tableformatting/TableGrid.cpp

    r254087 r258480  
    143143        }
    144144    }
    145     auto cellInfo = makeUnique<CellInfo>(tableCellBox, initialSlotPosition, CellSize { rowSpan, columnSpan });
     145    auto cellInfo = makeUnique<CellInfo>(tableCellBox, initialSlotPosition, CellSize { columnSpan, rowSpan });
    146146    // Row and column spanners create additional slots.
    147147    for (int row = 1; row <= rowSpan; ++row) {
    148148        for (int column = 1; column <= columnSpan; ++column) {
    149             auto position = SlotPosition { initialSlotPosition.x() + row - 1, initialSlotPosition.y() + column - 1 };
     149            auto position = SlotPosition { initialSlotPosition.x() + column - 1, initialSlotPosition.y() + row - 1 };
    150150            ASSERT(!m_slotMap.contains(position));
    151151            m_slotMap.add(position, makeUnique<SlotInfo>(*cellInfo));
  • trunk/Source/WebCore/layout/tableformatting/TableGrid.h

    r254087 r258480  
    6262        WTF_MAKE_STRUCT_FAST_ALLOCATED;
    6363        CellInfo(const Box& tableCellBox, SlotPosition, CellSize);
     64
     65        size_t startColumn() const { return position.x(); }
     66        size_t endColumn() const { return position.x() + size.width(); }
     67
     68        size_t startRow() const { return position.y(); }
     69        size_t endRow() const { return position.y() + size.height(); }
     70
     71        size_t columnSpan() const { return size.width(); }
     72        size_t rowSpan() const { return size.height(); }
    6473
    6574        const Box& tableCellBox;
Note: See TracChangeset for help on using the changeset viewer.