Title: [260337] trunk/Source/WebCore
Revision
260337
Author
[email protected]
Date
2020-04-19 10:49:01 -0700 (Sun, 19 Apr 2020)

Log Message

[LFC][TFC] Take border spacing into account when distributing column spanners width.
https://bugs.webkit.org/show_bug.cgi?id=210712

Reviewed by Antti Koivisto.

While distributing the column spanner extra space among individual columns,
the spacing between these columns (set by border-spacing) should be taken into
account and subtract it from the width to distribute.

<table style="border-spacing: 50px"><tr><td colspan=2>long long text</td></tr><tr><td>lo</td><td>xt</td><tr></table>
[long long text]
[lo]        [xt]
The individual columns don't require any extra space from the spanner.

* layout/FormattingContext.h:
(WebCore::Layout::FormattingContext::IntrinsicWidthConstraints::operator+=):
(WebCore::Layout::FormattingContext::IntrinsicWidthConstraints::operator-=):
* layout/tableformatting/TableFormattingContext.cpp:
(WebCore::Layout::TableFormattingContext::computedIntrinsicWidthConstraints):
(WebCore::Layout::TableFormattingContext::computedPreferredWidthForColumns):
(WebCore::Layout::TableFormattingContext::computeAndDistributeExtraHorizontalSpace):
* layout/tableformatting/TableGrid.h:
(WebCore::Layout::TableGrid::horizontalSpacing const):
(WebCore::Layout::TableGrid::totalHorizontalSpacing const): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (260336 => 260337)


--- trunk/Source/WebCore/ChangeLog	2020-04-19 17:24:09 UTC (rev 260336)
+++ trunk/Source/WebCore/ChangeLog	2020-04-19 17:49:01 UTC (rev 260337)
@@ -1,3 +1,30 @@
+2020-04-19  Zalan Bujtas  <[email protected]>
+
+        [LFC][TFC] Take border spacing into account when distributing column spanners width.
+        https://bugs.webkit.org/show_bug.cgi?id=210712
+
+        Reviewed by Antti Koivisto.
+
+        While distributing the column spanner extra space among individual columns,
+        the spacing between these columns (set by border-spacing) should be taken into
+        account and subtract it from the width to distribute.
+
+        <table style="border-spacing: 50px"><tr><td colspan=2>long long text</td></tr><tr><td>lo</td><td>xt</td><tr></table>
+        [long long text]
+        [lo]        [xt]
+        The individual columns don't require any extra space from the spanner.
+ 
+        * layout/FormattingContext.h:
+        (WebCore::Layout::FormattingContext::IntrinsicWidthConstraints::operator+=):
+        (WebCore::Layout::FormattingContext::IntrinsicWidthConstraints::operator-=):
+        * layout/tableformatting/TableFormattingContext.cpp:
+        (WebCore::Layout::TableFormattingContext::computedIntrinsicWidthConstraints):
+        (WebCore::Layout::TableFormattingContext::computedPreferredWidthForColumns):
+        (WebCore::Layout::TableFormattingContext::computeAndDistributeExtraHorizontalSpace):
+        * layout/tableformatting/TableGrid.h:
+        (WebCore::Layout::TableGrid::horizontalSpacing const):
+        (WebCore::Layout::TableGrid::totalHorizontalSpacing const): Deleted.
+
 2020-04-19  Emilio Cobos Álvarez  <[email protected]>
 
         Fix the logic to decide whether a property is enumerated in a computed style declaration.

Modified: trunk/Source/WebCore/layout/FormattingContext.h (260336 => 260337)


--- trunk/Source/WebCore/layout/FormattingContext.h	2020-04-19 17:24:09 UTC (rev 260336)
+++ trunk/Source/WebCore/layout/FormattingContext.h	2020-04-19 17:49:01 UTC (rev 260337)
@@ -71,6 +71,7 @@
     struct IntrinsicWidthConstraints {
         void expand(LayoutUnit horizontalValue);
         IntrinsicWidthConstraints& operator+=(const IntrinsicWidthConstraints&);
+        IntrinsicWidthConstraints& operator+=(LayoutUnit);
         IntrinsicWidthConstraints& operator-=(const IntrinsicWidthConstraints&);
         IntrinsicWidthConstraints& operator-=(LayoutUnit);
 
@@ -230,6 +231,12 @@
     return *this;
 }
 
+inline FormattingContext::IntrinsicWidthConstraints& FormattingContext::IntrinsicWidthConstraints::operator+=(LayoutUnit value)
+{
+    expand(value);
+    return *this;
+}
+
 inline FormattingContext::IntrinsicWidthConstraints& FormattingContext::IntrinsicWidthConstraints::operator-=(const IntrinsicWidthConstraints& other)
 {
     minimum -= other.minimum;
@@ -239,8 +246,7 @@
 
 inline FormattingContext::IntrinsicWidthConstraints& FormattingContext::IntrinsicWidthConstraints::operator-=(LayoutUnit value)
 {
-    minimum -= value;
-    maximum -= value;
+    expand(-value);
     return *this;
 }
 

Modified: trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp (260336 => 260337)


--- trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp	2020-04-19 17:24:09 UTC (rev 260336)
+++ trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp	2020-04-19 17:49:01 UTC (rev 260337)
@@ -186,7 +186,6 @@
     ensureTableGrid();
     // 2. Compute the minimum/maximum width of each column.
     auto computedWidthConstraints = computedPreferredWidthForColumns();
-    computedWidthConstraints.expand(grid.totalHorizontalSpacing());
     grid.setWidthConstraints(computedWidthConstraints);
     return computedWidthConstraints;
 }
