mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:58:12 +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)
|
||||
{
|
||||
using GradientType = LinearGradientStyleValue::GradientType;
|
||||
using Repeating = LinearGradientStyleValue::Repeating;
|
||||
|
||||
if (!component_value.is_function())
|
||||
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();
|
||||
|
||||
GradientType gradient_type { GradientType::Standard };
|
||||
if (function_name.equals_ignoring_case("-webkit-linear-gradient"sv))
|
||||
function_name = consume_if_starts_with(function_name, "-webkit-"sv, [&] {
|
||||
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 {};
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue