Skip to content

Commit cc2c8e8

Browse files
Calme1709tcl3
authored andcommitted
LibWeb: Resolve percentages in <angular-color-stop-list> as angles
1 parent 62c0071 commit cc2c8e8

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

Libraries/LibWeb/CSS/Parser/GradientParsing.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ Optional<Vector<LinearColorStopListElement>> Parser::parse_linear_color_stop_lis
120120

121121
Optional<Vector<AngularColorStopListElement>> Parser::parse_angular_color_stop_list(TokenStream<ComponentValue>& tokens)
122122
{
123+
auto context_guard = push_temporary_value_parsing_context(SpecialContext::AngularColorStopList);
124+
123125
// <angular-color-stop-list> =
124126
// <angular-color-stop> , [ <angular-color-hint>? , <angular-color-stop> ]#
125127
return parse_color_stop_list<AngularColorStopListElement>(

Libraries/LibWeb/CSS/Parser/Parser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,7 @@ class Parser {
564564
DescriptorID descriptor;
565565
};
566566
enum SpecialContext : u8 {
567+
AngularColorStopList,
567568
ShadowBlurRadius,
568569
TranslateZArgument
569570
};

Libraries/LibWeb/CSS/Parser/ValueParsing.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4110,7 +4110,8 @@ RefPtr<CalculatedStyleValue const> Parser::parse_calculated_value(ComponentValue
41104110
return CalculationContext::for_property(PropertyNameAndID::from_id(property_id));
41114111
},
41124112
[](FunctionContext const& function) -> Optional<CalculationContext> {
4113-
// Gradients resolve percentages as lengths relative to the gradient-box.
4113+
// Gradients resolve percentages as lengths relative to the gradient-box (except within
4114+
// <angular-color-stop-list>s which are handled by a special context)
41144115
if (function.name.is_one_of_ignoring_ascii_case(
41154116
"linear-gradient"sv, "repeating-linear-gradient"sv,
41164117
"radial-gradient"sv, "repeating-radial-gradient"sv,
@@ -4140,6 +4141,8 @@ RefPtr<CalculatedStyleValue const> Parser::parse_calculated_value(ComponentValue
41404141
},
41414142
[](SpecialContext special_context) -> Optional<CalculationContext> {
41424143
switch (special_context) {
4144+
case SpecialContext::AngularColorStopList:
4145+
return CalculationContext { .percentages_resolve_as = ValueType::Angle };
41434146
case SpecialContext::ShadowBlurRadius:
41444147
return CalculationContext { .accepted_type_ranges = { { ValueType::Length, { 0, NumericLimits<float>::max() } } } };
41454148
case SpecialContext::TranslateZArgument:

0 commit comments

Comments
 (0)