Skip to content

Commit 1dfdfa3

Browse files
committed
LibWeb/MathML: Parse mathml attributes as <length>s
`HTML::parse_dimension_value()` doesn't parse units except for `%` for percentages; it just ignores them and treats it as a number of pixels. Now that we can parse `<length>` and pals directly, do that instead, which makes non-px units work.
1 parent 7aef324 commit 1dfdfa3

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

Libraries/LibWeb/MathML/MathMLElement.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ void MathMLElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties>
101101
// The mathsize attribute, if present, must have a value that is a valid <length-percentage>.
102102
// In that case, the user agent is expected to treat the attribute as a presentational hint setting the
103103
// element's font-size property to the corresponding value.
104-
if (auto parsed_value = HTML::parse_dimension_value(value))
104+
if (auto parsed_value = parse_css_type(CSS::Parser::ParsingParams { document() }, value, CSS::ValueType::LengthPercentage))
105105
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::FontSize, parsed_value.release_nonnull());
106106
} else if (name == AttributeNames::displaystyle) {
107107
// https://w3c.github.io/mathml-core/#dfn-displaystyle

Libraries/LibWeb/MathML/MathMLMspaceElement.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ void MathMLMspaceElement::apply_presentational_hints(GC::Ref<CSS::CascadedProper
3131
Base::apply_presentational_hints(cascaded_properties);
3232
// https://w3c.github.io/mathml-core/#attribute-mspace-width
3333
// The width, height, depth, if present, must have a value that is a valid <length-percentage>.
34+
CSS::Parser::ParsingParams parsing_params { document() };
3435
auto parse_non_percentage_value = [&](FlyString const& attribute_name) -> RefPtr<CSS::StyleValue const> {
3536
if (auto attribute = this->attribute(attribute_name); attribute.has_value()) {
36-
if (auto value = HTML::parse_dimension_value(attribute.value()); value && !value->is_percentage()) {
37+
if (auto value = parse_css_type(parsing_params, attribute.value(), CSS::ValueType::Length))
3738
return value;
38-
}
3939
}
4040
return nullptr;
4141
};

Tests/LibWeb/Text/expected/MathML/presentational_hints.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ color: rgb(255, 0, 0)
66
background-color: blue
77
background-color: rgb(0, 0, 255)
88
font-size: 10px
9+
font-size: 24px
10+
font-size: 32px
911
math-style: compact
1012
math-style: normal
1113
math-style: normal
@@ -19,6 +21,10 @@ text-transform: math-auto
1921
text-transform: none
2022
width: 10px
2123
width: auto
24+
width: 32px
2225
height: 20px
26+
height: auto
27+
height: 32px
2328
height: 30px
2429
height: auto
30+
height: 48px

Tests/LibWeb/Text/input/MathML/presentational_hints.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
</math>
1818
<math data-prop="font-size">
1919
<mi mathsize="10px"></mi>
20+
<mi mathsize="150%"></mi>
21+
<mi mathsize="2em"></mi>
2022
</math>
2123
<math data-prop="math-style">
2224
<mi displaystyle=""></mi>
@@ -38,11 +40,15 @@
3840
<math data-prop="width">
3941
<mspace width="10px"></mspace>
4042
<mspace width="10%"></mspace>
43+
<mspace width="2em"></mspace>
4144
</math>
4245
<math data-prop="height">
4346
<mspace height="20px"></mspace>
44-
<mspace depth="30px"></mspace>
4547
<mspace height="10%"></mspace>
48+
<mspace height="2em"></mspace>
49+
<mspace depth="30px"></mspace>
50+
<mspace depth="20%"></mspace>
51+
<mspace depth="3em"></mspace>
4652
</math>
4753
</body>
4854
<script>

0 commit comments

Comments
 (0)