style: Make scroll-timeline-{name|axis} be a coordinating list property group

Named scroll progress timelines are declared in the coordinated value list
constructed from the longhands of the scroll-timeline shorthand property,
which form a coordinating list property group with scroll-timeline-name as
the coordinating list base property.

In the meantime, we also update its shorthand to match the current spec.

Differential Revision: https://phabricator.services.mozilla.com/D166596
This commit is contained in:
Boris Chiou 2023-01-26 23:20:55 +00:00 committed by Martin Robinson
parent 47a54ced2b
commit b024f5b2e7
4 changed files with 52 additions and 50 deletions

View file

@ -327,63 +327,48 @@ macro_rules! try_parse_one {
context: &ParserContext,
input: &mut Parser<'i, '_>,
) -> Result<Longhands, ParseError<'i>> {
use crate::parser::Parse;
use crate::values::specified::box_::{ScrollAxis, ScrollTimelineName};
use crate::properties::longhands::{scroll_timeline_axis, scroll_timeline_name};
let mut name = None;
let mut axis = None;
// FIXME: Bug 1809005: 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
// production can claim it. So we try to parse `scroll-timeline-axis` first.
//
// https://drafts.csswg.org/css-values-4/#custom-idents
let mut names = Vec::with_capacity(1);
let mut axes = Vec::with_capacity(1);
input.parse_comma_separated(|input| {
let name = scroll_timeline_name::single_value::parse(context, input)?;
let axis = input.try_parse(|i| scroll_timeline_axis::single_value::parse(context, i));
if axis.is_none() {
axis = input.try_parse(ScrollAxis::parse).ok();
}
names.push(name);
axes.push(axis.unwrap_or_default());
if name.is_none() {
if let Ok(value) = input.try_parse(|i| ScrollTimelineName::parse(context, i)) {
name = Some(value);
continue;
}
}
break;
}
// Must occur one or more.
if name.is_none() && axis.is_none() {
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
}
Ok(())
})?;
Ok(expanded! {
scroll_timeline_name: name.unwrap_or(ScrollTimelineName::none()),
scroll_timeline_axis: axis.unwrap_or_default(),
scroll_timeline_name: scroll_timeline_name::SpecifiedValue(names.into()),
scroll_timeline_axis: scroll_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 {
use crate::values::specified::box_::ScrollAxis;
let is_default_axis = self.scroll_timeline_axis == &ScrollAxis::default();
let is_default_name = self.scroll_timeline_name.0.is_none();
// Note: if both are default values, we serialize the default axis (because it is the
// first value per spec).
if !is_default_axis || (is_default_axis && is_default_name) {
self.scroll_timeline_axis.to_css(dest)?;
// If any value list length is differs then we don't do a shorthand serialization
// either.
let len = self.scroll_timeline_name.0.len();
if len != self.scroll_timeline_axis.0.len() {
return Ok(());
}
if !is_default_name {
if !is_default_axis {
dest.write_char(' ')?;
for i in 0..len {
if i != 0 {
dest.write_str(", ")?;
}
self.scroll_timeline_name.to_css(dest)?;
}
self.scroll_timeline_name.0[i].to_css(dest)?;
if self.scroll_timeline_axis.0[i] != Default::default() {
dest.write_char(' ')?;
self.scroll_timeline_axis.0[i].to_css(dest)?;
}
}
Ok(())
}
}
@ -423,14 +408,9 @@ macro_rules! try_parse_one {
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.
let len = self.view_timeline_name.0.len();
if len != self.view_timeline_axis.0.len() {
return Ok(());
}