mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Combine AnimationAndTransitionDeclarations and AnimationRules
These two structs are very similar, so we can combine them.
This commit is contained in:
parent
a84b06065b
commit
36701e0223
6 changed files with 38 additions and 50 deletions
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -1256,7 +1257,7 @@ impl DocumentAnimationSet {
|
|||
let block = PropertyDeclarationBlock::from_animation_value_map(&map);
|
||||
Arc::new(shared_lock.wrap(block))
|
||||
});
|
||||
AnimationAndTransitionDeclarations {
|
||||
AnimationDeclarations {
|
||||
animations,
|
||||
transitions,
|
||||
}
|
||||
|
@ -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(
|
||||
|
|
|
@ -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;
|
||||
|
@ -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.
|
||||
|
|
|
@ -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>>>,
|
||||
);
|
||||
/// 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 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()
|
||||
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)]
|
||||
|
|
|
@ -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;
|
||||
|
@ -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>,
|
||||
|
@ -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>,
|
||||
|
@ -123,7 +123,7 @@ where
|
|||
pseudo_element,
|
||||
style_attribute,
|
||||
smil_override,
|
||||
animation_rules,
|
||||
animation_declarations,
|
||||
rule_inclusion,
|
||||
context,
|
||||
flags_setter,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
|
|
@ -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};
|
||||
|
@ -974,7 +974,7 @@ impl Stylist {
|
|||
Some(&pseudo),
|
||||
None,
|
||||
None,
|
||||
AnimationRules(None, None),
|
||||
/* animation_declarations = */ Default::default(),
|
||||
rule_inclusion,
|
||||
&mut declarations,
|
||||
&mut matching_context,
|
||||
|
@ -1004,7 +1004,7 @@ impl Stylist {
|
|||
Some(&pseudo),
|
||||
None,
|
||||
None,
|
||||
AnimationRules(None, None),
|
||||
/* animation_declarations = */ Default::default(),
|
||||
rule_inclusion,
|
||||
&mut declarations,
|
||||
&mut matching_context,
|
||||
|
@ -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>,
|
||||
|
@ -1142,7 +1142,7 @@ impl Stylist {
|
|||
pseudo_element,
|
||||
style_attribute,
|
||||
smil_override,
|
||||
animation_rules,
|
||||
animation_declarations,
|
||||
rule_inclusion,
|
||||
applicable_declarations,
|
||||
context,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue