mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-29 04:39:10 +00:00
LibWeb: Make parse_color_stop_list() a CSS Parser method
This lets us remove the color/dimension-parsing lambdas, since these always forwarded to the same methods. This will make it easier to later convert those methods to take a TokenStream.
This commit is contained in:
parent
8e56367092
commit
384b18b271
Notes:
sideshowbarker
2024-07-17 18:23:22 +09:00
Author: https://github.com/AtkinsSJ
Commit: 384b18b271
Pull-request: https://github.com/SerenityOS/serenity/pull/24062
Reviewed-by: https://github.com/Hendiadyoin1
2 changed files with 7 additions and 9 deletions
|
@ -18,7 +18,7 @@
|
||||||
namespace Web::CSS::Parser {
|
namespace Web::CSS::Parser {
|
||||||
|
|
||||||
template<typename TElement>
|
template<typename TElement>
|
||||||
static Optional<Vector<TElement>> parse_color_stop_list(auto& tokens, auto is_position, auto get_position, auto parse_color, auto parse_dimension)
|
Optional<Vector<TElement>> Parser::parse_color_stop_list(TokenStream<ComponentValue>& tokens, auto is_position, auto get_position)
|
||||||
{
|
{
|
||||||
enum class ElementType {
|
enum class ElementType {
|
||||||
Garbage,
|
Garbage,
|
||||||
|
@ -46,13 +46,13 @@ static Optional<Vector<TElement>> parse_color_stop_list(auto& tokens, auto is_po
|
||||||
return ElementType::ColorHint;
|
return ElementType::ColorHint;
|
||||||
}
|
}
|
||||||
// <T-percentage> <color>
|
// <T-percentage> <color>
|
||||||
auto maybe_color = parse_color(tokens.next_token());
|
auto maybe_color = parse_color_value(tokens.next_token());
|
||||||
if (!maybe_color)
|
if (!maybe_color)
|
||||||
return ElementType::Garbage;
|
return ElementType::Garbage;
|
||||||
color = maybe_color.release_nonnull();
|
color = maybe_color.release_nonnull();
|
||||||
} else {
|
} else {
|
||||||
// [<color> <T-percentage>?]
|
// [<color> <T-percentage>?]
|
||||||
auto maybe_color = parse_color(token);
|
auto maybe_color = parse_color_value(token);
|
||||||
if (!maybe_color)
|
if (!maybe_color)
|
||||||
return ElementType::Garbage;
|
return ElementType::Garbage;
|
||||||
color = maybe_color.release_nonnull();
|
color = maybe_color.release_nonnull();
|
||||||
|
@ -124,9 +124,7 @@ Optional<Vector<LinearColorStopListElement>> Parser::parse_linear_color_stop_lis
|
||||||
return parse_color_stop_list<LinearColorStopListElement>(
|
return parse_color_stop_list<LinearColorStopListElement>(
|
||||||
tokens,
|
tokens,
|
||||||
[](Dimension& dimension) { return dimension.is_length_percentage(); },
|
[](Dimension& dimension) { return dimension.is_length_percentage(); },
|
||||||
[](Dimension& dimension) { return dimension.length_percentage(); },
|
[](Dimension& dimension) { return dimension.length_percentage(); });
|
||||||
[&](auto& token) { return parse_color_value(token); },
|
|
||||||
[&](auto& token) { return parse_dimension(token); });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Vector<AngularColorStopListElement>> Parser::parse_angular_color_stop_list(TokenStream<ComponentValue>& tokens)
|
Optional<Vector<AngularColorStopListElement>> Parser::parse_angular_color_stop_list(TokenStream<ComponentValue>& tokens)
|
||||||
|
@ -136,9 +134,7 @@ Optional<Vector<AngularColorStopListElement>> Parser::parse_angular_color_stop_l
|
||||||
return parse_color_stop_list<AngularColorStopListElement>(
|
return parse_color_stop_list<AngularColorStopListElement>(
|
||||||
tokens,
|
tokens,
|
||||||
[](Dimension& dimension) { return dimension.is_angle_percentage(); },
|
[](Dimension& dimension) { return dimension.is_angle_percentage(); },
|
||||||
[](Dimension& dimension) { return dimension.angle_percentage(); },
|
[](Dimension& dimension) { return dimension.angle_percentage(); });
|
||||||
[&](auto& token) { return parse_color_value(token); },
|
|
||||||
[&](auto& token) { return parse_dimension(token); });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<StyleValue> Parser::parse_linear_gradient_function(ComponentValue const& component_value)
|
RefPtr<StyleValue> Parser::parse_linear_gradient_function(ComponentValue const& component_value)
|
||||||
|
|
|
@ -198,6 +198,8 @@ private:
|
||||||
Optional<URL::URL> parse_url_function(ComponentValue const&);
|
Optional<URL::URL> parse_url_function(ComponentValue const&);
|
||||||
RefPtr<StyleValue> parse_url_value(ComponentValue const&);
|
RefPtr<StyleValue> parse_url_value(ComponentValue const&);
|
||||||
|
|
||||||
|
template<typename TElement>
|
||||||
|
Optional<Vector<TElement>> parse_color_stop_list(TokenStream<ComponentValue>& tokens, auto is_position, auto get_position);
|
||||||
Optional<Vector<LinearColorStopListElement>> parse_linear_color_stop_list(TokenStream<ComponentValue>&);
|
Optional<Vector<LinearColorStopListElement>> parse_linear_color_stop_list(TokenStream<ComponentValue>&);
|
||||||
Optional<Vector<AngularColorStopListElement>> parse_angular_color_stop_list(TokenStream<ComponentValue>&);
|
Optional<Vector<AngularColorStopListElement>> parse_angular_color_stop_list(TokenStream<ComponentValue>&);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue