mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:17:34 +00:00
LibWeb: Parse repeating-conic-gradient()
s
This commit is contained in:
parent
bee4df7bfb
commit
2c2b9fb1d7
3 changed files with 38 additions and 25 deletions
|
@ -2388,23 +2388,23 @@ static Optional<Vector<TElement>> parse_color_stop_list(auto& tokens, auto is_po
|
||||||
return color_stops;
|
return color_stops;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static StringView consume_if_starts_with(StringView str, StringView start, auto found_callback)
|
||||||
|
{
|
||||||
|
if (str.starts_with(start, CaseSensitivity::CaseInsensitive)) {
|
||||||
|
found_callback();
|
||||||
|
return str.substring_view(start.length());
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
};
|
||||||
|
|
||||||
RefPtr<StyleValue> Parser::parse_linear_gradient_function(ComponentValue const& component_value)
|
RefPtr<StyleValue> Parser::parse_linear_gradient_function(ComponentValue const& component_value)
|
||||||
{
|
{
|
||||||
using GradientType = LinearGradientStyleValue::GradientType;
|
using GradientType = LinearGradientStyleValue::GradientType;
|
||||||
using Repeating = LinearGradientStyleValue::Repeating;
|
|
||||||
|
|
||||||
if (!component_value.is_function())
|
if (!component_value.is_function())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
auto consume_if_starts_with = [](StringView str, StringView start, auto found_callback) {
|
GradientRepeating repeating_gradient = GradientRepeating::No;
|
||||||
if (str.starts_with(start, CaseSensitivity::CaseInsensitive)) {
|
|
||||||
found_callback();
|
|
||||||
return str.substring_view(start.length());
|
|
||||||
}
|
|
||||||
return str;
|
|
||||||
};
|
|
||||||
|
|
||||||
Repeating repeating_gradient = Repeating::No;
|
|
||||||
GradientType gradient_type { GradientType::Standard };
|
GradientType gradient_type { GradientType::Standard };
|
||||||
|
|
||||||
auto function_name = component_value.function().name();
|
auto function_name = component_value.function().name();
|
||||||
|
@ -2414,7 +2414,7 @@ RefPtr<StyleValue> Parser::parse_linear_gradient_function(ComponentValue const&
|
||||||
});
|
});
|
||||||
|
|
||||||
function_name = consume_if_starts_with(function_name, "repeating-"sv, [&] {
|
function_name = consume_if_starts_with(function_name, "repeating-"sv, [&] {
|
||||||
repeating_gradient = Repeating::Yes;
|
repeating_gradient = GradientRepeating::Yes;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!function_name.equals_ignoring_case("linear-gradient"sv))
|
if (!function_name.equals_ignoring_case("linear-gradient"sv))
|
||||||
|
@ -2541,8 +2541,15 @@ RefPtr<StyleValue> Parser::parse_conic_gradient_function(ComponentValue const& c
|
||||||
{
|
{
|
||||||
if (!component_value.is_function())
|
if (!component_value.is_function())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
GradientRepeating repeating_gradient = GradientRepeating::No;
|
||||||
|
|
||||||
auto function_name = component_value.function().name();
|
auto function_name = component_value.function().name();
|
||||||
|
|
||||||
|
function_name = consume_if_starts_with(function_name, "repeating-"sv, [&] {
|
||||||
|
repeating_gradient = GradientRepeating::Yes;
|
||||||
|
});
|
||||||
|
|
||||||
if (!function_name.equals_ignoring_case("conic-gradient"sv))
|
if (!function_name.equals_ignoring_case("conic-gradient"sv))
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
@ -2636,7 +2643,7 @@ RefPtr<StyleValue> Parser::parse_conic_gradient_function(ComponentValue const& c
|
||||||
if (!color_stops.has_value())
|
if (!color_stops.has_value())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
return ConicGradientStyleValue::create(from_angle, at_position, move(*color_stops));
|
return ConicGradientStyleValue::create(from_angle, at_position, move(*color_stops), repeating_gradient);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<PositionValue> Parser::parse_position(TokenStream<ComponentValue>& tokens)
|
Optional<PositionValue> Parser::parse_position(TokenStream<ComponentValue>& tokens)
|
||||||
|
|
|
@ -1751,7 +1751,7 @@ String LinearGradientStyleValue::to_string() const
|
||||||
|
|
||||||
if (m_gradient_type == GradientType::WebKit)
|
if (m_gradient_type == GradientType::WebKit)
|
||||||
builder.append("-webkit-"sv);
|
builder.append("-webkit-"sv);
|
||||||
if (m_repeating == Repeating::Yes)
|
if (is_repeating())
|
||||||
builder.append("repeating-"sv);
|
builder.append("repeating-"sv);
|
||||||
builder.append("linear-gradient("sv);
|
builder.append("linear-gradient("sv);
|
||||||
m_direction.visit(
|
m_direction.visit(
|
||||||
|
@ -1958,6 +1958,8 @@ bool PositionValue::operator==(PositionValue const& other) const
|
||||||
String ConicGradientStyleValue::to_string() const
|
String ConicGradientStyleValue::to_string() const
|
||||||
{
|
{
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
|
if (is_repeating())
|
||||||
|
builder.append("repeating-"sv);
|
||||||
builder.append("conic-gradient("sv);
|
builder.append("conic-gradient("sv);
|
||||||
bool has_from_angle = false;
|
bool has_from_angle = false;
|
||||||
bool has_at_position = false;
|
bool has_at_position = false;
|
||||||
|
|
|
@ -1190,12 +1190,17 @@ private:
|
||||||
RefPtr<Gfx::Bitmap> m_bitmap;
|
RefPtr<Gfx::Bitmap> m_bitmap;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class GradientRepeating {
|
||||||
|
Yes,
|
||||||
|
No
|
||||||
|
};
|
||||||
|
|
||||||
class ConicGradientStyleValue final : public AbstractImageStyleValue {
|
class ConicGradientStyleValue final : public AbstractImageStyleValue {
|
||||||
public:
|
public:
|
||||||
static NonnullRefPtr<ConicGradientStyleValue> create(Angle from_angle, PositionValue position, Vector<AngularColorStopListElement> color_stop_list)
|
static NonnullRefPtr<ConicGradientStyleValue> create(Angle from_angle, PositionValue position, Vector<AngularColorStopListElement> color_stop_list, GradientRepeating repeating)
|
||||||
{
|
{
|
||||||
VERIFY(color_stop_list.size() >= 2);
|
VERIFY(color_stop_list.size() >= 2);
|
||||||
return adopt_ref(*new ConicGradientStyleValue(from_angle, position, move(color_stop_list)));
|
return adopt_ref(*new ConicGradientStyleValue(from_angle, position, move(color_stop_list), repeating));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual String to_string() const override;
|
virtual String to_string() const override;
|
||||||
|
@ -1219,12 +1224,15 @@ public:
|
||||||
|
|
||||||
Gfx::FloatPoint resolve_position(Layout::Node const&, Gfx::FloatRect const&) const;
|
Gfx::FloatPoint resolve_position(Layout::Node const&, Gfx::FloatRect const&) const;
|
||||||
|
|
||||||
|
bool is_repeating() const { return m_repeating == GradientRepeating::Yes; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ConicGradientStyleValue(Angle from_angle, PositionValue position, Vector<AngularColorStopListElement> color_stop_list)
|
ConicGradientStyleValue(Angle from_angle, PositionValue position, Vector<AngularColorStopListElement> color_stop_list, GradientRepeating repeating)
|
||||||
: AbstractImageStyleValue(Type::ConicGradient)
|
: AbstractImageStyleValue(Type::ConicGradient)
|
||||||
, m_from_angle(from_angle)
|
, m_from_angle(from_angle)
|
||||||
, m_position(position)
|
, m_position(position)
|
||||||
, m_color_stop_list(move(color_stop_list))
|
, m_color_stop_list(move(color_stop_list))
|
||||||
|
, m_repeating(repeating)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1232,6 +1240,7 @@ private:
|
||||||
Angle m_from_angle;
|
Angle m_from_angle;
|
||||||
PositionValue m_position;
|
PositionValue m_position;
|
||||||
Vector<AngularColorStopListElement> m_color_stop_list;
|
Vector<AngularColorStopListElement> m_color_stop_list;
|
||||||
|
GradientRepeating m_repeating;
|
||||||
|
|
||||||
struct ResolvedData {
|
struct ResolvedData {
|
||||||
Painting::ConicGradientData data;
|
Painting::ConicGradientData data;
|
||||||
|
@ -1250,12 +1259,7 @@ public:
|
||||||
WebKit
|
WebKit
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class Repeating {
|
static NonnullRefPtr<LinearGradientStyleValue> create(GradientDirection direction, Vector<LinearColorStopListElement> color_stop_list, GradientType type, GradientRepeating repeating)
|
||||||
Yes,
|
|
||||||
No
|
|
||||||
};
|
|
||||||
|
|
||||||
static NonnullRefPtr<LinearGradientStyleValue> create(GradientDirection direction, Vector<LinearColorStopListElement> color_stop_list, GradientType type, Repeating repeating)
|
|
||||||
{
|
{
|
||||||
VERIFY(color_stop_list.size() >= 2);
|
VERIFY(color_stop_list.size() >= 2);
|
||||||
return adopt_ref(*new LinearGradientStyleValue(direction, move(color_stop_list), type, repeating));
|
return adopt_ref(*new LinearGradientStyleValue(direction, move(color_stop_list), type, repeating));
|
||||||
|
@ -1270,7 +1274,7 @@ public:
|
||||||
return m_color_stop_list;
|
return m_color_stop_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_repeating() const { return m_repeating == Repeating::Yes; }
|
bool is_repeating() const { return m_repeating == GradientRepeating::Yes; }
|
||||||
|
|
||||||
float angle_degrees(Gfx::FloatSize const& gradient_size) const;
|
float angle_degrees(Gfx::FloatSize const& gradient_size) const;
|
||||||
|
|
||||||
|
@ -1280,7 +1284,7 @@ public:
|
||||||
void paint(PaintContext& context, Gfx::IntRect const& dest_rect, CSS::ImageRendering image_rendering) const override;
|
void paint(PaintContext& context, Gfx::IntRect const& dest_rect, CSS::ImageRendering image_rendering) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LinearGradientStyleValue(GradientDirection direction, Vector<LinearColorStopListElement> color_stop_list, GradientType type, Repeating repeating)
|
LinearGradientStyleValue(GradientDirection direction, Vector<LinearColorStopListElement> color_stop_list, GradientType type, GradientRepeating repeating)
|
||||||
: AbstractImageStyleValue(Type::LinearGradient)
|
: AbstractImageStyleValue(Type::LinearGradient)
|
||||||
, m_direction(direction)
|
, m_direction(direction)
|
||||||
, m_color_stop_list(move(color_stop_list))
|
, m_color_stop_list(move(color_stop_list))
|
||||||
|
@ -1292,7 +1296,7 @@ private:
|
||||||
GradientDirection m_direction;
|
GradientDirection m_direction;
|
||||||
Vector<LinearColorStopListElement> m_color_stop_list;
|
Vector<LinearColorStopListElement> m_color_stop_list;
|
||||||
GradientType m_gradient_type;
|
GradientType m_gradient_type;
|
||||||
Repeating m_repeating;
|
GradientRepeating m_repeating;
|
||||||
|
|
||||||
struct ResolvedData {
|
struct ResolvedData {
|
||||||
Painting::LinearGradientData data;
|
Painting::LinearGradientData data;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue