Bug 1340958 - Add a function to convert AnimationValueMap to PropertyDeclarationBlock. r?heycam draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Fri, 17 Mar 2017 06:42:30 +0900
changeset 500321 f883e23af4893c882015d9c5007194806c9385aa
parent 500320 91c344d940e2226e0bb89945c8e66f2025de09a4
child 500322 f8e561536c0e50fc245c0036adf5500e4daefbd8
push id49684
push userhikezoe@mozilla.com
push dateFri, 17 Mar 2017 02:12:39 +0000
reviewersheycam
bugs1340958
milestone55.0a1
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
servo/components/style/properties/declaration_block.rs
--- 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