Truly independent web browser
LibWeb: End a cell’s row span at the end of its row group
sideshowbarker00d9d3789236
diff --git a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rsindex 1182d1fd10d..468ec3c9d55 100644--- a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs@@ -792,6 +792,25 @@ impl TableGridOccupancy {fn finish_row(&mut self) {self.first_range_of_row.push(self.covered_columns.len());}++ /// Ends a row group, whose cells cover no row after it.+ fn finish_row_group(&mut self) {+ self.cells_spanning_later_rows.clear();+ }+}++/// Ends the row group whose cells start at `first_cell_of_group` in `cells`, now that every one of its rows is built:+/// No cell spans a row past the last row of its group.+fn finish_row_group(+ cells: &mut [TableCell],+ first_cell_of_group: usize,+ row_count: usize,+ occupancy: &mut TableGridOccupancy,+) {+ for cell in &mut cells[first_cell_of_group..] {+ cell.row_span = cell.row_span.min(row_count - cell.row_index);+ }+ occupancy.finish_row_group();}#[derive(Clone)]@@ -958,8 +977,19 @@ pub(crate) fn calculate_table_grid<T: TableTree>(tree: &T, table: Node, missing_rows.push(Row::new(row, tree.row_is_collapsed(row, row_group)));};+ // https://html.spec.whatwg.org/multipage/tables.html#forming-a-table+ // Each row group (and each run of rows that are children of the table itself) forms its own block of rows, which+ // the "algorithm for ending a row group" closes off. So, a cell's row span ends at the last row of its group.+ let mut first_cell_of_group = 0usize;+ let mut in_run_of_rows = false;for child in row_containers_in_layout_order(tree, table) {- if tree.display(child).is_table_row() {+ let is_row = tree.display(child).is_table_row();+ if !(is_row && in_run_of_rows) {+ finish_row_group(&mut cells, first_cell_of_group, rows.len(), &mut occupancy);+ first_cell_of_group = cells.len();+ }+ in_run_of_rows = is_row;+ if is_row {process_row(tree,child,@@ -984,8 +1014,9 @@ pub(crate) fn calculate_table_grid<T: TableTree>(tree: &T, table: Node, missing_}}+ finish_row_group(&mut cells, first_cell_of_group, rows.len(), &mut occupancy);+for cell in &mut cells {- cell.row_span = cell.row_span.min(rows.len() - cell.row_index);cell.column_span = cell.column_span.min(column_count - cell.column_index);}diff --git a/Tests/LibWeb/Text/expected/table/rowspan-ends-at-row-group.txt b/Tests/LibWeb/Text/expected/table/rowspan-ends-at-row-group.txtnew file mode 100644index 00000000000..d43b7f7d0cb--- /dev/null+++ b/Tests/LibWeb/Text/expected/table/rowspan-ends-at-row-group.txt@@ -0,0 +1,5 @@+huge-rowspans: 80x180; a@0,0+60 b@20,20+40 1@40,40+20 x@60,40+20 a@0,60+60 b@20,80+40 2@40,100+20 x@60,100+20 a@0,120+60 b@20,140+40 3@40,160+20 x@60,160+20+rowspan-into-next-tbody: 40x40; a@0,0+20 1@20,0+20 2@0,20+20 x@20,20+20+thead-rowspan: 40x40; h@0,0+20 1@20,0+20 2@0,20+20 x@20,20+20+tfoot-moved-after-tbody: 40x40; f@0,20+20 x@20,20+20 a@0,0+20 1@20,0+20+rowspan-within-tbody: 40x40; a@0,0+40 1@20,0+20 2@20,20+20diff --git a/Tests/LibWeb/Text/input/table/rowspan-ends-at-row-group.html b/Tests/LibWeb/Text/input/table/rowspan-ends-at-row-group.htmlnew file mode 100644index 00000000000..7a74a58acdc--- /dev/null+++ b/Tests/LibWeb/Text/input/table/rowspan-ends-at-row-group.html@@ -0,0 +1,38 @@+<!DOCTYPE html>+<style>+ table { border-spacing: 0; margin-bottom: 6px; }+ td { width: 20px; height: 20px; padding: 0; }+</style>+<table id="huge-rowspans">+ <tbody><tr><td rowspan="3000">a</td></tr><tr><td rowspan="3000">b</td></tr><tr><td>1</td><td>x</td></tr></tbody>+ <tbody><tr><td rowspan="3000">a</td></tr><tr><td rowspan="3000">b</td></tr><tr><td>2</td><td>x</td></tr></tbody>+ <tbody><tr><td rowspan="3000">a</td></tr><tr><td rowspan="3000">b</td></tr><tr><td>3</td><td>x</td></tr></tbody>+</table>+<table id="rowspan-into-next-tbody">+ <tbody><tr><td rowspan="5">a</td><td>1</td></tr></tbody>+ <tbody><tr><td>2</td><td>x</td></tr></tbody>+</table>+<table id="thead-rowspan">+ <thead><tr><td rowspan="3">h</td><td>1</td></tr></thead>+ <tbody><tr><td>2</td><td>x</td></tr></tbody>+</table>+<table id="tfoot-moved-after-tbody">+ <tfoot><tr><td>f</td><td>x</td></tr></tfoot>+ <tbody><tr><td rowspan="4">a</td><td>1</td></tr></tbody>+</table>+<table id="rowspan-within-tbody">+ <tbody><tr><td rowspan="2">a</td><td>1</td></tr><tr><td>2</td></tr></tbody>+</table>+<script src="../include.js"></script>+<script>+ test(() => {+ for (const table of document.querySelectorAll("table")) {+ const origin = table.getBoundingClientRect();+ const cells = [...table.querySelectorAll("td")].map(cell => {+ const r = cell.getBoundingClientRect();+ return `${cell.textContent}@${Math.round(r.left - origin.left)},${Math.round(r.top - origin.top)}+${Math.round(r.height)}`;+ });+ println(`${table.id}: ${Math.round(origin.width)}x${Math.round(origin.height)}; ${cells.join(" ")}`);+ }+ });+</script>