@@ -280,20 +279,25 @@
     Vector<FormattingContext::IntrinsicWidthConstraints> columnIntrinsicWidths(columnList.size());
     // 3. Collect he min/max width for each column but ignore column spans for now.
     Vector<SlotPosition> spanningCellPositionList;
+    size_t numberOfActualColumns = 0;
     for (size_t columnIndex = 0; columnIndex < columnList.size(); ++columnIndex) {
+        auto columnHasNonSpannedCell = false;
         for (size_t rowIndex = 0; rowIndex < grid.rows().size(); ++rowIndex) {
             auto& slot = *grid.slot({ columnIndex, rowIndex });
+            if (slot.isColumnSpanned())
+                continue;
+            columnHasNonSpannedCell = true;
             if (slot.hasColumnSpan()) {
                 spanningCellPositionList.append({ columnIndex, rowIndex });
                 continue;
             }
-            if (slot.isColumnSpanned())
-                continue;
             auto columnFixedWidth = fixedWidthColumns[columnIndex];
             auto widthConstraints = !columnFixedWidth ? slot.widthConstraints() : FormattingContext::IntrinsicWidthConstraints { *columnFixedWidth, *columnFixedWidth };
             columnIntrinsicWidths[columnIndex].minimum = std::max(widthConstraints.minimum, columnIntrinsicWidths[columnIndex].minimum);
             columnIntrinsicWidths[columnIndex].maximum = std::max(widthConstraints.maximum, columnIntrinsicWidths[columnIndex].maximum);
         }
+        if (columnHasNonSpannedCell)
+            ++numberOfActualColumns;
     }
 
     // 4. Distribute the spanning min/max widths.
@@ -304,6 +308,12 @@
         auto widthConstraintsToDistribute = slot.widthConstraints();
         for (size_t columnSpanIndex = cell.startColumn(); columnSpanIndex < cell.endColumn(); ++columnSpanIndex)
             widthConstraintsToDistribute -= columnIntrinsicWidths[columnSpanIndex];
+        // <table style="border-spacing: 50px"><tr><td colspan=2>long long text</td></tr><tr><td>lo</td><td>xt</td><tr></table>
+        // [long long text]
+        // [lo]        [xt]
+        // While it looks like the spanning cell has to distribute all its spanning width, the border-spacing takes most of the space and
+        // no distribution is needed at all.
+        widthConstraintsToDistribute -= (cell.columnSpan() - 1) * grid.horizontalSpacing();
         // FIXME: Check if fixed width columns should be skipped here.
         widthConstraintsToDistribute.minimum = std::max(LayoutUnit { }, widthConstraintsToDistribute.minimum / cell.columnSpan());
         widthConstraintsToDistribute.maximum = std::max(LayoutUnit { }, widthConstraintsToDistribute.maximum / cell.columnSpan());
@@ -317,6 +327,8 @@
     auto tableWidthConstraints = IntrinsicWidthConstraints { };
     for (auto& columnIntrinsicWidth : columnIntrinsicWidths)
         tableWidthConstraints += columnIntrinsicWidth;
+    // Exapand the preferred width with leading and trailing cell spacing (note that column spanners count as one cell).
+    tableWidthConstraints += (numberOfActualColumns + 1) * grid.horizontalSpacing();
     return tableWidthConstraints;
 }
 
@@ -418,9 +430,11 @@
                 // 2. Distribute the extra minimum width among the spanned columns based on the minimum colmn width.
                 // e.g. spanning mimimum width: [   9   ]. Current minimum widths for the spanned columns: [ 1 ] [ 2 ]
                 // New minimum widths: [ 3 ] [ 6 ].
-                auto spaceToDistribute = spanningMinimumWidth - currentSpanningMinimumWidth;
-                for (auto columnIndex = cell.startColumn(); columnIndex < cell.endColumn(); ++columnIndex)
-                    columnMinimumWidths[columnIndex]->value += spaceToDistribute / currentSpanningMinimumWidth * columnMinimumWidths[columnIndex]->value;
+                auto spaceToDistribute = std::max(0.0f, spanningMinimumWidth - (cell.columnSpan() - 1) * grid.horizontalSpacing() - currentSpanningMinimumWidth);
+                if (spaceToDistribute) {
+                    for (auto columnIndex = cell.startColumn(); columnIndex < cell.endColumn(); ++columnIndex)
+                        columnMinimumWidths[columnIndex]->value += spaceToDistribute / currentSpanningMinimumWidth * columnMinimumWidths[columnIndex]->value;
+                }
             }
         }
         // 3. Distribute the extra space using the final minimum widths.

Modified: trunk/Source/WebCore/layout/tableformatting/TableGrid.h (260336 => 260337)


--- trunk/Source/WebCore/layout/tableformatting/TableGrid.h	2020-04-19 17:24:09 UTC (rev 260336)
+++ trunk/Source/WebCore/layout/tableformatting/TableGrid.h	2020-04-19 17:49:01 UTC (rev 260337)
@@ -51,7 +51,6 @@
 
     void setHorizontalSpacing(LayoutUnit horizontalSpacing) { m_horizontalSpacing = horizontalSpacing; }
     LayoutUnit horizontalSpacing() const { return m_horizontalSpacing; }
-    LayoutUnit totalHorizontalSpacing() const { return (columns().size() + 1) * horizontalSpacing(); }
 
     void setVerticalSpacing(LayoutUnit verticalSpacing) { m_verticalSpacing = verticalSpacing; }
     LayoutUnit verticalSpacing() const { return m_verticalSpacing; }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to