Truly independent web browser
LibWeb: Give a colspan cell’s extra width to unconstrained columns
sideshowbarker208f93aef41f
diff --git a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rsindex 635a83dda55..65d38fe9ff2 100644--- a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs@@ -1768,7 +1768,8 @@ impl<'pass> TableFormattingContext<'pass> {for cell_index in 0..self.cells.len() {let cell = self.cells[cell_index];let style = self.style(cell.box_);- if style.width().is_length() {+ // "any of the cells spanning only that column"+ if cell.column_span == 1 && style.width().is_length() {self.columns[cell.column_index].is_constrained = true;}if style.height().is_length() {@@ -2335,6 +2336,33 @@ impl<'pass> TableFormattingContext<'pass> {(start..end).fold(CssPixels::default(), |sum, index| sum + self.track_min(axis, index));// Define the baseline border spacing as the sum of the horizontal border-spacing for any columns spanned by the cell, other than the one in which the cell originates.let spacing = track_spacing * (current_span - 1);+ // AD-HOC: The spec gives what the cell needs beyond the baseline max-content size to all the columns it+ // spans, in proportion to their max-content sizes. Other browsers give it to the spanned columns+ // that aren't constrained, and give a constrained column only what it needs itself, unless all+ // the spanned columns are constrained.+ let unconstrained_tracks = (start..end)+ .filter(|&index| axis == TrackAxis::Column && !self.columns[index].is_constrained)+ .collect::<Vec<_>>();+ let growing_tracks = if unconstrained_tracks.is_empty() {+ (start..end).collect::<Vec<_>>()+ } else {+ unconstrained_tracks+ };+ let growing_max = growing_tracks+ .iter()+ .fold(CssPixels::default(), |sum, &index| sum + self.track_max(axis, index));+ let share_beyond_max = |index: usize, beyond_max: CssPixels| {+ if !growing_tracks.contains(&index) {+ CssPixels::default()+ } else if growing_max != CssPixels::default() {+ CssPixels::nearest_value_for(self.track_max(axis, index).to_double() / growing_max.to_double())+ * beyond_max+ } else {+ // AD-HOC: The spec does not define behavior when baseline is zero. We distribute equally.+ // This matches how undefined ratios are handled elsewhere.+ beyond_max / growing_tracks.len()+ }+ };// Add contribution from all rows / columns, since we've weighted the gap to the desired spanned size by the the// ratio of the max-content size based on cells of span up to N-1 of the row / column to the baseline max-content width.for index in start..end {@@ -2362,17 +2390,10 @@ impl<'pass> TableFormattingContext<'pass> {// the product of:// - the ratio of the max-content size based on cells of span up to N-1 of the column to the baseline max-content size// - the outer min-content size of the cell minus the baseline max-content size and baseline border spacing, or 0 if this is negative- if baseline_max != CssPixels::default() {- min_contribution += CssPixels::nearest_value_for(- self.track_max(axis, index).to_double() / baseline_max.to_double(),- ) * (Self::cell_min(cell, axis) - baseline_max - spacing)- .max(CssPixels::default());- } else {- // AD-HOC: The spec does not define behavior when baseline is zero. We distribute equally.- // This matches how undefined ratios are handled elsewhere.- min_contribution +=- (Self::cell_min(cell, axis) - spacing).max(CssPixels::default()) / current_span;- }+ min_contribution += share_beyond_max(+ index,+ (Self::cell_min(cell, axis) - baseline_max - spacing).max(CssPixels::default()),+ );// The contribution of the cell is the sum of:// the max-content size of the column based on cells of span up to N-1@@ -2380,17 +2401,10 @@ impl<'pass> TableFormattingContext<'pass> {// and the product of:// - the ratio of the max-content size based on cells of span up to N-1 of the column to the baseline max-content size// - the outer max-content size of the cell minus the baseline max-content size and the baseline border spacing, or 0 if this is negative- if baseline_max != CssPixels::default() {- max_contribution += CssPixels::nearest_value_for(- self.track_max(axis, index).to_double() / baseline_max.to_double(),- ) * (Self::cell_max(cell, axis) - baseline_max - spacing)- .max(CssPixels::default());- } else {- // AD-HOC: The spec does not define behavior when baseline is zero. We distribute equally,- // This matches how undefined ratios are handled elsewhere.- max_contribution +=- (Self::cell_max(cell, axis) - spacing).max(CssPixels::default()) / current_span;- }+ max_contribution += share_beyond_max(+ index,+ (Self::cell_max(cell, axis) - baseline_max - spacing).max(CssPixels::default()),+ );min_contributions[index] = min_contributions[index].max(min_contribution);max_contributions[index] = max_contributions[index].max(max_contribution);}diff --git a/Tests/LibWeb/Layout/expected/table/colspan-width-goes-to-unconstrained-columns.txt b/Tests/LibWeb/Layout/expected/table/colspan-width-goes-to-unconstrained-columns.txtnew file mode 100644index 00000000000..b8942b0e8fd--- /dev/null+++ b/Tests/LibWeb/Layout/expected/table/colspan-width-goes-to-unconstrained-columns.txt@@ -0,0 +1,27 @@+Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children: not-inline+ BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 62 0+0+0] [BFC] children: not-inline+ BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 46 0+0+8] children: not-inline+ TableWrapper <(anonymous)> at [8,8] [0+0+0 508 0+0+276] [0+0+0 46 0+0+0] [BFC] children: not-inline+ Box <table> at [8,8] table-box [0+0+0 508 0+0+0] [0+0+0 46 0+0+0] [TFC] children: not-inline+ Box <tbody> at [10,10] table-row-group [0+0+0 504 0+0+0] [0+0+0 42 0+0+0] children: not-inline+ Box <tr> at [10,10] table-row [0+0+0 504 0+0+0] [0+0+0 20 0+0+0] children: not-inline+ BlockContainer <td> at [12,12] table-cell [0+1+1 500 1+1+0] [0+1+1 16 1+1+0] [BFC] children: inline+ frag 0 from TextNode start: 0, length: 4, rect: [12,12 32.359375x16] baseline: 12.796875+ "wide"+ TextNode <#text> (not painted)+ Box <tr> at [10,32] table-row [0+0+0 504 0+0+0] [0+0+0 20 0+0+0] children: not-inline+ BlockContainer <td> at [12,34] table-cell [0+1+1 249.578125 1+1+0] [0+1+1 16 1+1+0] [BFC] children: inline+ frag 0 from TextNode start: 0, length: 1, rect: [12,34 9.34375x16] baseline: 12.796875+ "a"+ TextNode <#text> (not painted)+ BlockContainer <td> at [267.578125,34] table-cell [0+1+1 4.34375 1+1+0] [0+1+1 16 1+1+0] [BFC] children: inline+ frag 0 from TextNode start: 0, length: 1, rect: [267.578125,34 4.34375x16] baseline: 12.796875+ "."+ TextNode <#text> (not painted)+ BlockContainer <td> at [277.921875,34] table-cell [0+1+1 234.078125 1+1+0] [0+1+1 16 1+1+0] [BFC] children: inline+ frag 0 from TextNode start: 0, length: 1, rect: [277.921875,34 8.390625x16] baseline: 12.796875+ "z"+ TextNode <#text> (not painted)++SC for Viewport<#document> [0,0 800x600] (z-index: auto)+ SC for BlockContainer<HTML> [0,0 800x62] (z-index: auto)diff --git a/Tests/LibWeb/Layout/input/table/colspan-width-goes-to-unconstrained-columns.html b/Tests/LibWeb/Layout/input/table/colspan-width-goes-to-unconstrained-columns.htmlnew file mode 100644index 00000000000..8882493df29--- /dev/null+++ b/Tests/LibWeb/Layout/input/table/colspan-width-goes-to-unconstrained-columns.html@@ -0,0 +1,6 @@+<!DOCTYPE html><style>+ td { border: 1px solid blue; }+</style><table>+<tr><td colspan="3" width="500">wide</td></tr>+<tr><td>a</td><td width="1">.</td><td>z</td></tr>+</table>diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-tables/height-distribution/computing-row-measure-1.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-tables/height-distribution/computing-row-measure-1.txtindex b406f8cc503..8ec63660c15 100644--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-tables/height-distribution/computing-row-measure-1.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-tables/height-distribution/computing-row-measure-1.txt@@ -2,9 +2,8 @@ Harness status: OKFound 4 tests-3 Pass-1 Fail+4 PassPass Checking intermediate min-content width for span 2 (1)-Fail Checking intermediate min-content width for span 2 (2)+Pass Checking intermediate min-content width for span 2 (2)Pass Checking intermediate min-content width for span 2 (3)Pass Checking intermediate min-content width for span 2 (4)\ No newline at end of file