Truly independent web browser
LibWeb: Center MathML tables on the math axis
sideshowbarker86beccee3792
diff --git a/Libraries/LibWeb/CSS/StyleEngineInput.cpp b/Libraries/LibWeb/CSS/StyleEngineInput.cppindex 8a45efaf6eb..746391e03c2 100644--- a/Libraries/LibWeb/CSS/StyleEngineInput.cpp+++ b/Libraries/LibWeb/CSS/StyleEngineInput.cpp@@ -1666,7 +1666,7 @@ static u32 kind_box_type_adjustment_facts(DOM::Element const& element)set(is_html_element && local_name == HTML::TagNames::table, ElementStyleAdjustmentFact::IsTable);set(is_svg_element && local_name != "svg"sv, ElementStyleAdjustmentFact::ForcePositionStatic);set(is_mathml_element, ElementStyleAdjustmentFact::IsMathML);- set(local_name.equals_ignoring_ascii_case("mtable"sv), ElementStyleAdjustmentFact::IsMathMLMtable);+ set(is_mathml_element && local_name == MathML::TagNames::mtable, ElementStyleAdjustmentFact::IsMathMLMtable);set(local_name.equals_ignoring_ascii_case("mtr"sv), ElementStyleAdjustmentFact::IsMathMLMtr);set(local_name.equals_ignoring_ascii_case("mtd"sv), ElementStyleAdjustmentFact::IsMathMLMtd);set(is_html_element && local_name.equals_ignoring_ascii_case(HTML::TagNames::th), ElementStyleAdjustmentFact::IsTh);diff --git a/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rsindex c2e9c089f40..f696ec7715f 100644--- a/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs@@ -118,6 +118,13 @@ pub(super) fn size_token_line_to_ink(line: &mut line_box::LineBoxData) {line.next_line_block_offset = line.block_end;}+// https://w3c.github.io/mathml-core/#table-or-matrix-mtable+pub(super) fn table_baseline(style: &StyleValues<'_>, cells: used_values::RootInputCells) -> CssPixels {+ let collapsed = cells.uses_collapsing_borders_model();+ cells.border_box_block_size(collapsed) / 2 + MathConstants::for_style(style).axis_height()+ - cells.border_box_top(collapsed)+}+/// The unit of a MathML attribute value that is a `<length-percentage>`. Mirrors the C++ `MathLengthUnit`, where 0/// stands for an attribute that is absent or invalid.pub(crate) mod math_length_unit {diff --git a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rsindex c028b1663ff..06f30f0db8d 100644--- a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs@@ -5,6 +5,7 @@*/use super::*;+use crate::css::style::bridge::element_adjustment_fact;use std::ops::Range;pub(crate) const LINE_STYLE_NONE: u8 = 0;@@ -3929,6 +3930,20 @@ impl<'pass> TableFormattingContext<'pass> {/// Rows are positioned in the coordinate space of the table wrapper (see position_row_boxes), so the baselines are/// made relative to the content box of the table box here.fn derive_table_box_baselines(&self) {+ let arena = self.run.pass.arena();+ if arena.element_adjustment_facts(arena.dom_node_style_node(self.run.box_))+ & element_adjustment_fact::IS_MATHML_MTABLE+ != 0+ {+ let baseline = math_formatting_context::table_baseline(&self.style(self.run.box_), self.table_box_cells());+ self.derived_baselines_of_root_box.set(DerivedBaselines {+ first: Some(baseline),+ last: Some(baseline),+ inline_alignment: Some(baseline),+ });+ return;+ }+let baseline_in_wrapper =|row_index: usize| self.row_boxes[row_index].content_offset.get().y + self.row_baseline(row_index);// Collapsed rows are removed from the display (https://www.w3.org/TR/CSS22/tables.html#dynamic-effects).diff --git a/Tests/LibWeb/Text/expected/MathML/mtable-namespace-baseline.txt b/Tests/LibWeb/Text/expected/MathML/mtable-namespace-baseline.txtnew file mode 100644index 00000000000..ab013286b3f--- /dev/null+++ b/Tests/LibWeb/Text/expected/MathML/mtable-namespace-baseline.txt@@ -0,0 +1,3 @@+HTML mtable uses the first row: true+XML mtable uses the first row: true+Uppercase MathML MTABLE uses the first row: truediff --git a/Tests/LibWeb/Text/expected/wpt-import/mathml/presentation-markup/tables/table-axis-height.txt b/Tests/LibWeb/Text/expected/wpt-import/mathml/presentation-markup/tables/table-axis-height.txtindex 10f36dbc6f0..8c2ca788c0c 100644--- a/Tests/LibWeb/Text/expected/wpt-import/mathml/presentation-markup/tables/table-axis-height.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/mathml/presentation-markup/tables/table-axis-height.txt@@ -2,5 +2,5 @@ Harness status: OKFound 1 tests-1 Fail-Fail AxisHeight\ No newline at end of file+1 Pass+Pass AxisHeight\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/MathML/mtable-namespace-baseline.html b/Tests/LibWeb/Text/input/MathML/mtable-namespace-baseline.htmlnew file mode 100644index 00000000000..63b10d78ebf--- /dev/null+++ b/Tests/LibWeb/Text/input/MathML/mtable-namespace-baseline.html@@ -0,0 +1,38 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<style>+ .probe { display: inline-table; border-spacing: 0; }+ .row { display: table-row; }+ .cell { display: table-cell; height: 20px; }+ #baseline { display: inline-block; width: 1px; height: 0; }+</style>+<div><i id="baseline"></i></div>+<script>+ test(() => {+ const marker = document.getElementById("baseline");+ function baseline(namespace, name) {+ const table = document.createElementNS(namespace, name);+ table.setAttribute("class", "probe");+ for (let i = 0; i < 3; ++i) {+ const row = document.createElement("span");+ row.className = "row";+ const cell = document.createElement("span");+ cell.className = "cell";+ cell.textContent = "x";+ row.append(cell);+ table.append(row);+ }+ marker.before(table);+ const offset = marker.getBoundingClientRect().top - table.getBoundingClientRect().top;+ table.remove();+ return offset;+ }++ const html = "http://www.w3.org/1999/xhtml";+ const mathml = "http://www.w3.org/1998/Math/MathML";+ const ordinary = baseline(html, "table");+ println("HTML mtable uses the first row: " + (baseline(html, "mtable") === ordinary));+ println("XML mtable uses the first row: " + (baseline("urn:test", "mtable") === ordinary));+ println("Uppercase MathML MTABLE uses the first row: " + (baseline(mathml, "MTABLE") === ordinary));+ });+</script>