Skip to content

Commit

Permalink
Combine AnimationAndTransitionDeclarations and AnimationRules
Browse files Browse the repository at this point in the history
These two structs are very similar, so we can combine them.
  • Loading branch information
mrobinson committed Jun 16, 2020
1 parent a84b060 commit 36701e0
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 51 deletions.
24 changes: 4 additions & 20 deletions components/style/animation.rs
Expand Up @@ -14,6 +14,7 @@ use crate::properties::animated_properties::{AnimationValue, AnimationValueMap};
use crate::properties::longhands::animation_direction::computed_value::single_value::T as AnimationDirection;
use crate::properties::longhands::animation_fill_mode::computed_value::single_value::T as AnimationFillMode;
use crate::properties::longhands::animation_play_state::computed_value::single_value::T as AnimationPlayState;
use crate::properties::AnimationDeclarations;
use crate::properties::{
ComputedValues, Importance, LonghandId, LonghandIdSet, PropertyDeclarationBlock,
PropertyDeclarationId,
Expand Down Expand Up @@ -1235,13 +1236,13 @@ impl DocumentAnimationSet {
}

/// Get all the animation declarations for the given key, returning an empty
/// `AnimationAndTransitionDeclarations` if there are no animations.
/// `AnimationDeclarations` if there are no animations.
pub(crate) fn get_all_declarations(
&self,
key: &AnimationSetKey,
time: f64,
shared_lock: &SharedRwLock,
) -> AnimationAndTransitionDeclarations {
) -> AnimationDeclarations {
let sets = self.sets.read();
let set = match sets.get(key) {
Some(set) => set,
Expand All @@ -1256,7 +1257,7 @@ impl DocumentAnimationSet {
let block = PropertyDeclarationBlock::from_animation_value_map(&map);
Arc::new(shared_lock.wrap(block))
});
AnimationAndTransitionDeclarations {
AnimationDeclarations {
animations,
transitions,
}
Expand All @@ -1270,23 +1271,6 @@ impl DocumentAnimationSet {
}
}

/// A set of property declarations for a node, including animations and
/// transitions.
#[derive(Default)]
pub struct AnimationAndTransitionDeclarations {
/// Declarations for animations.
pub animations: Option<Arc<Locked<PropertyDeclarationBlock>>>,
/// Declarations for transitions.
pub transitions: Option<Arc<Locked<PropertyDeclarationBlock>>>,
}

impl AnimationAndTransitionDeclarations {
/// Whether or not this `AnimationAndTransitionDeclarations` is empty.
pub(crate) fn is_empty(&self) -> bool {
self.animations.is_none() && self.transitions.is_none()
}
}

/// Kick off any new transitions for this node and return all of the properties that are
/// transitioning. This is at the end of calculating style for a single node.
pub fn start_transitions_if_applicable(
Expand Down
11 changes: 7 additions & 4 deletions components/style/dom.rs
Expand Up @@ -15,7 +15,7 @@ use crate::data::ElementData;
use crate::element_state::ElementState;
use crate::font_metrics::FontMetricsProvider;
use crate::media_queries::Device;
use crate::properties::{AnimationRules, ComputedValues, PropertyDeclarationBlock};
use crate::properties::{AnimationDeclarations, ComputedValues, PropertyDeclarationBlock};
use crate::selector_parser::{AttrValue, Lang, PseudoElement, SelectorImpl};
use crate::shared_lock::{Locked, SharedRwLock};
use crate::stylist::CascadeData;
Expand Down Expand Up @@ -479,12 +479,15 @@ pub trait TElement:
/// Get the combined animation and transition rules.
///
/// FIXME(emilio): Is this really useful?
fn animation_rules(&self, context: &SharedStyleContext) -> AnimationRules {
fn animation_declarations(&self, context: &SharedStyleContext) -> AnimationDeclarations {
if !self.may_have_animations() {
return AnimationRules(None, None);
return Default::default();
}

AnimationRules(self.animation_rule(context), self.transition_rule(context))
AnimationDeclarations {
animations: self.animation_rule(context),
transitions: self.transition_rule(context),
}
}

/// Get this element's animation rule.
Expand Down
27 changes: 14 additions & 13 deletions components/style/properties/declaration_block.rs
Expand Up @@ -28,22 +28,23 @@ use std::iter::{DoubleEndedIterator, Zip};
use std::slice::Iter;
use style_traits::{CssWriter, ParseError, ParsingMode, StyleParseErrorKind, ToCss};

/// The animation rules.
///
/// The first one is for Animation cascade level, and the second one is for
/// Transition cascade level.
pub struct AnimationRules(
pub Option<Arc<Locked<PropertyDeclarationBlock>>>,
pub Option<Arc<Locked<PropertyDeclarationBlock>>>,
);

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()
/// A set of property declarations including animations and transitions.
#[derive(Default)]
pub struct AnimationDeclarations {
/// Declarations for animations.
pub animations: Option<Arc<Locked<PropertyDeclarationBlock>>>,
/// Declarations for transitions.
pub transitions: Option<Arc<Locked<PropertyDeclarationBlock>>>,
}

impl AnimationDeclarations {
/// Whether or not this `AnimationDeclarations` is empty.
pub(crate) fn is_empty(&self) -> bool {
self.animations.is_none() && self.transitions.is_none()
}
}


/// An enum describes how a declaration should update
/// the declaration block.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
Expand Down
12 changes: 6 additions & 6 deletions components/style/rule_collector.rs
Expand Up @@ -6,7 +6,7 @@

use crate::applicable_declarations::{ApplicableDeclarationBlock, ApplicableDeclarationList};
use crate::dom::{TElement, TNode, TShadowRoot};
use crate::properties::{AnimationRules, PropertyDeclarationBlock};
use crate::properties::{AnimationDeclarations, PropertyDeclarationBlock};
use crate::rule_tree::{CascadeLevel, ShadowCascadeOrder};
use crate::selector_map::SelectorMap;
use crate::selector_parser::PseudoElement;
Expand Down Expand Up @@ -70,7 +70,7 @@ where
pseudo_element: Option<&'a PseudoElement>,
style_attribute: Option<ArcBorrow<'a, Locked<PropertyDeclarationBlock>>>,
smil_override: Option<ArcBorrow<'a, Locked<PropertyDeclarationBlock>>>,
animation_rules: AnimationRules,
animation_declarations: AnimationDeclarations,
rule_inclusion: RuleInclusion,
rules: &'a mut ApplicableDeclarationList,
context: &'a mut MatchingContext<'b, E::Impl>,
Expand All @@ -92,7 +92,7 @@ where
pseudo_element: Option<&'a PseudoElement>,
style_attribute: Option<ArcBorrow<'a, Locked<PropertyDeclarationBlock>>>,
smil_override: Option<ArcBorrow<'a, Locked<PropertyDeclarationBlock>>>,
animation_rules: AnimationRules,
animation_declarations: AnimationDeclarations,
rule_inclusion: RuleInclusion,
rules: &'a mut ApplicableDeclarationList,
context: &'a mut MatchingContext<'b, E::Impl>,
Expand Down Expand Up @@ -123,7 +123,7 @@ where
pseudo_element,
style_attribute,
smil_override,
animation_rules,
animation_declarations,
rule_inclusion,
context,
flags_setter,
Expand Down Expand Up @@ -450,7 +450,7 @@ where
// The animations sheet (CSS animations, script-generated
// animations, and CSS transitions that are no longer tied to CSS
// markup).
if let Some(anim) = self.animation_rules.0.take() {
if let Some(anim) = self.animation_declarations.animations.take() {
self.rules
.push(ApplicableDeclarationBlock::from_declarations(
anim,
Expand All @@ -460,7 +460,7 @@ where

// The transitions sheet (CSS transitions that are tied to CSS
// markup).
if let Some(anim) = self.animation_rules.1.take() {
if let Some(anim) = self.animation_declarations.transitions.take() {
self.rules
.push(ApplicableDeclarationBlock::from_declarations(
anim,
Expand Down
6 changes: 3 additions & 3 deletions components/style/style_resolver.rs
Expand Up @@ -10,7 +10,7 @@ use crate::data::{EagerPseudoStyles, ElementStyles};
use crate::dom::TElement;
use crate::matching::MatchMethods;
use crate::properties::longhands::display::computed_value::T as Display;
use crate::properties::{AnimationRules, ComputedValues};
use crate::properties::ComputedValues;
use crate::rule_tree::StrongRuleNode;
use crate::selector_parser::{PseudoElement, SelectorImpl};
use crate::stylist::RuleInclusion;
Expand Down Expand Up @@ -473,7 +473,7 @@ where
implemented_pseudo.as_ref(),
self.element.style_attribute(),
self.element.smil_override(),
self.element.animation_rules(self.context.shared),
self.element.animation_declarations(self.context.shared),
self.rule_inclusion,
&mut applicable_declarations,
&mut matching_context,
Expand Down Expand Up @@ -552,7 +552,7 @@ where
Some(pseudo_element),
None,
None,
AnimationRules(None, None),
/* animation_declarations = */ Default::default(),
self.rule_inclusion,
&mut applicable_declarations,
&mut matching_context,
Expand Down
10 changes: 5 additions & 5 deletions components/style/stylist.rs
Expand Up @@ -15,7 +15,7 @@ use crate::invalidation::element::invalidation_map::InvalidationMap;
use crate::invalidation::media_queries::{EffectiveMediaQueryResults, ToMediaListKey};
use crate::media_queries::Device;
use crate::properties::{self, CascadeMode, ComputedValues};
use crate::properties::{AnimationRules, PropertyDeclarationBlock};
use crate::properties::{AnimationDeclarations, PropertyDeclarationBlock};
use crate::rule_cache::{RuleCache, RuleCacheConditions};
use crate::rule_collector::{containing_shadow_ignoring_svg_use, RuleCollector};
use crate::rule_tree::{CascadeLevel, RuleTree, StrongRuleNode, StyleSource};
Expand Down Expand Up @@ -974,7 +974,7 @@ impl Stylist {
Some(&pseudo),
None,
None,
AnimationRules(None, None),
/* animation_declarations = */ Default::default(),
rule_inclusion,
&mut declarations,
&mut matching_context,
Expand Down Expand Up @@ -1004,7 +1004,7 @@ impl Stylist {
Some(&pseudo),
None,
None,
AnimationRules(None, None),
/* animation_declarations = */ Default::default(),
rule_inclusion,
&mut declarations,
&mut matching_context,
Expand Down Expand Up @@ -1127,7 +1127,7 @@ impl Stylist {
pseudo_element: Option<&PseudoElement>,
style_attribute: Option<ArcBorrow<Locked<PropertyDeclarationBlock>>>,
smil_override: Option<ArcBorrow<Locked<PropertyDeclarationBlock>>>,
animation_rules: AnimationRules,
animation_declarations: AnimationDeclarations,
rule_inclusion: RuleInclusion,
applicable_declarations: &mut ApplicableDeclarationList,
context: &mut MatchingContext<E::Impl>,
Expand All @@ -1142,7 +1142,7 @@ impl Stylist {
pseudo_element,
style_attribute,
smil_override,
animation_rules,
animation_declarations,
rule_inclusion,
applicable_declarations,
context,
Expand Down

0 comments on commit 36701e0

Please sign in to comment.