LibWeb/CSS: Parse @font-face descriptors as style values

CSSFontFaceRule now stores its values as a CSSFontFaceDescriptors, with
a ParsedFontFace produced on request. This is exposed via the `style`
attribute, so we pass a lot of tests that try to read values from
that.

We have one test regression, which we passed by mistake before: The test
wanted to ensure we don't allow `@font-face` nested inside other rules.
We passed it just because we discarded any `@font-face` without a
`font-family`. What we're supposed to do is 1) keep at-rules with
missing required descriptors and just not use them, and 2) reject
certain ones when nested.

We may want to cache the ParsedFontFace in the future, but I didn't here
because 1) it's called rarely, and 2) that would mean knowing to
invalidate it when the CSSFontFaceDescriptors changes, which isn't
obvious to me right now.
This commit is contained in:
Sam Atkins 2025-04-03 12:05:49 +01:00
parent 3c9685ff1a
commit f87b454fa9
Notes: github-actions[bot] 2025-04-04 09:41:41 +00:00
12 changed files with 118 additions and 378 deletions

View file

@ -45,16 +45,17 @@ Parser::ParseErrorOr<NonnullRefPtr<CSSStyleValue>> Parser::parse_descriptor_valu
return parse_all_as_single_keyword_value(tokens, keyword);
},
[&](PropertyID property_id) -> RefPtr<CSSStyleValue> {
auto value_for_property = parse_css_value_for_property(property_id, tokens);
if (!value_for_property)
auto value_or_error = parse_css_value(property_id, tokens);
if (value_or_error.is_error())
return nullptr;
auto value_for_property = value_or_error.release_value();
// Descriptors don't accept the following, which properties do:
// - CSS-wide keywords
// - Shorthands
// - Arbitrary substitution functions (so, UnresolvedStyleValue)
if (value_for_property->is_css_wide_keyword() || value_for_property->is_shorthand() || value_for_property->is_unresolved())
return nullptr;
return value_for_property.release_nonnull();
return value_for_property;
},
[&](DescriptorMetadata::ValueType value_type) -> RefPtr<CSSStyleValue> {
switch (value_type) {