From f078bb8294b946e5d8b762d815a2725aa1300e43 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Wed, 23 Mar 2022 16:59:44 +0000 Subject: LibWeb: Implement disallowing `inset` when parsing shadows `text-shadow` does not support this, so this way we can still use the same parsing code. It's OK that we still assign a ShadowPlacement value to the ShadowStyleValue, since it will just get ignored when painting text-shadows, but if it appears in the property value then that is a syntax error. --- Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp | 13 +++++++------ Userland/Libraries/LibWeb/CSS/Parser/Parser.h | 8 ++++++-- 2 files changed, 13 insertions(+), 8 deletions(-) (limited to 'Userland/Libraries/LibWeb') diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index 3f5d927d3d..70e69133b1 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -3318,7 +3318,7 @@ RefPtr Parser::parse_border_radius_shorthand_value(Vector Parser::parse_shadow_value(Vector const& component_values) +RefPtr Parser::parse_shadow_value(Vector const& component_values, AllowInsetKeyword allow_inset_keyword) { // "none" if (component_values.size() == 1 && component_values.first().is(Token::Type::Ident)) { @@ -3327,12 +3327,12 @@ RefPtr Parser::parse_shadow_value(Vector co return ident; } - return parse_comma_separated_value_list(component_values, [this](auto& tokens) { - return parse_single_shadow_value(tokens); + return parse_comma_separated_value_list(component_values, [this, allow_inset_keyword](auto& tokens) { + return parse_single_shadow_value(tokens, allow_inset_keyword); }); } -RefPtr Parser::parse_single_shadow_value(TokenStream& tokens) +RefPtr Parser::parse_single_shadow_value(TokenStream& tokens, AllowInsetKeyword allow_inset_keyword) { auto start_position = tokens.position(); auto error = [&]() { @@ -3395,7 +3395,8 @@ RefPtr Parser::parse_single_shadow_value(TokenStream, Parser::ParsingResult> Parser::parse_css_value return parsed_value.release_nonnull(); return ParsingResult::SyntaxError; case PropertyID::BoxShadow: - if (auto parsed_value = parse_shadow_value(component_values)) + if (auto parsed_value = parse_shadow_value(component_values, AllowInsetKeyword::Yes)) return parsed_value.release_nonnull(); return ParsingResult::SyntaxError; case PropertyID::Content: diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h index 9bb5114a91..d3d13cb10f 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h @@ -294,8 +294,12 @@ private: RefPtr parse_font_family_value(Vector const&, size_t start_index = 0); RefPtr parse_list_style_value(Vector const&); RefPtr parse_overflow_value(Vector const&); - RefPtr parse_shadow_value(Vector const&); - RefPtr parse_single_shadow_value(TokenStream&); + enum class AllowInsetKeyword { + No, + Yes, + }; + RefPtr parse_shadow_value(Vector const&, AllowInsetKeyword); + RefPtr parse_single_shadow_value(TokenStream&, AllowInsetKeyword); RefPtr parse_text_decoration_value(Vector const&); RefPtr parse_transform_value(Vector const&); RefPtr parse_transform_origin_value(Vector const&); -- cgit v1.2.3