Title: [260726] trunk/Source/WebCore
Revision
260726
Author
za...@apple.com
Date
2020-04-26 09:34:24 -0700 (Sun, 26 Apr 2020)

Log 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):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (260725 => 260726)


--- trunk/Source/WebCore/ChangeLog	2020-04-26 15:33:03 UTC (rev 260725)
+++ trunk/Source/WebCore/ChangeLog	2020-04-26 16:34:24 UTC (rev 260726)
@@ -1,3 +1,16 @@
+2020-04-26  Zalan Bujtas  <za...@apple.com>
+
+        [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):
+
 2020-04-11  Darin Adler  <da...@apple.com>
 
         Stop using live ranges in functions that return range of the selection

Modified: trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp (260725 => 260726)


--- trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp	2020-04-26 15:33:03 UTC (rev 260725)
+++ trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp	2020-04-26 16:34:24 UTC (rev 260726)
@@ -492,15 +492,19 @@
     computeColumnWidths(ColumnWidthBalancingBase::MinimumWidth, horizontalSpaceToDistribute);
 }
 
-void TableFormattingContext::computeAndDistributeExtraVerticalSpace(LayoutUnit availableHorizontalSpace, Optional<LayoutUnit>)
+void TableFormattingContext::computeAndDistributeExtraVerticalSpace(LayoutUnit availableHorizontalSpace, Optional<LayoutUnit> verticalConstraint)
 {
     auto& grid = formattingState().tableGrid();
     auto& columns = grid.columns().list();
     auto& rows = grid.rows();
 
-    Vector<LayoutUnit> rowsHeight;
+    Vector<float> rowsHeight;
     Vector<InlineLayoutUnit> rowsBaselineOffset;
+    Vector<bool> isFixedRowList(rows.size(), true);
+    float tableUsedHeight = 0;
+    size_t flexibleRowCount = 0;
     // 1. Collect initial row heights.
+    float flexibleSpace = 0;
     for (size_t rowIndex = 0; rowIndex < rows.size(); ++rowIndex) {
         auto maximumColumnAscent = InlineLayoutUnit { };
         auto maximumColumnDescent = InlineLayoutUnit { };
@@ -518,17 +522,39 @@
             maximumColumnDescent = std::max(maximumColumnDescent, geometryForBox(cellBox).height() - cell.baselineOffset());
         }
         // <tr style="height: 10px"> is considered as min height.
-        auto computedRowHeight = geometry().computedContentHeight(rows.list()[rowIndex].box(), { }).valueOr(LayoutUnit { });
-        rowsHeight.append(std::max(computedRowHeight, LayoutUnit { maximumColumnAscent + maximumColumnDescent }));
+        auto maximumRowHeight = maximumColumnAscent + maximumColumnDescent;
+        if (auto computedRowHeight = geometry().computedContentHeight(rows.list()[rowIndex].box(), { }))
+            maximumRowHeight = std::max(computedRowHeight->toFloat(), maximumRowHeight);
+        else {
+            flexibleSpace += maximumRowHeight;
+            ++flexibleRowCount;
+            isFixedRowList[rowIndex] = false;
+        }
+        tableUsedHeight += maximumRowHeight;
+        rowsHeight.append(maximumRowHeight);
         rowsBaselineOffset.append(maximumColumnAscent);
     }
 
+    // Distribute extra space if the table is supposed to be taller than the sum of the row heights.
+    auto minimumTableHeight = verticalConstraint;
+    if (!minimumTableHeight)
+        minimumTableHeight = geometry().fixedValue(root().style().logicalHeight());
+
+    if (minimumTableHeight && *minimumTableHeight > tableUsedHeight) {
+        float spaceToDistribute = std::max(0.0f, *minimumTableHeight - tableUsedHeight - ((rows.size() + 1) * grid.verticalSpacing()));
+        for (size_t rowIndex = 0; rowIndex < rows.size(); ++rowIndex) {
+            if (isFixedRowList[rowIndex])
+                continue;
+            rowsHeight[rowIndex] += spaceToDistribute / flexibleSpace * rowsHeight[rowIndex];
+        }
+    }
+
     auto rowLogicalTop = grid.verticalSpacing();
     for (size_t rowIndex = 0; rowIndex < rows.size(); ++rowIndex) {
         auto& row = grid.rows().list()[rowIndex];
         auto rowHeight = rowsHeight[rowIndex];
 
-        row.setLogicalHeight(rowHeight);
+        row.setLogicalHeight(LayoutUnit { rowHeight });
         row.setBaselineOffset(rowsBaselineOffset[rowIndex]);
         row.setLogicalTop(rowLogicalTop);
         rowLogicalTop += rowHeight + grid.verticalSpacing();
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to