1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:57:45 +00:00

LibWeb: Split ConicGradientStyleValue out of StyleValue.{h,cpp}

This commit is contained in:
Sam Atkins 2023-03-24 16:09:41 +00:00 committed by Linus Groh
parent 35b240c87d
commit f30b042890
7 changed files with 158 additions and 102 deletions

View file

@ -19,6 +19,7 @@
#include <LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h>
#include <LibWeb/CSS/StyleValues/BorderStyleValue.h>
#include <LibWeb/CSS/StyleValues/ColorStyleValue.h>
#include <LibWeb/CSS/StyleValues/ConicGradientStyleValue.h>
#include <LibWeb/CSS/StyleValues/ContentStyleValue.h>
#include <LibWeb/CSS/StyleValues/FilterValueListStyleValue.h>
#include <LibWeb/CSS/StyleValues/FlexFlowStyleValue.h>
@ -1455,55 +1456,6 @@ void RadialGradientStyleValue::paint(PaintContext& context, DevicePixelRect cons
context.rounded_device_size(m_resolved->gradient_size.to_type<CSSPixels>()));
}
ErrorOr<String> ConicGradientStyleValue::to_string() const
{
StringBuilder builder;
if (is_repeating())
TRY(builder.try_append("repeating-"sv));
TRY(builder.try_append("conic-gradient("sv));
bool has_from_angle = false;
bool has_at_position = false;
if ((has_from_angle = m_properties.from_angle.to_degrees() != 0))
TRY(builder.try_appendff("from {}", TRY(m_properties.from_angle.to_string())));
if ((has_at_position = m_properties.position != PositionValue::center())) {
if (has_from_angle)
TRY(builder.try_append(' '));
TRY(builder.try_appendff("at "sv));
TRY(m_properties.position.serialize(builder));
}
if (has_from_angle || has_at_position)
TRY(builder.try_append(", "sv));
TRY(serialize_color_stop_list(builder, m_properties.color_stop_list));
TRY(builder.try_append(')'));
return builder.to_string();
}
void ConicGradientStyleValue::resolve_for_size(Layout::Node const& node, CSSPixelSize size) const
{
if (!m_resolved.has_value())
m_resolved = ResolvedData { Painting::resolve_conic_gradient_data(node, *this), {} };
m_resolved->position = m_properties.position.resolved(node, CSSPixelRect { { 0, 0 }, size });
}
void ConicGradientStyleValue::paint(PaintContext& context, DevicePixelRect const& dest_rect, CSS::ImageRendering) const
{
VERIFY(m_resolved.has_value());
Painting::paint_conic_gradient(context, dest_rect, m_resolved->data, context.rounded_device_point(m_resolved->position));
}
bool ConicGradientStyleValue::equals(StyleValue const& other) const
{
if (type() != other.type())
return false;
auto& other_gradient = other.as_conic_gradient();
return m_properties == other_gradient.m_properties;
}
float ConicGradientStyleValue::angle_degrees() const
{
return m_properties.from_angle.to_degrees();
}
ErrorOr<String> ListStyleStyleValue::to_string() const
{
return String::formatted("{} {} {}", TRY(m_properties.position->to_string()), TRY(m_properties.image->to_string()), TRY(m_properties.style_type->to_string()));