diff --git a/components/style/context.rs b/components/style/context.rs index c0ded1483ce..39643af2f8e 100644 --- a/components/style/context.rs +++ b/components/style/context.rs @@ -5,7 +5,7 @@ //! The context within which style is calculated. #![deny(missing_docs)] -use animation::Animation; +use animation::{Animation, PropertyAnimation}; use app_units::Au; use bloom::StyleBloom; use data::ElementData; @@ -103,13 +103,16 @@ impl<'a> SharedStyleContext<'a> { /// Information about the current element being processed. We group this together /// into a single struct within ThreadLocalStyleContext so that we can instantiate /// and destroy it easily at the beginning and end of element processing. -struct CurrentElementInfo { +pub struct CurrentElementInfo { /// The element being processed. Currently we use an OpaqueNode since we only /// use this for identity checks, but we could use SendElement if there were /// a good reason to. element: OpaqueNode, /// Whether the element is being styled for the first time. is_initial_style: bool, + /// A Vec of possibly expired animations. Used only by Servo. + #[allow(dead_code)] + pub possibly_expired_animations: Vec, } /// Statistics gathered during the traversal. We gather statistics on each thread @@ -276,7 +279,7 @@ pub struct ThreadLocalStyleContext { /// Statistics about the traversal. pub statistics: TraversalStatistics, /// Information related to the current element, non-None during processing. - current_element_info: Option, + pub current_element_info: Option, } impl ThreadLocalStyleContext { @@ -298,6 +301,7 @@ impl ThreadLocalStyleContext { self.current_element_info = Some(CurrentElementInfo { element: element.as_node().opaque(), is_initial_style: !data.has_styles(), + possibly_expired_animations: Vec::new(), }); } diff --git a/components/style/matching.rs b/components/style/matching.rs index 49c521e87fd..dbcb0040216 100644 --- a/components/style/matching.rs +++ b/components/style/matching.rs @@ -534,7 +534,6 @@ trait PrivateMatchMethods: TElement { context: &mut StyleContext, data: &mut ElementData, pseudo: Option<&PseudoElement>, - possibly_expired_animations: &mut Vec, animate: bool) { // Collect some values. let (mut styles, restyle) = data.styles_and_restyle_mut(); @@ -553,8 +552,7 @@ trait PrivateMatchMethods: TElement { self.process_animations(context, &mut old_values, &mut new_values, - pseudo, - possibly_expired_animations); + pseudo); } // Accumulate restyle damage. @@ -602,8 +600,7 @@ trait PrivateMatchMethods: TElement { context: &mut StyleContext, old_values: &mut Option>, new_values: &mut Arc, - pseudo: Option<&PseudoElement>, - _possibly_expired_animations: &mut Vec) { + pseudo: Option<&PseudoElement>) { use context::{CSS_ANIMATIONS, EFFECT_PROPERTIES}; use context::UpdateAnimationsTasks; @@ -646,8 +643,10 @@ trait PrivateMatchMethods: TElement { context: &mut StyleContext, old_values: &mut Option>, new_values: &mut Arc, - _pseudo: Option<&PseudoElement>, - possibly_expired_animations: &mut Vec) { + _pseudo: Option<&PseudoElement>) { + let possibly_expired_animations = + &mut context.thread_local.current_element_info.as_mut().unwrap() + .possibly_expired_animations; let shared_context = context.shared; if let Some(ref mut old) = *old_values { self.update_animations_for_cascade(shared_context, old, @@ -797,14 +796,13 @@ pub trait MatchMethods : TElement { let _rule_node_changed = self.match_primary(context, data, &mut primary_relations); // Cascade properties and compute primary values. - let mut expired = vec![]; - self.cascade_primary(context, data, &mut expired); + self.cascade_primary(context, data); // Match and cascade eager pseudo-elements. if !data.styles().is_display_none() { let _pseudo_rule_nodes_changed = self.match_pseudos(context, data); - self.cascade_pseudos(context, data, &mut expired); + self.cascade_pseudos(context, data); } // If we have any pseudo elements, indicate so in the primary StyleRelations. @@ -827,9 +825,8 @@ pub trait MatchMethods : TElement { context: &mut StyleContext, mut data: &mut ElementData) { - let mut possibly_expired_animations = vec![]; - self.cascade_primary(context, &mut data, &mut possibly_expired_animations); - self.cascade_pseudos(context, &mut data, &mut possibly_expired_animations); + self.cascade_primary(context, &mut data); + self.cascade_pseudos(context, &mut data); } /// Runs selector matching to (re)compute the primary rule node for this element. @@ -1218,18 +1215,15 @@ pub trait MatchMethods : TElement { /// Performs the cascade for the element's primary style. fn cascade_primary(&self, context: &mut StyleContext, - mut data: &mut ElementData, - possibly_expired_animations: &mut Vec) + mut data: &mut ElementData) { - self.cascade_primary_or_pseudo(context, &mut data, None, - possibly_expired_animations, /* animate = */ true); + self.cascade_primary_or_pseudo(context, &mut data, None, /* animate = */ true); } /// Performs the cascade for the element's eager pseudos. fn cascade_pseudos(&self, context: &mut StyleContext, - mut data: &mut ElementData, - possibly_expired_animations: &mut Vec) + mut data: &mut ElementData) { // Note that we've already set up the map of matching pseudo-elements // in match_pseudos (and handled the damage implications of changing @@ -1240,8 +1234,7 @@ pub trait MatchMethods : TElement { for pseudo in matched_pseudos { // Only ::before and ::after are animatable. let animate = pseudo.is_before_or_after(); - self.cascade_primary_or_pseudo(context, data, Some(&pseudo), - possibly_expired_animations, animate); + self.cascade_primary_or_pseudo(context, data, Some(&pseudo), animate); } } diff --git a/components/style/traversal.rs b/components/style/traversal.rs index f221a4c4780..f334c40f225 100644 --- a/components/style/traversal.rs +++ b/components/style/traversal.rs @@ -395,7 +395,9 @@ fn resolve_style_internal(context: &mut StyleContext, } // Compute our style. + context.thread_local.begin_element(element, &data); element.match_and_cascade(context, &mut data, StyleSharingBehavior::Disallow); + context.thread_local.end_element(element); // Conservatively mark us as having dirty descendants, since there might // be other unstyled siblings we miss when walking straight up the parent