Skip to content

Commit

Permalink
Add a function to convert AnimationValueMap to PropertyDeclarationBlock.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Hiroyuki Ikezoe committed Mar 17, 2017
1 parent 52bee9a commit c0baac4
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions components/style/properties/declaration_block.rs
Expand Up @@ -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].
///
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit c0baac4

Please sign in to comment.