Title: [278869] trunk
Revision
278869
Author
za...@apple.com
Date
2021-06-15 06:11:25 -0700 (Tue, 15 Jun 2021)

Log Message

[LFC][TFC] Add support for preferred width computation when mixed width types are present
https://bugs.webkit.org/show_bug.cgi?id=227010

Reviewed by Antti Koivisto.

Source/WebCore:

This is in preparation for supporting available space distribution with mixed width types (e.g. percent and fixed).
While this patch only addresses the preferred width computation for the table, certain values already work with the existing distribution code.

Test: fast/layoutformattingcontext/table-space-distribution-mixed-width-type-simple.html

* layout/formattingContexts/table/TableFormattingContext.cpp:
(WebCore::Layout::TableFormattingContext::computedPreferredWidthForColumns):

LayoutTests:

* fast/layoutformattingcontext/table-space-distribution-mixed-width-type-simple-expected.html: Added.
* fast/layoutformattingcontext/table-space-distribution-mixed-width-type-simple.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (278868 => 278869)


--- trunk/LayoutTests/ChangeLog	2021-06-15 11:09:34 UTC (rev 278868)
+++ trunk/LayoutTests/ChangeLog	2021-06-15 13:11:25 UTC (rev 278869)
@@ -1,3 +1,13 @@
+2021-06-15  Alan Bujtas  <za...@apple.com>
+
+        [LFC][TFC] Add support for preferred width computation when mixed width types are present
+        https://bugs.webkit.org/show_bug.cgi?id=227010
+
+        Reviewed by Antti Koivisto.
+
+        * fast/layoutformattingcontext/table-space-distribution-mixed-width-type-simple-expected.html: Added.
+        * fast/layoutformattingcontext/table-space-distribution-mixed-width-type-simple.html: Added.
+
 2021-06-15  Martin Robinson  <mrobin...@igalia.com>
 
         [css-scroll-snap] Scroll snap offsets are interpreted as scroll positions in ScrollableArea

Added: trunk/LayoutTests/fast/layoutformattingcontext/table-space-distribution-mixed-width-type-simple-expected.html (0 => 278869)


--- trunk/LayoutTests/fast/layoutformattingcontext/table-space-distribution-mixed-width-type-simple-expected.html	                        (rev 0)
+++ trunk/LayoutTests/fast/layoutformattingcontext/table-space-distribution-mixed-width-type-simple-expected.html	2021-06-15 13:11:25 UTC (rev 278869)
@@ -0,0 +1,24 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ LayoutFormattingContextEnabled=true LayoutFormattingContextIntegrationEnabled=false ] -->
+<style>
+body {
+  font-size: 16px;
+  overflow: hidden;
+}
+
+div {
+  height: 20px;
+  background-color: blue;
+}
+
+.inner {
+  background-color: green;
+}
+</style>
+
+<div style="width: 43px"><div class=inner style="width: 30px"></div></div>
+<div style="width: 67px"><div class=inner style="width: 40px"></div></div>
+<div style="width: 100px"><div class=inner style="width: 50px"></div></div>
+<div style="width: 150px"><div class=inner style="width: 60px"></div></div>
+<div style="width: 233px"><div class=inner style="width: 70px"></div></div>
+<div style="width: 400px"><div class=inner style="width: 80px"></div></div>
+<div style="width: 900px"><div class=inner style="width: 90px"></div></div>

Added: trunk/LayoutTests/fast/layoutformattingcontext/table-space-distribution-mixed-width-type-simple.html (0 => 278869)


--- trunk/LayoutTests/fast/layoutformattingcontext/table-space-distribution-mixed-width-type-simple.html	                        (rev 0)
+++ trunk/LayoutTests/fast/layoutformattingcontext/table-space-distribution-mixed-width-type-simple.html	2021-06-15 13:11:25 UTC (rev 278869)
@@ -0,0 +1,35 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ LayoutFormattingContextEnabled=true LayoutFormattingContextIntegrationEnabled=false ] -->
+<style>
+body {
+  font-size: 16px;
+  overflow: hidden;
+}
+
+table {
+  border-spacing: 0px;
+}
+
+td {
+  height: 20px;
+  padding: 0px;
+  background-color: blue;
+  white-space: pre-wrap;
+}
+
+td:nth-child(odd) {
+  background-color: green;
+}
+
+div {
+  height: 20px;
+}
+</style>
+<div style="width: 1200px; height: auto;">
+<table><tr><td style="width: 30px;"></td><td style="width: 30%;"></td></tr></table>
+<table><tr><td style="width: 40px;"></td><td style="width: 40%;"></td></tr></table>
+<table><tr><td style="width: 50px;"></td><td style="width: 50%;"></td></tr></table>
+<table><tr><td style="width: 60px;"></td><td style="width: 60%;"></td></tr></table>
+<table><tr><td style="width: 70px;"></td><td style="width: 70%;"></td></tr></table>
+<table><tr><td style="width: 80px;"></td><td style="width: 80%;"></td></tr></table>
+<table><tr><td style="width: 90px;"></td><td style="width: 90%;"></td></tr></table>
+</div>
\ No newline at end of file

Modified: trunk/Source/WebCore/ChangeLog (278868 => 278869)


