mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-07 21:59:54 +00:00
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.
This commit is contained in:
parent
1a5933cb04
commit
e937f5db57
Notes:
github-actions[bot]
2025-12-01 10:19:04 +00:00
Author: https://github.com/Calme1709
Commit: e937f5db57
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6972
Reviewed-by: https://github.com/AtkinsSJ ✅
5 changed files with 19 additions and 20 deletions
|
|
@ -17,6 +17,7 @@
|
|||
#include <LibWeb/CSS/StyleComputer.h>
|
||||
#include <LibWeb/CSS/StyleInvalidation.h>
|
||||
#include <LibWeb/CSS/StyleValues/KeywordStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/StyleValueList.h>
|
||||
#include <LibWeb/DOM/Element.h>
|
||||
#include <LibWeb/Layout/Node.h>
|
||||
#include <LibWeb/WebIDL/ExceptionOr.h>
|
||||
|
|
@ -609,11 +610,16 @@ Optional<double> AnimationEffect::transformed_progress() const
|
|||
Optional<CSS::EasingFunction> AnimationEffect::parse_easing_string(StringView value)
|
||||
{
|
||||
if (auto style_value = parse_css_value(CSS::Parser::ParsingParams(), value, CSS::PropertyID::AnimationTimingFunction)) {
|
||||
if (style_value->is_unresolved() || style_value->is_value_list() || style_value->is_css_wide_keyword())
|
||||
if (style_value->is_unresolved() || style_value->is_css_wide_keyword())
|
||||
return {};
|
||||
|
||||
// FIXME: We should absolutize style_value to resolve relative lengths within calcs
|
||||
return CSS::EasingFunction::from_style_value(style_value.release_nonnull());
|
||||
auto easing_values = style_value->as_value_list().values();
|
||||
|
||||
if (easing_values.size() != 1)
|
||||
return {};
|
||||
|
||||
// FIXME: We should absolutize the style value to resolve relative lengths within calcs
|
||||
return CSS::EasingFunction::from_style_value(easing_values[0]);
|
||||
}
|
||||
|
||||
return {};
|
||||
|
|
|
|||
|
|
@ -879,7 +879,7 @@ RefPtr<StyleValue const> CSSStyleProperties::style_value_for_computed_property(L
|
|||
auto const& animation_timeline_computed_value = get_computed_value(PropertyID::AnimationTimeline);
|
||||
auto const& animation_duration_computed_value = get_computed_value(PropertyID::AnimationDuration);
|
||||
|
||||
if (animation_timeline_computed_value.to_keyword() == Keyword::Auto) {
|
||||
if (animation_timeline_computed_value.as_value_list().size() == 1 && animation_timeline_computed_value.as_value_list().values()[0]->to_keyword() == Keyword::Auto) {
|
||||
|
||||
// FIXME: We can remove these two branches once parse_comma_separated_value_list always returns StyleValueList.
|
||||
if (animation_duration_computed_value.to_keyword() == Keyword::Auto)
|
||||
|
|
|
|||
|
|
@ -448,8 +448,8 @@ private:
|
|||
RefPtr<ViewFunctionStyleValue const> parse_view_function_value(TokenStream<ComponentValue>&);
|
||||
|
||||
using ParseFunction = AK::Function<RefPtr<StyleValue const>(TokenStream<ComponentValue>&)>;
|
||||
RefPtr<StyleValue const> parse_comma_separated_value_list(TokenStream<ComponentValue>&, ParseFunction);
|
||||
RefPtr<StyleValue const> parse_simple_comma_separated_value_list(PropertyID, TokenStream<ComponentValue>&);
|
||||
RefPtr<StyleValueList const> parse_comma_separated_value_list(TokenStream<ComponentValue>&, ParseFunction);
|
||||
RefPtr<StyleValueList const> parse_simple_comma_separated_value_list(PropertyID, TokenStream<ComponentValue>&);
|
||||
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);
|
||||
RefPtr<StyleValue const> parse_all_as_single_keyword_value(TokenStream<ComponentValue>&, Keyword);
|
||||
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ RefPtr<StyleValue const> Parser::parse_all_as_single_keyword_value(TokenStream<C
|
|||
return keyword_value;
|
||||
}
|
||||
|
||||
RefPtr<StyleValue const> Parser::parse_simple_comma_separated_value_list(PropertyID property_id, TokenStream<ComponentValue>& tokens)
|
||||
RefPtr<StyleValueList const> Parser::parse_simple_comma_separated_value_list(PropertyID property_id, TokenStream<ComponentValue>& tokens)
|
||||
{
|
||||
return parse_comma_separated_value_list(tokens, [this, property_id](auto& tokens) -> RefPtr<StyleValue const> {
|
||||
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
|
|||
longhand_ids_including_reset_only_longhands.extend(reset_only_longhand_ids);
|
||||
StyleValueVector longhand_values {};
|
||||
|
||||
// FIXME: This is for compatibility with parse_comma_separated_value_list(), which returns a single value directly
|
||||
// instead of a list if there's only one, it would be nicer if we always returned a list.
|
||||
if (longhand_vectors.get(longhand_ids[0])->size() == 1) {
|
||||
for (auto const& longhand_id : longhand_ids)
|
||||
longhand_values.append((*longhand_vectors.get(longhand_id))[0]);
|
||||
} else {
|
||||
for (auto const& longhand_id : longhand_ids)
|
||||
longhand_values.append(StyleValueList::create(move(*longhand_vectors.get(longhand_id)), StyleValueList::Separator::Comma));
|
||||
}
|
||||
for (auto const& longhand_id : longhand_ids)
|
||||
longhand_values.append(StyleValueList::create(move(*longhand_vectors.get(longhand_id)), StyleValueList::Separator::Comma));
|
||||
|
||||
for (auto reset_only_longhand_id : reset_only_longhand_ids)
|
||||
longhand_values.append(property_initial_value(reset_only_longhand_id));
|
||||
|
|
@ -5079,7 +5072,7 @@ RefPtr<StyleValue const> Parser::parse_transition_property_value(TokenStream<Com
|
|||
|
||||
// none
|
||||
if (auto none = parse_all_as_single_keyword_value(tokens, Keyword::None))
|
||||
return none;
|
||||
return StyleValueList::create({ none.release_nonnull() }, StyleValueList::Separator::Comma);
|
||||
|
||||
// <single-transition-property>#
|
||||
// <single-transition-property> = all | <custom-ident>
|
||||
|
|
|
|||
|
|
@ -80,13 +80,13 @@
|
|||
|
||||
namespace Web::CSS::Parser {
|
||||
|
||||
RefPtr<StyleValue const> Parser::parse_comma_separated_value_list(TokenStream<ComponentValue>& tokens, ParseFunction parse_one_value)
|
||||
RefPtr<StyleValueList const> Parser::parse_comma_separated_value_list(TokenStream<ComponentValue>& tokens, ParseFunction parse_one_value)
|
||||
{
|
||||
tokens.discard_whitespace();
|
||||
auto first = parse_one_value(tokens);
|
||||
tokens.discard_whitespace();
|
||||
if (!first || !tokens.has_next_token())
|
||||
return first;
|
||||
if (!first)
|
||||
return nullptr;
|
||||
|
||||
StyleValueVector values;
|
||||
values.append(first.release_nonnull());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue