diff --git a/components/style/dom.rs b/components/style/dom.rs index 44d1b0c3147..188cbb10d32 100644 --- a/components/style/dom.rs +++ b/components/style/dom.rs @@ -506,6 +506,11 @@ pub trait TElement : Eq + PartialEq + Debug + Hash + Sized + Copy + Clone + /// Returns true if the element has all the specified selector flags. fn has_selector_flags(&self, flags: ElementSelectorFlags) -> bool; + /// In Gecko, element has a flag that represents the element may have + /// any type of animations or not to bail out animation stuff early. + /// Whereas Servo doesn't have such flag. + fn may_have_animations(&self) -> bool { false } + /// Creates a task to update various animation state on a given (pseudo-)element. #[cfg(feature = "gecko")] fn update_animations(&self, diff --git a/components/style/gecko/wrapper.rs b/components/style/gecko/wrapper.rs index 38f2af26249..919f17bb0d5 100644 --- a/components/style/gecko/wrapper.rs +++ b/components/style/gecko/wrapper.rs @@ -422,11 +422,6 @@ impl<'le> GeckoElement<'le> { } } - #[inline] - fn may_have_animations(&self) -> bool { - self.as_node().get_bool_flag(nsINode_BooleanFlag::ElementHasAnimations) - } - #[inline] fn has_id(&self) -> bool { self.as_node().get_bool_flag(nsINode_BooleanFlag::ElementHasID) @@ -777,6 +772,11 @@ impl<'le> TElement for GeckoElement<'le> { (self.flags() & node_flags) == node_flags } + #[inline] + fn may_have_animations(&self) -> bool { + self.as_node().get_bool_flag(nsINode_BooleanFlag::ElementHasAnimations) + } + fn update_animations(&self, before_change_style: Option>, tasks: UpdateAnimationsTasks) { diff --git a/components/style/matching.rs b/components/style/matching.rs index 5dd820f1666..e11141e8d63 100644 --- a/components/style/matching.rs +++ b/components/style/matching.rs @@ -254,12 +254,15 @@ trait PrivateMatchMethods: TElement { // We could make that a bit better if the complexity cost is not too // big, but given further restyles are posted directly to // pseudo-elements, it doesn't seem worth the effort at a glance. - if pseudo.is_eager() && primary_style.rules.get_animation_rules().is_empty() { + if pseudo.is_eager() { let parent = self.parent_element().unwrap(); - let parent_data = parent.borrow_data().unwrap(); - let pseudo_style = - parent_data.styles().pseudos.get(&pseudo).unwrap(); - return pseudo_style.values().clone() + if !parent.may_have_animations() || + primary_style.rules.get_animation_rules().is_empty() { + let parent_data = parent.borrow_data().unwrap(); + let pseudo_style = + parent_data.styles().pseudos.get(&pseudo).unwrap(); + return pseudo_style.values().clone() + } } } @@ -692,7 +695,7 @@ pub trait MatchMethods : TElement { let pseudo_style = parent_data.styles().pseudos.get(&pseudo).unwrap(); let mut rules = pseudo_style.rules.clone(); - { + if parent.may_have_animations() { let animation_rules = data.get_animation_rules(); // Handle animations here. @@ -739,7 +742,11 @@ pub trait MatchMethods : TElement { let style_attribute = self.style_attribute(); { let smil_override = data.get_smil_override(); - let animation_rules = data.get_animation_rules(); + let animation_rules = if self.may_have_animations() { + data.get_animation_rules() + } else { + AnimationRules(None, None) + }; let bloom = context.thread_local.bloom_filter.filter(); let map = &mut context.thread_local.selector_flags;