mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 00:47:34 +00:00
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.
This commit is contained in:
parent
1094654adc
commit
f078bb8294
2 changed files with 13 additions and 8 deletions
|
@ -3318,7 +3318,7 @@ RefPtr<StyleValue> Parser::parse_border_radius_shorthand_value(Vector<StyleCompo
|
||||||
return StyleValueList::create(move(border_radii), StyleValueList::Separator::Space);
|
return StyleValueList::create(move(border_radii), StyleValueList::Separator::Space);
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<StyleValue> Parser::parse_shadow_value(Vector<StyleComponentValueRule> const& component_values)
|
RefPtr<StyleValue> Parser::parse_shadow_value(Vector<StyleComponentValueRule> const& component_values, AllowInsetKeyword allow_inset_keyword)
|
||||||
{
|
{
|
||||||
// "none"
|
// "none"
|
||||||
if (component_values.size() == 1 && component_values.first().is(Token::Type::Ident)) {
|
if (component_values.size() == 1 && component_values.first().is(Token::Type::Ident)) {
|
||||||
|
@ -3327,12 +3327,12 @@ RefPtr<StyleValue> Parser::parse_shadow_value(Vector<StyleComponentValueRule> co
|
||||||
return ident;
|
return ident;
|
||||||
}
|
}
|
||||||
|
|
||||||
return parse_comma_separated_value_list(component_values, [this](auto& tokens) {
|
return parse_comma_separated_value_list(component_values, [this, allow_inset_keyword](auto& tokens) {
|
||||||
return parse_single_shadow_value(tokens);
|
return parse_single_shadow_value(tokens, allow_inset_keyword);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<StyleValue> Parser::parse_single_shadow_value(TokenStream<StyleComponentValueRule>& tokens)
|
RefPtr<StyleValue> Parser::parse_single_shadow_value(TokenStream<StyleComponentValueRule>& tokens, AllowInsetKeyword allow_inset_keyword)
|
||||||
{
|
{
|
||||||
auto start_position = tokens.position();
|
auto start_position = tokens.position();
|
||||||
auto error = [&]() {
|
auto error = [&]() {
|
||||||
|
@ -3395,7 +3395,8 @@ RefPtr<StyleValue> Parser::parse_single_shadow_value(TokenStream<StyleComponentV
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (token.is(Token::Type::Ident) && token.token().ident().equals_ignoring_case("inset"sv)) {
|
if (allow_inset_keyword == AllowInsetKeyword::Yes
|
||||||
|
&& token.is(Token::Type::Ident) && token.token().ident().equals_ignoring_case("inset"sv)) {
|
||||||
if (placement.has_value())
|
if (placement.has_value())
|
||||||
return error();
|
return error();
|
||||||
placement = ShadowPlacement::Inner;
|
placement = ShadowPlacement::Inner;
|
||||||
|
@ -4248,7 +4249,7 @@ Result<NonnullRefPtr<StyleValue>, Parser::ParsingResult> Parser::parse_css_value
|
||||||
return parsed_value.release_nonnull();
|
return parsed_value.release_nonnull();
|
||||||
return ParsingResult::SyntaxError;
|
return ParsingResult::SyntaxError;
|
||||||
case PropertyID::BoxShadow:
|
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 parsed_value.release_nonnull();
|
||||||
return ParsingResult::SyntaxError;
|
return ParsingResult::SyntaxError;
|
||||||
case PropertyID::Content:
|
case PropertyID::Content:
|
||||||
|
|
|
@ -294,8 +294,12 @@ private:
|
||||||
RefPtr<StyleValue> parse_font_family_value(Vector<StyleComponentValueRule> const&, size_t start_index = 0);
|
RefPtr<StyleValue> parse_font_family_value(Vector<StyleComponentValueRule> const&, size_t start_index = 0);
|
||||||
RefPtr<StyleValue> parse_list_style_value(Vector<StyleComponentValueRule> const&);
|
RefPtr<StyleValue> parse_list_style_value(Vector<StyleComponentValueRule> const&);
|
||||||
RefPtr<StyleValue> parse_overflow_value(Vector<StyleComponentValueRule> const&);
|
RefPtr<StyleValue> parse_overflow_value(Vector<StyleComponentValueRule> const&);
|
||||||
RefPtr<StyleValue> parse_shadow_value(Vector<StyleComponentValueRule> const&);
|
enum class AllowInsetKeyword {
|
||||||
RefPtr<StyleValue> parse_single_shadow_value(TokenStream<StyleComponentValueRule>&);
|
No,
|
||||||
|
Yes,
|
||||||
|
};
|
||||||
|
RefPtr<StyleValue> parse_shadow_value(Vector<StyleComponentValueRule> const&, AllowInsetKeyword);
|
||||||
|
RefPtr<StyleValue> parse_single_shadow_value(TokenStream<StyleComponentValueRule>&, AllowInsetKeyword);
|
||||||
RefPtr<StyleValue> parse_text_decoration_value(Vector<StyleComponentValueRule> const&);
|
RefPtr<StyleValue> parse_text_decoration_value(Vector<StyleComponentValueRule> const&);
|
||||||
RefPtr<StyleValue> parse_transform_value(Vector<StyleComponentValueRule> const&);
|
RefPtr<StyleValue> parse_transform_value(Vector<StyleComponentValueRule> const&);
|
||||||
RefPtr<StyleValue> parse_transform_origin_value(Vector<StyleComponentValueRule> const&);
|
RefPtr<StyleValue> parse_transform_origin_value(Vector<StyleComponentValueRule> const&);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue