Truly independent web browser
LibWeb: Lay out mpadded with its requested parameters
Andreas Kling4377fcfb7ad5
diff --git a/Libraries/LibWeb/MathML/MathMLElement.cpp b/Libraries/LibWeb/MathML/MathMLElement.cppindex 7d1b78185cc..12b5865cca1 100644--- a/Libraries/LibWeb/MathML/MathMLElement.cpp+++ b/Libraries/LibWeb/MathML/MathMLElement.cpp@@ -83,6 +83,8 @@ void MathMLElement::visit_edges(JS::Cell::Visitor& visitor)bool MathMLElement::is_presentational_hint(Utf16FlyString const& name) const{+ if (local_name() == TagNames::mpadded && name == AttributeNames::width)+ return true;return first_is_one_of(name, AttributeNames::dir, AttributeNames::mathcolor, AttributeNames::mathbackground,AttributeNames::mathsize, AttributeNames::displaystyle, AttributeNames::scriptlevel);}@@ -90,6 +92,15 @@ bool MathMLElement::is_presentational_hint(Utf16FlyString const& name) constvoid MathMLElement::apply_presentational_hints(Vector<CSS::StyleProperty>& properties) const{Base::apply_presentational_hints(properties);+ // https://w3c.github.io/mathml-core/#inner-box-and-requested-parameters+ // If the width attribute is present, valid and not a percentage then that attribute is used as a presentational+ // hint setting the element's width property to the corresponding value.+ if (local_name() == TagNames::mpadded) {+ if (auto width = attribute(AttributeNames::width); width.has_value()) {+ if (auto value = parse_css_type(CSS::Parser::ParsingParams { document() }, width->utf16_view(), CSS::ValueType::Length))+ properties.append({ .property_id = CSS::PropertyID::Width, .value = value.release_nonnull() });+ }+ }for_each_attribute([&](Utf16FlyString const& name, Utf16View value) {if (name == AttributeNames::dir) {// https://w3c.github.io/mathml-core/#attributes-common-to-html-and-mathml-elementsdiff --git a/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rsindex cae722791e9..174a7cb4f81 100644--- a/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs@@ -866,6 +866,12 @@ impl<'pass> MathFormattingContext<'pass> {self.accents(root),),(MathLayoutKind::Mspace, _) => self.layout_space(&root_style),+ (MathLayoutKind::Mpadded, _) => {+ // The <mpadded> element generates an anonymous <mrow> box called the mpadded inner box.+ let add_space = self.core_operator(root).is_none();+ let inner = self.layout_row_with_operator_spacing(&children, kind, add_space);+ self.layout_padded(inner, &root_style)+ }(MathLayoutKind::Mmultiscripts, _) if self.is_valid_multiscripts(&children) => {layout_multiscripts(&children, self.prescripts_separator_index(&children), &constants)}@@ -995,6 +1001,52 @@ impl<'pass> MathFormattingContext<'pass> {)}+ // https://w3c.github.io/mathml-core/#adjust-space-around-content-mpadded+ fn layout_padded(&self, inner: MathContent, style: &StyleValues<'_>) -> MathContent {+ let attributes = self.run.callbacks.arena().math_attribute_facts(self.run.box_);+ let resolve = |length: FfiMathLength| {+ (!length.is_percentage())+ .then(|| length.resolve(style, CssPixels::default()))+ .flatten()+ };+ // If the height attribute is absent, invalid or a percentage then the requested height is the inner+ // line-ascent. Otherwise the requested height is the resolved value of the height attribute, clamping negative+ // values to 0.+ let requested_height =+ resolve(attributes.height).map_or(inner.ascent, |height| height.max(CssPixels::default()));+ // If the depth attribute is absent, invalid or a percentage then the requested depth is the inner line-ascent.+ // Otherwise the requested depth is the resolved value of the depth attribute, clamping negative values to 0.+ // AD-HOC: The inner line-descent is used as the default requested depth, as the depth of the inner box is what+ // it stands for. The inner line-ascent would give the content the depth of its height.+ let requested_depth = resolve(attributes.depth).map_or(inner.descent, |depth| depth.max(CssPixels::default()));+ // If the lspace attribute is absent, invalid or a percentage then the requested lspace is 0. Otherwise the+ // requested lspace is the resolved value of the lspace attribute, clamping negative values to 0.+ let requested_lspace =+ resolve(attributes.lspace).map_or(CssPixels::default(), |lspace| lspace.max(CssPixels::default()));+ // If the voffset attribute is absent, invalid or a percentage then the requested voffset is 0. Otherwise the+ // requested voffset is the resolved value of the voffset attribute.+ let requested_voffset = resolve(attributes.voffset).unwrap_or_default();+ // The inline size of the math content is the requested width.+ // NB: The width attribute is a presentational hint for the width property, which sizes the content box. The+ // math content itself is as wide as the inner box.+ // The line-ascent of the math content is the requested height. The line-descent of the math content is the+ // requested depth. The mpadded inner box is placed so that its alphabetic baseline is shifted away from the+ // alphabetic baseline by the requested voffset towards the line-over.+ MathContent {+ inline_size: inner.inline_size,+ ascent: requested_height,+ descent: requested_depth,+ positions: inner+ .positions+ .into_iter()+ .map(|position| ChildPosition {+ line_left_offset: position.line_left_offset + requested_lspace,+ baseline_shift: position.baseline_shift - requested_voffset,+ })+ .collect(),+ }+ }+// https://w3c.github.io/mathml-core/#space-mspacefn layout_space(&self, style: &StyleValues<'_>) -> MathContent {// If the height attribute is absent, invalid or a percentage then the requested line-ascent is 0. Otherwisediff --git a/Tests/LibWeb/Text/expected/wpt-import/mathml/presentation-markup/mpadded/mpadded-001.txt b/Tests/LibWeb/Text/expected/wpt-import/mathml/presentation-markup/mpadded/mpadded-001.txtindex 9004d5ef0c8..93ad2864ecb 100644--- a/Tests/LibWeb/Text/expected/wpt-import/mathml/presentation-markup/mpadded/mpadded-001.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/mathml/presentation-markup/mpadded/mpadded-001.txt@@ -2,14 +2,13 @@ Harness status: OKFound 9 tests-3 Pass-6 Fail+9 PassPass mpadded (no attributes)-Fail Different widths-Fail Different heights-Fail Different depths-Fail Various combinations of height, depth and width.+Pass Different widths+Pass Different heights+Pass Different depths+Pass Various combinations of height, depth and width.Pass Preferred widthPass dynamic attributes (remove)-Fail dynamic attributes (attach)-Fail dynamic attributes (modify)\ No newline at end of file+Pass dynamic attributes (attach)+Pass dynamic attributes (modify)\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/mathml/presentation-markup/mpadded/mpadded-002.txt b/Tests/LibWeb/Text/expected/wpt-import/mathml/presentation-markup/mpadded/mpadded-002.txtindex 69f8d028093..72da40159db 100644--- a/Tests/LibWeb/Text/expected/wpt-import/mathml/presentation-markup/mpadded/mpadded-002.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/mathml/presentation-markup/mpadded/mpadded-002.txt@@ -2,15 +2,14 @@ Harness status: OKFound 10 tests-2 Pass-8 Fail-Fail mpadded with no attributes-Fail Different widths-Fail Different heights-Fail Percentage calculation for width, height and depth-Fail Different depths-Fail Various combinations of height, depth and width.+10 Pass+Pass mpadded with no attributes+Pass Different widths+Pass Different heights+Pass Percentage calculation for width, height and depth+Pass Different depths+Pass Various combinations of height, depth and width.Pass Preferred widthPass dynamic attributes (remove)-Fail dynamic attributes (attach)-Fail dynamic attributes (modify)\ No newline at end of file+Pass dynamic attributes (attach)+Pass dynamic attributes (modify)\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/mathml/presentation-markup/mpadded/mpadded-003.txt b/Tests/LibWeb/Text/expected/wpt-import/mathml/presentation-markup/mpadded/mpadded-003.txtindex e2ff86c023b..015306dabc9 100644--- a/Tests/LibWeb/Text/expected/wpt-import/mathml/presentation-markup/mpadded/mpadded-003.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/mathml/presentation-markup/mpadded/mpadded-003.txt@@ -2,10 +2,9 @@ Harness status: OKFound 5 tests-2 Pass-3 Fail+5 PassPass lspace/voffset shifts don't affect mpadded preferred widthPass lspace/voffset shifts don't affect mpadded size-Fail content is shifted by the specified lspace/voffset-Fail content is shifted by the specified lspace/voffset (RTL)-Fail dynamic changes of lspace/voffset\ No newline at end of file+Pass content is shifted by the specified lspace/voffset+Pass content is shifted by the specified lspace/voffset (RTL)+Pass dynamic changes of lspace/voffset\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/mathml/relations/css-styling/lengths-2.txt b/Tests/LibWeb/Text/expected/wpt-import/mathml/relations/css-styling/lengths-2.txtindex f52687faaf9..5e0f7b42d74 100644--- a/Tests/LibWeb/Text/expected/wpt-import/mathml/relations/css-styling/lengths-2.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/mathml/relations/css-styling/lengths-2.txt@@ -2,11 +2,10 @@ Harness status: OKFound 6 tests-5 Pass-1 Fail+6 PassPass UnitsPass Trimming of spacePass Non-negative numbers-Fail Non-positive numbers+Pass Non-positive numbersPass Legacy namedspacesPass Legacy numbers\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/mathml/relations/css-styling/padding-border-margin/padding-border-mpadded-baseline.txt b/Tests/LibWeb/Text/expected/wpt-import/mathml/relations/css-styling/padding-border-margin/padding-border-mpadded-baseline.txtindex 580a01b47c5..83b3052c643 100644--- a/Tests/LibWeb/Text/expected/wpt-import/mathml/relations/css-styling/padding-border-margin/padding-border-mpadded-baseline.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/mathml/relations/css-styling/padding-border-margin/padding-border-mpadded-baseline.txt@@ -2,7 +2,7 @@ Harness status: OKFound 3 tests-3 Fail-Fail Empty mpadded with padding-top and border-top-Fail Empty mpadded with padding and border on all sides-Fail Non-empty mpadded with padding-top and border-top\ No newline at end of file+3 Pass+Pass Empty mpadded with padding-top and border-top+Pass Empty mpadded with padding and border on all sides+Pass Non-empty mpadded with padding-top and border-top\ No newline at end of file