style: Implement CSS parsing for the @font-palette-values rule

Not yet hooked up to any rendering functionality.

The intention is for both the @font-palette-values at-rule and the font-palette property
to be behind the same pref being introduced here.

Differential Revision: https://phabricator.services.mozilla.com/D157953
This commit is contained in:
Jonathan Kew 2022-10-07 23:00:43 +00:00 committed by Martin Robinson
parent ab4580e112
commit a4ad5e19b0
12 changed files with 353 additions and 30 deletions

View file

@ -492,6 +492,44 @@ impl ToCss for CustomIdent {
}
}
/// <https://www.w3.org/TR/css-values-4/#dashed-idents>
/// This is simply an Atom, but will only parse if the identifier starts with "--".
#[repr(transparent)]
#[derive(
Clone,
Debug,
Eq,
Hash,
MallocSizeOf,
PartialEq,
SpecifiedValueInfo,
ToComputedValue,
ToResolvedValue,
ToShmem,
)]
pub struct DashedIdent(pub Atom);
impl Parse for DashedIdent {
fn parse<'i, 't>(_: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
let location = input.current_source_location();
let ident = input.expect_ident()?;
if ident.starts_with("--") {
Ok(Self(Atom::from(ident.as_ref())))
} else {
Err(location.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(ident.clone())))
}
}
}
impl ToCss for DashedIdent {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: Write,
{
serialize_atom_identifier(&self.0, dest)
}
}
/// The <timeline-name> or <keyframes-name>.
/// The definition of these two names are the same, so we use the same type for them.
///