mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 01:35:08 +02:00
LibWeb: Set context for parsing against <foo-percentage> syntax
This means that we correctly parse dimension percentage mixes (i.e. `calc(10px + 10%)` is a valid `<length-percentage>`)
This commit is contained in:
Notes:
github-actions[bot]
2026-03-26 01:13:21 +00:00
Author: https://github.com/Calme1709 Commit: https://github.com/LadybirdBrowser/ladybird/commit/614a5cf33ef Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/8330 Reviewed-by: https://github.com/AtkinsSJ ✅
@@ -62,6 +62,9 @@ struct NegateNode {
|
||||
|
||||
}
|
||||
|
||||
struct SyntaxParsingContext {
|
||||
ValueType type;
|
||||
};
|
||||
struct FunctionContext {
|
||||
StringView name;
|
||||
};
|
||||
@@ -85,7 +88,7 @@ enum SpecialContext : u8 {
|
||||
TranslateZArgument,
|
||||
};
|
||||
// FIXME: Use PropertyNameAndID instead of PropertyID as the context, for registered custom properties.
|
||||
using ValueParsingContext = Variant<PropertyID, FunctionContext, DescriptorContext, SpecialContext>;
|
||||
using ValueParsingContext = Variant<PropertyID, FunctionContext, DescriptorContext, SpecialContext, SyntaxParsingContext>;
|
||||
|
||||
enum class ParsingMode {
|
||||
Normal,
|
||||
|
||||
@@ -246,6 +246,7 @@ RefPtr<StyleValue const> Parser::parse_according_to_syntax_node(TokenStream<Comp
|
||||
auto const& type_node = as<TypeSyntaxNode>(syntax_node);
|
||||
auto const& type_name = type_node.type_name();
|
||||
if (auto value_type = value_type_from_string(type_name); value_type.has_value()) {
|
||||
auto scope_guard = push_temporary_value_parsing_context(SyntaxParsingContext { *value_type });
|
||||
if (auto result = parse_value(*value_type, tokens)) {
|
||||
transaction.commit();
|
||||
return result.release_nonnull();
|
||||
|
||||
@@ -5162,6 +5162,20 @@ RefPtr<CalculatedStyleValue const> Parser::parse_calculated_value(ComponentValue
|
||||
return {};
|
||||
}
|
||||
VERIFY_NOT_REACHED();
|
||||
},
|
||||
[](SyntaxParsingContext const& syntax_context) -> Optional<CalculationContext> {
|
||||
switch (syntax_context.type) {
|
||||
case ValueType::AnglePercentage:
|
||||
return CalculationContext { .percentages_resolve_as = ValueType::Angle };
|
||||
case ValueType::FrequencyPercentage:
|
||||
return CalculationContext { .percentages_resolve_as = ValueType::Frequency };
|
||||
case ValueType::LengthPercentage:
|
||||
return CalculationContext { .percentages_resolve_as = ValueType::Length };
|
||||
case ValueType::TimePercentage:
|
||||
return CalculationContext { .percentages_resolve_as = ValueType::Time };
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
});
|
||||
if (maybe_context.has_value()) {
|
||||
context = maybe_context.release_value();
|
||||
|
||||
Reference in New Issue
Block a user