Index: services/view_manager/animation_runner.h |
diff --git a/services/view_manager/animation_runner.h b/services/view_manager/animation_runner.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..24e3bde16e0fbf33c17d7ef77bb32cd4f936168d |
--- /dev/null |
+++ b/services/view_manager/animation_runner.h |
@@ -0,0 +1,73 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef SERVICES_VIEW_MANAGER_ANIMATION_RUNNER_H_ |
+#define SERVICES_VIEW_MANAGER_ANIMATION_RUNNER_H_ |
+ |
+#include "base/containers/scoped_ptr_hash_map.h" |
+#include "base/observer_list.h" |
+#include "base/time/time.h" |
+ |
+namespace mojo { |
+ |
+class AnimationGroup; |
+ |
+namespace service { |
+ |
+class AnimationRunnerObserver; |
+class ScheduledAnimationGroup; |
+class ServerView; |
+ |
+// AnimationRunner is responsible for maintaing and running a set of animations. |
+// The animations are represented as a set of AnimationGroups. New animations |
+// are scheduled by way of Schedule(). A |view| may only have one animation |
+// running at a time. Schedule()ing a new animation implicitly cancels the |
+// outstanding animation. Animations progress by way of the Tick() function. |
+class AnimationRunner { |
+ public: |
+ explicit AnimationRunner(base::TimeTicks now); |
+ ~AnimationRunner(); |
+ |
+ void AddObserver(AnimationRunnerObserver* observer); |
+ void RemoveObserver(AnimationRunnerObserver* observer); |
+ |
+ // Schedules an animation for |view|. If there is an existing animation in |
+ // progress for |view| it is canceled and any properties that were animating |
+ // but are no longer animating are set to their target value. |
+ // Returns 0 if |transport_group| is not valid. |
+ uint32_t Schedule(ServerView* view, const AnimationGroup& transport_group); |
+ |
+ // Returns the view the animation identified by |id| was scheduled for. |
+ ServerView* GetViewForAnimation(uint32_t id); |
+ |
+ // Cancels the animation scheduled for |view|. Does nothing if there is no |
+ // animation scheduled for |view|. This does not change |view|. That is, any |
+ // in progress animations are stopped. |
+ void CancelAnimationForView(ServerView* view); |
+ |
+ // Advance the animations updating values appropriately. |
+ void Tick(base::TimeTicks time); |
+ |
+ // Returns true if there are animations currently scheduled. |
+ bool HasAnimations() const { return !animation_map_.empty(); } |
+ |
+ private: |
+ using ViewAnimationMap = |
+ base::ScopedPtrHashMap<ServerView*, ScheduledAnimationGroup>; |
+ |
+ uint32_t next_id_; |
+ |
+ base::TimeTicks last_tick_time_; |
+ |
+ ObserverList<AnimationRunnerObserver> observers_; |
+ |
+ ViewAnimationMap animation_map_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(AnimationRunner); |
+}; |
+ |
+} // namespace service |
+} // namespace mojo |
+ |
+#endif // SERVICES_VIEW_MANAGER_ANIMATION_RUNNER_H_ |