Skip to content

Commit e937f5d

Browse files
Calme1709AtkinsSJ
authored andcommitted
LibWeb: Always parse comma separated value lists as StyleValueList
Previously we would either parse these as `StyleValueList<T>` or `T` depending on whether or not there was more than one value, this meant we always had to handle both cases anywhere we used these values.
1 parent 1a5933c commit e937f5d

File tree

5 files changed

+19
-20
lines changed

5 files changed

+19
-20
lines changed

Libraries/LibWeb/Animations/AnimationEffect.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <LibWeb/CSS/StyleComputer.h>
1818
#include <LibWeb/CSS/StyleInvalidation.h>
1919
#include <LibWeb/CSS/StyleValues/KeywordStyleValue.h>
20+
#include <LibWeb/CSS/StyleValues/StyleValueList.h>
2021
#include <LibWeb/DOM/Element.h>
2122
#include <LibWeb/Layout/Node.h>
2223
#include <LibWeb/WebIDL/ExceptionOr.h>
@@ -609,11 +610,16 @@ Optional<double> AnimationEffect::transformed_progress() const
609610
Optional<CSS::EasingFunction> AnimationEffect::parse_easing_string(StringView value)
610611
{
611612
if (auto style_value = parse_css_value(CSS::Parser::ParsingParams(), value, CSS::PropertyID::AnimationTimingFunction)) {
612-
if (style_value->is_unresolved() || style_value->is_value_list() || style_value->is_css_wide_keyword())
613+
if (style_value->is_unresolved() || style_value->is_css_wide_keyword())
613614
return {};
614615

615-
// FIXME: We should absolutize style_value to resolve relative lengths within calcs
616-
return CSS::EasingFunction::from_style_value(style_value.release_nonnull());
616+
auto easing_values = style_value->as_value_list().values();
617+
618+
if (easing_values.size() != 1)
619+
return {};
620+
621+
// FIXME: We should absolutize the style value to resolve relative lengths within calcs
622+
return CSS::EasingFunction::from_style_value(easing_values[0]);
617623
}
618624

619625
return {};

Libraries/LibWeb/CSS/CSSStyleProperties.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ RefPtr<StyleValue const> CSSStyleProperties::style_value_for_computed_property(L
879879
auto const& animation_timeline_computed_value = get_computed_value(PropertyID::AnimationTimeline);
880880
auto const& animation_duration_computed_value = get_computed_value(PropertyID::AnimationDuration);
881881

882-
if (animation_timeline_computed_value.to_keyword() == Keyword::Auto) {
882+
if (animation_timeline_computed_value.as_value_list().size() == 1 && animation_timeline_computed_value.as_value_list().values()[0]->to_keyword() == Keyword::Auto) {
883883

884884
// FIXME: We can remove these two branches once parse_comma_separated_value_list always returns StyleValueList.
885885
if (animation_duration_computed_value.to_keyword() == Keyword::Auto)

Libraries/LibWeb/CSS/Parser/Parser.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,8 @@ class Parser {
448448
RefPtr<ViewFunctionStyleValue const> parse_view_function_value(TokenStream<ComponentValue>&);
449449

450450
using ParseFunction = AK::Function<RefPtr<StyleValue const>(TokenStream<ComponentValue>&)>;
451-
RefPtr<StyleValue const> parse_comma_separated_value_list(TokenStream<ComponentValue>&, ParseFunction);
452-
RefPtr<StyleValue const> parse_simple_comma_separated_value_list(PropertyID, TokenStream<ComponentValue>&);
451+
RefPtr<StyleValueList const> parse_comma_separated_value_list(TokenStream<ComponentValue>&, ParseFunction);
452+
RefPtr<StyleValueList const> parse_simple_comma_separated_value_list(PropertyID, TokenStream<ComponentValue>&);
453453
RefPtr<StyleValue const> parse_coordinating_value_list_shorthand(TokenStream<ComponentValue>&, PropertyID shorthand_id, Vector<PropertyID> const& longhand_ids, Vector<PropertyID> const& reset_only_longhand_ids);
454454
RefPtr<StyleValue const> parse_all_as_single_keyword_value(TokenStream<ComponentValue>&, Keyword);
455455

Libraries/LibWeb/CSS/Parser/PropertyParsing.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ RefPtr<StyleValue const> Parser::parse_all_as_single_keyword_value(TokenStream<C
8888
return keyword_value;
8989
}
9090

91-
RefPtr<StyleValue const> Parser::parse_simple_comma_separated_value_list(PropertyID property_id, TokenStream<ComponentValue>& tokens)
91+
RefPtr<StyleValueList const> Parser::parse_simple_comma_separated_value_list(PropertyID property_id, TokenStream<ComponentValue>& tokens)
9292
{
9393
return parse_comma_separated_value_list(tokens, [this, property_id](auto& tokens) -> RefPtr<StyleValue const> {
9494
if (auto value = parse_css_value_for_property(property_id, tokens))
@@ -149,15 +149,8 @@ RefPtr<StyleValue const> Parser::parse_coordinating_value_list_shorthand(TokenSt
149149
longhand_ids_including_reset_only_longhands.extend(reset_only_longhand_ids);
150150
StyleValueVector longhand_values {};
151151

152-
// FIXME: This is for compatibility with parse_comma_separated_value_list(), which returns a single value directly
153-
// instead of a list if there's only one, it would be nicer if we always returned a list.
154-
if (longhand_vectors.get(longhand_ids[0])->size() == 1) {
155-
for (auto const& longhand_id : longhand_ids)
156-
longhand_values.append((*longhand_vectors.get(longhand_id))[0]);
157-
} else {
158-
for (auto const& longhand_id : longhand_ids)
159-
longhand_values.append(StyleValueList::create(move(*longhand_vectors.get(longhand_id)), StyleValueList::Separator::Comma));
160-
}
152+
for (auto const& longhand_id : longhand_ids)
153+
longhand_values.append(StyleValueList::create(move(*longhand_vectors.get(longhand_id)), StyleValueList::Separator::Comma));
161154

162155
for (auto reset_only_longhand_id : reset_only_longhand_ids)
163156
longhand_values.append(property_initial_value(reset_only_longhand_id));
@@ -5079,7 +5072,7 @@ RefPtr<StyleValue const> Parser::parse_transition_property_value(TokenStream<Com
50795072

50805073
// none
50815074
if (auto none = parse_all_as_single_keyword_value(tokens, Keyword::None))
5082-
return none;
5075+
return StyleValueList::create({ none.release_nonnull() }, StyleValueList::Separator::Comma);
50835076

50845077
// <single-transition-property>#
50855078
// <single-transition-property> = all | <custom-ident>

Libraries/LibWeb/CSS/Parser/ValueParsing.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@
8080

8181
namespace Web::CSS::Parser {
8282

83-
RefPtr<StyleValue const> Parser::parse_comma_separated_value_list(TokenStream<ComponentValue>& tokens, ParseFunction parse_one_value)
83+
RefPtr<StyleValueList const> Parser::parse_comma_separated_value_list(TokenStream<ComponentValue>& tokens, ParseFunction parse_one_value)
8484
{
8585
tokens.discard_whitespace();
8686
auto first = parse_one_value(tokens);
8787
tokens.discard_whitespace();
88-
if (!first || !tokens.has_next_token())
89-
return first;
88+
if (!first)
89+
return nullptr;
9090

9191
StyleValueVector values;
9292
values.append(first.release_nonnull());

0 commit comments

Comments
 (0)