Truly independent web browser
LibWeb: Size a percentage row as auto in an auto-height table
sideshowbarkerd9ef44d452ea
diff --git a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rsindex eb8f375f8da..635a83dda55 100644--- a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs@@ -1972,7 +1972,14 @@ impl<'pass> TableFormattingContext<'pass> {}fn initialize_row_content_sizes(&mut self) {- let basis = self.table_constraints.block_basis();+ // NB: A row's percentage block sizes resolve against the table's block size, which an auto-height table doesn't+ // have yet, so they count as 0px there: "the computed height (if definite, percentages being considered 0px)"+ // https://www.w3.org/TR/css-tables-3/#computing-the-table-height+ let basis = if self.table_block_size_is_auto() {+ CssPixels::default()+ } else {+ self.table_constraints.block_basis()+ };for row_index in 0..self.rows.len() {let style = self.style(self.rows[row_index].box_);let min_size = style.min_height().to_px(basis);@@ -3156,7 +3163,10 @@ impl<'pass> TableFormattingContext<'pass> {continue;}let style = self.style(self.rows[row_index].box_);- if style.height().is_percentage() {+ // NB: A percentage block size resolves against the table's, which an auto-height table doesn't have before+ // its rows are sized. So in such a table, a row with a percentage block size is sized as an auto row+ // is, as a cell with one is (see cell_has_resolvable_percentage_block_size()).+ if style.height().is_percentage() && !self.table_block_size_is_auto() {let used = style.height().to_px(table_percentage_basis);self.rows[row_index].reference_block_size = self.rows[row_index].reference_block_size.max(used);}@@ -3293,7 +3303,12 @@ impl<'pass> TableFormattingContext<'pass> {return;}let auto_rows = (0..self.rows.len())- .filter(|index| !self.rows[*index].is_collapsed && self.style(self.rows[*index].box_).height().is_auto())+ .filter(|index| {+ // NB: A row with a percentage block size counts as an auto row in an auto-height table.+ let height = self.style(self.rows[*index].box_).height();+ !self.rows[*index].is_collapsed+ && (height.is_auto() || (height.is_percentage() && self.table_block_size_is_auto()))+ }).collect::<Vec<_>>();if self.table_block_size <= sum && sum != CssPixels::default() {// If the table block size is no larger than the sum of reference sizes, each final row block size is thediff --git a/Tests/LibWeb/Layout/expected/table/percentage-row-heights-in-auto-height-table-with-definite-parent.txt b/Tests/LibWeb/Layout/expected/table/percentage-row-heights-in-auto-height-table-with-definite-parent.txtnew file mode 100644index 00000000000..fc325dc016a--- /dev/null+++ b/Tests/LibWeb/Layout/expected/table/percentage-row-heights-in-auto-height-table-with-definite-parent.txt@@ -0,0 +1,15 @@+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 216 0+0+0] [BFC] children: not-inline+ BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 200 0+0+8] children: not-inline+ BlockContainer <div#parent> at [8,8] [0+0+0 784 0+0+0] [0+0+0 200 0+0+0] children: not-inline+ TableWrapper <(anonymous)> at [8,8] [0+0+0 784 0+0+0] [0+0+0 68 0+0+0] [BFC] children: not-inline+ Box <table> at [8,8] table-box [0+0+0 784 0+0+0] [0+0+0 68 0+0+0] [TFC] children: not-inline+ Box <tbody> at [10,10] table-row-group [0+0+0 780 0+0+0] [0+0+0 64 0+0+0] children: not-inline+ Box <tr> at [10,10] table-row [0+0+0 780 0+0+0] [0+0+0 62 0+0+0] children: not-inline+ BlockContainer <td> at [11,11] table-cell [0+0+1 778 1+0+0] [0+0+1 60 1+0+0] [BFC] children: not-inline+ BlockContainer <div.image> at [11,11] [0+0+0 400 0+0+378] [0+0+0 60 0+0+0] children: not-inline+ Box <tr> at [10,74] table-row [0+0+0 780 0+0+0] [0+0+0 0 0+0+0] children: not-inline+ BlockContainer <(anonymous)> at [10,74] table-cell [0+0+0 780 0+0+0] [0+0+0 0 0+0+0] [BFC] children: not-inline++SC for Viewport<#document> [0,0 800x600] (z-index: auto)+ SC for BlockContainer<HTML> [0,0 800x216] (z-index: auto)diff --git a/Tests/LibWeb/Layout/expected/table/percentage-row-heights-in-auto-height-table.txt b/Tests/LibWeb/Layout/expected/table/percentage-row-heights-in-auto-height-table.txtnew file mode 100644index 00000000000..fdedbc84598--- /dev/null+++ b/Tests/LibWeb/Layout/expected/table/percentage-row-heights-in-auto-height-table.txt@@ -0,0 +1,14 @@+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 84 0+0+0] [BFC] children: not-inline+ BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 68 0+0+8] children: not-inline+ TableWrapper <(anonymous)> at [8,8] [0+0+0 784 0+0+0] [0+0+0 68 0+0+0] [BFC] children: not-inline+ Box <table> at [8,8] table-box [0+0+0 784 0+0+0] [0+0+0 68 0+0+0] [TFC] children: not-inline+ Box <tbody> at [10,10] table-row-group [0+0+0 780 0+0+0] [0+0+0 64 0+0+0] children: not-inline+ Box <tr> at [10,10] table-row [0+0+0 780 0+0+0] [0+0+0 62 0+0+0] children: not-inline+ BlockContainer <td> at [11,11] table-cell [0+0+1 778 1+0+0] [0+0+1 60 1+0+0] [BFC] children: not-inline+ BlockContainer <div.image> at [11,11] [0+0+0 400 0+0+378] [0+0+0 60 0+0+0] children: not-inline+ Box <tr> at [10,74] table-row [0+0+0 780 0+0+0] [0+0+0 0 0+0+0] children: not-inline+ BlockContainer <(anonymous)> at [10,74] table-cell [0+0+0 780 0+0+0] [0+0+0 0 0+0+0] [BFC] children: not-inline++SC for Viewport<#document> [0,0 800x600] (z-index: auto)+ SC for BlockContainer<HTML> [0,0 800x84] (z-index: auto)diff --git a/Tests/LibWeb/Layout/input/table/percentage-row-heights-in-auto-height-table-with-definite-parent.html b/Tests/LibWeb/Layout/input/table/percentage-row-heights-in-auto-height-table-with-definite-parent.htmlnew file mode 100644index 00000000000..654d64ac148--- /dev/null+++ b/Tests/LibWeb/Layout/input/table/percentage-row-heights-in-auto-height-table-with-definite-parent.html@@ -0,0 +1,5 @@+<!DOCTYPE html><style>+ #parent { height: 200px; }+ td { background-color: black; }+ .image { width: 400px; height: 60px; background-color: gray; }+</style><div id="parent"><table width="100%"><tr height="100%"><td><div class="image"></div></td></tr><tr height="500%"></tr></table></div>diff --git a/Tests/LibWeb/Layout/input/table/percentage-row-heights-in-auto-height-table.html b/Tests/LibWeb/Layout/input/table/percentage-row-heights-in-auto-height-table.htmlnew file mode 100644index 00000000000..7c6a85489a7--- /dev/null+++ b/Tests/LibWeb/Layout/input/table/percentage-row-heights-in-auto-height-table.html@@ -0,0 +1,4 @@+<!DOCTYPE html><style>+ td { background-color: black; }+ .image { width: 400px; height: 60px; background-color: gray; }+</style><table width="100%"><tr height="100%"><td><div class="image"></div></td></tr><tr height="500%"></tr></table>