From c0baac4194cf4a73332710c2d651dd46ea718a45 Mon Sep 17 00:00:00 2001 From: Hiroyuki Ikezoe Date: Fri, 17 Mar 2017 12:30:00 +0900 Subject: [PATCH] Add a function to convert AnimationValueMap to PropertyDeclarationBlock. 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. --- .../style/properties/declaration_block.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/components/style/properties/declaration_block.rs b/components/style/properties/declaration_block.rs index 721396e8b3a5..9d76adf1383c 100644 --- a/components/style/properties/declaration_block.rs +++ b/components/style/properties/declaration_block.rs @@ -15,6 +15,7 @@ use std::fmt; use style_traits::ToCss; use stylesheets::Origin; use super::*; +#[cfg(feature = "gecko")] use properties::animated_properties::AnimationValueMap; /// A declaration [importance][importance]. /// @@ -341,6 +342,24 @@ impl PropertyDeclarationBlock { } } } + + /// 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 {