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

Changeset 279504 in webkit


Ignore:
Timestamp:
Jul 2, 2021, 8:28:05 AM (5 years ago)
Author:
Alan Bujtas
Message:

[LFC][TFC] TableGrid::Column holds both the computed and the used width values
​https://bugs.webkit.org/show_bug.cgi?id=227488

Reviewed by Antti Koivisto.

This patch cleans up TableGrid::Column interface to ensure we don't confused
the computed and the used widths for columns.
This is also in prepartion for adding mixed width type support.

  • layout/formattingContexts/table/TableFormattingContext.cpp:

(WebCore::Layout::TableFormattingContext::setUsedGeometryForCells):
(WebCore::Layout::TableFormattingContext::computedPreferredWidthForColumns):
(WebCore::Layout::TableFormattingContext::computeAndDistributeExtraSpace):

  • layout/formattingContexts/table/TableFormattingGeometry.cpp:

(WebCore::Layout::TableFormattingGeometry::horizontalSpaceForCellContent const):

  • layout/formattingContexts/table/TableGrid.cpp:

(WebCore::Layout::TableGrid::Column::setLogicalWidth): Deleted.
(WebCore::Layout::TableGrid::Column::logicalWidth const): Deleted.
(WebCore::Layout::TableGrid::Column::setLogicalLeft): Deleted.
(WebCore::Layout::TableGrid::Column::logicalLeft const): Deleted.

  • layout/formattingContexts/table/TableGrid.h:

(WebCore::Layout::TableGrid::Column::usedLogicalRight const):
(WebCore::Layout::TableGrid::Column::computedLogicalWidth const):
(WebCore::Layout::TableGrid::Columns::logicalWidth const):
(WebCore::Layout::TableGrid::Column::setComputedLogicalWidth):
(WebCore::Layout::TableGrid::Column::setUsedLogicalWidth):
(WebCore::Layout::TableGrid::Column::usedLogicalWidth const):
(WebCore::Layout::TableGrid::Column::setUsedLogicalLeft):
(WebCore::Layout::TableGrid::Column::usedLogicalLeft const):
(WebCore::Layout::TableGrid::Column::logicalRight const): Deleted.
(WebCore::Layout::TableGrid::Column::fixedWidth const): Deleted.
(WebCore::Layout::TableGrid::Column::percent const): Deleted.
(WebCore::Layout::TableGrid::Column::setFixedWidth): Deleted.
(WebCore::Layout::TableGrid::Column::setPercent): Deleted.

  • layout/formattingContexts/table/TableLayout.cpp:

