diff --git a/components/style/data.rs b/components/style/data.rs index 197f2818714..a62d1359e1a 100644 --- a/components/style/data.rs +++ b/components/style/data.rs @@ -8,11 +8,11 @@ use arrayvec::ArrayVec; use context::SharedStyleContext; use dom::TElement; use invalidation::element::restyle_hints::RestyleHint; -use properties::{AnimationRules, ComputedValues, PropertyDeclarationBlock}; +use properties::ComputedValues; use properties::longhands::display::computed_value as display; use rule_tree::StrongRuleNode; use selector_parser::{EAGER_PSEUDO_COUNT, PseudoElement, RestyleDamage}; -use shared_lock::{Locked, StylesheetGuards}; +use shared_lock::StylesheetGuards; use std::ops::{Deref, DerefMut}; use stylearc::Arc; @@ -402,29 +402,4 @@ impl ElementData { pub fn clear_restyle_state(&mut self) { self.restyle.clear(); } - - /// Returns SMIL overriden value if exists. - pub fn get_smil_override(&self) -> Option<&Arc>> { - if cfg!(feature = "servo") { - // Servo has no knowledge of a SMIL rule, so just avoid looking for it. - return None; - } - - match self.styles.get_primary() { - Some(v) => v.rules().get_smil_animation_rule(), - None => None, - } - } - - /// Returns AnimationRules that has processed during animation-only restyles. - pub fn get_animation_rules(&self) -> AnimationRules { - if cfg!(feature = "servo") { - return AnimationRules(None, None) - } - - match self.styles.get_primary() { - Some(v) => v.rules().get_animation_rules(), - None => AnimationRules(None, None), - } - } } diff --git a/components/style/dom.rs b/components/style/dom.rs index ac5d051e865..ffb874430f6 100644 --- a/components/style/dom.rs +++ b/components/style/dom.rs @@ -15,7 +15,7 @@ use data::ElementData; use element_state::ElementState; use font_metrics::FontMetricsProvider; use media_queries::Device; -use properties::{ComputedValues, PropertyDeclarationBlock}; +use properties::{AnimationRules, ComputedValues, PropertyDeclarationBlock}; #[cfg(feature = "gecko")] use properties::animated_properties::AnimationValue; #[cfg(feature = "gecko")] use properties::animated_properties::TransitionProperty; use rule_tree::CascadeLevel; @@ -379,6 +379,18 @@ pub trait TElement : Eq + PartialEq + Debug + Hash + Sized + Copy + Clone + None } + /// Get the combined animation and transition rules. + fn get_animation_rules(&self) -> AnimationRules { + if !self.may_have_animations() { + return AnimationRules(None, None) + } + + AnimationRules( + self.get_animation_rule(), + self.get_transition_rule(), + ) + } + /// Get this element's animation rule. fn get_animation_rule(&self) -> Option>> { diff --git a/components/style/matching.rs b/components/style/matching.rs index bb510840bea..0cd55918457 100644 --- a/components/style/matching.rs +++ b/components/style/matching.rs @@ -237,7 +237,7 @@ impl CascadeVisitedMode { /// Returns whether there might be visited values that should be inserted /// within the regular computed values based on the cascade mode. - fn visited_values_for_insertion(&self) -> bool { + pub fn visited_values_for_insertion(&self) -> bool { *self == CascadeVisitedMode::Unvisited } @@ -258,7 +258,7 @@ impl CascadeVisitedMode { /// Returns whether the cascade should filter to only visited dependent /// properties based on the cascade mode. - fn visited_dependent_only(&self) -> bool { + pub fn visited_dependent_only(&self) -> bool { *self == CascadeVisitedMode::Visited } } @@ -446,7 +446,7 @@ trait PrivateMatchMethods: TElement { debug_assert!(pseudo.is_before_or_after()); let parent = self.parent_element().unwrap(); if !parent.may_have_animations() || - primary_inputs.rules().get_animation_rules().is_empty() { + self.get_animation_rules().is_empty() { let parent_data = parent.borrow_data().unwrap(); let pseudo_style = parent_data.styles.pseudos.get(&pseudo).unwrap(); @@ -994,12 +994,12 @@ impl MatchingResults { pub trait MatchMethods : TElement { /// Performs selector matching and property cascading on an element and its /// eager pseudos. - fn match_and_cascade(&self, - context: &mut StyleContext, - data: &mut ElementData, - sharing: StyleSharingBehavior) - -> ChildCascadeRequirement - { + fn match_and_cascade( + &self, + context: &mut StyleContext, + data: &mut ElementData, + sharing: StyleSharingBehavior + ) -> ChildCascadeRequirement { debug!("Match and cascade for {:?}", self); // Perform selector matching for the primary style. @@ -1021,16 +1021,24 @@ pub trait MatchMethods : TElement { // if our parent has visited styles. let parent_and_styles = self.get_inherited_style_and_parent(); if relevant_link_found || parent_and_styles.has_visited_style() { - self.cascade_primary(context, data, important_rules_changed, - &parent_and_styles, - CascadeVisitedMode::Visited); + self.cascade_primary( + context, + data, + important_rules_changed, + &parent_and_styles, + CascadeVisitedMode::Visited + ); } // Cascade properties and compute primary values. let child_cascade_requirement = - self.cascade_primary(context, data, important_rules_changed, - &parent_and_styles, - CascadeVisitedMode::Unvisited); + self.cascade_primary( + context, + data, + important_rules_changed, + &parent_and_styles, + CascadeVisitedMode::Unvisited + ); // Match and cascade eager pseudo-elements. if !data.styles.is_display_none() { @@ -1109,12 +1117,12 @@ pub trait MatchMethods : TElement { /// /// Returns `MatchingResults` with the new rules and other associated data /// from the matching process. - fn match_primary(&self, - context: &mut StyleContext, - data: &mut ElementData, - visited_handling: VisitedHandlingMode) - -> MatchingResults - { + fn match_primary( + &self, + context: &mut StyleContext, + data: &mut ElementData, + visited_handling: VisitedHandlingMode + ) -> MatchingResults { debug!("Match primary for {:?}, visited: {:?}", self, visited_handling); let mut primary_inputs = context.thread_local.current_element_info @@ -1145,7 +1153,7 @@ pub trait MatchMethods : TElement { parent_data.styles.pseudos.get(&pseudo).unwrap(); let mut rules = pseudo_style.rules().clone(); if parent.may_have_animations() { - let animation_rules = data.get_animation_rules(); + let animation_rules = self.get_animation_rules(); // Handle animations here. if let Some(animation_rule) = animation_rules.0 { @@ -1208,12 +1216,8 @@ pub trait MatchMethods : TElement { context.shared.quirks_mode); { - let smil_override = data.get_smil_override(); - let animation_rules = if self.may_have_animations() { - data.get_animation_rules() - } else { - AnimationRules(None, None) - }; + let smil_override = self.get_smil_override(); + let animation_rules = self.get_animation_rules(); // Compute the primary rule node. stylist.push_applicable_declarations(self, diff --git a/components/style/properties/declaration_block.rs b/components/style/properties/declaration_block.rs index 5a6eed8c5af..a90627aae41 100644 --- a/components/style/properties/declaration_block.rs +++ b/components/style/properties/declaration_block.rs @@ -28,10 +28,10 @@ use values::computed::Context; /// /// The first one is for Animation cascade level, and the second one is for /// Transition cascade level. -pub struct AnimationRules<'a>(pub Option<&'a Arc>>, - pub Option<&'a Arc>>); +pub struct AnimationRules(pub Option>>, + pub Option>>); -impl<'a> AnimationRules<'a> { +impl AnimationRules { /// Returns whether these animation rules represents an actual rule or not. pub fn is_empty(&self) -> bool { self.0.is_none() && self.1.is_none() diff --git a/components/style/rule_tree/mod.rs b/components/style/rule_tree/mod.rs index 4ef94cd12a2..25cf08efb2b 100644 --- a/components/style/rule_tree/mod.rs +++ b/components/style/rule_tree/mod.rs @@ -9,7 +9,7 @@ use applicable_declarations::ApplicableDeclarationList; #[cfg(feature = "servo")] use heapsize::HeapSizeOf; -use properties::{AnimationRules, Importance, LonghandIdSet, PropertyDeclarationBlock}; +use properties::{Importance, LonghandIdSet, PropertyDeclarationBlock}; use shared_lock::{Locked, StylesheetGuards, SharedRwLockReadGuard}; use smallvec::SmallVec; use std::io::{self, Write}; @@ -1321,32 +1321,6 @@ impl StrongRuleNode { .find(|node| node.cascade_level() == CascadeLevel::SMILOverride) .map(|node| node.get_animation_style()) } - - /// Returns AnimationRules that has processed during animation-only restyles. - pub fn get_animation_rules(&self) -> AnimationRules { - if cfg!(feature = "servo") { - return AnimationRules(None, None); - } - - let mut animation = None; - let mut transition = None; - - for node in self.self_and_ancestors() - .take_while(|node| node.cascade_level() >= CascadeLevel::Animations) { - match node.cascade_level() { - CascadeLevel::Animations => { - debug_assert!(animation.is_none()); - animation = Some(node.get_animation_style()) - }, - CascadeLevel::Transitions => { - debug_assert!(transition.is_none()); - transition = Some(node.get_animation_style()) - }, - _ => {}, - } - } - AnimationRules(animation, transition) - } } /// An iterator over a rule node and its ancestors.