LibWeb/CSS: Replace Parser "current property" with a stack of contexts

`current_property_id()` is insufficient to determine if a quirk is
allowed. For example, unitless lengths are allowed in certain
properties, but NOT if they are inside a calc() or other function. It's
also incorrect when we are parsing a longhand inside a shorthand. So
instead, replace that with a stack of value-parsing contexts. For now,
this is either properties or CSS functions, but in future can be
expanded to include media features and other places.

This lets us disallow quirks inside functions, like we're supposed to.

It also lays the groundwork for being able to more easily determine
what type a percentage inside a calculation should become, as this is
based on the same stack of contexts.
This commit is contained in:
Sam Atkins 2025-01-06 12:48:17 +00:00
commit bc00ef8314
Notes: github-actions[bot] 2025-01-13 11:00:39 +00:00
4 changed files with 196 additions and 76 deletions

View file

@ -150,6 +150,8 @@ RefPtr<CSSStyleValue> Parser::parse_linear_gradient_function(TokenStream<Compone
gradient_type = GradientType::WebKit;
});
auto context_guard = push_temporary_value_parsing_context(FunctionContext { function_name });
function_name = consume_if_starts_with(function_name, "repeating-"sv, [&] {
repeating_gradient = GradientRepeating::Yes;
});
@ -274,6 +276,7 @@ RefPtr<CSSStyleValue> Parser::parse_conic_gradient_function(TokenStream<Componen
GradientRepeating repeating_gradient = GradientRepeating::No;
auto function_name = component_value.function().name.bytes_as_string_view();
auto context_guard = push_temporary_value_parsing_context(FunctionContext { function_name });
function_name = consume_if_starts_with(function_name, "repeating-"sv, [&] {
repeating_gradient = GradientRepeating::Yes;
@ -384,6 +387,7 @@ RefPtr<CSSStyleValue> Parser::parse_radial_gradient_function(TokenStream<Compone
auto repeating_gradient = GradientRepeating::No;
auto function_name = component_value.function().name.bytes_as_string_view();
auto context_guard = push_temporary_value_parsing_context(FunctionContext { function_name });
function_name = consume_if_starts_with(function_name, "repeating-"sv, [&] {
repeating_gradient = GradientRepeating::Yes;