mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:47:44 +00:00
LibWeb: Add ConicGradientStyleValue
This commit adds a simple style value (which is an abstract image) to represent conic-gradient()s. This commit also starts to factor out some reusable parts of the linear-gradient() style value for other gradient types.
This commit is contained in:
parent
5eeb6bbee3
commit
067759c0e9
3 changed files with 139 additions and 48 deletions
|
@ -90,6 +90,12 @@ ColorStyleValue const& StyleValue::as_color() const
|
|||
return static_cast<ColorStyleValue const&>(*this);
|
||||
}
|
||||
|
||||
ConicGradientStyleValue const& StyleValue::as_conic_gradient() const
|
||||
{
|
||||
VERIFY(is_conic_gradient());
|
||||
return static_cast<ConicGradientStyleValue const&>(*this);
|
||||
}
|
||||
|
||||
ContentStyleValue const& StyleValue::as_content() const
|
||||
{
|
||||
VERIFY(is_content());
|
||||
|
@ -1697,6 +1703,26 @@ void ImageStyleValue::paint(PaintContext& context, Gfx::IntRect const& dest_rect
|
|||
context.painter().draw_scaled_bitmap(dest_rect, *m_bitmap, m_bitmap->rect(), 1.0f, to_gfx_scaling_mode(image_rendering));
|
||||
}
|
||||
|
||||
static void serialize_color_stop_list(StringBuilder& builder, auto const& color_stop_list)
|
||||
{
|
||||
bool first = true;
|
||||
for (auto const& element : color_stop_list) {
|
||||
if (!first)
|
||||
builder.append(", "sv);
|
||||
|
||||
if (element.transition_hint.has_value()) {
|
||||
builder.appendff("{}, "sv, element.transition_hint->value.to_string());
|
||||
}
|
||||
|
||||
serialize_a_srgb_value(builder, element.color_stop.color);
|
||||
for (auto position : Array { &element.color_stop.position, &element.color_stop.second_position }) {
|
||||
if (position->has_value())
|
||||
builder.appendff(" {}"sv, (*position)->to_string());
|
||||
}
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
|
||||
String LinearGradientStyleValue::to_string() const
|
||||
{
|
||||
StringBuilder builder;
|
||||
|
@ -1736,22 +1762,7 @@ String LinearGradientStyleValue::to_string() const
|
|||
builder.appendff("{}, "sv, angle.to_string());
|
||||
});
|
||||
|
||||
bool first = true;
|
||||
for (auto const& element : m_color_stop_list) {
|
||||
if (!first)
|
||||
builder.append(", "sv);
|
||||
|
||||
if (element.transition_hint.has_value()) {
|
||||
builder.appendff("{}, "sv, element.transition_hint->value.to_string());
|
||||
}
|
||||
|
||||
serialize_a_srgb_value(builder, element.color_stop.color);
|
||||
for (auto position : Array { &element.color_stop.position, &element.color_stop.second_position }) {
|
||||
if (position->has_value())
|
||||
builder.appendff(" {}"sv, (*position)->to_string());
|
||||
}
|
||||
first = false;
|
||||
}
|
||||
serialize_color_stop_list(builder, m_color_stop_list);
|
||||
builder.append(")"sv);
|
||||
return builder.to_string();
|
||||
}
|
||||
|
@ -1765,21 +1776,6 @@ static bool operator==(LinearGradientStyleValue::GradientDirection const& a, Lin
|
|||
return false;
|
||||
}
|
||||
|
||||
static bool operator==(GradientColorHint const& a, GradientColorHint const& b)
|
||||
{
|
||||
return a.value == b.value;
|
||||
}
|
||||
|
||||
static bool operator==(GradientColorStop const& a, GradientColorStop const& b)
|
||||
{
|
||||
return a.color == b.color && a.position == b.position && a.second_position == b.second_position;
|
||||
}
|
||||
|
||||
static bool operator==(ColorStopListElement const& a, ColorStopListElement const& b)
|
||||
{
|
||||
return a.transition_hint == b.transition_hint && a.color_stop == b.color_stop;
|
||||
}
|
||||
|
||||
static bool operator==(EdgeRect const& a, EdgeRect const& b)
|
||||
{
|
||||
return a.top_edge == b.top_edge && a.right_edge == b.right_edge && a.bottom_edge == b.bottom_edge && a.left_edge == b.left_edge;
|
||||
|
@ -1857,6 +1853,45 @@ void LinearGradientStyleValue::paint(PaintContext& context, Gfx::IntRect const&
|
|||
Painting::paint_linear_gradient(context, dest_rect, m_resolved->data);
|
||||
}
|
||||
|
||||
String ConicGradientStyleValue::to_string() const
|
||||
{
|
||||
StringBuilder builder;
|
||||
builder.append("conic-gradient("sv);
|
||||
bool has_from_angle = false;
|
||||
bool has_at_position = false;
|
||||
if ((has_from_angle = m_from_angle.to_degrees() != 0))
|
||||
builder.appendff("from {}", m_from_angle.to_string());
|
||||
if ((has_at_position = m_position != PositionValue::center())) {
|
||||
if (has_from_angle)
|
||||
builder.append(' ');
|
||||
builder.appendff("at "sv);
|
||||
m_position.serialize(builder);
|
||||
}
|
||||
if (has_from_angle || has_at_position)
|
||||
builder.append(", "sv);
|
||||
serialize_color_stop_list(builder, m_color_stop_list);
|
||||
builder.append(')');
|
||||
return builder.to_string();
|
||||
}
|
||||
|
||||
void ConicGradientStyleValue::resolve_for_size(Layout::Node const&, Gfx::FloatSize const&) const
|
||||
{
|
||||
}
|
||||
|
||||
void ConicGradientStyleValue::paint(PaintContext&, Gfx::IntRect const&, CSS::ImageRendering) const
|
||||
{
|
||||
}
|
||||
|
||||
bool ConicGradientStyleValue::equals(StyleValue const&) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
float ConicGradientStyleValue::angle_degrees() const
|
||||
{
|
||||
return m_from_angle.to_degrees();
|
||||
}
|
||||
|
||||
bool InheritStyleValue::equals(StyleValue const& other) const
|
||||
{
|
||||
return type() == other.type();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue