1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 23:17:46 +00:00

LibWeb: Allow any valid <color> in CSS gradients

We now keep the color value as a StyleValue up until we go to paint the
gradient, which makes `currentColor` work, along with any other color
values that can't be immediately converted into a `Gfx::Color` while
parsing.
This commit is contained in:
Sam Atkins 2023-08-16 12:45:23 +01:00 committed by Andreas Kling
parent 2971ae59d8
commit 631a988a57
13 changed files with 53 additions and 28 deletions

View file

@ -24,7 +24,7 @@ public:
virtual Optional<CSSPixels> natural_height() const { return {}; }
virtual void load_any_resources(DOM::Document&) {};
virtual void resolve_for_size(Layout::Node const&, CSSPixelSize) const {};
virtual void resolve_for_size(Layout::NodeWithStyleAndBoxModelMetrics const&, CSSPixelSize) const {};
virtual bool is_paintable() const = 0;
virtual void paint(PaintContext& context, DevicePixelRect const& dest_rect, ImageRendering) const = 0;
@ -47,7 +47,7 @@ struct ColorStopListElement {
Optional<ColorHint> transition_hint;
struct ColorStop {
Color color;
RefPtr<StyleValue> color;
Optional<TPosition> position;
Optional<TPosition> second_position = {};
inline bool operator==(ColorStop const&) const = default;
@ -69,7 +69,7 @@ static ErrorOr<void> serialize_color_stop_list(StringBuilder& builder, auto cons
if (element.transition_hint.has_value())
TRY(builder.try_appendff("{}, "sv, TRY(element.transition_hint->value.to_string())));
TRY(serialize_a_srgb_value(builder, element.color_stop.color));
TRY(builder.try_append(TRY(element.color_stop.color->to_string())));
for (auto position : Array { &element.color_stop.position, &element.color_stop.second_position }) {
if (position->has_value())
TRY(builder.try_appendff(" {}"sv, TRY((*position)->to_string())));

View file

@ -8,6 +8,7 @@
*/
#include "ConicGradientStyleValue.h"
#include <LibWeb/Layout/Node.h>
namespace Web::CSS {
@ -34,7 +35,7 @@ ErrorOr<String> ConicGradientStyleValue::to_string() const
return builder.to_string();
}
void ConicGradientStyleValue::resolve_for_size(Layout::Node const& node, CSSPixelSize size) const
void ConicGradientStyleValue::resolve_for_size(Layout::NodeWithStyleAndBoxModelMetrics const& node, CSSPixelSize size) const
{
if (!m_resolved.has_value())
m_resolved = ResolvedData { Painting::resolve_conic_gradient_data(node, *this), {} };

View file

@ -39,7 +39,7 @@ public:
bool is_paintable() const override { return true; }
void resolve_for_size(Layout::Node const&, CSSPixelSize) const override;
void resolve_for_size(Layout::NodeWithStyleAndBoxModelMetrics const&, CSSPixelSize) const override;
virtual ~ConicGradientStyleValue() override = default;

View file

@ -102,7 +102,7 @@ float LinearGradientStyleValue::angle_degrees(CSSPixelSize gradient_size) const
});
}
void LinearGradientStyleValue::resolve_for_size(Layout::Node const& node, CSSPixelSize size) const
void LinearGradientStyleValue::resolve_for_size(Layout::NodeWithStyleAndBoxModelMetrics const& node, CSSPixelSize size) const
{
if (m_resolved.has_value() && m_resolved->size == size)
return;

View file

@ -57,7 +57,7 @@ public:
float angle_degrees(CSSPixelSize gradient_size) const;
void resolve_for_size(Layout::Node const&, CSSPixelSize) const override;
void resolve_for_size(Layout::NodeWithStyleAndBoxModelMetrics const&, CSSPixelSize) const override;
bool is_paintable() const override { return true; }
void paint(PaintContext& context, DevicePixelRect const& dest_rect, CSS::ImageRendering image_rendering) const override;

View file

@ -8,6 +8,7 @@
*/
#include "RadialGradientStyleValue.h"
#include <LibWeb/Layout/Node.h>
namespace Web::CSS {
@ -184,7 +185,7 @@ Gfx::FloatSize RadialGradientStyleValue::resolve_size(Layout::Node const& node,
return resolved_size;
}
void RadialGradientStyleValue::resolve_for_size(Layout::Node const& node, CSSPixelSize paint_size) const
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).to_type<float>();

View file

@ -63,7 +63,7 @@ public:
bool is_paintable() const override { return true; }
void resolve_for_size(Layout::Node const&, CSSPixelSize) const override;
void resolve_for_size(Layout::NodeWithStyleAndBoxModelMetrics const&, CSSPixelSize) const override;
Gfx::FloatSize resolve_size(Layout::Node const&, Gfx::FloatPoint, Gfx::FloatRect const&) const;