LibWeb/CSS: Store linear-gradient() angle as a StyleValue

This means we now support calc() there too.
This commit is contained in:
Sam Atkins 2025-11-28 17:23:13 +00:00
parent 73fbaaba77
commit d327f677c5
Notes: github-actions[bot] 2025-12-01 11:10:08 +00:00
5 changed files with 24 additions and 22 deletions

View file

@ -8,6 +8,8 @@
*/
#include "LinearGradientStyleValue.h"
#include <LibWeb/CSS/StyleValues/AngleStyleValue.h>
#include <LibWeb/CSS/StyleValues/CalculatedStyleValue.h>
#include <LibWeb/Layout/Node.h>
#include <LibWeb/Painting/DisplayListRecorder.h>
@ -53,8 +55,8 @@ String LinearGradientStyleValue::to_string(SerializationMode mode) const
[&](SideOrCorner side_or_corner) {
builder.appendff("{}{}", m_properties.gradient_type == GradientType::Standard ? "to "sv : ""sv, side_or_corner_to_string(side_or_corner));
},
[&](Angle const& angle) {
builder.append(angle.to_string());
[&](NonnullRefPtr<StyleValue const> const& angle) {
builder.append(angle->to_string(mode));
});
if (has_color_space)
@ -114,8 +116,14 @@ float LinearGradientStyleValue::angle_degrees(CSSPixelSize gradient_size) const
return angle + 180.0;
return angle;
},
[&](Angle const& angle) {
return angle.to_degrees();
[&](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;
});
}