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
parent 619df0bc2c
commit bc00ef8314
4 changed files with 196 additions and 76 deletions

View File

@@ -443,6 +443,18 @@ private:
Vector<Token> m_tokens;
TokenStream<Token> m_token_stream;
struct FunctionContext {
StringView name;
};
using ValueParsingContext = Variant<PropertyID, FunctionContext>;
Vector<ValueParsingContext> m_value_context;
auto push_temporary_value_parsing_context(ValueParsingContext&& context)
{
m_value_context.append(context);
return ScopeGuard { [&] { m_value_context.take_last(); } };
}
bool context_allows_quirky_length() const;
enum class ContextType {
Unknown,
Style,