⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 278279 in webkit


Ignore:
Timestamp:
May 31, 2021, 8:47:28 AM (5 years ago)
Author:
Alan Bujtas
Message:

[LFC][TFC] Move ensureTableGrid to TableFormattingState
https://bugs.webkit.org/show_bug.cgi?id=226424

Reviewed by Antti Koivisto.

We can certainly have this much logic in a formatting state class.

  • layout/formattingContexts/table/TableFormattingContext.cpp:

(WebCore::Layout::TableFormattingContext::ensureTableGrid): Deleted.

  • layout/formattingContexts/table/TableFormattingContext.h:
  • layout/formattingContexts/table/TableFormattingState.cpp:

(WebCore::Layout::ensureTableGrid):
(WebCore::Layout::TableFormattingState::TableFormattingState):

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r278277 r278279  
     12021-05-31  Alan Bujtas  <zalan@apple.com>
     2
     3        [LFC][TFC] Move ensureTableGrid to TableFormattingState
     4        https://bugs.webkit.org/show_bug.cgi?id=226424
     5
     6        Reviewed by Antti Koivisto.
     7
     8        We can certainly have this much logic in a formatting state class.
     9
     10        * layout/formattingContexts/table/TableFormattingContext.cpp:
     11        (WebCore::Layout::TableFormattingContext::ensureTableGrid): Deleted.
     12        * layout/formattingContexts/table/TableFormattingContext.h:
     13        * layout/formattingContexts/table/TableFormattingState.cpp:
     14        (WebCore::Layout::ensureTableGrid):
     15        (WebCore::Layout::TableFormattingState::TableFormattingState):
     16
    1172021-05-31  Antti Koivisto  <antti@apple.com>
    218
  • trunk/Source/WebCore/layout/formattingContexts/table/TableFormattingContext.cpp

    r278253 r278279  
    340340}
    341341
    342 UniqueRef<TableGrid> TableFormattingContext::ensureTableGrid(const ContainerBox& tableBox)
    343 {
    344     auto tableGrid = makeUniqueRef<TableGrid>();
    345     auto& tableStyle = tableBox.style();
    346     auto shouldApplyBorderSpacing = tableStyle.borderCollapse() == BorderCollapse::Separate;
    347     tableGrid->setHorizontalSpacing(LayoutUnit { shouldApplyBorderSpacing ? tableStyle.horizontalBorderSpacing() : 0 });
    348     tableGrid->setVerticalSpacing(LayoutUnit { shouldApplyBorderSpacing ? tableStyle.verticalBorderSpacing() : 0 });
    349 
    350     auto* firstChild = tableBox.firstChild();
    351     if (!firstChild) {
    352         // The rare case of empty table.
    353         return tableGrid;
    354     }
    355 
    356     const Box* tableCaption = nullptr;
    357     const Box* colgroup = nullptr;
    358     // Table caption is an optional element; if used, it is always the first child of a <table>.
    359     if (firstChild->isTableCaption())
    360         tableCaption = firstChild;
    361     // The <colgroup> must appear after any optional <caption> element but before any <thead>, <th>, <tbody>, <tfoot> and <tr> element.
    362     auto* colgroupCandidate = firstChild;
    363     if (tableCaption)
    364         colgroupCandidate = tableCaption->nextSibling();
    365     if (colgroupCandidate->isTableColumnGroup())
    366         colgroup = colgroupCandidate;
    367 
    368     if (colgroup) {
    369         auto& columns = tableGrid->columns();
    370         for (auto* column = downcast<ContainerBox>(*colgroup).firstChild(); column; column = column->nextSibling()) {
    371             ASSERT(column->isTableColumn());
    372             auto columnSpanCount = column->columnSpan();
    373             ASSERT(columnSpanCount > 0);
    374             while (columnSpanCount--)
    375                 columns.addColumn(downcast<ContainerBox>(*column));
    376         }
    377     }
    378 
    379     auto* firstSection = colgroup ? colgroup->nextSibling() : tableCaption ? tableCaption->nextSibling() : firstChild;
    380     for (auto* section = firstSection; section; section = section->nextSibling()) {
    381         ASSERT(section->isTableHeader() || section->isTableBody() || section->isTableFooter());
    382         for (auto* row = downcast<ContainerBox>(*section).firstChild(); row; row = row->nextSibling()) {
    383             ASSERT(row->isTableRow());
    384             for (auto* cell = downcast<ContainerBox>(*row).firstChild(); cell; cell = cell->nextSibling()) {
    385                 ASSERT(cell->isTableCell());
    386                 tableGrid->appendCell(downcast<ContainerBox>(*cell));
    387             }
    388         }
    389     }
    390     return tableGrid;
    391 }
    392 
    393342IntrinsicWidthConstraints TableFormattingContext::computedPreferredWidthForColumns()
    394343{
  • trunk/Source/WebCore/layout/formattingContexts/table/TableFormattingContext.h

    r278253 r278279  
    5252    const TableFormattingGeometry& formattingGeometry() const final { return m_tableFormattingGeometry; }
    5353    const TableFormattingQuirks& formattingQuirks() const final { return m_tableFormattingQuirks; }
    54 
    55     static UniqueRef<TableGrid> ensureTableGrid(const ContainerBox& tableBox);
    56 
    5754    const TableFormattingState& formattingState() const { return downcast<TableFormattingState>(FormattingContext::formattingState()); }
    5855
  • trunk/Source/WebCore/layout/formattingContexts/table/TableFormattingState.cpp

    r276886 r278279  
    3737WTF_MAKE_ISO_ALLOCATED_IMPL(TableFormattingState);
    3838
     39static UniqueRef<TableGrid> ensureTableGrid(const ContainerBox& tableBox)
     40{
     41    auto tableGrid = makeUniqueRef<TableGrid>();
     42    auto& tableStyle = tableBox.style();
     43    auto shouldApplyBorderSpacing = tableStyle.borderCollapse() == BorderCollapse::Separate;
     44    tableGrid->setHorizontalSpacing(LayoutUnit { shouldApplyBorderSpacing ? tableStyle.horizontalBorderSpacing() : 0 });
     45    tableGrid->setVerticalSpacing(LayoutUnit { shouldApplyBorderSpacing ? tableStyle.verticalBorderSpacing() : 0 });
     46
     47    auto* firstChild = tableBox.firstChild();
     48    if (!firstChild) {
     49        // The rare case of empty table.
     50        return tableGrid;
     51    }
     52
     53    const Box* tableCaption = nullptr;
     54    const Box* colgroup = nullptr;
     55    // Table caption is an optional element; if used, it is always the first child of a <table>.
     56    if (firstChild->isTableCaption())
     57        tableCaption = firstChild;
     58    // The <colgroup> must appear after any optional <caption> element but before any <thead>, <th>, <tbody>, <tfoot> and <tr> element.
     59    auto* colgroupCandidate = firstChild;
     60    if (tableCaption)
     61        colgroupCandidate = tableCaption->nextSibling();
     62    if (colgroupCandidate->isTableColumnGroup())
     63        colgroup = colgroupCandidate;
     64
     65    if (colgroup) {
     66        auto& columns = tableGrid->columns();
     67        for (auto* column = downcast<ContainerBox>(*colgroup).firstChild(); column; column = column->nextSibling()) {
     68            ASSERT(column->isTableColumn());
     69            auto columnSpanCount = column->columnSpan();
     70            ASSERT(columnSpanCount > 0);
     71            while (columnSpanCount--)
     72                columns.addColumn(downcast<ContainerBox>(*column));
     73        }
     74    }
     75
     76    auto* firstSection = colgroup ? colgroup->nextSibling() : tableCaption ? tableCaption->nextSibling() : firstChild;
     77    for (auto* section = firstSection; section; section = section->nextSibling()) {
     78        ASSERT(section->isTableHeader() || section->isTableBody() || section->isTableFooter());
     79        for (auto* row = downcast<ContainerBox>(*section).firstChild(); row; row = row->nextSibling()) {
     80            ASSERT(row->isTableRow());
     81            for (auto* cell = downcast<ContainerBox>(*row).firstChild(); cell; cell = cell->nextSibling()) {
     82                ASSERT(cell->isTableCell());
     83                tableGrid->appendCell(downcast<ContainerBox>(*cell));
     84            }
     85        }
     86    }
     87    return tableGrid;
     88}
     89
     90
    3991TableFormattingState::TableFormattingState(Ref<FloatingState>&& floatingState, LayoutState& layoutState, const ContainerBox& tableBox)
    4092    : FormattingState(WTFMove(floatingState), Type::Table, layoutState)
    41     , m_tableGrid(TableFormattingContext::ensureTableGrid(tableBox))
     93    , m_tableGrid(ensureTableGrid(tableBox))
    4294{
    4395}
Note: See TracChangeset for help on using the changeset viewer.