mirror of
https://github.com/SerenityOS/serenity
synced 2024-07-22 18:46:18 +00:00
LibWeb: Store ConicGradientStyleValue's position as PositionStyleValue
This commit is contained in:
parent
5cf85d30aa
commit
7bcabbb325
|
@ -292,7 +292,7 @@ RefPtr<StyleValue> Parser::parse_conic_gradient_function(ComponentValue const& c
|
|||
return nullptr;
|
||||
|
||||
Angle from_angle(0, Angle::Type::Deg);
|
||||
PositionValue at_position = PositionValue::center();
|
||||
RefPtr<PositionStyleValue> at_position;
|
||||
|
||||
// conic-gradient( [ [ from <angle> ]? [ at <position> ]? ] ||
|
||||
// <color-interpolation-method> , <angular-color-stop-list> )
|
||||
|
@ -333,10 +333,10 @@ RefPtr<StyleValue> Parser::parse_conic_gradient_function(ComponentValue const& c
|
|||
// at <position>
|
||||
if (got_at_position)
|
||||
return nullptr;
|
||||
auto position = parse_position(tokens);
|
||||
if (!position.has_value())
|
||||
auto position = parse_position_value(tokens);
|
||||
if (!position)
|
||||
return nullptr;
|
||||
at_position = *position;
|
||||
at_position = position;
|
||||
got_at_position = true;
|
||||
} else if (consume_identifier("in"sv)) {
|
||||
// <color-interpolation-method>
|
||||
|
@ -363,7 +363,10 @@ RefPtr<StyleValue> Parser::parse_conic_gradient_function(ComponentValue const& c
|
|||
if (!color_stops.has_value())
|
||||
return nullptr;
|
||||
|
||||
return ConicGradientStyleValue::create(from_angle, at_position, move(*color_stops), repeating_gradient);
|
||||
if (!at_position)
|
||||
at_position = PositionStyleValue::create_center();
|
||||
|
||||
return ConicGradientStyleValue::create(from_angle, at_position.release_nonnull(), move(*color_stops), repeating_gradient);
|
||||
}
|
||||
|
||||
RefPtr<StyleValue> Parser::parse_radial_gradient_function(ComponentValue const& component_value)
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
*/
|
||||
|
||||
#include "ConicGradientStyleValue.h"
|
||||
#include <LibWeb/CSS/StyleValues/PositionStyleValue.h>
|
||||
#include <LibWeb/Layout/Node.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
@ -18,15 +19,14 @@ String ConicGradientStyleValue::to_string() const
|
|||
if (is_repeating())
|
||||
builder.append("repeating-"sv);
|
||||
builder.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))
|
||||
bool has_from_angle = m_properties.from_angle.to_degrees() != 0;
|
||||
bool has_at_position = !m_properties.position->is_center();
|
||||
if (has_from_angle)
|
||||
builder.appendff("from {}", m_properties.from_angle.to_string());
|
||||
if ((has_at_position = m_properties.position != PositionValue::center())) {
|
||||
if (has_at_position) {
|
||||
if (has_from_angle)
|
||||
builder.append(' ');
|
||||
builder.appendff("at "sv);
|
||||
m_properties.position.serialize(builder);
|
||||
builder.appendff("at {}"sv, m_properties.position->to_string());
|
||||
}
|
||||
if (has_from_angle || has_at_position)
|
||||
builder.append(", "sv);
|
||||
|
@ -39,7 +39,7 @@ void ConicGradientStyleValue::resolve_for_size(Layout::NodeWithStyleAndBoxModelM
|
|||
{
|
||||
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 });
|
||||
m_resolved->position = m_properties.position->resolved(node, CSSPixelRect { { 0, 0 }, size });
|
||||
}
|
||||
|
||||
void ConicGradientStyleValue::paint(PaintContext& context, DevicePixelRect const& dest_rect, CSS::ImageRendering) const
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <LibWeb/CSS/Angle.h>
|
||||
#include <LibWeb/CSS/Position.h>
|
||||
#include <LibWeb/CSS/StyleValues/AbstractImageStyleValue.h>
|
||||
#include <LibWeb/Painting/GradientPainting.h>
|
||||
|
||||
|
@ -18,10 +17,10 @@ namespace Web::CSS {
|
|||
|
||||
class ConicGradientStyleValue final : public AbstractImageStyleValue {
|
||||
public:
|
||||
static ValueComparingNonnullRefPtr<ConicGradientStyleValue> create(Angle from_angle, PositionValue position, Vector<AngularColorStopListElement> color_stop_list, GradientRepeating repeating)
|
||||
static ValueComparingNonnullRefPtr<ConicGradientStyleValue> create(Angle from_angle, ValueComparingNonnullRefPtr<PositionStyleValue> position, Vector<AngularColorStopListElement> color_stop_list, GradientRepeating repeating)
|
||||
{
|
||||
VERIFY(color_stop_list.size() >= 2);
|
||||
return adopt_ref(*new (nothrow) ConicGradientStyleValue(from_angle, position, move(color_stop_list), repeating));
|
||||
return adopt_ref(*new (nothrow) ConicGradientStyleValue(from_angle, move(position), move(color_stop_list), repeating));
|
||||
}
|
||||
|
||||
virtual String to_string() const override;
|
||||
|
@ -46,16 +45,16 @@ public:
|
|||
bool is_repeating() const { return m_properties.repeating == GradientRepeating::Yes; }
|
||||
|
||||
private:
|
||||
ConicGradientStyleValue(Angle from_angle, PositionValue position, Vector<AngularColorStopListElement> color_stop_list, GradientRepeating repeating)
|
||||
ConicGradientStyleValue(Angle from_angle, ValueComparingNonnullRefPtr<PositionStyleValue> position, Vector<AngularColorStopListElement> color_stop_list, GradientRepeating repeating)
|
||||
: AbstractImageStyleValue(Type::ConicGradient)
|
||||
, m_properties { .from_angle = from_angle, .position = position, .color_stop_list = move(color_stop_list), .repeating = repeating }
|
||||
, m_properties { .from_angle = from_angle, .position = move(position), .color_stop_list = move(color_stop_list), .repeating = repeating }
|
||||
{
|
||||
}
|
||||
|
||||
struct Properties {
|
||||
// FIXME: Support <color-interpolation-method>
|
||||
Angle from_angle;
|
||||
PositionValue position;
|
||||
ValueComparingNonnullRefPtr<PositionStyleValue> position;
|
||||
Vector<AngularColorStopListElement> color_stop_list;
|
||||
GradientRepeating repeating;
|
||||
bool operator==(Properties const&) const = default;
|
||||
|
|
Loading…
Reference in a new issue