Bug 1346663 - Add a function that returns new rules by removing transition and animation level rules. r?emilio
This will be used for additive animations and SMIL.
MozReview-Commit-ID: JR1u8z9pLB8
--- a/servo/components/style/rule_tree/mod.rs
+++ b/servo/components/style/rule_tree/mod.rs
@@ -245,16 +245,40 @@ impl RuleTree {
pub fn remove_transition_rule(&self, path: &StrongRuleNode) -> StrongRuleNode {
// Return a clone if there is no transition level.
if path.cascade_level() != CascadeLevel::Transitions {
return path.clone();
}
path.parent().unwrap().clone()
}
+
+ /// Returns new rule node without Animations and Transitions level rules.
+ /// Note: this funciton supposes that rule nodes have been already ordered.
+ pub fn remove_animation_rules(&self, path: &StrongRuleNode) -> StrongRuleNode {
+ // Return a clone if there is neither animation nor transition level.
+ if !path.self_and_ancestors().take_while(|node| node.cascade_level() >= CascadeLevel::Animations)
+ .any(|node| node.cascade_level() == CascadeLevel::Animations ||
+ node.cascade_level() == CascadeLevel::Transitions ) {
+ 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
/// doing a GC when calling maybe_gc(). (The value is copied from Gecko,
/// where it likely did not result from a rigorous performance analysis.)
const RULE_TREE_GC_INTERVAL: usize = 300;
/// The cascade level these rules are relevant at, as per[1].