From f96c75c8d0aea0b6b04e87369cbfb5853b4ef89a Mon Sep 17 00:00:00 2001 From: Boris Chiou Date: Thu, 4 May 2023 21:35:14 +0000 Subject: [PATCH] style: Update the syntax of scroll() to accept and in any order The order of and doesn't matter in the parser. However, we serialize first, if it is not the initial value. Differential Revision: https://phabricator.services.mozilla.com/D173906 --- .../style/values/specified/animation.rs | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/components/style/values/specified/animation.rs b/components/style/values/specified/animation.rs index 767f5c54814..d832cd5aa63 100644 --- a/components/style/values/specified/animation.rs +++ b/components/style/values/specified/animation.rs @@ -283,12 +283,12 @@ impl Default for ScrollAxis { #[css(function = "scroll")] #[repr(C)] pub struct ScrollFunction { - /// The axis of scrolling that drives the progress of the timeline. - #[css(skip_if = "ScrollAxis::is_default")] - pub axis: ScrollAxis, /// The scroll container element whose scroll position drives the progress of the timeline. #[css(skip_if = "Scroller::is_default")] pub scroller: Scroller, + /// The axis of scrolling that drives the progress of the timeline. + #[css(skip_if = "ScrollAxis::is_default")] + pub axis: ScrollAxis, } impl ScrollFunction { @@ -296,11 +296,25 @@ impl ScrollFunction { fn parse_arguments<'i, 't>(input: &mut Parser<'i, 't>) -> Result> { // = scroll( [ || ]? ) // https://drafts.csswg.org/scroll-animations-1/#funcdef-scroll - // - // FIXME: This doesn't match the spec. I will update it in Bug 1814444. + let mut scroller = None; + let mut axis = None; + loop { + if scroller.is_none() { + scroller = input.try_parse(Scroller::parse).ok(); + } + + if axis.is_none() { + axis = input.try_parse(ScrollAxis::parse).ok(); + if axis.is_some() { + continue; + } + } + break; + } + Ok(Self { - axis: input.try_parse(ScrollAxis::parse).unwrap_or_default(), - scroller: input.try_parse(Scroller::parse).unwrap_or_default(), + scroller: scroller.unwrap_or_default(), + axis: axis.unwrap_or_default(), }) } }