Implement ToCss serialization for CSSRules

This commit is contained in:
Nazım Can Altınova 2016-11-15 23:25:03 +03:00
parent 22aebdf5d4
commit fdbadcdce2
10 changed files with 198 additions and 28 deletions

View file

@ -9,7 +9,9 @@ use parser::{ParserContext, log_css_error};
use properties::{Importance, PropertyDeclaration, PropertyDeclarationBlock};
use properties::PropertyDeclarationParseResult;
use properties::animated_properties::TransitionProperty;
use std::fmt;
use std::sync::Arc;
use style_traits::ToCss;
/// A number from 1 to 100, indicating the percentage of the animation where
/// this keyframe should run.
@ -82,6 +84,21 @@ pub struct Keyframe {
pub block: Arc<RwLock<PropertyDeclarationBlock>>,
}
impl ToCss for Keyframe {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
let mut iter = self.selector.percentages().iter();
try!(write!(dest, "{}%", iter.next().unwrap().0));
for percentage in iter {
try!(write!(dest, ", "));
try!(write!(dest, "{}%", percentage.0));
}
try!(dest.write_str(" { "));
try!(self.block.read().to_css(dest));
try!(dest.write_str(" }"));
Ok(())
}
}
/// A keyframes step value. This can be a synthetised keyframes animation, that
/// is, one autogenerated from the current computed values, or a list of
/// declarations to apply.