mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Make animation-name parse none
This commit is contained in:
parent
4bc0cac395
commit
6273fa0305
6 changed files with 53 additions and 12 deletions
|
@ -398,7 +398,7 @@ impl<E: TElement> StyleSharingCandidateCache<E> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if box_style.animation_name_count() > 0 {
|
if box_style.specifies_animations() {
|
||||||
debug!("Failing to insert to the cache: animations");
|
debug!("Failing to insert to the cache: animations");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1727,15 +1727,14 @@ fn static_assert() {
|
||||||
|
|
||||||
pub fn set_animation_name(&mut self, v: longhands::animation_name::computed_value::T) {
|
pub fn set_animation_name(&mut self, v: longhands::animation_name::computed_value::T) {
|
||||||
use nsstring::nsCString;
|
use nsstring::nsCString;
|
||||||
|
|
||||||
|
debug_assert!(!v.0.is_empty());
|
||||||
unsafe { self.gecko.mAnimations.ensure_len(v.0.len()) };
|
unsafe { self.gecko.mAnimations.ensure_len(v.0.len()) };
|
||||||
|
|
||||||
if v.0.len() > 0 {
|
self.gecko.mAnimationNameCount = v.0.len() as u32;
|
||||||
self.gecko.mAnimationNameCount = v.0.len() as u32;
|
for (servo, gecko) in v.0.into_iter().zip(self.gecko.mAnimations.iter_mut()) {
|
||||||
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_utf8(&nsCString::from(servo.0.to_string()));
|
gecko.mName.assign_utf8(&nsCString::from(servo.0.to_string()));
|
||||||
}
|
|
||||||
} else {
|
|
||||||
unsafe { self.gecko.mAnimations[0].mName.truncate(); }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn animation_name_at(&self, index: usize)
|
pub fn animation_name_at(&self, index: usize)
|
||||||
|
|
|
@ -776,7 +776,6 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
|
||||||
</%helpers:vector_longhand>
|
</%helpers:vector_longhand>
|
||||||
|
|
||||||
<%helpers:vector_longhand name="animation-name"
|
<%helpers:vector_longhand name="animation-name"
|
||||||
allow_empty="True"
|
|
||||||
need_index="True"
|
need_index="True"
|
||||||
animatable="False",
|
animatable="False",
|
||||||
extra_prefixes="moz webkit"
|
extra_prefixes="moz webkit"
|
||||||
|
@ -797,6 +796,16 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
pub struct SpecifiedValue(pub Atom);
|
pub struct SpecifiedValue(pub Atom);
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn get_initial_value() -> computed_value::T {
|
||||||
|
get_initial_specified_value()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn get_initial_specified_value() -> SpecifiedValue {
|
||||||
|
SpecifiedValue(atom!(""))
|
||||||
|
}
|
||||||
|
|
||||||
impl fmt::Display for SpecifiedValue {
|
impl fmt::Display for SpecifiedValue {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
self.0.fmt(f)
|
self.0.fmt(f)
|
||||||
|
@ -805,7 +814,11 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
|
||||||
|
|
||||||
impl ToCss for SpecifiedValue {
|
impl ToCss for SpecifiedValue {
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||||
dest.write_str(&*self.0.to_string())
|
if self.0 == atom!("") {
|
||||||
|
dest.write_str("none")
|
||||||
|
} else {
|
||||||
|
dest.write_str(&*self.0.to_string())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -813,7 +826,12 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
|
||||||
fn parse(_context: &ParserContext, input: &mut ::cssparser::Parser) -> Result<Self, ()> {
|
fn parse(_context: &ParserContext, input: &mut ::cssparser::Parser) -> Result<Self, ()> {
|
||||||
use cssparser::Token;
|
use cssparser::Token;
|
||||||
Ok(match input.next() {
|
Ok(match input.next() {
|
||||||
Ok(Token::Ident(ref value)) if value != "none" => SpecifiedValue(Atom::from(&**value)),
|
Ok(Token::Ident(ref value)) => SpecifiedValue(if value == "none" {
|
||||||
|
// FIXME We may want to support `@keyframes ""` at some point.
|
||||||
|
atom!("")
|
||||||
|
} else {
|
||||||
|
Atom::from(&**value)
|
||||||
|
}),
|
||||||
Ok(Token::QuotedString(value)) => SpecifiedValue(Atom::from(&*value)),
|
Ok(Token::QuotedString(value)) => SpecifiedValue(Atom::from(&*value)),
|
||||||
_ => return Err(()),
|
_ => return Err(()),
|
||||||
})
|
})
|
||||||
|
|
|
@ -1295,6 +1295,14 @@ pub mod style_structs {
|
||||||
}
|
}
|
||||||
% endif
|
% endif
|
||||||
% endfor
|
% endfor
|
||||||
|
|
||||||
|
% if style_struct.name == "Box":
|
||||||
|
/// 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 != atom!(""))
|
||||||
|
}
|
||||||
|
% endif
|
||||||
}
|
}
|
||||||
|
|
||||||
% for longhand in style_struct.longhands:
|
% for longhand in style_struct.longhands:
|
||||||
|
|
|
@ -14,7 +14,7 @@ extern crate parking_lot;
|
||||||
extern crate rayon;
|
extern crate rayon;
|
||||||
extern crate rustc_serialize;
|
extern crate rustc_serialize;
|
||||||
extern crate selectors;
|
extern crate selectors;
|
||||||
extern crate servo_atoms;
|
#[macro_use] extern crate servo_atoms;
|
||||||
extern crate servo_config;
|
extern crate servo_config;
|
||||||
extern crate servo_url;
|
extern crate servo_url;
|
||||||
extern crate style;
|
extern crate style;
|
||||||
|
|
|
@ -5,11 +5,27 @@
|
||||||
use cssparser::Parser;
|
use cssparser::Parser;
|
||||||
use media_queries::CSSErrorReporterTest;
|
use media_queries::CSSErrorReporterTest;
|
||||||
use parsing::parse;
|
use parsing::parse;
|
||||||
|
use servo_atoms::Atom;
|
||||||
use style::parser::{Parse, ParserContext};
|
use style::parser::{Parse, ParserContext};
|
||||||
use style::properties::longhands::animation_iteration_count::single_value::computed_value::T as AnimationIterationCount;
|
use style::properties::longhands::animation_iteration_count::single_value::computed_value::T as AnimationIterationCount;
|
||||||
|
use style::properties::longhands::animation_name;
|
||||||
use style::stylesheets::Origin;
|
use style::stylesheets::Origin;
|
||||||
use style_traits::ToCss;
|
use style_traits::ToCss;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_animation_name() {
|
||||||
|
use self::animation_name::single_value::SpecifiedValue as SingleValue;
|
||||||
|
let other_name = Atom::from("other-name");
|
||||||
|
assert_eq!(parse_longhand!(animation_name, "none"),
|
||||||
|
animation_name::SpecifiedValue(vec![SingleValue(atom!(""))]));
|
||||||
|
assert_eq!(parse_longhand!(animation_name, "other-name, none, 'other-name', \"other-name\""),
|
||||||
|
animation_name::SpecifiedValue(
|
||||||
|
vec![SingleValue(other_name.clone()),
|
||||||
|
SingleValue(atom!("")),
|
||||||
|
SingleValue(other_name.clone()),
|
||||||
|
SingleValue(other_name.clone())]));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_animation_iteration() {
|
fn test_animation_iteration() {
|
||||||
assert_roundtrip_with_context!(AnimationIterationCount::parse, "0", "0");
|
assert_roundtrip_with_context!(AnimationIterationCount::parse, "0", "0");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue