Bug 1340958 - Add a function to convert AnimationValueMap to PropertyDeclarationBlock. r?heycam
We need to convert all AnimationValue (AnimationValueMap) on an element
to PropertyDeclarationBlock in order to push the value inside the CSS cascade.
Two reasons we did not add the function in AnimationValueMap:
1) All members of PropertyDeclarationBlock are private.
2) Rust does not allow us impl for type alias, so if we do impl the function
in AnimationValueMap we need to make AnimationValueMap as a tuple or struct.
MozReview-Commit-ID: 3bWsjMIRc7l
--- a/servo/components/style/properties/declaration_block.rs
+++ b/servo/components/style/properties/declaration_block.rs
@@ -10,16 +10,17 @@ use cssparser::{DeclarationListParser, p
use cssparser::{Parser, AtRuleParser, DeclarationParser, Delimiter};
use error_reporting::ParseErrorReporter;
use parser::{ParserContext, ParserContextExtraData, log_css_error};
use servo_url::ServoUrl;
use std::fmt;
use style_traits::ToCss;
use stylesheets::Origin;
use super::*;
+#[cfg(feature = "gecko")] use properties::animated_properties::AnimationValueMap;
/// A declaration [importance][importance].
///
/// [importance]: https://drafts.csswg.org/css-cascade/#importance
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum Importance {
/// Indicates a declaration without `!important`.
@@ -336,16 +337,34 @@ impl PropertyDeclarationBlock {
Some(AppendableValue::DeclarationsForShorthand(_, decls)) => {
shorthand.longhands_to_css(decls, dest)
}
_ => Ok(())
}
}
}
}
+
+ /// Convert AnimationValueMap to PropertyDeclarationBlock.
+ #[cfg(feature = "gecko")]
+ pub fn from_animation_value_map(animation_value_map: &AnimationValueMap) -> Self {
+ let mut declarations = vec![];
+ let mut longhands = LonghandIdSet::new();
+
+ for (property, animation_value) in animation_value_map.iter() {
+ longhands.set_transition_property_bit(property);
+ declarations.push((animation_value.uncompute(), Importance::Normal));
+ }
+
+ PropertyDeclarationBlock {
+ declarations: declarations,
+ important_count: 0,
+ longhands: longhands,
+ }
+ }
}
impl ToCss for PropertyDeclarationBlock {
// https://drafts.csswg.org/cssom/#serialize-a-css-declaration-block
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
where W: fmt::Write,
{
let mut is_first_serialization = true; // trailing serializations should have a prepended space