Skip to content

Commit

Permalink
Bug 1317209 - Part 4: Put animation rule to cascade. r=emilio
Browse files Browse the repository at this point in the history
We try to get the servo animation rule and declarations during elements
matching, and put the rule to the right priority.
Note: According to CSS Cascade Level spec, Animations is between
      Important author declarations and Normal override declarations.
  • Loading branch information
BorisChiou committed Jan 24, 2017
1 parent c09b204 commit 3a89e89
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
4 changes: 4 additions & 0 deletions components/style/matching.rs
Expand Up @@ -589,12 +589,14 @@ pub trait MatchMethods : TElement {
let mut applicable_declarations: Vec<ApplicableDeclarationBlock> = Vec::with_capacity(16);
let stylist = &context.shared.stylist;
let style_attribute = self.style_attribute();
let animation_rule = self.get_animation_rule(None);

// Compute the primary rule node.
let mut primary_relations =
stylist.push_applicable_declarations(self,
parent_bf,
style_attribute,
animation_rule,
None,
&mut applicable_declarations,
MatchingReason::ForStyling);
Expand All @@ -604,7 +606,9 @@ pub trait MatchMethods : TElement {
let mut per_pseudo: PseudoRuleNodes = HashMap::with_hasher(Default::default());
SelectorImpl::each_eagerly_cascaded_pseudo_element(|pseudo| {
debug_assert!(applicable_declarations.is_empty());
let pseudo_animation_rule = self.get_animation_rule(Some(&pseudo));
stylist.push_applicable_declarations(self, parent_bf, None,
pseudo_animation_rule,
Some(&pseudo.clone()),
&mut applicable_declarations,
MatchingReason::ForStyling);
Expand Down
20 changes: 16 additions & 4 deletions components/style/stylist.rs
Expand Up @@ -21,6 +21,7 @@ use rule_tree::{RuleTree, StrongRuleNode, StyleSource};
use selector_parser::{ElementExt, SelectorImpl, PseudoElement, Snapshot};
use selectors::Element;
use selectors::bloom::BloomFilter;
use selectors::matching::AFFECTED_BY_ANIMATIONS;
use selectors::matching::{AFFECTED_BY_STYLE_ATTRIBUTE, AFFECTED_BY_PRESENTATIONAL_HINTS};
use selectors::matching::{MatchingReason, StyleRelations, matches_complex_selector};
use selectors::parser::{Selector, SimpleSelector, LocalName as LocalNameSelector, ComplexSelector};
Expand Down Expand Up @@ -384,6 +385,7 @@ impl Stylist {
let mut declarations = vec![];

self.push_applicable_declarations(element,
None,
None,
None,
Some(pseudo),
Expand Down Expand Up @@ -490,6 +492,7 @@ impl Stylist {
element: &E,
parent_bf: Option<&BloomFilter>,
style_attribute: Option<&Arc<RwLock<PropertyDeclarationBlock>>>,
animation_rule: Option<Arc<RwLock<PropertyDeclarationBlock>>>,
pseudo_element: Option<&PseudoElement>,
applicable_declarations: &mut V,
reason: MatchingReason) -> StyleRelations
Expand Down Expand Up @@ -560,7 +563,16 @@ impl Stylist {

debug!("style attr: {:?}", relations);

// Step 5: Author-supplied `!important` rules.
// Step 5: Animations.
if let Some(anim) = animation_rule {
relations |= AFFECTED_BY_ANIMATIONS;
Push::push(
applicable_declarations,
ApplicableDeclarationBlock::from_declarations(anim.clone(), Importance::Normal));
}
debug!("animation: {:?}", relations);

// Step 6: Author-supplied `!important` rules.
map.author.get_all_matching_rules(element,
parent_bf,
applicable_declarations,
Expand All @@ -570,7 +582,7 @@ impl Stylist {

debug!("author important: {:?}", relations);

// Step 6: `!important` style attributes.
// Step 7: `!important` style attributes.
if let Some(sa) = style_attribute {
if sa.read().any_important() {
relations |= AFFECTED_BY_STYLE_ATTRIBUTE;
Expand All @@ -582,7 +594,7 @@ impl Stylist {

debug!("style attr important: {:?}", relations);

// Step 7: User `!important` rules.
// Step 8: User `!important` rules.
map.user.get_all_matching_rules(element,
parent_bf,
applicable_declarations,
Expand All @@ -595,7 +607,7 @@ impl Stylist {
debug!("skipping non-agent rules");
}

// Step 8: UA `!important` rules.
// Step 9: UA `!important` rules.
map.user_agent.get_all_matching_rules(element,
parent_bf,
applicable_declarations,
Expand Down

0 comments on commit 3a89e89

Please sign in to comment.