From 33b593d32e8bcd4f5575ba46499aa420efe843c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sat, 5 May 2018 17:19:06 +0200 Subject: [PATCH] style: Fix servo build. --- components/layout/animation.rs | 6 ++-- components/layout/generated_content.rs | 16 ++++----- components/style/animation.rs | 35 +++++++++---------- components/style/matching.rs | 1 + .../style/stylesheets/keyframes_rule.rs | 6 ++-- 5 files changed, 32 insertions(+), 32 deletions(-) diff --git a/components/layout/animation.rs b/components/layout/animation.rs index 3ea59e7b972..05718dda00a 100644 --- a/components/layout/animation.rs +++ b/components/layout/animation.rs @@ -39,14 +39,14 @@ where let mut new_running_animations = vec![]; while let Ok(animation) = new_animations_receiver.try_recv() { let mut should_push = true; - if let Animation::Keyframes(ref node, ref name, ref state) = animation { + if let Animation::Keyframes(ref node, _, ref name, ref state) = animation { // If the animation was already present in the list for the // node, just update its state, else push the new animation to // run. if let Some(ref mut animations) = running_animations.get_mut(node) { // TODO: This being linear is probably not optimal. for anim in animations.iter_mut() { - if let Animation::Keyframes(_, ref anim_name, ref mut anim_state) = *anim { + if let Animation::Keyframes(_, _, ref anim_name, ref mut anim_state) = *anim { if *name == *anim_name { debug!("update_animation_state: Found other animation {}", name); anim_state.update_from_other(&state, timer); @@ -83,7 +83,7 @@ where Animation::Transition(_, started_at, ref frame, _expired) => { now < started_at + frame.duration } - Animation::Keyframes(_, _, ref mut state) => { + Animation::Keyframes(_, _, _, ref mut state) => { // This animation is still running, or we need to keep // iterating. now < state.started_at + state.duration || state.tick() diff --git a/components/layout/generated_content.rs b/components/layout/generated_content.rs index 700e9bc9ddd..da390cc9cec 100644 --- a/components/layout/generated_content.rs +++ b/components/layout/generated_content.rs @@ -272,27 +272,27 @@ impl<'a, 'b> ResolveGeneratedContentFragmentMutator<'a, 'b> { } self.traversal.list_item.truncate_to_level(self.level); - for &(ref counter_name, value) in &*fragment.style().get_counters().counter_reset { - let counter_name = &*counter_name.0; + for pair in &*fragment.style().get_counters().counter_reset { + let counter_name = &*pair.name.0; if let Some(ref mut counter) = self.traversal.counters.get_mut(counter_name) { - counter.reset(self.level, value); + counter.reset(self.level, pair.value); continue } let mut counter = Counter::new(); - counter.reset(self.level, value); + counter.reset(self.level, pair.value); self.traversal.counters.insert(counter_name.to_owned(), counter); } - for &(ref counter_name, value) in &*fragment.style().get_counters().counter_increment { - let counter_name = &*counter_name.0; + for pair in &*fragment.style().get_counters().counter_increment { + let counter_name = &*pair.name.0; if let Some(ref mut counter) = self.traversal.counters.get_mut(counter_name) { - counter.increment(self.level, value); + counter.increment(self.level, pair.value); continue } let mut counter = Counter::new(); - counter.increment(self.level, value); + counter.increment(self.level, pair.value); self.traversal.counters.insert(counter_name.to_owned(), counter); } diff --git a/components/style/animation.rs b/components/style/animation.rs index 9fc93a6cd5b..983078e8d9d 100644 --- a/components/style/animation.rs +++ b/components/style/animation.rs @@ -17,7 +17,7 @@ use properties::longhands::animation_play_state::computed_value::single_value::T use rule_tree::CascadeLevel; use servo_arc::Arc; use std::sync::mpsc::Sender; -use stylesheets::keyframes_rule::{KeyframesStep, KeyframesStepValue}; +use stylesheets::keyframes_rule::{KeyframesAnimation, KeyframesStep, KeyframesStepValue}; use timer::Timer; use values::computed::Time; use values::computed::transform::TimingFunction; @@ -194,7 +194,9 @@ pub enum Animation { Transition(OpaqueNode, f64, AnimationFrame, bool), /// A keyframes animation is identified by a name, and can have a /// node-dependent state (i.e. iteration count, etc.). - Keyframes(OpaqueNode, Atom, KeyframesAnimationState), + /// + /// TODO(emilio): The animation object could be refcounted. + Keyframes(OpaqueNode, KeyframesAnimation, Atom, KeyframesAnimationState), } impl Animation { @@ -204,7 +206,7 @@ impl Animation { debug_assert!(!self.is_expired()); match *self { Animation::Transition(_, _, _, ref mut expired) => *expired = true, - Animation::Keyframes(_, _, ref mut state) => state.expired = true, + Animation::Keyframes(_, _, _, ref mut state) => state.expired = true, } } @@ -213,7 +215,7 @@ impl Animation { pub fn is_expired(&self) -> bool { match *self { Animation::Transition(_, _, _, expired) => expired, - Animation::Keyframes(_, _, ref state) => state.expired, + Animation::Keyframes(_, _, _, ref state) => state.expired, } } @@ -222,7 +224,7 @@ impl Animation { pub fn node(&self) -> &OpaqueNode { match *self { Animation::Transition(ref node, _, _, _) => node, - Animation::Keyframes(ref node, _, _) => node, + Animation::Keyframes(ref node, _, _, _) => node, } } @@ -231,7 +233,7 @@ impl Animation { pub fn is_paused(&self) -> bool { match *self { Animation::Transition(..) => false, - Animation::Keyframes(_, _, ref state) => state.is_paused(), + Animation::Keyframes(_, _, _, ref state) => state.is_paused(), } } @@ -500,12 +502,16 @@ where /// Triggers animations for a given node looking at the animation property /// values. -pub fn maybe_start_animations( +pub fn maybe_start_animations( + element: E, context: &SharedStyleContext, new_animations_sender: &Sender, node: OpaqueNode, new_style: &Arc, -) -> bool { +) -> bool +where + E: TElement, +{ let mut had_animations = false; let box_style = new_style.get_box(); @@ -522,7 +528,7 @@ pub fn maybe_start_animations( continue; } - if let Some(ref anim) = context.stylist.get_animation(name) { + if let Some(anim) = context.stylist.get_animation(name, element) { debug!("maybe_start_animations: animation {} found", name); // If this animation doesn't have any keyframe, we can just continue @@ -561,6 +567,7 @@ pub fn maybe_start_animations( new_animations_sender .send(Animation::Keyframes( node, + anim.clone(), name.clone(), KeyframesAnimationState { started_at: animation_start, @@ -628,7 +635,7 @@ pub fn update_style_for_animation( *style = new_style } }, - Animation::Keyframes(_, ref name, ref state) => { + Animation::Keyframes(_, ref animation, ref name, ref state) => { debug!( "update_style_for_animation: animation found: \"{}\", {:?}", name, state @@ -641,14 +648,6 @@ pub fn update_style_for_animation( KeyframesRunningState::Paused(progress) => started_at + duration * progress, }; - let animation = match context.stylist.get_animation(name) { - None => { - warn!("update_style_for_animation: Animation {:?} not found", name); - return; - }, - Some(animation) => animation, - }; - debug_assert!(!animation.steps.is_empty()); let maybe_index = style diff --git a/components/style/matching.rs b/components/style/matching.rs index 97b31f4f6b0..1d5cbf8d375 100644 --- a/components/style/matching.rs +++ b/components/style/matching.rs @@ -425,6 +425,7 @@ trait PrivateMatchMethods: TElement { let this_opaque = self.as_node().opaque(); // Trigger any present animations if necessary. animation::maybe_start_animations( + *self, &shared_context, new_animations_sender, this_opaque, diff --git a/components/style/stylesheets/keyframes_rule.rs b/components/style/stylesheets/keyframes_rule.rs index c4649dc135f..4de3acbaff5 100644 --- a/components/style/stylesheets/keyframes_rule.rs +++ b/components/style/stylesheets/keyframes_rule.rs @@ -259,7 +259,7 @@ impl DeepCloneWithLock for Keyframe { /// declarations to apply. /// /// TODO: Find a better name for this? -#[derive(Debug, MallocSizeOf)] +#[derive(Clone, Debug, MallocSizeOf)] pub enum KeyframesStepValue { /// A step formed by a declaration block specified by the CSS. Declarations { @@ -275,7 +275,7 @@ pub enum KeyframesStepValue { } /// A single step from a keyframe animation. -#[derive(Debug, MallocSizeOf)] +#[derive(Clone, Debug, MallocSizeOf)] pub struct KeyframesStep { /// The percentage of the animation duration when this step starts. pub start_percentage: KeyframePercentage, @@ -352,7 +352,7 @@ impl KeyframesStep { /// of keyframes, in order. /// /// It only takes into account animable properties. -#[derive(Debug, MallocSizeOf)] +#[derive(Clone, Debug, MallocSizeOf)] pub struct KeyframesAnimation { /// The difference steps of the animation. pub steps: Vec,