Add SMIL override cascade level

This commit is contained in:
Brian Birtles 2017-04-27 12:35:12 +09:00
parent 18c72ac28d
commit 97ce9ed5b0
4 changed files with 49 additions and 14 deletions

View file

@ -254,19 +254,19 @@ impl RuleTree {
path.parent().unwrap().clone()
}
/// Returns new rule node without Animations and Transitions level rules.
/// Returns new rule node without rules from declarative animations.
pub fn remove_animation_and_transition_rules(&self, path: &StrongRuleNode) -> StrongRuleNode {
// Return a clone if there is neither animation nor transition level.
// Return a clone if there are no animation rules.
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 iter = path.self_and_ancestors().take_while(
|node| node.cascade_level() >= CascadeLevel::SMILOverride);
let mut last = path;
let mut children = vec![];
for node in iter {
if node.cascade_level() != CascadeLevel::Animations &&
node.cascade_level() != CascadeLevel::Transitions {
if node.cascade_level().is_animation() {
children.push((node.get().source.clone().unwrap(), node.cascade_level()));
}
last = node;
@ -301,6 +301,8 @@ pub enum CascadeLevel {
AuthorNormal,
/// Style attribute normal rules.
StyleAttributeNormal,
/// SVG SMIL animations.
SMILOverride,
/// CSS animations and script-generated animations.
Animations,
/// Author-supplied important rules.
@ -333,6 +335,7 @@ impl CascadeLevel {
match *self {
CascadeLevel::Transitions |
CascadeLevel::Animations |
CascadeLevel::SMILOverride |
CascadeLevel::StyleAttributeNormal |
CascadeLevel::StyleAttributeImportant => true,
_ => false,
@ -362,6 +365,17 @@ impl CascadeLevel {
Importance::Normal
}
}
/// Returns whether this cascade level represents an animation rules.
#[inline]
pub fn is_animation(&self) -> bool {
match *self {
CascadeLevel::SMILOverride |
CascadeLevel::Animations |
CascadeLevel::Transitions => true,
_ => false,
}
}
}
struct RuleNode {
@ -780,8 +794,8 @@ impl StrongRuleNode {
/// 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))
.take_while(|node| node.cascade_level() >= CascadeLevel::SMILOverride)
.any(|node| node.cascade_level().is_animation())
}
}