Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Side by Side Diff: app/animation_container.h

Issue 1575011: Adds AnimationContainer, which can be used to group a set of (Closed)
Patch Set: Incorporated review feedback Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2010 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 APP_ANIMATION_CONTAINER_H_
6 #define APP_ANIMATION_CONTAINER_H_
7
8 #include <set>
9
10 #include "base/ref_counted.h"
11 #include "base/time.h"
12 #include "base/timer.h"
13
14 class Animation;
15
16 // AnimationContainer is used by Animation to manage the underlying timer.
17 // Internally each Animation creates a single AnimationContainer. You can
18 // group a set of Animations into the same AnimationContainer by way of
19 // Animation::SetContainer. Grouping a set of Animations into the same
20 // AnimationContainer ensures they all update and start at the same time.
21 //
22 // AnimationContainer is ref counted. Each Animation contained within the
23 // AnimationContainer own it.
24 class AnimationContainer : public base::RefCounted<AnimationContainer> {
25 public:
26 // The observer is notified after every update of the animations managed by
27 // the container.
28 class Observer {
29 public:
30 // Invoked on every tick of the timer managed by the container and after
31 // all the animations have updated.
32 virtual void AnimationContainerProgressed(
33 AnimationContainer* container) = 0;
34
35 // Invoked when no more animations are being managed by this container.
36 virtual void AnimationContainerEmpty(AnimationContainer* container) = 0;
37 };
38
39 AnimationContainer();
40
41 void set_observer(Observer* observer) { observer_ = observer; }
42
43 // The time the last animation ran at.
44 base::TimeTicks last_tick_time() const { return last_tick_time_; }
45
46 // Are there any timers running?
47 bool is_running() const { return !animations_.empty(); }
48
49 private:
50 friend class Animation;
51 friend class base::RefCounted<AnimationContainer>;
52
53 typedef std::set<Animation*> Animations;
54
55 ~AnimationContainer();
56
57 // Invoked by Animation when it needs to start. Starts the timer if necessary.
58 void Start(Animation* animation);
59
60 // Invoked by Animation when it needs to stop. If there are no more animations
61 // running the timer stops.
62 void Stop(Animation* animation);
63
64 // Timer callback method.
65 void Run();
66
67 // Sets min_timer_interval_ and restarts the timer.
68 void SetMinTimerInterval(base::TimeDelta delta);
69
70 // Returns the min timer interval of all the timers.
71 base::TimeDelta GetMinInterval();
72
73 // Represents one of two possible values:
74 // . If only a single animation has been started and the timer hasn't yet
75 // fired this is the time the animation was added.
76 // . The time the last animation ran at (::Run was invoked).
77 base::TimeTicks last_tick_time_;
78
79 // Set of animations being managed.
80 Animations animations_;
81
82 // Minimum interval the timers run at.
83 base::TimeDelta min_timer_interval_;
84
85 base::RepeatingTimer<AnimationContainer> timer_;
86
87 Observer* observer_;
88
89 DISALLOW_COPY_AND_ASSIGN(AnimationContainer);
90 };
91
92 #endif // APP_ANIMATION_CONTAINER_H_
OLDNEW
« no previous file with comments | « app/animation.cc ('k') | app/animation_container.cc » ('j') | views/animation/bounds_animator.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698