LibWeb: Move check for CSS-wide keywords to ValueID.h

This feels like a better home for it. The new name better reflects the
spec phrasing.
This commit is contained in:
Sam Atkins 2023-09-04 14:39:10 +01:00 committed by Andreas Kling
parent bf8aa33b68
commit e9b58ff096
3 changed files with 10 additions and 10 deletions

View file

@ -70,6 +70,14 @@ enum class ValueID {
Optional<ValueID> value_id_from_string(StringView);
StringView string_from_value_id(ValueID);
// https://www.w3.org/TR/css-values-4/#common-keywords
inline bool is_css_wide_keyword(StringView name)
{
return name.equals_ignoring_ascii_case("inherit"sv)
|| name.equals_ignoring_ascii_case("initial"sv)
|| name.equals_ignoring_ascii_case("unset"sv);
}
}
)~~~");

View file

@ -1488,7 +1488,7 @@ CSSRule* Parser::convert_to_rule(NonnullRefPtr<Rule> rule)
return {};
}
if (name_token.is(Token::Type::Ident) && (is_builtin(name_token.ident()) || name_token.ident().equals_ignoring_ascii_case("none"sv))) {
if (name_token.is(Token::Type::Ident) && (is_css_wide_keyword(name_token.ident()) || name_token.ident().equals_ignoring_ascii_case("none"sv))) {
dbgln_if(CSS_PARSER_DEBUG, "CSSParser: @keyframes rule name is invalid: {}; discarding.", name_token.ident());
return {};
}
@ -4246,7 +4246,7 @@ CSSRule* Parser::parse_font_face_rule(TokenStream<ComponentValue>& tokens)
continue;
}
if (part.is(Token::Type::Ident)) {
if (is_builtin(part.token().ident())) {
if (is_css_wide_keyword(part.token().ident())) {
dbgln_if(CSS_PARSER_DEBUG, "CSSParser: @font-face font-family format invalid; discarding.");
had_syntax_error = true;
break;
@ -6483,13 +6483,6 @@ bool Parser::has_ignored_vendor_prefix(StringView string)
return true;
}
bool Parser::is_builtin(StringView name)
{
return name.equals_ignoring_ascii_case("inherit"sv)
|| name.equals_ignoring_ascii_case("initial"sv)
|| name.equals_ignoring_ascii_case("unset"sv);
}
RefPtr<CalculatedStyleValue> Parser::parse_calculated_value(Badge<StyleComputer>, ParsingContext const& context, ComponentValue const& token)
{
auto parser = MUST(Parser::create(context, ""sv));

View file

@ -286,7 +286,6 @@ private:
Optional<Supports::Feature> parse_supports_feature(TokenStream<ComponentValue>&);
static bool has_ignored_vendor_prefix(StringView);
static bool is_builtin(StringView);
struct PropertiesAndCustomProperties {
Vector<StyleProperty> properties;