OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef SERVICES_VIEW_MANAGER_ANIMATION_RUNNER_H_ |
| 6 #define SERVICES_VIEW_MANAGER_ANIMATION_RUNNER_H_ |
| 7 |
| 8 #include "base/containers/scoped_ptr_hash_map.h" |
| 9 #include "base/observer_list.h" |
| 10 #include "base/time/time.h" |
| 11 |
| 12 namespace mojo { |
| 13 |
| 14 class AnimationGroup; |
| 15 |
| 16 namespace service { |
| 17 |
| 18 class AnimationRunnerObserver; |
| 19 class ScheduledAnimationGroup; |
| 20 class ServerView; |
| 21 |
| 22 // AnimationRunner is responsible for maintaing and running a set of animations. |
| 23 // The animations are represented as a set of AnimationGroups. New animations |
| 24 // are scheduled by way of Schedule(). A |view| may only have one animation |
| 25 // running at a time. Schedule()ing a new animation implicitly cancels the |
| 26 // outstanding animation. Animations progress by way of the Tick() function. |
| 27 class AnimationRunner { |
| 28 public: |
| 29 explicit AnimationRunner(base::TimeTicks now); |
| 30 ~AnimationRunner(); |
| 31 |
| 32 void AddObserver(AnimationRunnerObserver* observer); |
| 33 void RemoveObserver(AnimationRunnerObserver* observer); |
| 34 |
| 35 // Schedules an animation for |view|. If there is an existing animation in |
| 36 // progress for |view| it is canceled and any properties that were animating |
| 37 // but are no longer animating are set to their target value. |
| 38 // Returns 0 if |transport_group| is not valid. |
| 39 uint32_t Schedule(ServerView* view, const AnimationGroup& transport_group); |
| 40 |
| 41 // Returns the view the animation identified by |id| was scheduled for. |
| 42 ServerView* GetViewForAnimation(uint32_t id); |
| 43 |
| 44 // Cancels the animation scheduled for |view|. Does nothing if there is no |
| 45 // animation scheduled for |view|. This does not change |view|. That is, any |
| 46 // in progress animations are stopped. |
| 47 void CancelAnimationForView(ServerView* view); |
| 48 |
| 49 // Advance the animations updating values appropriately. |
| 50 void Tick(base::TimeTicks time); |
| 51 |
| 52 // Returns true if there are animations currently scheduled. |
| 53 bool HasAnimations() const { return !animation_map_.empty(); } |
| 54 |
| 55 private: |
| 56 using ViewAnimationMap = |
| 57 base::ScopedPtrHashMap<ServerView*, ScheduledAnimationGroup>; |
| 58 |
| 59 uint32_t next_id_; |
| 60 |
| 61 base::TimeTicks last_tick_time_; |
| 62 |
| 63 ObserverList<AnimationRunnerObserver> observers_; |
| 64 |
| 65 ViewAnimationMap animation_map_; |
| 66 |
| 67 DISALLOW_COPY_AND_ASSIGN(AnimationRunner); |
| 68 }; |
| 69 |
| 70 } // namespace service |
| 71 } // namespace mojo |
| 72 |
| 73 #endif // SERVICES_VIEW_MANAGER_ANIMATION_RUNNER_H_ |
OLD | NEW |