Truly independent web browser
LibWeb: Use column group widths for the columns without their own
Andreas Kling3362037717b8
diff --git a/Libraries/LibWeb/CSS/StyleEngineBridge.h b/Libraries/LibWeb/CSS/StyleEngineBridge.hindex 351a6ec754f..86904e4bcc2 100644--- a/Libraries/LibWeb/CSS/StyleEngineBridge.h+++ b/Libraries/LibWeb/CSS/StyleEngineBridge.h@@ -50,7 +50,7 @@ void style_engine_set_text_is_in_user_agent_shadow_tree(DocumentHost const*, Styvoid style_engine_set_text_is_password_input(DocumentHost const*, StyleNodeID node, bool value);void style_engine_set_node_dom_paint_facts(DocumentHost const*, StyleNodeID node, u8 facts);void style_engine_set_element_unique_node_id(DocumentHost const*, StyleNodeID node, u64 unique_node_id);-void style_engine_set_element_table_spans(DocumentHost const*, StyleNodeID node, u32 column_span, u32 row_span, u32 raw_column_span);+void style_engine_set_element_table_spans(DocumentHost const*, StyleNodeID node, u32 column_span, u32 row_span);void style_engine_set_element_id_name(DocumentHost const*, StyleNodeID node, StyleAtomID name);void style_engine_set_shadow_root(DocumentHost const*, StyleNodeID shadow_host, StyleNodeID shadow_root);void style_engine_record_environment_change(DocumentHost const*);diff --git a/Libraries/LibWeb/Layout/LayoutRustBridge.cpp b/Libraries/LibWeb/Layout/LayoutRustBridge.cppindex 23f1da71d77..7e918edff02 100644--- a/Libraries/LibWeb/Layout/LayoutRustBridge.cpp+++ b/Libraries/LibWeb/Layout/LayoutRustBridge.cpp@@ -363,19 +363,15 @@ void publish_table_spans(DOM::Element const& element)return;u16 column_span = 1;u16 row_span = 1;- u32 raw_column_span = 1;if (auto const* cell = as_if<HTML::HTMLTableCellElement>(element)) {column_span = static_cast<u16>(cell->col_span());row_span = static_cast<u16>(cell->row_span());} else if (auto const* column = as_if<HTML::HTMLTableColElement>(element)) {column_span = static_cast<u16>(column->span());- // The raw span keeps the unclamped attribute value; its only consumer is the table formatting context's column- // handling, so other elements' span attributes stay out of the mirror.- raw_column_span = column->get_attribute_value(HTML::AttributeNames::span).to_number<u32>().value_or(1);} else {return;}- CSS::StyleEngineFFI::style_engine_set_element_table_spans(const_cast<DOM::Document&>(element.document()).style_computer().style_engine().host(), element.style_node_id(), column_span, row_span, raw_column_span);+ CSS::StyleEngineFFI::style_engine_set_element_table_spans(const_cast<DOM::Document&>(element.document()).style_computer().style_engine().host(), element.style_node_id(), column_span, row_span);}// The publication is keyed by the element's style node rather than by a row, because an element that draws nothingdiff --git a/Libraries/LibWeb/Rust/src/css/style/boundary.rs b/Libraries/LibWeb/Rust/src/css/style/boundary.rsindex 2947f1ac32f..d40b1cf3728 100644--- a/Libraries/LibWeb/Rust/src/css/style/boundary.rs+++ b/Libraries/LibWeb/Rust/src/css/style/boundary.rs@@ -234,12 +234,11 @@ style_boundary! {set_node_dom_paint_facts => SetNodeDomPaintFacts { node: StyleNodeID, facts: u8 };set_element_unique_node_id => SetElementUniqueNodeId { node: StyleNodeID, unique_node_id: i64 };set_element_table_spans => SetElementTableSpans {- node: StyleNodeID, column_span: u32, row_span: u32, raw_column_span: u32+ node: StyleNodeID, column_span: u32, row_span: u32} =>engine.set_element_table_spans(node, TableSpans {column_span: u16::try_from(column_span).expect("a column span is clamped to 1000"),row_span: u16::try_from(row_span).expect("a row span is clamped to 65534"),- raw_column_span,});set_element_id_name => SetElementIdName { node: StyleNodeID, name: StyleAtomID };set_shadow_root => SetShadowRoot { shadow_host: StyleNodeID, shadow_root: StyleNodeID };diff --git a/Libraries/LibWeb/Rust/src/css/style/tree.rs b/Libraries/LibWeb/Rust/src/css/style/tree.rsindex fe347d1578a..6da5beafa4d 100644--- a/Libraries/LibWeb/Rust/src/css/style/tree.rs+++ b/Libraries/LibWeb/Rust/src/css/style/tree.rs@@ -595,7 +595,6 @@ impl Iterator for FlatTreeChildren<'_> {pub struct TableSpans {pub column_span: u16,pub row_span: u16,- pub raw_column_span: u32,}impl Default for TableSpans {@@ -603,7 +602,6 @@ impl Default for TableSpans {Self {column_span: 1,row_span: 1,- raw_column_span: 1,}}}@@ -2463,7 +2461,6 @@ mod tests {let spans = TableSpans {column_span: 2,row_span: 3,- raw_column_span: 2,};fixture.tree.set_table_spans(element, spans);assert_eq!(fixture.tree.table_spans(element), spans);diff --git a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rsindex 7ac92fa140b..bd2eaa4a27b 100644--- a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs+++ b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs@@ -1278,7 +1278,6 @@ pub(crate) struct LayoutNodeArena {text_slots: TextSlots,pub(super) searchable_text: Option<Vec<super::text_queries::MappedText>>,replaced_content_facts: Vec<ReplacedContentFactsSlot>,- raw_table_column_spans: RefCell<HashMap<NodeSlotId, u32>>,/// The layout kind of each row built for a MathML element, from its tag name.math_layout_kinds: RefCell<HashMap<NodeSlotId, super::math_formatting_context::MathLayoutKind>>,replaced_paint_facts: RefCell<Arc<crate::painting::replaced_paint_facts::ReplacedPaintFactsTable>>,@@ -1395,7 +1394,6 @@ impl LayoutNodeArena {text_slots: TextSlots::default(),searchable_text: None,replaced_content_facts: Vec::new(),- raw_table_column_spans: RefCell::default(),math_layout_kinds: RefCell::default(),replaced_paint_facts: RefCell::default(),layer_image_paint_facts: RefCell::default(),@@ -1752,7 +1750,6 @@ impl LayoutNodeArena {self.fc_run_cache_store.remove_entry(index);self.in_flow_block_cache_store.remove_entry(index);self.remove_layout_update_flag_node(id);- self.raw_table_column_spans.get_mut().remove(&id);self.math_layout_kinds.get_mut().remove(&id);if self.replaced_paint_facts.get_mut().contains_key(&id) {Arc::make_mut(self.replaced_paint_facts.get_mut()).remove(&id);@@ -5251,17 +5248,10 @@ impl LayoutNodeArena {/// they changed.pub(crate) fn set_table_spans(&self, id: NodeSlotId, spans: TableSpans) -> bool {let data = self.data(id);- let effective_spans_changed =- data.table_column_span.get() != spans.column_span || data.table_row_span.get() != spans.row_span;+ let changed = data.table_column_span.get() != spans.column_span || data.table_row_span.get() != spans.row_span;data.table_column_span.set(spans.column_span);data.table_row_span.set(spans.row_span);- let mut raw_spans = self.raw_table_column_spans.borrow_mut();- let previous_raw_column_span = if spans.raw_column_span == 1 {- raw_spans.remove(&id)- } else {- raw_spans.insert(id, spans.raw_column_span)- };- effective_spans_changed || previous_raw_column_span.unwrap_or(1) != spans.raw_column_span+ changed}/// The layout algorithm the MathML element a row is built for selects by its tag name.@@ -5273,12 +5263,6 @@ impl LayoutNodeArena {.unwrap_or(super::math_formatting_context::MathLayoutKind::NotMathML)}- pub(crate) fn raw_table_column_span(&self, id: NodeSlotId) -> u32 {- // data() validates that id names a live slot with a matching generation.- self.data(id);- self.raw_table_column_spans.borrow().get(&id).copied().unwrap_or(1)- }-pub(crate) fn text_content(&self, id: NodeSlotId) -> Option<&TextContent> {self.text_node_state(id)?.content.as_ref()}@@ -6625,7 +6609,6 @@ mod tests {let spans = TableSpans {column_span: 2,row_span: 3,- raw_column_span: 1,};engine.set_element_table_spans(element, spans);let mut arena = LayoutNodeArena::new();diff --git a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rsindex 2f92bc05e46..4fc53c1d698 100644--- a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs@@ -1018,10 +1018,6 @@ impl<'pass> TableFormattingContext<'pass> {StyleValues::for_node(&self.run.callbacks, node)}- fn raw_column_span(&self, column: Node) -> usize {- self.run.callbacks.arena().raw_table_column_span(column) as usize- }-pub(super) fn new(run: &FormattingContextRun<'pass>) -> Self {Self {run: FormattingContextRun {@@ -1118,8 +1114,9 @@ impl<'pass> TableFormattingContext<'pass> {/// The grid columns of the table-column boxes in tree order, each spanning the columns that its span attribute/// gives it. A table-column-group box without table-column children stands for the columns it spans itself, as/// the HTML table forming algorithm forms them: https://html.spec.whatwg.org/multipage/tables.html#forming-a-table- /// A table-column box is a child of a table-column-group, or a direct child of the table root (see- /// table_columns()).+ /// A table-column box is a child of a table-column-group, or a direct child of the table root: the fixup+ /// algorithm leaves the latter in place, as "A table-column box is misparented if its parent is neither a+ /// table-column-group box nor a table-root box": https://www.w3.org/TR/css-tables-3/#fixup-algorithmfn column_track_ranges(&mut self) -> Vec<ColumnTrackRange> {let column_count = self.columns.len();let mut ranges = Vec::new();@@ -1147,25 +1144,23 @@ impl<'pass> TableFormattingContext<'pass> {ranges}- /// The table-column boxes of the table in grid order. A table-column box is a child of a table-column-group, or- /// a direct child of the table root: the fixup algorithm leaves the latter in place, as "A table-column box is- /// misparented if its parent is neither a table-column-group box nor a table-root box":- /// https://www.w3.org/TR/css-tables-3/#fixup-algorithm- fn table_columns(&mut self) -> Vec<Node> {- let mut columns = Vec::new();- for child in self.matching_children(self.run.box_, |facts| {- facts.is_table_column_group() || facts.is_table_column()- }) {- if self.node_facts(child).is_table_column() {- columns.push(child);- } else {- columns.extend(self.matching_children(child, |facts| facts.is_table_column()));- }+ /// The box whose style gives the width specified for the columns of a range, which is also the one that makes+ /// them constrained and gives them a percentage contribution.+ fn column_sizing_box(&self, range: ColumnTrackRange) -> Node {+ // https://www.w3.org/TR/css-tables-3/#min-content-width-of-a-column-based-on-cells-of-span-up-to-1+ // the width specified for the column:+ // - the outer min-content width of its corresponding table-column, if any (and not auto)+ // - the outer min-content width of its corresponding table-column-group, if any+ // - or 0, if there is none+ // NB: The first of these that applies is the width specified for the column, for its outer max-content+ // width, its constrainedness and its percentage contribution as well.+ match range.group {+ Some(group) if range.is_group_without_columns() || self.style(range.box_).width().is_auto() => group,+ _ => range.box_,}- columns}- /// The table-column-group boxes and table-column boxes of the table in tree order (see table_columns()).+ /// The table-column-group boxes and table-column boxes of the table in tree order (see column_track_ranges()).fn column_boxes(&mut self) -> Vec<Node> {let mut boxes = Vec::new();for child in self.matching_children(self.run.box_, |facts| {@@ -1503,12 +1498,12 @@ impl<'pass> TableFormattingContext<'pass> {// Definition of constrainedness: https://www.w3.org/TR/css-tables-3/#constrainedness// NB: The definition uses https://www.w3.org/TR/CSS21/visudet.html#propdef-width for width, which doesn't include// keyword values. The remaining checks can be simplified to checking whether the size is a length.- let mut column_index = 0usize;- for column in self.table_columns() {- if self.style(column).width().is_length() {- self.columns[column_index].is_constrained = true;+ for range in self.column_track_ranges() {+ if self.style(self.column_sizing_box(range)).width().is_length() {+ for index in range.start..range.end {+ self.columns[index].is_constrained = true;+ }}- column_index += self.raw_column_span(column);}for row_index in 0..self.rows.len() {let row_box = self.rows[row_index].box_;@@ -1730,12 +1725,10 @@ impl<'pass> TableFormattingContext<'pass> {fn compute_outer_content_sizes(&mut self) {let basis = self.table_constraints.inline_basis();- let mut column_index = 0usize;- for column in self.table_columns() {- let style = self.style(column);- // Only lengths take part in the outer sizes of a column. A percentage width or max-width is the column's- // percentage contribution (https://www.w3.org/TR/css-tables-3/#percentage-contribution) and is resolved- // against the assignable table inline size during distribution, not against the containing block.+ // Only lengths take part in the outer sizes of a column. A percentage width or max-width is the column's+ // percentage contribution (https://www.w3.org/TR/css-tables-3/#percentage-contribution) and is resolved+ // against the assignable table inline size during distribution, not against the containing block.+ let outer_sizes = |style: StyleValues<'_>| {let length_or_zero = |size: &ComputedSize| {if size.is_length() {size.to_px(basis)@@ -1750,11 +1743,17 @@ impl<'pass> TableFormattingContext<'pass> {CssPixels::from_raw(i32::MAX)};let size = length_or_zero(style.width());- // The outer min-content inline size of a table-column or table-column-group is max(min-width, width).- self.columns[column_index].min_size = min_size.max(size);- // The outer max-content inline size of a table-column or table-column-group is max(min-width, min(max-width, width)).- self.columns[column_index].max_size = min_size.max(max_size.min(size));- column_index += self.raw_column_span(column);+ // The outer min-content width of a table-column or table-column-group is max('min-width', 'width').+ // The outer max-content width of a table-column or table-column-group is+ // max('min-width', min('max-width', 'width')).+ (min_size.max(size), min_size.max(max_size.min(size)))+ };+ for range in self.column_track_ranges() {+ let (min_size, max_size) = outer_sizes(self.style(self.column_sizing_box(range)));+ for index in range.start..range.end {+ self.columns[index].min_size = min_size;+ self.columns[index].max_size = max_size;+ }}self.initialize_row_content_sizes();}@@ -1874,14 +1873,15 @@ impl<'pass> TableFormattingContext<'pass> {self.rows[index].intrinsic_percentage = Self::cell_percentage(style, axis);}} else {- let mut column_index = 0usize;- for column in self.table_columns() {- let style = self.style(column);+ for range in self.column_track_ranges() {+ let style = self.style(self.column_sizing_box(range));// Definition of percentage contribution: https://www.w3.org/TR/css-tables-3/#percentage-contribution- self.columns[column_index].has_intrinsic_percentage =- style.max_width().is_percentage() || style.width().is_percentage();- self.columns[column_index].intrinsic_percentage = Self::cell_percentage(style, axis);- column_index += self.raw_column_span(column);+ let has_intrinsic_percentage = style.max_width().is_percentage() || style.width().is_percentage();+ let intrinsic_percentage = Self::cell_percentage(style, axis);+ for index in range.start..range.end {+ self.columns[index].has_intrinsic_percentage = has_intrinsic_percentage;+ self.columns[index].intrinsic_percentage = intrinsic_percentage;+ }}}diff --git a/Tests/LibWeb/Text/expected/table/column-group-spans.txt b/Tests/LibWeb/Text/expected/table/column-group-spans.txtnew file mode 100644index 00000000000..e53e8ffaf39--- /dev/null+++ b/Tests/LibWeb/Text/expected/table/column-group-spans.txt@@ -0,0 +1,8 @@+group-span-two-cells: table 200, cells 100 100, columns colgroup@0+200+group-span-one-cell: table 200, cells 100, columns colgroup@0+200+column-span-two-cells: table 200, cells 100 100, columns colgroup@0+200 col@0+200+empty-group-then-column: table 170, cells 50 120, columns colgroup@0+50 colgroup@50+120 col@50+120+empty-group-then-percentage-column: table 400, cells 100 300, columns colgroup@0+100 colgroup@100+300 col@100+300+constrained-empty-group: table 400, cells 50 350, columns colgroup@0+50 colgroup@50+350 col@50+350+collapsed-group-span: table 22.25, cells 0 0 22.25, columns colgroup@0+0+collapsed-group-span-one-cell: table 30, cells 0, columns colgroup@0+0 colgroup@0+30 col@0+30diff --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 72a43d4a668..b406f8cc503 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,9 @@ Harness status: OKFound 4 tests-2 Pass-2 Fail+3 Pass+1 FailPass 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 (3)-Fail Checking intermediate min-content width for span 2 (4)\ No newline at end of file+Pass Checking intermediate min-content width for span 2 (4)\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-tables/width-distribution/computing-column-measure-0.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-tables/width-distribution/computing-column-measure-0.txtindex 603fda8139c..b8c5174ef97 100644--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-tables/width-distribution/computing-column-measure-0.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-tables/width-distribution/computing-column-measure-0.txt@@ -2,9 +2,8 @@ Harness status: OKFound 4 tests-3 Pass-1 Fail+4 PassPass Checking intermediate min-content width for span 1 (1)Pass Checking intermediate min-content width for span 1 (2)Pass Checking intermediate min-content width for span 1 (3)-Fail Checking intermediate min-content width for span 1 (4)\ No newline at end of file+Pass Checking intermediate min-content width for span 1 (4)\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/table/column-group-spans.html b/Tests/LibWeb/Text/input/table/column-group-spans.htmlnew file mode 100644index 00000000000..007b33b3610--- /dev/null+++ b/Tests/LibWeb/Text/input/table/column-group-spans.html@@ -0,0 +1,60 @@+<!DOCTYPE html>+<style>+ table {+ border-spacing: 0;+ font: 10px/1 monospace;+ margin-bottom: 4px;+ }+ td {+ padding: 0;+ }+</style>+<table id="group-span-two-cells">+ <colgroup span="2" style="width: 100px"></colgroup>+ <tr><td>a</td><td>b</td></tr>+</table>+<table id="group-span-one-cell">+ <colgroup span="2" style="width: 100px"></colgroup>+ <tr><td>a</td></tr>+</table>+<table id="column-span-two-cells">+ <col span="2" style="width: 100px">+ <tr><td>a</td><td>b</td></tr>+</table>+<table id="empty-group-then-column">+ <colgroup style="width: 50px"></colgroup>+ <col style="width: 120px">+ <tr><td>a</td><td>b</td></tr>+</table>+<table id="empty-group-then-percentage-column" style="width: 400px">+ <colgroup></colgroup>+ <col style="width: 75%">+ <tr><td>a</td><td>b</td></tr>+</table>+<table id="constrained-empty-group" style="width: 400px">+ <colgroup style="width: 50px"></colgroup>+ <col>+ <tr><td>a</td><td>b</td></tr>+</table>+<table id="collapsed-group-span">+ <colgroup span="2" style="visibility: collapse"></colgroup>+ <tr><td>aaaa</td><td>bbbb</td><td>cccc</td></tr>+</table>+<table id="collapsed-group-span-one-cell">+ <colgroup span="2" style="width: 100px; visibility: collapse"></colgroup>+ <col style="width: 30px">+ <tr><td>a</td></tr>+</table>+<script src="../include.js"></script>+<script>+ test(() => {+ for (const table of document.querySelectorAll("table")) {+ const cells = [...table.querySelectorAll("td")].map(cell => cell.getBoundingClientRect().width);+ const columns = [...table.querySelectorAll("colgroup, col")].map(column => {+ const rect = column.getBoundingClientRect();+ return `${column.localName}@${rect.left - table.getBoundingClientRect().left}+${rect.width}`;+ });+ println(`${table.id}: table ${table.getBoundingClientRect().width}, cells ${cells.join(" ")}, columns ${columns.join(" ")}`);+ }+ });+</script>