LibWeb: Resolve percentages in <angular-color-stop-list> as angles

This commit is contained in:
Callum Law 2025-10-17 17:11:02 +13:00 committed by Tim Ledbetter
parent 62c00712fa
commit cc2c8e8615
Notes: github-actions[bot] 2025-10-17 07:38:54 +00:00
4 changed files with 11 additions and 5 deletions

View file

@ -120,6 +120,8 @@ Optional<Vector<LinearColorStopListElement>> Parser::parse_linear_color_stop_lis
Optional<Vector<AngularColorStopListElement>> Parser::parse_angular_color_stop_list(TokenStream<ComponentValue>& tokens) Optional<Vector<AngularColorStopListElement>> Parser::parse_angular_color_stop_list(TokenStream<ComponentValue>& tokens)
{ {
auto context_guard = push_temporary_value_parsing_context(SpecialContext::AngularColorStopList);
// <angular-color-stop-list> = // <angular-color-stop-list> =
// <angular-color-stop> , [ <angular-color-hint>? , <angular-color-stop> ]# // <angular-color-stop> , [ <angular-color-hint>? , <angular-color-stop> ]#
return parse_color_stop_list<AngularColorStopListElement>( return parse_color_stop_list<AngularColorStopListElement>(

View file

@ -564,6 +564,7 @@ private:
DescriptorID descriptor; DescriptorID descriptor;
}; };
enum SpecialContext : u8 { enum SpecialContext : u8 {
AngularColorStopList,
ShadowBlurRadius, ShadowBlurRadius,
TranslateZArgument TranslateZArgument
}; };

View file

@ -4110,7 +4110,8 @@ RefPtr<CalculatedStyleValue const> Parser::parse_calculated_value(ComponentValue
return CalculationContext::for_property(PropertyNameAndID::from_id(property_id)); return CalculationContext::for_property(PropertyNameAndID::from_id(property_id));
}, },
[](FunctionContext const& function) -> Optional<CalculationContext> { [](FunctionContext const& function) -> Optional<CalculationContext> {
// Gradients resolve percentages as lengths relative to the gradient-box. // Gradients resolve percentages as lengths relative to the gradient-box (except within
// <angular-color-stop-list>s which are handled by a special context)
if (function.name.is_one_of_ignoring_ascii_case( if (function.name.is_one_of_ignoring_ascii_case(
"linear-gradient"sv, "repeating-linear-gradient"sv, "linear-gradient"sv, "repeating-linear-gradient"sv,
"radial-gradient"sv, "repeating-radial-gradient"sv, "radial-gradient"sv, "repeating-radial-gradient"sv,
@ -4140,6 +4141,8 @@ RefPtr<CalculatedStyleValue const> Parser::parse_calculated_value(ComponentValue
}, },
[](SpecialContext special_context) -> Optional<CalculationContext> { [](SpecialContext special_context) -> Optional<CalculationContext> {
switch (special_context) { switch (special_context) {
case SpecialContext::AngularColorStopList:
return CalculationContext { .percentages_resolve_as = ValueType::Angle };
case SpecialContext::ShadowBlurRadius: case SpecialContext::ShadowBlurRadius:
return CalculationContext { .accepted_type_ranges = { { ValueType::Length, { 0, NumericLimits<float>::max() } } } }; return CalculationContext { .accepted_type_ranges = { { ValueType::Length, { 0, NumericLimits<float>::max() } } } };
case SpecialContext::TranslateZArgument: case SpecialContext::TranslateZArgument:

File diff suppressed because one or more lines are too long