mirror of
https://github.com/servo/servo.git
synced 2025-08-18 03:45:33 +01:00
Keep custom-ident and string separate in animation/keyframes name.
This commit is contained in:
parent
82c04113d0
commit
1146921866
13 changed files with 123 additions and 67 deletions
|
@ -62,7 +62,7 @@ use std::ptr;
|
|||
use std::sync::Arc;
|
||||
use std::cmp;
|
||||
use values::computed::ToComputedValue;
|
||||
use values::{Either, Auto, CustomIdent};
|
||||
use values::{Either, Auto, KeyframesName};
|
||||
use computed_values::border_style;
|
||||
|
||||
pub mod style_structs {
|
||||
|
@ -2202,16 +2202,22 @@ fn static_assert() {
|
|||
self.gecko.mAnimationNameCount = v.0.len() as u32;
|
||||
for (servo, gecko) in v.0.into_iter().zip(self.gecko.mAnimations.iter_mut()) {
|
||||
// TODO This is inefficient. We should fix this in bug 1329169.
|
||||
gecko.mName.assign(servo.0 .0.as_slice());
|
||||
gecko.mName.assign(match servo.0 {
|
||||
Some(ref name) => name.as_atom().as_slice(),
|
||||
None => &[], // Empty string for 'none'
|
||||
});
|
||||
}
|
||||
}
|
||||
pub fn animation_name_at(&self, index: usize)
|
||||
-> longhands::animation_name::computed_value::SingleComputedValue {
|
||||
use Atom;
|
||||
use properties::longhands::animation_name::single_value::SpecifiedValue as AnimationName;
|
||||
// XXX: Is there any effective ways?
|
||||
AnimationName(CustomIdent(Atom::from(
|
||||
String::from_utf16_lossy(&self.gecko.mAnimations[index].mName[..]))))
|
||||
let atom = &self.gecko.mAnimations[index].mName;
|
||||
if atom.is_empty() {
|
||||
AnimationName(None)
|
||||
} else {
|
||||
AnimationName(Some(KeyframesName::from_ident(atom.to_string())))
|
||||
}
|
||||
}
|
||||
pub fn copy_animation_name_from(&mut self, other: &Self) {
|
||||
unsafe { self.gecko.mAnimations.ensure_len(other.gecko.mAnimations.len()) };
|
||||
|
|
|
@ -796,7 +796,7 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
|
|||
use std::ops::Deref;
|
||||
use style_traits::ToCss;
|
||||
use values::computed::ComputedValueAsSpecified;
|
||||
use values::{HasViewportPercentage, CustomIdent};
|
||||
use values::{HasViewportPercentage, KeyframesName};
|
||||
|
||||
pub mod computed_value {
|
||||
pub use super::SpecifiedValue as T;
|
||||
|
@ -804,7 +804,14 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
|
|||
|
||||
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct SpecifiedValue(pub CustomIdent);
|
||||
pub struct SpecifiedValue(pub Option<KeyframesName>);
|
||||
|
||||
impl SpecifiedValue {
|
||||
/// As an Atom
|
||||
pub fn as_atom(&self) -> Option< &Atom> {
|
||||
self.0.as_ref().map(|n| n.as_atom())
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
|
@ -813,44 +820,32 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
|
|||
|
||||
#[inline]
|
||||
pub fn get_initial_specified_value() -> SpecifiedValue {
|
||||
SpecifiedValue(CustomIdent(atom!("")))
|
||||
SpecifiedValue(None)
|
||||
}
|
||||
|
||||
impl fmt::Display for SpecifiedValue {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.0 .0.fmt(f)
|
||||
self.to_css(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for SpecifiedValue {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
if self.0 .0 == atom!("") {
|
||||
dest.write_str("none")
|
||||
if let Some(ref name) = self.0 {
|
||||
name.to_css(dest)
|
||||
} else {
|
||||
self.0.to_css(dest)
|
||||
dest.write_str("none")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for SpecifiedValue {
|
||||
fn parse(_context: &ParserContext, input: &mut ::cssparser::Parser) -> Result<Self, ()> {
|
||||
use cssparser::Token;
|
||||
use std::ascii::AsciiExt;
|
||||
use values::CustomIdent;
|
||||
|
||||
let atom = match input.next() {
|
||||
Ok(Token::Ident(value)) => {
|
||||
if value.eq_ignore_ascii_case("none") {
|
||||
// FIXME We may want to support `@keyframes ""` at some point.
|
||||
CustomIdent(atom!(""))
|
||||
} else {
|
||||
CustomIdent::from_ident(value, &[])?
|
||||
}
|
||||
}
|
||||
Ok(Token::QuotedString(value)) => CustomIdent(Atom::from(value)),
|
||||
_ => return Err(()),
|
||||
};
|
||||
Ok(SpecifiedValue(atom))
|
||||
fn parse(context: &ParserContext, input: &mut ::cssparser::Parser) -> Result<Self, ()> {
|
||||
if let Ok(name) = input.try(|input| KeyframesName::parse(context, input)) {
|
||||
Ok(SpecifiedValue(Some(name)))
|
||||
} else {
|
||||
input.expect_ident_matching("none").map(|()| SpecifiedValue(None))
|
||||
}
|
||||
}
|
||||
}
|
||||
no_viewport_percentage!(SpecifiedValue);
|
||||
|
|
|
@ -1617,7 +1617,7 @@ pub mod style_structs {
|
|||
/// Returns whether there is any animation specified with
|
||||
/// animation-name other than `none`.
|
||||
pub fn specifies_animations(&self) -> bool {
|
||||
self.animation_name_iter().any(|name| name.0 .0 != atom!(""))
|
||||
self.animation_name_iter().any(|name| name.0.is_some())
|
||||
}
|
||||
|
||||
/// Returns whether there are any transitions specified.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue