mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-24 02:12:09 -05:00
LibWeb: Store RadialGradientStyleValue's position as PositionStyleValue
This commit is contained in:
parent
2ae53bc5eb
commit
5cf85d30aa
4 changed files with 19 additions and 16 deletions
|
@ -12,6 +12,7 @@
|
|||
#include <LibWeb/CSS/Parser/Parser.h>
|
||||
#include <LibWeb/CSS/StyleValues/ConicGradientStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/LinearGradientStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/PositionStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/RadialGradientStyleValue.h>
|
||||
|
||||
namespace Web::CSS::Parser {
|
||||
|
@ -403,7 +404,7 @@ RefPtr<StyleValue> Parser::parse_radial_gradient_function(ComponentValue const&
|
|||
|
||||
Size size = Extent::FarthestCorner;
|
||||
EndingShape ending_shape = EndingShape::Circle;
|
||||
PositionValue at_position = PositionValue::center();
|
||||
RefPtr<PositionStyleValue> at_position;
|
||||
|
||||
auto parse_ending_shape = [&]() -> Optional<EndingShape> {
|
||||
auto transaction = tokens.begin_transaction();
|
||||
|
@ -495,10 +496,10 @@ RefPtr<StyleValue> Parser::parse_radial_gradient_function(ComponentValue const&
|
|||
auto& token = tokens.peek_token();
|
||||
if (token.is(Token::Type::Ident) && token.token().ident().equals_ignoring_ascii_case("at"sv)) {
|
||||
(void)tokens.next_token();
|
||||
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;
|
||||
expect_comma = true;
|
||||
}
|
||||
|
||||
|
@ -513,7 +514,10 @@ RefPtr<StyleValue> Parser::parse_radial_gradient_function(ComponentValue const&
|
|||
if (!color_stops.has_value())
|
||||
return nullptr;
|
||||
|
||||
return RadialGradientStyleValue::create(ending_shape, size, at_position, move(*color_stops), repeating_gradient);
|
||||
if (!at_position)
|
||||
at_position = PositionStyleValue::create_center();
|
||||
|
||||
return RadialGradientStyleValue::create(ending_shape, size, at_position.release_nonnull(), move(*color_stops), repeating_gradient);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
*/
|
||||
|
||||
#include "RadialGradientStyleValue.h"
|
||||
#include <LibWeb/CSS/StyleValues/PositionStyleValue.h>
|
||||
#include <LibWeb/Layout/Node.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
@ -44,10 +45,8 @@ String RadialGradientStyleValue::to_string() const
|
|||
builder.appendff("{} {}", ellipse_size.radius_a.to_string(), ellipse_size.radius_b.to_string());
|
||||
});
|
||||
|
||||
if (m_properties.position != PositionValue::center()) {
|
||||
builder.appendff(" at "sv);
|
||||
m_properties.position.serialize(builder);
|
||||
}
|
||||
if (!m_properties.position->is_center())
|
||||
builder.appendff(" at {}"sv, m_properties.position->to_string());
|
||||
|
||||
builder.append(", "sv);
|
||||
serialize_color_stop_list(builder, m_properties.color_stop_list);
|
||||
|
@ -189,7 +188,7 @@ CSSPixelSize RadialGradientStyleValue::resolve_size(Layout::Node const& node, CS
|
|||
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);
|
||||
auto center = m_properties.position->resolved(node, gradient_box);
|
||||
auto gradient_size = resolve_size(node, center, gradient_box);
|
||||
if (m_resolved.has_value() && m_resolved->gradient_size == gradient_size)
|
||||
return;
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
|
||||
#include <AK/Vector.h>
|
||||
#include <LibWeb/CSS/Enums.h>
|
||||
#include <LibWeb/CSS/Position.h>
|
||||
#include <LibWeb/CSS/StyleValues/AbstractImageStyleValue.h>
|
||||
#include <LibWeb/Painting/GradientPainting.h>
|
||||
|
||||
|
@ -44,10 +43,10 @@ public:
|
|||
|
||||
using Size = Variant<Extent, CircleSize, EllipseSize>;
|
||||
|
||||
static ValueComparingNonnullRefPtr<RadialGradientStyleValue> create(EndingShape ending_shape, Size size, PositionValue position, Vector<LinearColorStopListElement> color_stop_list, GradientRepeating repeating)
|
||||
static ValueComparingNonnullRefPtr<RadialGradientStyleValue> create(EndingShape ending_shape, Size size, ValueComparingNonnullRefPtr<PositionStyleValue> position, Vector<LinearColorStopListElement> color_stop_list, GradientRepeating repeating)
|
||||
{
|
||||
VERIFY(color_stop_list.size() >= 2);
|
||||
return adopt_ref(*new (nothrow) RadialGradientStyleValue(ending_shape, size, position, move(color_stop_list), repeating));
|
||||
return adopt_ref(*new (nothrow) RadialGradientStyleValue(ending_shape, size, move(position), move(color_stop_list), repeating));
|
||||
}
|
||||
|
||||
virtual String to_string() const override;
|
||||
|
@ -72,16 +71,16 @@ public:
|
|||
virtual ~RadialGradientStyleValue() override = default;
|
||||
|
||||
private:
|
||||
RadialGradientStyleValue(EndingShape ending_shape, Size size, PositionValue position, Vector<LinearColorStopListElement> color_stop_list, GradientRepeating repeating)
|
||||
RadialGradientStyleValue(EndingShape ending_shape, Size size, ValueComparingNonnullRefPtr<PositionStyleValue> position, Vector<LinearColorStopListElement> color_stop_list, GradientRepeating repeating)
|
||||
: AbstractImageStyleValue(Type::RadialGradient)
|
||||
, m_properties { .ending_shape = ending_shape, .size = size, .position = position, .color_stop_list = move(color_stop_list), .repeating = repeating }
|
||||
, m_properties { .ending_shape = ending_shape, .size = size, .position = move(position), .color_stop_list = move(color_stop_list), .repeating = repeating }
|
||||
{
|
||||
}
|
||||
|
||||
struct Properties {
|
||||
EndingShape ending_shape;
|
||||
Size size;
|
||||
PositionValue position;
|
||||
ValueComparingNonnullRefPtr<PositionStyleValue> position;
|
||||
Vector<LinearColorStopListElement> color_stop_list;
|
||||
GradientRepeating repeating;
|
||||
bool operator==(Properties const&) const = default;
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <LibGfx/Gradients.h>
|
||||
#include <LibWeb/CSS/StyleValues/ConicGradientStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/LinearGradientStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/PositionStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/RadialGradientStyleValue.h>
|
||||
#include <LibWeb/Layout/Node.h>
|
||||
#include <LibWeb/Painting/GradientPainting.h>
|
||||
|
|
Loading…
Add table
Reference in a new issue