(WebCore::Layout::TableFormattingContext::TableLayout::distributedHorizontalSpace):

Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r279503 r279504  
     12021-07-02  Alan Bujtas  <zalan@apple.com>
     2
     3        [LFC][TFC] TableGrid::Column holds both the computed and the used width values
     4        https://bugs.webkit.org/show_bug.cgi?id=227488
     5
     6        Reviewed by Antti Koivisto.
     7
     8        This patch cleans up TableGrid::Column interface to ensure we don't confused
     9        the computed and the used widths for columns.
     10        This is also in prepartion for adding mixed width type support.
     11
     12        * layout/formattingContexts/table/TableFormattingContext.cpp:
     13        (WebCore::Layout::TableFormattingContext::setUsedGeometryForCells):
     14        (WebCore::Layout::TableFormattingContext::computedPreferredWidthForColumns):
     15        (WebCore::Layout::TableFormattingContext::computeAndDistributeExtraSpace):
     16        * layout/formattingContexts/table/TableFormattingGeometry.cpp:
     17        (WebCore::Layout::TableFormattingGeometry::horizontalSpaceForCellContent const):
     18        * layout/formattingContexts/table/TableGrid.cpp:
     19        (WebCore::Layout::TableGrid::Column::setLogicalWidth): Deleted.
     20        (WebCore::Layout::TableGrid::Column::logicalWidth const): Deleted.
     21        (WebCore::Layout::TableGrid::Column::setLogicalLeft): Deleted.
     22        (WebCore::Layout::TableGrid::Column::logicalLeft const): Deleted.
     23        * layout/formattingContexts/table/TableGrid.h:
     24        (WebCore::Layout::TableGrid::Column::usedLogicalRight const):
     25        (WebCore::Layout::TableGrid::Column::computedLogicalWidth const):
     26        (WebCore::Layout::TableGrid::Columns::logicalWidth const):
     27        (WebCore::Layout::TableGrid::Column::setComputedLogicalWidth):
     28        (WebCore::Layout::TableGrid::Column::setUsedLogicalWidth):
     29        (WebCore::Layout::TableGrid::Column::usedLogicalWidth const):
     30        (WebCore::Layout::TableGrid::Column::setUsedLogicalLeft):
     31        (WebCore::Layout::TableGrid::Column::usedLogicalLeft const):
     32        (WebCore::Layout::TableGrid::Column::logicalRight const): Deleted.
     33        (WebCore::Layout::TableGrid::Column::fixedWidth const): Deleted.
     34        (WebCore::Layout::TableGrid::Column::percent const): Deleted.
     35        (WebCore::Layout::TableGrid::Column::setFixedWidth): Deleted.
     36        (WebCore::Layout::TableGrid::Column::setPercent): Deleted.
     37        * layout/formattingContexts/table/TableLayout.cpp:
     38        (WebCore::Layout::TableFormattingContext::TableLayout::distributedHorizontalSpace):
     39
    1402021-07-02  Commit Queue  <commit-queue@webkit.org>
    241
  • trunk/Source/WebCore/layout/formattingContexts/table/TableFormattingContext.cpp

    r278869 r279504  
    102102        cellBoxGeometry.setPadding(formattingGeometry.computedPadding(cellBox, availableHorizontalSpace));
    103103        cellBoxGeometry.setLogicalTop(rowList[cell->startRow()].logicalTop() - sectionOffset);
    104         cellBoxGeometry.setLogicalLeft(columnList[cell->startColumn()].logicalLeft());
     104        cellBoxGeometry.setLogicalLeft(columnList[cell->startColumn()].usedLogicalLeft());
    105105        cellBoxGeometry.setContentBoxWidth(formattingGeometry.horizontalSpaceForCellContent(*cell));
    106106
    … …  
    337337        }();
    338338        if (fixedWidth)
    339             column.setFixedWidth(*fixedWidth);
     339            column.setComputedLogicalWidth({ *fixedWidth, LengthType::Fixed });
    340340    }
    341341
    … …  
    361361        if (auto fixedWidth = formattingGeometry.fixedValue(cellBox.style().logicalWidth())) {
    362362            *fixedWidth += horizontalBorderAndPaddingWidth;
    363             columnList[cellPosition.column].setFixedWidth(std::max(*fixedWidth, columnList[cellPosition.column].fixedWidth().value_or(0)));
     363            auto& column = columnList[cellPosition.column];
     364            if (*fixedWidth > column.computedLogicalWidth().value())
     365                column.setComputedLogicalWidth({ *fixedWidth, LengthType::Fixed });
    364366        }
    365367        // Collect the percent values so that we can compute the maximum values per column.
    … …  
    388390            }
    389391            auto widthConstraints = slot.widthConstraints();
    390             if (auto columnFixedWidth = columnList[columnIndex].fixedWidth())
    391                 widthConstraints.maximum = std::max(*columnFixedWidth, widthConstraints.minimum);
     392            if (auto columnLogicalWidth = columnList[columnIndex].computedLogicalWidth(); columnLogicalWidth.isFixed())
     393                widthConstraints.maximum = std::max(LayoutUnit { columnLogicalWidth.value() }, widthConstraints.minimum);
    392394
    393395            columnIntrinsicWidths[columnIndex].minimum = std::max(widthConstraints.minimum, columnIntrinsicWidths[columnIndex].minimum);
    … …  
    443445            }
    444446            ASSERT(*percent > 0);
    445             columnList[columnIndex].setPercent(std::min(remainingPercent, *percent));
    446             percentMaximumWidth = std::max(percentMaximumWidth, LayoutUnit { columnIntrinsicWidths[columnIndex].maximum * 100.0f / *columnList[columnIndex].percent() });
    447             remainingPercent -= *columnList[columnIndex].percent();
     447            percent = std::min(*percent, remainingPercent);
     448            columnList[columnIndex].setComputedLogicalWidth({ *percent, LengthType::Percent });
     449            percentMaximumWidth = std::max(percentMaximumWidth, LayoutUnit { columnIntrinsicWidths[columnIndex].maximum * 100.0f / *percent });
     450            remainingPercent -= *percent;
    448451        }
    449452
    … …  
    473476    for (size_t columnIndex = 0; columnIndex < columns.size(); ++columnIndex) {
    474477        auto& column = columns[columnIndex];
    475         column.setLogicalLeft(columnLogicalLeft);
    476         column.setLogicalWidth(distributedHorizontalSpaces[columnIndex]);
     478        column.setUsedLogicalLeft(columnLogicalLeft);
     479        column.setUsedLogicalWidth(distributedHorizontalSpaces[columnIndex]);
    477480        columnLogicalLeft += distributedHorizontalSpaces[columnIndex] + grid.horizontalSpacing();
    478481    }
  • trunk/Source/WebCore/layout/formattingContexts/table/TableFormattingGeometry.cpp

    r278537 r279504  
    153153    auto logicalWidth = LayoutUnit { };
    154154    for (auto columnIndex = cell.startColumn(); columnIndex < cell.endColumn(); ++columnIndex)
    155         logicalWidth += columnList.at(columnIndex).logicalWidth();
     155        logicalWidth += columnList.at(columnIndex).usedLogicalWidth();
    156156    // No column spacing when spanning.
    157157    logicalWidth += (cell.columnSpan() - 1) * grid.horizontalSpacing();
  • trunk/Source/WebCore/layout/formattingContexts/table/TableGrid.cpp

    r278537 r279504  
    3939    : m_layoutBox(makeWeakPtr(columnBox))
    4040{
    41 }
    42 
    43 void TableGrid::Column::setLogicalWidth(LayoutUnit computedLogicalWidth)
    44 {
    45 #if ASSERT_ENABLED
    46     m_hasComputedWidth = true;
    47 #endif
    48     m_computedLogicalWidth = computedLogicalWidth;
    49 }
    50 
    51 LayoutUnit TableGrid::Column::logicalWidth() const
    52 {
    53     ASSERT(m_hasComputedWidth);
    54     return m_computedLogicalWidth;
    55 }
    56 
    57 void TableGrid::Column::setLogicalLeft(LayoutUnit computedLogicalLeft)
    58 {
    59 #if ASSERT_ENABLED
    60     m_hasComputedLeft = true;
    61 #endif
    62     m_computedLogicalLeft = computedLogicalLeft;
    63 }
    64 
    65 LayoutUnit TableGrid::Column::logicalLeft() const
    66 {
    67     ASSERT(m_hasComputedLeft);
    68     return m_computedLogicalLeft;
    6941}
    7042
  • trunk/Source/WebCore/layout/formattingContexts/table/TableGrid.h

    r278605 r279504  
    6868        Column(const ContainerBox*);
    6969
    70         void setLogicalLeft(LayoutUnit);
    71         LayoutUnit logicalLeft() const;
    72         LayoutUnit logicalRight() const { return logicalLeft() + logicalWidth(); }
    73         void setLogicalWidth(LayoutUnit);
    74         LayoutUnit logicalWidth() const;
    75 
    76         void setFixedWidth(LayoutUnit fixedValue);
    77         std::optional<LayoutUnit> fixedWidth() const { return m_fixedWidth; }
    78 
    79         void setPercent(float);
    80         std::optional<float> percent() const { return m_percent; }
     70        void setUsedLogicalLeft(LayoutUnit);
     71        LayoutUnit usedLogicalLeft() const;
     72        LayoutUnit usedLogicalRight() const { return usedLogicalLeft() + usedLogicalWidth(); }
     73        void setUsedLogicalWidth(LayoutUnit);
     74        LayoutUnit usedLogicalWidth() const;
     75
     76        void setComputedLogicalWidth(Length&&);
     77        const Length& computedLogicalWidth() const { return m_computedLogicalWidth; }
    8178
    8279        const ContainerBox* box() const { return m_layoutBox.get(); }
    8380
    8481    private:
    85         LayoutUnit m_computedLogicalWidth;
    86         LayoutUnit m_computedLogicalLeft;
    87         std::optional<LayoutUnit> m_fixedWidth;
    88         std::optional<float> m_percent;
     82        LayoutUnit m_usedLogicalWidth;
     83        LayoutUnit m_usedLogicalLeft;
     84        Length m_computedLogicalWidth;
    8985        WeakPtr<const ContainerBox> m_layoutBox;
    9086
    9187#if ASSERT_ENABLED
    92         bool m_hasComputedWidth { false };
    93         bool m_hasComputedLeft { false };
     88        bool m_hasUsedWidth { false };
     89        bool m_hasUsedLeft { false };
    9490#endif
    9591    };
    … …  
    105101        void addAnonymousColumn();
    106102
    107         LayoutUnit logicalWidth() const { return m_columnList.last().logicalRight() - m_columnList.first().logicalLeft(); }
     103        LayoutUnit logicalWidth() const { return m_columnList.last().usedLogicalRight() - m_columnList.first().usedLogicalLeft(); }
    108104
    109105    private:
    … …  
    235231};
    236232
    237 
    238 inline void TableGrid::Column::setFixedWidth(LayoutUnit fixedValue)
    239 {
    240     ASSERT(!m_percent);
    241     m_fixedWidth = fixedValue;
    242 }
    243 
    244 inline void TableGrid::Column::setPercent(float percent)
    245 {
    246     ASSERT(!m_fixedWidth);
    247     m_percent = percent;
    248 }
    249 
    250 }
    251 }
    252 
    253 #endif
     233inline void TableGrid::Column::setComputedLogicalWidth(Length&& computedLogicalWidth)
     234{
     235    ASSERT(computedLogicalWidth.type() == LengthType::Fixed || computedLogicalWidth.type() == LengthType::Percent || computedLogicalWidth.type() == LengthType::Relative);
     236    m_computedLogicalWidth = WTFMove(computedLogicalWidth);
     237}
     238
     239inline void TableGrid::Column::setUsedLogicalWidth(LayoutUnit usedLogicalWidth)
     240{
     241#if ASSERT_ENABLED
     242    m_hasUsedWidth = true;
     243#endif
     244    m_usedLogicalWidth = usedLogicalWidth;
     245}
     246
     247inline LayoutUnit TableGrid::Column::usedLogicalWidth() const
     248{
     249    ASSERT(m_hasUsedWidth);
     250    return m_usedLogicalWidth;
     251}
     252
     253inline void TableGrid::Column::setUsedLogicalLeft(LayoutUnit usedLogicalLeft)
     254{
     255#if ASSERT_ENABLED
     256    m_hasUsedLeft = true;
     257#endif
     258    m_usedLogicalLeft = usedLogicalLeft;
     259}
     260
     261inline LayoutUnit TableGrid::Column::usedLogicalLeft() const
     262{
     263    ASSERT(m_hasUsedLeft);
     264    return m_usedLogicalLeft;
     265}
     266
     267}
     268}
     269
     270#endif
  • trunk/Source/WebCore/layout/formattingContexts/table/TableLayout.cpp

    r279318 r279504  
    295295        auto columnWidth = std::optional<float> { };
    296296        auto type = GridSpace::Type::Auto;
    297         if (auto fixedWidth = column.fixedWidth()) {
    298             columnWidth = *fixedWidth;
     297
     298        auto& computedLogicalWidth = column.computedLogicalWidth();
     299        switch (computedLogicalWidth.type()) {
     300        case LengthType::Fixed:
     301            columnWidth = computedLogicalWidth.value();
    299302            type = GridSpace::Type::Fixed;
    300         } else if (auto percent = column.percent()) {
    301             columnWidth = *percent * availableHorizontalSpace / 100.0f;
     303            break;
     304        case LengthType::Percent:
     305            columnWidth = computedLogicalWidth.value() * availableHorizontalSpace / 100.0f;
    302306            type = GridSpace::Type::Percent;
     307            break;
     308        case LengthType::Relative:
     309            ASSERT_NOT_IMPLEMENTED_YET();
     310            break;
     311        default:
     312            break;
    303313        }
    304314
Note: See TracChangeset for help on using the changeset viewer.