Changeset 248596 in webkit


Ignore:
Timestamp:
Aug 13, 2019 10:05:20 AM (5 years ago)
Author:
Alan Bujtas
Message:

[LFC][TFC] Introduce TableGrid
https://bugs.webkit.org/show_bug.cgi?id=200656
<rdar://problem/54240833>

Reviewed by Antti Koivisto.

table grid:
A matrix containing as many rows and columns as needed to describe the position of all the table-rows
and table-cells of a table-root, as determined by the grid-dimensioning algorithm.
Each row of the grid might correspond to a table-row, and each column to a table-column.

slot of the table grid:
A slot (r,c) is an available space created by the intersection of a row r and a column c in the table grid.

https://www.w3.org/TR/css-tables-3/#terminology

  • Sources.txt:
  • WebCore.xcodeproj/project.pbxproj:
  • layout/layouttree/LayoutBox.h:

(WebCore::Layout::Box::isTableHeader const):
(WebCore::Layout::Box::isTableBody const):
(WebCore::Layout::Box::isTableFooter const):

  • layout/layouttree/LayoutTreeBuilder.cpp:

(WebCore::Layout::TreeBuilder::createLayoutBox):

  • layout/tableformatting/TableFormattingContext.cpp:

(WebCore::Layout::TableFormattingContext::layout const):
(WebCore::Layout::TableFormattingContext::ensureTableGrid const):
(WebCore::Layout::TableFormattingContext::computePreferredWidthForColumns const):
(WebCore::Layout::TableFormattingContext::computeTableWidth const):
(WebCore::Layout::TableFormattingContext::distributeAvailabeWidth const):
(WebCore::Layout::TableFormattingContext::computeTableHeight const):
(WebCore::Layout::TableFormattingContext::distributeAvailableHeight const):

  • layout/tableformatting/TableFormattingContext.h:

(WebCore::Layout::TableFormattingContext::formattingState const):

  • layout/tableformatting/TableFormattingState.h:

(WebCore::Layout::TableFormattingState::tableGrid):

  • layout/tableformatting/TableGrid.cpp: Added.

(WebCore::Layout::TableGrid::CellInfo::CellInfo):
(WebCore::Layout::TableGrid::SlotInfo::SlotInfo):
(WebCore::Layout::TableGrid::TableGrid):
(WebCore::Layout::TableGrid::appendCell):
(WebCore::Layout::TableGrid::insertCell):
(WebCore::Layout::TableGrid::removeCell):

  • layout/tableformatting/TableGrid.h: Copied from Source/WebCore/layout/tableformatting/TableFormattingContext.h.
