зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1907210 - Part 2: Simplify KeyframeName. r=firefox-style-system-reviewers,zrhoffman
Now, `TimelineOrKeyframeName` is used only for `KeyframeName`, so we can merge them. Differential Revision: https://phabricator.services.mozilla.com/D216459
This commit is contained in:
Родитель
be88cfaa3d
Коммит
f870ccfc39
|
@ -643,17 +643,16 @@ impl ToCss for DashedIdent {
|
|||
}
|
||||
}
|
||||
|
||||
/// The <timeline-name> or <keyframes-name>.
|
||||
/// The definition of these two names are the same, so we use the same type for them.
|
||||
/// The <keyframes-name>.
|
||||
///
|
||||
/// <https://drafts.csswg.org/css-animations-2/#typedef-timeline-name>
|
||||
/// <https://drafts.csswg.org/css-animations/#typedef-keyframes-name>
|
||||
///
|
||||
/// We use a single atom for these. Empty atom represents `none` animation.
|
||||
/// We use a single atom for this. Empty atom represents `none` animation.
|
||||
#[repr(transparent)]
|
||||
#[derive(
|
||||
Clone,
|
||||
Debug,
|
||||
Eq,
|
||||
Hash,
|
||||
PartialEq,
|
||||
MallocSizeOf,
|
||||
|
@ -662,9 +661,9 @@ impl ToCss for DashedIdent {
|
|||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
pub struct TimelineOrKeyframesName(Atom);
|
||||
pub struct KeyframesName(Atom);
|
||||
|
||||
impl TimelineOrKeyframesName {
|
||||
impl KeyframesName {
|
||||
/// <https://drafts.csswg.org/css-animations/#dom-csskeyframesrule-name>
|
||||
pub fn from_ident(value: &str) -> Self {
|
||||
Self(Atom::from(value))
|
||||
|
@ -680,7 +679,7 @@ impl TimelineOrKeyframesName {
|
|||
self.0 == atom!("")
|
||||
}
|
||||
|
||||
/// Create a new TimelineOrKeyframesName from Atom.
|
||||
/// Create a new KeyframesName from Atom.
|
||||
#[cfg(feature = "gecko")]
|
||||
pub fn from_atom(atom: Atom) -> Self {
|
||||
Self(atom)
|
||||
|
@ -690,67 +689,6 @@ impl TimelineOrKeyframesName {
|
|||
pub fn as_atom(&self) -> &Atom {
|
||||
&self.0
|
||||
}
|
||||
|
||||
fn parse<'i, 't>(input: &mut Parser<'i, 't>, invalid: &[&str]) -> Result<Self, ParseError<'i>> {
|
||||
debug_assert!(invalid.contains(&"none"));
|
||||
let location = input.current_source_location();
|
||||
Ok(match *input.next()? {
|
||||
Token::Ident(ref s) => Self(CustomIdent::from_ident(location, s, invalid)?.0),
|
||||
Token::QuotedString(ref s) => Self(Atom::from(s.as_ref())),
|
||||
ref t => return Err(location.new_unexpected_token_error(t.clone())),
|
||||
})
|
||||
}
|
||||
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>, invalid: &[&str]) -> fmt::Result
|
||||
where
|
||||
W: Write,
|
||||
{
|
||||
debug_assert!(invalid.contains(&"none"));
|
||||
|
||||
if self.0 == atom!("") {
|
||||
return dest.write_str("none");
|
||||
}
|
||||
|
||||
self.0.with_str(|s| {
|
||||
if CustomIdent::is_valid(s, invalid) {
|
||||
serialize_identifier(s, dest)
|
||||
} else {
|
||||
s.to_css(dest)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for TimelineOrKeyframesName {}
|
||||
|
||||
/// The typedef of <keyframes-name>.
|
||||
#[repr(transparent)]
|
||||
#[derive(
|
||||
Clone,
|
||||
Debug,
|
||||
Deref,
|
||||
Hash,
|
||||
Eq,
|
||||
PartialEq,
|
||||
MallocSizeOf,
|
||||
SpecifiedValueInfo,
|
||||
ToComputedValue,
|
||||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
pub struct KeyframesName(TimelineOrKeyframesName);
|
||||
|
||||
impl KeyframesName {
|
||||
/// Create a new KeyframesName from Atom.
|
||||
#[cfg(feature = "gecko")]
|
||||
pub fn from_atom(atom: Atom) -> Self {
|
||||
Self(TimelineOrKeyframesName::from_atom(atom))
|
||||
}
|
||||
|
||||
/// Returns the `none` value.
|
||||
pub fn none() -> Self {
|
||||
Self(TimelineOrKeyframesName::none())
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for KeyframesName {
|
||||
|
@ -758,7 +696,12 @@ impl Parse for KeyframesName {
|
|||
_: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
Ok(Self(TimelineOrKeyframesName::parse(input, &["none"])?))
|
||||
let location = input.current_source_location();
|
||||
Ok(match *input.next()? {
|
||||
Token::Ident(ref s) => Self(CustomIdent::from_ident(location, s, &["none"])?.0),
|
||||
Token::QuotedString(ref s) => Self(Atom::from(s.as_ref())),
|
||||
ref t => return Err(location.new_unexpected_token_error(t.clone())),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -767,6 +710,16 @@ impl ToCss for KeyframesName {
|
|||
where
|
||||
W: Write,
|
||||
{
|
||||
self.0.to_css(dest, &["none"])
|
||||
if self.is_none() {
|
||||
return dest.write_str("none");
|
||||
}
|
||||
|
||||
self.0.with_str(|s| {
|
||||
if CustomIdent::is_valid(s, &["none"]) {
|
||||
serialize_identifier(s, dest)
|
||||
} else {
|
||||
s.to_css(dest)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче