1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 14:47:35 +00:00

LibWeb: Store RadialGradientStyleValue's position as PositionStyleValue

This commit is contained in:
Sam Atkins 2023-11-07 12:11:04 +00:00 committed by Sam Atkins
parent 2ae53bc5eb
commit 5cf85d30aa
4 changed files with 19 additions and 16 deletions

View file

@ -8,6 +8,7 @@
*/
#include "RadialGradientStyleValue.h"
#include <LibWeb/CSS/StyleValues/PositionStyleValue.h>
#include <LibWeb/Layout/Node.h>
namespace Web::CSS {
@ -44,10 +45,8 @@ String RadialGradientStyleValue::to_string() const
builder.appendff("{} {}", ellipse_size.radius_a.to_string(), ellipse_size.radius_b.to_string());
});
if (m_properties.position != PositionValue::center()) {
builder.appendff(" at "sv);
m_properties.position.serialize(builder);
}
if (!m_properties.position->is_center())
builder.appendff(" at {}"sv, m_properties.position->to_string());
builder.append(", "sv);
serialize_color_stop_list(builder, m_properties.color_stop_list);
@ -189,7 +188,7 @@ CSSPixelSize RadialGradientStyleValue::resolve_size(Layout::Node const& node, CS
void RadialGradientStyleValue::resolve_for_size(Layout::NodeWithStyleAndBoxModelMetrics const& node, CSSPixelSize paint_size) const
{
CSSPixelRect gradient_box { { 0, 0 }, paint_size };
auto center = m_properties.position.resolved(node, gradient_box);
auto center = m_properties.position->resolved(node, gradient_box);
auto gradient_size = resolve_size(node, center, gradient_box);
if (m_resolved.has_value() && m_resolved->gradient_size == gradient_size)
return;

View file

@ -11,7 +11,6 @@
#include <AK/Vector.h>
#include <LibWeb/CSS/Enums.h>
#include <LibWeb/CSS/Position.h>
#include <LibWeb/CSS/StyleValues/AbstractImageStyleValue.h>
#include <LibWeb/Painting/GradientPainting.h>
@ -44,10 +43,10 @@ public:
using Size = Variant<Extent, CircleSize, EllipseSize>;
static ValueComparingNonnullRefPtr<RadialGradientStyleValue> create(EndingShape ending_shape, Size size, PositionValue position, Vector<LinearColorStopListElement> color_stop_list, GradientRepeating repeating)
static ValueComparingNonnullRefPtr<RadialGradientStyleValue> create(EndingShape ending_shape, Size size, ValueComparingNonnullRefPtr<PositionStyleValue> position, Vector<LinearColorStopListElement> color_stop_list, GradientRepeating repeating)
{
VERIFY(color_stop_list.size() >= 2);
return adopt_ref(*new (nothrow) RadialGradientStyleValue(ending_shape, size, position, move(color_stop_list), repeating));
return adopt_ref(*new (nothrow) RadialGradientStyleValue(ending_shape, size, move(position), move(color_stop_list), repeating));
}
virtual String to_string() const override;
@ -72,16 +71,16 @@ public:
virtual ~RadialGradientStyleValue() override = default;
private:
RadialGradientStyleValue(EndingShape ending_shape, Size size, PositionValue position, Vector<LinearColorStopListElement> color_stop_list, GradientRepeating repeating)
RadialGradientStyleValue(EndingShape ending_shape, Size size, ValueComparingNonnullRefPtr<PositionStyleValue> position, Vector<LinearColorStopListElement> color_stop_list, GradientRepeating repeating)
: AbstractImageStyleValue(Type::RadialGradient)
, m_properties { .ending_shape = ending_shape, .size = size, .position = position, .color_stop_list = move(color_stop_list), .repeating = repeating }
, m_properties { .ending_shape = ending_shape, .size = size, .position = move(position), .color_stop_list = move(color_stop_list), .repeating = repeating }
{
}
struct Properties {
EndingShape ending_shape;
Size size;
PositionValue position;
ValueComparingNonnullRefPtr<PositionStyleValue> position;
Vector<LinearColorStopListElement> color_stop_list;
GradientRepeating repeating;
bool operator==(Properties const&) const = default;