Skip to content

Commit e561749

Browse files
committed
LibWeb/MathML: Parse mathcolor and mathbackground as <color>
The difference is that parsing as the `color` property's value also allows the CSS-wide keywords, which we don't want here. The added test cases make sure that those keywords are *not* valid: - `color` should inherit its parent value of `orange` - `background-color` doesn't inherit, so should be its initial value of `transparent`
1 parent 2512a93 commit e561749

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

Libraries/LibWeb/MathML/MathMLElement.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ void MathMLElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties>
9191
// The mathcolor and mathbackground attributes, if present, must have a value that is a <color>. In that case,
9292
// the user agent is expected to treat these attributes as a presentational hint setting the element's color
9393
// and background-color properties to the corresponding values.
94-
if (auto parsed_value = parse_css_value(CSS::Parser::ParsingParams { document() }, value, CSS::PropertyID::Color))
94+
if (auto parsed_value = parse_css_type(CSS::Parser::ParsingParams { document() }, value, CSS::ValueType::Color))
9595
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::Color, parsed_value.release_nonnull());
9696
} else if (name == AttributeNames::mathbackground) {
97-
if (auto parsed_value = parse_css_value(CSS::Parser::ParsingParams { document() }, value, CSS::PropertyID::BackgroundColor))
97+
if (auto parsed_value = parse_css_type(CSS::Parser::ParsingParams { document() }, value, CSS::ValueType::Color))
9898
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BackgroundColor, parsed_value.release_nonnull());
9999
} else if (name == AttributeNames::mathsize) {
100100
// https://w3c.github.io/mathml-core/#dfn-mathsize

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ direction: ltr
33
direction: rtl
44
color: red
55
color: rgb(255, 0, 0)
6+
color: orange
67
background-color: blue
78
background-color: rgb(0, 0, 255)
9+
background-color: transparent
810
font-size: 10px
911
font-size: 24px
1012
font-size: 32px

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
<mi dir="LTR"></mi>
88
<mi dir="rtl"></mi>
99
</math>
10-
<math data-prop="color">
10+
<math data-prop="color" style="color: orange">
1111
<mi mathcolor="red"></mi>
1212
<mi mathcolor="#f00"></mi>
13+
<mi mathcolor="initial"></mi>
1314
</math>
14-
<math data-prop="background-color">
15+
<math data-prop="background-color" style="background-color: orange">
1516
<mi mathbackground="blue"></mi>
1617
<mi mathbackground="#0000ff"></mi>
18+
<mi mathbackground="inherit"></mi>
1719
</math>
1820
<math data-prop="font-size">
1921
<mi mathsize="10px"></mi>

0 commit comments

Comments
 (0)