Skip to content

Commit

Permalink
style: Support view-timeline shorthand
Browse files Browse the repository at this point in the history
view-timeline shorthand includes view-timeline-name and
view-timeline-axis, but excludes view-timeline-inset.

Note: We will fix the test of "view-timeline-name: auto" in the next patch.

Differential Revision: https://phabricator.services.mozilla.com/D166404
  • Loading branch information
BorisChiou authored and Loirooriol committed Nov 3, 2023
1 parent 71518ab commit 013d77d
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions components/style/properties/shorthands/ui.mako.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ macro_rules! try_parse_one {

let mut name = None;
let mut axis = None;
// FIXME: Bug 1804573: The order of |name| and |axis| should be fixed.
loop {
// Note: When parsing positionally-ambiguous keywords in a property value, a
// <custom-ident> production can only claim the keyword if no other unfulfilled
Expand Down Expand Up @@ -387,3 +388,67 @@ macro_rules! try_parse_one {
}
}
</%helpers:shorthand>

// Note: view-timeline shorthand doesn't take view-timeline-inset into account.
<%helpers:shorthand
engines="gecko"
name="view-timeline"
sub_properties="view-timeline-name view-timeline-axis"
gecko_pref="layout.css.scroll-driven-animations.enabled",
spec="https://drafts.csswg.org/scroll-animations-1/#view-timeline-shorthand"
>
pub fn parse_value<'i>(
context: &ParserContext,
input: &mut Parser<'i, '_>,
) -> Result<Longhands, ParseError<'i>> {
use crate::properties::longhands::{view_timeline_axis, view_timeline_name};

let mut names = Vec::with_capacity(1);
let mut axes = Vec::with_capacity(1);
input.parse_comma_separated(|input| {
let name = view_timeline_name::single_value::parse(context, input)?;
let axis = input.try_parse(|i| view_timeline_axis::single_value::parse(context, i));

names.push(name);
axes.push(axis.unwrap_or_default());

Ok(())
})?;

Ok(expanded! {
view_timeline_name: view_timeline_name::SpecifiedValue(names.into()),
view_timeline_axis: view_timeline_axis::SpecifiedValue(axes.into()),
})
}

impl<'a> ToCss for LonghandsToSerialize<'a> {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
let len = self.view_timeline_name.0.len();
// There should be at least one declared value
if len == 0 {
return Ok(());
}

// If any value list length is differs then we don't do a shorthand serialization
// either.
if len != self.view_timeline_axis.0.len() {
return Ok(());
}

for i in 0..len {
if i != 0 {
dest.write_str(", ")?;
}

self.view_timeline_name.0[i].to_css(dest)?;

if self.view_timeline_axis.0[i] != Default::default() {
dest.write_char(' ')?;
self.view_timeline_axis.0[i].to_css(dest)?;
}

}
Ok(())
}
}
</%helpers:shorthand>

0 comments on commit 013d77d

Please sign in to comment.