mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-08 06:09:58 +00:00
LibWeb/CSS: Absolutize GradientStyleValues
This lets us not care about non-absolute Length units when resolving gradient data, as they'll already have been converted to px. We can also use Angle::from_style_value() safely on absolutized angles, which reduces some boilerplate code.
This commit is contained in:
parent
fbe0567f90
commit
f81bb1bd8c
Notes:
github-actions[bot]
2025-12-01 11:09:51 +00:00
Author: https://github.com/AtkinsSJ
Commit: f81bb1bd8c
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6894
Reviewed-by: https://github.com/Calme1709
Reviewed-by: https://github.com/gmta
10 changed files with 205 additions and 161 deletions
|
|
@ -74,6 +74,16 @@ String LinearGradientStyleValue::to_string(SerializationMode mode) const
|
|||
return MUST(builder.to_string());
|
||||
}
|
||||
|
||||
ValueComparingNonnullRefPtr<StyleValue const> LinearGradientStyleValue::absolutized(ComputationContext const& context) const
|
||||
{
|
||||
Vector<ColorStopListElement> absolutized_color_stops;
|
||||
absolutized_color_stops.ensure_capacity(m_properties.color_stop_list.size());
|
||||
for (auto const& color_stop : m_properties.color_stop_list) {
|
||||
absolutized_color_stops.unchecked_append(color_stop.absolutized(context));
|
||||
}
|
||||
return create(m_properties.direction, move(absolutized_color_stops), m_properties.gradient_type, m_properties.repeating, m_properties.interpolation_method);
|
||||
}
|
||||
|
||||
bool LinearGradientStyleValue::equals(StyleValue const& other_) const
|
||||
{
|
||||
if (type() != other_.type())
|
||||
|
|
@ -117,13 +127,7 @@ float LinearGradientStyleValue::angle_degrees(CSSPixelSize gradient_size) const
|
|||
return angle;
|
||||
},
|
||||
[&](NonnullRefPtr<StyleValue const> const& style_value) {
|
||||
if (style_value->is_angle())
|
||||
return style_value->as_angle().angle().to_degrees();
|
||||
if (style_value->is_calculated()) {
|
||||
if (auto maybe_angle = style_value->as_calculated().resolve_angle({}); maybe_angle.has_value())
|
||||
return maybe_angle->to_degrees();
|
||||
}
|
||||
return 0.0;
|
||||
return Angle::from_style_value(style_value, {}).to_degrees();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue