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