LibWeb/CSS: Parse font-display descriptor

This commit is contained in:
Sam Atkins 2024-09-26 14:07:46 +01:00 committed by Andreas Kling
commit 3eb6d510fd
Notes: github-actions[bot] 2024-09-28 12:43:50 +00:00
7 changed files with 39 additions and 4 deletions

View file

@ -5458,6 +5458,7 @@ JS::GCPtr<CSSFontFaceRule> Parser::parse_font_face_rule(TokenStream<ComponentVal
Optional<Percentage> ascent_override;
Optional<Percentage> descent_override;
Optional<Percentage> line_gap_override;
FontDisplay font_display = FontDisplay::Auto;
// "normal" is returned as nullptr
auto parse_as_percentage_or_normal = [&](Vector<ComponentValue> const& values) -> ErrorOr<Optional<Percentage>> {
@ -5516,6 +5517,23 @@ JS::GCPtr<CSSFontFaceRule> Parser::parse_font_face_rule(TokenStream<ComponentVal
}
continue;
}
if (declaration.name().equals_ignoring_ascii_case("font-display"sv)) {
TokenStream token_stream { declaration.values() };
if (auto keyword_value = parse_keyword_value(token_stream)) {
token_stream.skip_whitespace();
if (token_stream.has_next_token()) {
dbgln_if(CSS_PARSER_DEBUG, "CSSParser: Unexpected trailing tokens in font-display");
} else {
auto value = keyword_to_font_display(keyword_value->to_keyword());
if (value.has_value()) {
font_display = *value;
} else {
dbgln_if(CSS_PARSER_DEBUG, "CSSParser: `{}` is not a valid value for font-display", keyword_value->to_string());
}
}
}
continue;
}
if (declaration.name().equals_ignoring_ascii_case("font-family"sv)) {
// FIXME: This is very similar to, but different from, the logic in parse_font_family_value().
// Ideally they could share code.
@ -5612,7 +5630,7 @@ JS::GCPtr<CSSFontFaceRule> Parser::parse_font_face_rule(TokenStream<ComponentVal
unicode_range.empend(0x0u, 0x10FFFFu);
}
return CSSFontFaceRule::create(m_context.realm(), ParsedFontFace { font_family.release_value(), weight, slope, move(src), move(unicode_range), move(ascent_override), move(descent_override), move(line_gap_override) });
return CSSFontFaceRule::create(m_context.realm(), ParsedFontFace { font_family.release_value(), weight, slope, move(src), move(unicode_range), move(ascent_override), move(descent_override), move(line_gap_override), font_display });
}
Vector<ParsedFontFace::Source> Parser::parse_as_font_face_src()