Truly independent web browser
LibWeb: Don’t take an easing keyword in “transition” as a property
sideshowbarker02d184909857
diff --git a/Libraries/LibWeb/Rust/src/css/parser/value_parser.rs b/Libraries/LibWeb/Rust/src/css/parser/value_parser.rsindex 0895029f39e..eb85d687b44 100644--- a/Libraries/LibWeb/Rust/src/css/parser/value_parser.rs+++ b/Libraries/LibWeb/Rust/src/css/parser/value_parser.rs@@ -5880,6 +5880,22 @@ fn parse_animation_transition_shorthand(),_ => return ParseOutcome::NotHandled,};+ // https://drafts.csswg.org/css-values-4/#custom-idents+ // When parsing positionally-ambiguous keywords in a property value, a <custom-ident> production can only claim the+ // keyword if no other unfulfilled production can claim it.+ // NB: So the longhand whose value is a <custom-ident> is tried last: "transition: ease" sets the timing function,+ // rather than naming a property "ease".+ let custom_ident_longhand = if property == property_id::ANIMATION {+ property_id::ANIMATION_NAME+ } else {+ property_id::TRANSITION_PROPERTY+ };+ let parse_order = parsed_longhands+ .iter()+ .copied()+ .filter(|&longhand| longhand != custom_ident_longhand)+ .chain([custom_ident_longhand])+ .collect::<Vec<_>>();let layers = values.split(ComponentValue::is_comma).collect::<Vec<_>>();let mut coordinated = vec![Vec::with_capacity(layers.len()); parsed_longhands.len()];for layer in &layers {@@ -5887,12 +5903,16 @@ fn parse_animation_transition_shorthand(if components.is_empty() {return ParseOutcome::Invalid;}- let mut parsed = vec![None; parsed_longhands.len()];- if !assign_shorthand_components(context, &components, parsed_longhands, 0, &mut parsed) {+ let mut parsed = vec![None; parse_order.len()];+ if !assign_shorthand_components(context, &components, &parse_order, 0, &mut parsed) {return ParseOutcome::Invalid;}for (index, &longhand) in parsed_longhands.iter().enumerate() {- let Some(value) = parsed[index]+ let parsed_index = parse_order+ .iter()+ .position(|&parsed_longhand| parsed_longhand == longhand)+ .expect("every longhand is in the parse order");+ let Some(value) = parsed[parsed_index].take().or_else(|| coordinating_initial_item(context, longhand))else {diff --git a/Tests/LibWeb/Text/expected/css/native-shorthand-serialization.txt b/Tests/LibWeb/Text/expected/css/native-shorthand-serialization.txtindex 5bbe6b6d4f5..e08e32b6815 100644--- a/Tests/LibWeb/Text/expected/css/native-shorthand-serialization.txt+++ b/Tests/LibWeb/Text/expected/css/native-shorthand-serialization.txt@@ -3,7 +3,7 @@ animation: 2s ease 1s 3 alternate both paused 雪 => 2s 1s 3 alternate both pausanimation: 1s linear linear, 2s ease-in 雨 => 1s linear linear, 2s ease-in 雨transition: all => alltransition: opacity 1s ease 2s, color 3s linear => opacity 1s 2s, color 3s linear-transition: ease 1s => ease 1s+transition: ease 1s => 1sscroll-timeline: --雪 => --雪scroll-timeline: --雪 inline, --雨 block => --雪 inline, --雨view-timeline: --雪 => --雪diff --git a/Tests/LibWeb/Text/expected/css/transition-shorthand-easing-keyword-is-not-a-property-name.txt b/Tests/LibWeb/Text/expected/css/transition-shorthand-easing-keyword-is-not-a-property-name.txtnew file mode 100644index 00000000000..3758e888eac--- /dev/null+++ b/Tests/LibWeb/Text/expected/css/transition-shorthand-easing-keyword-is-not-a-property-name.txt@@ -0,0 +1,22 @@+transition: 0.15s ease -> property all; timing ease; duration 0.15s+transition: ease -> property all; timing ease; duration 0s+transition: linear -> property all; timing linear; duration 0s+transition: ease-in -> property all; timing ease-in; duration 0s+transition: ease-out -> property all; timing ease-out; duration 0s+transition: ease-in-out -> property all; timing ease-in-out; duration 0s+transition: step-start -> property all; timing steps(1, start); duration 0s+transition: step-end -> property all; timing steps(1); duration 0s+transition: steps(2) 1s -> property all; timing steps(2); duration 1s+transition: cubic-bezier(0.1, 0.2, 0.3, 0.4) 1s -> property all; timing cubic-bezier(0.1, 0.2, 0.3, 0.4); duration 1s+transition: linear(0, 1) 1s -> property all; timing linear(0 0%, 1 100%); duration 1s+transition: none -> property none; timing ease; duration 0s+transition: all ease 1s -> property all; timing ease; duration 1s+transition: ease ease -> property ease; timing ease; duration 0s+transition: opacity 1s ease, ease 2s -> property opacity, all; timing ease, ease; duration 1s, 2s+transition: 1s ease allow-discrete -> property all; timing ease; duration 1s+transition: ease 1s 2s -> property all; timing ease; duration 1s+animation: ease -> name none; timing ease+animation: 1s ease-in ease-out -> name ease-out; timing ease-in+animation: 1s linear -> name none; timing linear+animation: 1s steps(2) step-end -> name step-end; timing steps(2)+transitions running after a change: 1diff --git a/Tests/LibWeb/Text/input/css/transition-shorthand-easing-keyword-is-not-a-property-name.html b/Tests/LibWeb/Text/input/css/transition-shorthand-easing-keyword-is-not-a-property-name.htmlnew file mode 100644index 00000000000..220a9d6b4c7--- /dev/null+++ b/Tests/LibWeb/Text/input/css/transition-shorthand-easing-keyword-is-not-a-property-name.html@@ -0,0 +1,34 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<div id="target"></div>+<div id="animated" style="width: 10px; transition: 0.15s ease"></div>+<script>+ // A keyword the easing function can take goes to the easing function, not to transition-property or+ // animation-name, whose <custom-ident> claims a keyword only where nothing else can.+ asyncTest(async done => {+ const target = document.getElementById("target");+ const transitions = [+ "0.15s ease", "ease", "linear", "ease-in", "ease-out", "ease-in-out", "step-start", "step-end",+ "steps(2) 1s", "cubic-bezier(0.1, 0.2, 0.3, 0.4) 1s", "linear(0, 1) 1s", "none", "all ease 1s",+ "ease ease", "opacity 1s ease, ease 2s", "1s ease allow-discrete", "ease 1s 2s",+ ];+ for (const value of transitions) {+ target.style.transition = value;+ const style = getComputedStyle(target);+ println(`transition: ${value} -> property ${style.transitionProperty}; timing ${style.transitionTimingFunction}; duration ${style.transitionDuration}`);+ }+ target.style.transition = "";+ const animations = ["ease", "1s ease-in ease-out", "1s linear", "1s steps(2) step-end"];+ for (const value of animations) {+ target.style.animation = value;+ const style = getComputedStyle(target);+ println(`animation: ${value} -> name ${style.animationName}; timing ${style.animationTimingFunction}`);+ }++ const animated = document.getElementById("animated");+ getComputedStyle(animated).width;+ animated.style.width = "100px";+ println(`transitions running after a change: ${animated.getAnimations().length}`);+ done();+ });+</script>