From aa6433b6d6fd1f0d0fef72bcf2ec9901a02dedb2 Mon Sep 17 00:00:00 2001 From: Hiroyuki Ikezoe Date: Fri, 24 Mar 2017 09:54:49 +0900 Subject: [PATCH] Add a function that returns new rules by removing transition and animation level rules. This will be used for additive animations and SMIL. --- components/style/rule_tree/mod.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/components/style/rule_tree/mod.rs b/components/style/rule_tree/mod.rs index f9c92fa3c25..53a78ac2cad 100644 --- a/components/style/rule_tree/mod.rs +++ b/components/style/rule_tree/mod.rs @@ -249,6 +249,27 @@ impl RuleTree { path.parent().unwrap().clone() } + + /// Returns new rule node without Animations and Transitions level rules. + pub fn remove_animation_and_transition_rules(&self, path: &StrongRuleNode) -> StrongRuleNode { + // Return a clone if there is neither animation nor transition level. + if !path.has_animation_or_transition_rules() { + return path.clone(); + } + + let iter = path.self_and_ancestors().take_while(|node| node.cascade_level() >= CascadeLevel::Animations); + let mut last = path; + let mut children = vec![]; + for node in iter { + if node.cascade_level() != CascadeLevel::Animations && + node.cascade_level() != CascadeLevel::Transitions { + children.push((node.get().source.clone().unwrap(), node.cascade_level())); + } + last = node; + } + + self.insert_ordered_rules_from(last.parent().unwrap().clone(), children.into_iter().rev()) + } } /// The number of RuleNodes added to the free list before we will consider @@ -738,6 +759,13 @@ impl StrongRuleNode { self.gc(); } } + + /// Returns true if there is either animation or transition level rule. + pub fn has_animation_or_transition_rules(&self) -> bool { + self.self_and_ancestors() + .take_while(|node| node.cascade_level() >= CascadeLevel::Animations) + .any(|node| matches!(node.cascade_level(), CascadeLevel::Animations | CascadeLevel::Transitions)) + } } /// An iterator over a rule node and its ancestors.