mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 16:37:35 +00:00
LibWeb: Parse repeating-linear-gradient()
Including `-webkit-repeating-linear-gradient()`
This commit is contained in:
parent
b123309b0d
commit
f9a685437f
3 changed files with 35 additions and 7 deletions
|
@ -2362,16 +2362,33 @@ Optional<AK::URL> Parser::parse_url_function(ComponentValue const& component_val
|
||||||
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) {
|
||||||
|
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 };
|
||||||
|
|
||||||
auto function_name = component_value.function().name();
|
auto function_name = component_value.function().name();
|
||||||
|
|
||||||
GradientType gradient_type { GradientType::Standard };
|
function_name = consume_if_starts_with(function_name, "-webkit-"sv, [&] {
|
||||||
if (function_name.equals_ignoring_case("-webkit-linear-gradient"sv))
|
|
||||||
gradient_type = GradientType::WebKit;
|
gradient_type = GradientType::WebKit;
|
||||||
else if (!function_name.equals_ignoring_case("linear-gradient"sv))
|
});
|
||||||
|
|
||||||
|
function_name = consume_if_starts_with(function_name, "repeating-"sv, [&] {
|
||||||
|
repeating_gradient = Repeating::Yes;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!function_name.equals_ignoring_case("linear-gradient"sv))
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
// linear-gradient() = linear-gradient([ <angle> | to <side-or-corner> ]?, <color-stop-list>)
|
// linear-gradient() = linear-gradient([ <angle> | to <side-or-corner> ]?, <color-stop-list>)
|
||||||
|
@ -2558,7 +2575,7 @@ RefPtr<StyleValue> Parser::parse_linear_gradient_function(ComponentValue const&
|
||||||
color_stops.append(list_element);
|
color_stops.append(list_element);
|
||||||
}
|
}
|
||||||
|
|
||||||
return LinearGradientStyleValue::create(gradient_direction, move(color_stops), gradient_type);
|
return LinearGradientStyleValue::create(gradient_direction, move(color_stops), gradient_type, repeating_gradient);
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<CSSRule> Parser::convert_to_rule(NonnullRefPtr<Rule> rule)
|
RefPtr<CSSRule> Parser::convert_to_rule(NonnullRefPtr<Rule> rule)
|
||||||
|
|
|
@ -1491,6 +1491,8 @@ 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)
|
||||||
|
builder.append("repeating-"sv);
|
||||||
builder.append("linear-gradient("sv);
|
builder.append("linear-gradient("sv);
|
||||||
m_direction.visit(
|
m_direction.visit(
|
||||||
[&](SideOrCorner side_or_corner) {
|
[&](SideOrCorner side_or_corner) {
|
||||||
|
|
|
@ -978,10 +978,15 @@ public:
|
||||||
WebKit
|
WebKit
|
||||||
};
|
};
|
||||||
|
|
||||||
static NonnullRefPtr<LinearGradientStyleValue> create(GradientDirection direction, Vector<ColorStopListElement> color_stop_list, GradientType type)
|
enum class Repeating {
|
||||||
|
Yes,
|
||||||
|
No
|
||||||
|
};
|
||||||
|
|
||||||
|
static NonnullRefPtr<LinearGradientStyleValue> create(GradientDirection direction, Vector<ColorStopListElement> 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));
|
return adopt_ref(*new LinearGradientStyleValue(direction, move(color_stop_list), type, repeating));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual String to_string() const override;
|
virtual String to_string() const override;
|
||||||
|
@ -993,6 +998,8 @@ public:
|
||||||
return m_color_stop_list;
|
return m_color_stop_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool is_repeating() const { return m_repeating == Repeating::Yes; }
|
||||||
|
|
||||||
float angle_degrees(Gfx::FloatSize const& gradient_size) const;
|
float angle_degrees(Gfx::FloatSize const& gradient_size) const;
|
||||||
|
|
||||||
void resolve_for_size(Layout::Node const&, Gfx::FloatSize const&) const override;
|
void resolve_for_size(Layout::Node const&, Gfx::FloatSize const&) const override;
|
||||||
|
@ -1001,17 +1008,19 @@ 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<ColorStopListElement> color_stop_list, GradientType type)
|
LinearGradientStyleValue(GradientDirection direction, Vector<ColorStopListElement> color_stop_list, GradientType type, Repeating 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))
|
||||||
, m_gradient_type(type)
|
, m_gradient_type(type)
|
||||||
|
, m_repeating(repeating)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
GradientDirection m_direction;
|
GradientDirection m_direction;
|
||||||
Vector<ColorStopListElement> m_color_stop_list;
|
Vector<ColorStopListElement> m_color_stop_list;
|
||||||
GradientType m_gradient_type;
|
GradientType m_gradient_type;
|
||||||
|
Repeating m_repeating;
|
||||||
|
|
||||||
mutable Optional<Painting::LinearGradientData> m_resolved_data;
|
mutable Optional<Painting::LinearGradientData> m_resolved_data;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue