diff --git a/Libraries/LibWeb/CSS/StyleComputer.cpp b/Libraries/LibWeb/CSS/StyleComputer.cpp index 2ce9b9b557c..0a80995522a 100644 --- a/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -3174,9 +3174,25 @@ static CSSPixels snap_a_length_as_a_border_width(double device_pixels_per_css_pi return length; } +static NonnullRefPtr compute_style_value_list(NonnullRefPtr const& style_value, Function(NonnullRefPtr const&)> const& compute_entry) +{ + if (style_value->is_value_list()) { + StyleValueVector computed_entries; + + for (auto const& entry : style_value->as_value_list().values()) + computed_entries.append(compute_entry(entry)); + + return StyleValueList::create(move(computed_entries), StyleValueList::Separator::Comma); + } + + return compute_entry(style_value); +} + NonnullRefPtr StyleComputer::compute_value_of_property(PropertyID property_id, NonnullRefPtr const& specified_value, Function(PropertyID)> const& get_property_specified_value, PropertyValueComputationContext const& computation_context) { switch (property_id) { + case PropertyID::AnimationName: + return compute_animation_name(specified_value, computation_context); case PropertyID::BorderBottomWidth: return compute_border_or_outline_width(specified_value, get_property_specified_value(PropertyID::BorderBottomStyle), computation_context); case PropertyID::BorderLeftWidth: @@ -3208,6 +3224,31 @@ NonnullRefPtr StyleComputer::compute_value_of_property(Propert VERIFY_NOT_REACHED(); } +NonnullRefPtr StyleComputer::compute_animation_name(NonnullRefPtr const& specified_value, PropertyValueComputationContext const&) +{ + // https://drafts.csswg.org/css-animations-1/#animation-name + // list, each item either a case-sensitive css identifier or the keyword none + + return compute_style_value_list(specified_value, [](NonnullRefPtr const& entry) -> NonnullRefPtr { + // none | + if (entry->to_keyword() == Keyword::None || entry->is_custom_ident()) + return entry; + + // + if (entry->is_string()) { + auto const& string_value = entry->as_string().string_value(); + + // AD-HOC: We shouldn't convert strings that aren't valid s + if (is_css_wide_keyword(string_value) || string_value.is_one_of_ignoring_ascii_case("default"sv, "none"sv)) + return entry; + + return CustomIdentStyleValue::create(entry->as_string().string_value()); + } + + VERIFY_NOT_REACHED(); + }); +} + NonnullRefPtr StyleComputer::compute_border_or_outline_width(NonnullRefPtr const& specified_value, NonnullRefPtr const& style_specified_value, PropertyValueComputationContext const& computation_context) { // https://drafts.csswg.org/css-backgrounds/#border-width diff --git a/Libraries/LibWeb/CSS/StyleComputer.h b/Libraries/LibWeb/CSS/StyleComputer.h index 296011294a8..c8c04e1b6e2 100644 --- a/Libraries/LibWeb/CSS/StyleComputer.h +++ b/Libraries/LibWeb/CSS/StyleComputer.h @@ -203,6 +203,7 @@ public: double device_pixels_per_css_pixel; }; static NonnullRefPtr compute_value_of_property(PropertyID, NonnullRefPtr const& specified_value, Function(PropertyID)> const& get_property_specified_value, PropertyValueComputationContext const&); + static NonnullRefPtr compute_animation_name(NonnullRefPtr const& specified_value, PropertyValueComputationContext const&); static NonnullRefPtr compute_border_or_outline_width(NonnullRefPtr const& specified_value, NonnullRefPtr const& style_specified_value, PropertyValueComputationContext const&); static NonnullRefPtr compute_font_size(NonnullRefPtr const& specified_value, int computed_math_depth, CSSPixels inherited_font_size, int inherited_math_depth, Length::ResolutionContext const& parent_length_resolution_context); static NonnullRefPtr compute_font_style(NonnullRefPtr const& specified_value, Length::ResolutionContext const& parent_length_resolution_context); diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-animations/parsing/animation-name-computed.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-animations/parsing/animation-name-computed.txt index ef317f69ffd..36c5c625088 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/css/css-animations/parsing/animation-name-computed.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-animations/parsing/animation-name-computed.txt @@ -2,8 +2,8 @@ Harness status: OK Found 27 tests -24 Pass -3 Fail +25 Pass +2 Fail Pass Property animation-name value 'none' Pass Property animation-name value 'NONE' Pass Property animation-name value 'foo' @@ -12,7 +12,7 @@ Pass Property animation-name value 'ease-in' Pass Property animation-name value 'infinite' Pass Property animation-name value 'paused' Pass Property animation-name value 'first, second, third' -Fail Property animation-name value '"something"' +Pass Property animation-name value '"something"' Fail Property animation-name value '"---\22---"' Fail Property animation-name value '"multi word string"' Pass Property animation-name value '"none"'