--- trunk/Source/WebCore/ChangeLog	2021-06-15 11:09:34 UTC (rev 278868)
+++ trunk/Source/WebCore/ChangeLog	2021-06-15 13:11:25 UTC (rev 278869)
@@ -1,3 +1,18 @@
+2021-06-15  Alan Bujtas  <za...@apple.com>
+
+        [LFC][TFC] Add support for preferred width computation when mixed width types are present
+        https://bugs.webkit.org/show_bug.cgi?id=227010
+
+        Reviewed by Antti Koivisto.
+
+        This is in preparation for supporting available space distribution with mixed width types (e.g. percent and fixed).
+        While this patch only addresses the preferred width computation for the table, certain values already work with the existing distribution code. 
+
+        Test: fast/layoutformattingcontext/table-space-distribution-mixed-width-type-simple.html
+
+        * layout/formattingContexts/table/TableFormattingContext.cpp:
+        (WebCore::Layout::TableFormattingContext::computedPreferredWidthForColumns):
+
 2021-06-15  Martin Robinson  <mrobin...@igalia.com>
 
         [css-scroll-snap] Scroll snap offsets are interpreted as scroll positions in ScrollableArea

Modified: trunk/Source/WebCore/layout/formattingContexts/table/TableFormattingContext.cpp (278868 => 278869)


--- trunk/Source/WebCore/layout/formattingContexts/table/TableFormattingContext.cpp	2021-06-15 11:09:34 UTC (rev 278868)
+++ trunk/Source/WebCore/layout/formattingContexts/table/TableFormattingContext.cpp	2021-06-15 13:11:25 UTC (rev 278869)
@@ -340,6 +340,7 @@
     }
 
     Vector<std::optional<float>> columnPercentList(columnList.size());
+    auto hasColumnWithPercentWidth = false;
     for (auto& cell : grid.cells()) {
         auto& cellBox = cell->box();
         ASSERT(cellBox.establishesBlockFormattingContext());
@@ -366,6 +367,7 @@
         if (cellLogicalWidth.isPercent()) {
             // FIXME: Add support for column spanning distribution.
             columnPercentList[cellPosition.column] = std::max(cellLogicalWidth.percent(), columnPercentList[cellPosition.column].value_or(0.0f));
+            hasColumnWithPercentWidth = true;
         }
     }
 
@@ -418,25 +420,40 @@
         }
     }
 
-    // 5. Resolve the percent values.
-    auto remainingPercent = 100.0f;
-    auto percentMaximumConstraint = LayoutUnit { };
-    for (size_t columnIndex = 0; columnIndex < columnList.size(); ++columnIndex) {
-        auto percent = columnPercentList[columnIndex];
-        // FIXME: Add support for mixed content with and without percent values.
-        if (!percent)
-            continue;
-        ASSERT(*percent > 0);
-        columnList[columnIndex].setPercent(std::min(remainingPercent, *percent));
-        percentMaximumConstraint = std::max(percentMaximumConstraint, LayoutUnit { columnIntrinsicWidths[columnIndex].maximum * 100.0f / *columnList[columnIndex].percent() });
-        remainingPercent -= *columnList[columnIndex].percent();
-    }
-
-    // 6. The final table min/max widths is just the accumulated column constraints.
+    // 5. The table min/max widths is just the accumulated column constraints with the percent adjustment.
     auto tableWidthConstraints = IntrinsicWidthConstraints { };
     for (auto& columnIntrinsicWidth : columnIntrinsicWidths)
         tableWidthConstraints += columnIntrinsicWidth;
-    tableWidthConstraints.maximum = std::max(tableWidthConstraints.maximum, percentMaximumConstraint);
+
+    // 6. Adjust the table max width with the percent column values if applicable.
+    if (hasColumnWithPercentWidth) {
+        auto remainingPercent = 100.0f;
+        auto percentMaximumWidth = LayoutUnit { };
+        auto nonPercentColumnsWidth = LayoutUnit { };
+        // Resolve the percent values as follows
+        // - the percent value is resolved against the column maximum width (fixed or content based) as if the max value represented the percentage value
+        //   e.g 50% with the maximum width of 100px produces a resolved width of 200px for the column.
+        // - find the largest resolved value across the columns and used that as the maxiumum width for the precent based columns.
+        // - Compute the non-percent based columns width by using the remaining percent value (e.g 50% and 10% columns would leave 40% for the rest of the columns)
+        for (size_t columnIndex = 0; columnIndex < columnList.size(); ++columnIndex) {
+            auto percent = columnPercentList[columnIndex];
+            if (!percent) {
+                nonPercentColumnsWidth += columnIntrinsicWidths[columnIndex].maximum;
+                continue;
+            }
+            ASSERT(*percent > 0);
+            columnList[columnIndex].setPercent(std::min(remainingPercent, *percent));
+            percentMaximumWidth = std::max(percentMaximumWidth, LayoutUnit { columnIntrinsicWidths[columnIndex].maximum * 100.0f / *columnList[columnIndex].percent() });
+            remainingPercent -= *columnList[columnIndex].percent();
+        }
+
+        ASSERT(remainingPercent >= 0.f);
+        auto adjustedMaximumWidth = percentMaximumWidth;
+        if (remainingPercent)
+            adjustedMaximumWidth = std::max(adjustedMaximumWidth, LayoutUnit { nonPercentColumnsWidth * 100.0f / remainingPercent });
+        tableWidthConstraints.maximum = std::max(tableWidthConstraints.maximum, adjustedMaximumWidth);
+    }
+
     // Expand the preferred width with leading and trailing cell spacing (note that column spanners count as one cell).
     tableWidthConstraints += (numberOfActualColumns + 1) * grid.horizontalSpacing();
     return tableWidthConstraints;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to