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`
This commit is contained in:
Sam Atkins 2025-11-13 14:53:02 +00:00
parent 2512a934d6
commit e561749164
Notes: github-actions[bot] 2025-11-14 09:56:21 +00:00
3 changed files with 8 additions and 4 deletions

View file

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

View file

@ -3,8 +3,10 @@ direction: ltr
direction: rtl
color: red
color: rgb(255, 0, 0)
color: orange
background-color: blue
background-color: rgb(0, 0, 255)
background-color: transparent
font-size: 10px
font-size: 24px
font-size: 32px

View file

@ -7,13 +7,15 @@
<mi dir="LTR"></mi>
<mi dir="rtl"></mi>
</math>
<math data-prop="color">
<math data-prop="color" style="color: orange">
<mi mathcolor="red"></mi>
<mi mathcolor="#f00"></mi>
<mi mathcolor="initial"></mi>
</math>
<math data-prop="background-color">
<math data-prop="background-color" style="background-color: orange">
<mi mathbackground="blue"></mi>
<mi mathbackground="#0000ff"></mi>
<mi mathbackground="inherit"></mi>
</math>
<math data-prop="font-size">
<mi mathsize="10px"></mi>