Skip to content

Commit

Permalink
Add a function that returns new rules by removing transition and anim…
Browse files Browse the repository at this point in the history
…ation level rules.

This will be used for additive animations and SMIL.
  • Loading branch information
Hiroyuki Ikezoe committed Mar 24, 2017
1 parent 959f1c8 commit aa6433b
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions components/style/rule_tree/mod.rs
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit aa6433b

Please sign in to comment.