Location:
trunk/Source/WebCore
Files:
1 added
8 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r248594 r248596  
     12019-08-13  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][TFC] Introduce TableGrid
     4        https://bugs.webkit.org/show_bug.cgi?id=200656
     5        <rdar://problem/54240833>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        table grid:
     10        A matrix containing as many rows and columns as needed to describe the position of all the table-rows
     11        and table-cells of a table-root, as determined by the grid-dimensioning algorithm.
     12        Each row of the grid might correspond to a table-row, and each column to a table-column.
     13
     14        slot of the table grid:
     15        A slot (r,c) is an available space created by the intersection of a row r and a column c in the table grid.
     16
     17        https://www.w3.org/TR/css-tables-3/#terminology
     18
     19        * Sources.txt:
     20        * WebCore.xcodeproj/project.pbxproj:
     21        * layout/layouttree/LayoutBox.h:
     22        (WebCore::Layout::Box::isTableHeader const):
     23        (WebCore::Layout::Box::isTableBody const):
     24        (WebCore::Layout::Box::isTableFooter const):
     25        * layout/layouttree/LayoutTreeBuilder.cpp:
     26        (WebCore::Layout::TreeBuilder::createLayoutBox):
     27        * layout/tableformatting/TableFormattingContext.cpp:
     28        (WebCore::Layout::TableFormattingContext::layout const):
     29        (WebCore::Layout::TableFormattingContext::ensureTableGrid const):
     30        (WebCore::Layout::TableFormattingContext::computePreferredWidthForColumns const):
     31        (WebCore::Layout::TableFormattingContext::computeTableWidth const):
     32        (WebCore::Layout::TableFormattingContext::distributeAvailabeWidth const):
     33        (WebCore::Layout::TableFormattingContext::computeTableHeight const):
     34        (WebCore::Layout::TableFormattingContext::distributeAvailableHeight const):
     35        * layout/tableformatting/TableFormattingContext.h:
     36        (WebCore::Layout::TableFormattingContext::formattingState const):
     37        * layout/tableformatting/TableFormattingState.h:
     38        (WebCore::Layout::TableFormattingState::tableGrid):
     39        * layout/tableformatting/TableGrid.cpp: Added.
     40        (WebCore::Layout::TableGrid::CellInfo::CellInfo):
     41        (WebCore::Layout::TableGrid::SlotInfo::SlotInfo):
     42        (WebCore::Layout::TableGrid::TableGrid):
     43        (WebCore::Layout::TableGrid::appendCell):
     44        (WebCore::Layout::TableGrid::insertCell):
     45        (WebCore::Layout::TableGrid::removeCell):
     46        * layout/tableformatting/TableGrid.h: Copied from Source/WebCore/layout/tableformatting/TableFormattingContext.h.
     47
    1482019-08-13  Zalan Bujtas  <zalan@apple.com>
    249
  • trunk/Source/WebCore/Sources.txt

    r248517 r248596  
    14191419layout/tableformatting/TableFormattingContext.cpp
    14201420layout/tableformatting/TableFormattingState.cpp
     1421layout/tableformatting/TableGrid.cpp
    14211422layout/tableformatting/TableInvalidation.cpp
    14221423
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r248517 r248596  
    91399139                6F3E1F612136141700A65A08 /* FloatBox.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FloatBox.h; sourceTree = "<group>"; };
    91409140                6F4A5BD522F9F16B00A80F25 /* LayoutPhase.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = LayoutPhase.cpp; sourceTree = "<group>"; };
     9141                6F5B7EAA2300A79E0067D9C3 /* TableGrid.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TableGrid.cpp; sourceTree = "<group>"; };
    91419142                6F73918C2106CEDD006AF262 /* LayoutUnits.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LayoutUnits.h; sourceTree = "<group>"; };
    91429143                6F7CA3C4208C2956002F29AB /* LayoutState.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LayoutState.h; sourceTree = "<group>"; };
     
    91739174                6FB11B5921783FCF00E2A574 /* TextUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextUtil.h; sourceTree = "<group>"; };
    91749175                6FB11B5B21783FCF00E2A574 /* TextUtil.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextUtil.cpp; sourceTree = "<group>"; };
     9176                6FB22E30230097E300C20866 /* TableGrid.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TableGrid.h; sourceTree = "<group>"; };
    91759177                6FB47E612277425A00C7BCB0 /* InlineLineBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InlineLineBox.h; sourceTree = "<group>"; };
    91769178                6FB5E212221F2447003989CF /* ContentChangeObserver.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ContentChangeObserver.h; sourceTree = "<group>"; };
     
    1708517087                                C21BF72621CD89E300227979 /* WHLSLEnumerationMember.h */,
    1708617088                                C21BF70221CD89C400227979 /* WHLSLEnumerationMemberLiteral.h */,
     17089                                522D07A322FBAB4300B905BE /* WHLSLExpression.cpp */,
    1708717090                                C21BF70C21CD89CC00227979 /* WHLSLExpression.h */,
    17088                                 522D07A322FBAB4300B905BE /* WHLSLExpression.cpp */,
    1708917091                                C21BF70021CD89C200227979 /* WHLSLFallthrough.h */,
    1709017092                                C21BF73521CD89F200227979 /* WHLSLFloatLiteral.h */,
     
    2044720449                                6FC5CA9222E3599300B13E11 /* TableFormattingState.cpp */,
    2044820450                                6FC5CA9622E3599500B13E11 /* TableFormattingState.h */,
     20451                                6F5B7EAA2300A79E0067D9C3 /* TableGrid.cpp */,
     20452                                6FB22E30230097E300C20866 /* TableGrid.h */,
    2044920453                                6FC5CA9722E3599500B13E11 /* TableInvalidation.cpp */,
    2045020454                                6FC5CA9322E3599300B13E11 /* TableInvalidation.h */,
  • trunk/Source/WebCore/layout/layouttree/LayoutBox.h

    r248594 r248596  
    5353        TableRowGroup,
    5454        TableHeaderGroup,
     55        TableBodyGroup,
    5556        TableFooterGroup,
    5657        Image,
     
    117118    bool isTableBox() const { return m_elementAttributes && m_elementAttributes.value().elementType == ElementType::TableBox; }
    118119    bool isTableCaption() const { return style().display() == DisplayType::TableCaption; }
     120    bool isTableHeader() const { return m_elementAttributes && m_elementAttributes.value().elementType == ElementType::TableHeaderGroup; }
     121    bool isTableBody() const { return m_elementAttributes && m_elementAttributes.value().elementType == ElementType::TableBodyGroup; }
     122    bool isTableFooter() const { return m_elementAttributes && m_elementAttributes.value().elementType == ElementType::TableFooterGroup; }
    119123    bool isTableRow() const { return m_elementAttributes && m_elementAttributes.value().elementType == ElementType::TableRow; }
    120124    bool isTableCell() const { return style().display() == DisplayType::TableCell;; }
  • trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp

    r248594 r248596  
    111111            if (element->hasTagName(HTMLNames::theadTag))
    112112                return Box::ElementAttributes { Box::ElementType::TableHeaderGroup };
    113             if (element->hasTagName(HTMLNames::tfootTag))
    114                 return Box::ElementAttributes { Box::ElementType::TableFooterGroup };
     113            if (element->hasTagName(HTMLNames::tbodyTag))
     114                return Box::ElementAttributes { Box::ElementType::TableBodyGroup };
    115115            if (element->hasTagName(HTMLNames::tfootTag))
    116116                return Box::ElementAttributes { Box::ElementType::TableFooterGroup };
  • trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp

    r248262 r248596  
    4545void TableFormattingContext::layout() const
    4646{
     47    // https://www.w3.org/TR/css-tables-3/#table-layout-algorithm
     48    // To layout a table, user agents must apply the following actions:
     49
     50    // 1. Ensure each cell slot is occupied by at least one cell.
     51    ensureTableGrid();
     52    // 2. Compute the minimum width of each column.
     53    computePreferredWidthForColumns();
     54    // 3. Compute the width of the table.
     55    computeTableWidth();
     56    // 4. Distribute the width of the table among columns.
     57    distributeAvailabeWidth();
     58    // 5. Compute the height of the table.
     59    computeTableHeight();
     60    // 6. Distribute the height of the table among rows.
     61    distributeAvailableHeight();
    4762}
    4863
     
    5267}
    5368
     69void TableFormattingContext::ensureTableGrid() const
     70{
     71    auto& tableWrapperBox = downcast<Container>(root());
     72    auto& tableGrid = formattingState().tableGrid();
     73
     74    for (auto* section = tableWrapperBox.firstChild(); section; section = section->nextSibling()) {
     75        ASSERT(section->isTableHeader() || section->isTableBody() || section->isTableFooter());
     76        for (auto* row = downcast<Container>(*section).firstChild(); row; row = row->nextSibling()) {
     77            ASSERT(row->isTableRow());
     78            for (auto* cell = downcast<Container>(*row).firstChild(); cell; cell = cell->nextSibling()) {
     79                ASSERT(cell->isTableCell());
     80                tableGrid.appendCell(*cell);
     81            }
     82        }
     83    }
     84}
     85
     86void TableFormattingContext::computePreferredWidthForColumns() const
     87{
     88}
     89
     90void TableFormattingContext::computeTableWidth() const
     91{
     92}
     93
     94void TableFormattingContext::distributeAvailabeWidth() const
     95{
     96}
     97
     98void TableFormattingContext::computeTableHeight() const
     99{
     100}
     101
     102void TableFormattingContext::distributeAvailableHeight() const
     103{
     104}
     105
    54106}
    55107}
  • trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.h

    r248262 r248596  
    4545private:
    4646    IntrinsicWidthConstraints computedIntrinsicWidthConstraints() const override;
     47
     48    void ensureTableGrid() const;
     49    void computePreferredWidthForColumns() const;
     50    void computeTableWidth() const;
     51    void distributeAvailabeWidth() const;
     52    void computeTableHeight() const;
     53    void distributeAvailableHeight() const;
     54
     55    TableFormattingState& formattingState() const { return downcast<TableFormattingState>(FormattingContext::formattingState()); }
    4756};
    4857
  • trunk/Source/WebCore/layout/tableformatting/TableFormattingState.h

    r247669 r248596  
    2929
    3030#include "FormattingState.h"
     31#include "TableGrid.h"
    3132#include <wtf/IsoMalloc.h>
    3233
     
    4041    TableFormattingState(Ref<FloatingState>&&, LayoutState&);
    4142    virtual ~TableFormattingState();
     43
     44    TableGrid& tableGrid() { return m_tableGrid; }
     45
     46private:
     47    TableGrid m_tableGrid;
    4248};
    4349
  • trunk/Source/WebCore/layout/tableformatting/TableGrid.h

    r248595 r248596  
    2828#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
    2929
    30 #include "FormattingContext.h"
    31 #include "TableFormattingState.h"
     30#include "IntPointHash.h"
     31#include "LayoutBox.h"
     32#include <wtf/HashMap.h>
    3233#include <wtf/IsoMalloc.h>
     34#include <wtf/ListHashSet.h>
     35#include <wtf/WeakPtr.h>
    3336
    3437namespace WebCore {
    3538namespace Layout {
    3639
    37 // This class implements the layout logic for table formatting contexts.
    38 // https://www.w3.org/TR/CSS22/tables.html
    39 class TableFormattingContext : public FormattingContext {
    40     WTF_MAKE_ISO_ALLOCATED(TableFormattingContext);
     40class TableGrid {
     41    WTF_MAKE_ISO_ALLOCATED(TableGrid);
    4142public:
    42     TableFormattingContext(const Box& formattingContextRoot, TableFormattingState&);
    43     void layout() const override;
     43    TableGrid();
     44
     45    void appendCell(const Box&);
     46    void insertCell(const Box&, const Box& before);
     47    void removeCell(const Box&);
    4448
    4549private:
    46     IntrinsicWidthConstraints computedIntrinsicWidthConstraints() const override;
     50    using SlotPosition = IntPoint;
     51    using CellSize = IntSize;
     52    using SlotLogicalSize = LayoutSize;
     53
     54    struct CellInfo : public CanMakeWeakPtr<CellInfo> {
     55        CellInfo(const Box& tableCellBox, SlotPosition, CellSize);
     56
     57        const Box& tableCellBox;
     58        SlotPosition position;
     59        CellSize size;
     60    };
     61
     62    struct SlotInfo {
     63        SlotInfo() = default;
     64        SlotInfo(CellInfo&);
     65
     66        WeakPtr<CellInfo> cell;
     67        SlotLogicalSize size;
     68    };
     69
     70    using CellList = WTF::ListHashSet<std::unique_ptr<CellInfo>>;
     71    using SlotMap = WTF::HashMap<SlotPosition, SlotInfo>;
     72    SlotMap m_slotMap;
     73    CellList m_cellList;
    4774};
    4875
Note: See TracChangeset for help on using the changeset viewer.