Changeset 260726 in webkit


Ignore:
Timestamp:
Apr 26, 2020 9:34:24 AM (4 years ago)
Author:
Alan Bujtas
Message:

[LFC][TFC] Compute and distribute extra vertical space for rows
https://bugs.webkit.org/show_bug.cgi?id=211046

Reviewed by Antti Koivisto.

When the table computed height is bigger than the sum of the row heigts, we need to distribute the extra vertical
space among the non-fixed height rows. The distribution is based on the preferred height of those non-fixed rows.

  • layout/tableformatting/TableFormattingContext.cpp:

(WebCore::Layout::TableFormattingContext::computeAndDistributeExtraVerticalSpace):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r260725 r260726  
     12020-04-26  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][TFC] Compute and distribute extra vertical space for rows
     4        https://bugs.webkit.org/show_bug.cgi?id=211046
     5
     6        Reviewed by Antti Koivisto.
     7
     8        When the table computed height is bigger than the sum of the row heigts, we need to distribute the extra vertical
     9        space among the non-fixed height rows. The distribution is based on the preferred height of those non-fixed rows.
     10
     11        * layout/tableformatting/TableFormattingContext.cpp:
     12        (WebCore::Layout::TableFormattingContext::computeAndDistributeExtraVerticalSpace):
     13
    1142020-04-11  Darin Adler  <darin@apple.com>
    215
  • trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp

    r260708 r260726  
    493493}
    494494
    495 void TableFormattingContext::computeAndDistributeExtraVerticalSpace(LayoutUnit availableHorizontalSpace, Optional<LayoutUnit>)
     495void TableFormattingContext::computeAndDistributeExtraVerticalSpace(LayoutUnit availableHorizontalSpace, Optional<LayoutUnit> verticalConstraint)
    496496{
    497497    auto& grid = formattingState().tableGrid();
     
    499499    auto& rows = grid.rows();
    500500
    501     Vector<LayoutUnit> rowsHeight;
     501    Vector<float> rowsHeight;
    502502    Vector<InlineLayoutUnit> rowsBaselineOffset;
     503    Vector<bool> isFixedRowList(rows.size(), true);
     504    float tableUsedHeight = 0;
     505    size_t flexibleRowCount = 0;
    503506    // 1. Collect initial row heights.
     507    float flexibleSpace = 0;
    504508    for (size_t rowIndex = 0; rowIndex < rows.size(); ++rowIndex) {
    505509        auto maximumColumnAscent = InlineLayoutUnit { };
     
    519523        }
    520524        // <tr style="height: 10px"> is considered as min height.
    521         auto computedRowHeight = geometry().computedContentHeight(rows.list()[rowIndex].box(), { }).valueOr(LayoutUnit { });
    522         rowsHeight.append(std::max(computedRowHeight, LayoutUnit { maximumColumnAscent + maximumColumnDescent }));
     525        auto maximumRowHeight = maximumColumnAscent + maximumColumnDescent;
     526        if (auto computedRowHeight = geometry().computedContentHeight(rows.list()[rowIndex].box(), { }))
     527            maximumRowHeight = std::max(computedRowHeight->toFloat(), maximumRowHeight);
     528        else {
     529            flexibleSpace += maximumRowHeight;
     530            ++flexibleRowCount;
     531            isFixedRowList[rowIndex] = false;
     532        }
     533        tableUsedHeight += maximumRowHeight;
     534        rowsHeight.append(maximumRowHeight);
    523535        rowsBaselineOffset.append(maximumColumnAscent);
     536    }
     537
     538    // Distribute extra space if the table is supposed to be taller than the sum of the row heights.
     539    auto minimumTableHeight = verticalConstraint;
     540    if (!minimumTableHeight)
     541        minimumTableHeight = geometry().fixedValue(root().style().logicalHeight());
     542
     543    if (minimumTableHeight && *minimumTableHeight > tableUsedHeight) {
     544        float spaceToDistribute = std::max(0.0f, *minimumTableHeight - tableUsedHeight - ((rows.size() + 1) * grid.verticalSpacing()));
     545        for (size_t rowIndex = 0; rowIndex < rows.size(); ++rowIndex) {
     546            if (isFixedRowList[rowIndex])
     547                continue;
     548            rowsHeight[rowIndex] += spaceToDistribute / flexibleSpace * rowsHeight[rowIndex];
     549        }
    524550    }
    525551
     
    529555        auto rowHeight = rowsHeight[rowIndex];
    530556
    531         row.setLogicalHeight(rowHeight);
     557        row.setLogicalHeight(LayoutUnit { rowHeight });
    532558        row.setBaselineOffset(rowsBaselineOffset[rowIndex]);
    533559        row.setLogicalTop(rowLogicalTop);
Note: See TracChangeset for help on using the changeset viewer.