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

Side by Side Diff: app/animation_container.h

Issue 1961001: Refactors animation to allow for cleaner subclassing. I'm doing this (Closed)
Patch Set: Incorporated review feedback Created 10 years, 7 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
« no previous file with comments | « app/animation.cc ('k') | app/animation_container.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef APP_ANIMATION_CONTAINER_H_ 5 #ifndef APP_ANIMATION_CONTAINER_H_
6 #define APP_ANIMATION_CONTAINER_H_ 6 #define APP_ANIMATION_CONTAINER_H_
7 7
8 #include <set> 8 #include <set>
9 9
10 #include "base/ref_counted.h" 10 #include "base/ref_counted.h"
11 #include "base/time.h" 11 #include "base/time.h"
12 #include "base/timer.h" 12 #include "base/timer.h"
13 13
14 class Animation;
15
16 // AnimationContainer is used by Animation to manage the underlying timer. 14 // AnimationContainer is used by Animation to manage the underlying timer.
17 // Internally each Animation creates a single AnimationContainer. You can 15 // Internally each Animation creates a single AnimationContainer. You can
18 // group a set of Animations into the same AnimationContainer by way of 16 // group a set of Animations into the same AnimationContainer by way of
19 // Animation::SetContainer. Grouping a set of Animations into the same 17 // Animation::SetContainer. Grouping a set of Animations into the same
20 // AnimationContainer ensures they all update and start at the same time. 18 // AnimationContainer ensures they all update and start at the same time.
21 // 19 //
22 // AnimationContainer is ref counted. Each Animation contained within the 20 // AnimationContainer is ref counted. Each Animation contained within the
23 // AnimationContainer own it. 21 // AnimationContainer own it.
24 class AnimationContainer : public base::RefCounted<AnimationContainer> { 22 class AnimationContainer : public base::RefCounted<AnimationContainer> {
25 public: 23 public:
26 // The observer is notified after every update of the animations managed by 24 // The observer is notified after every update of the animations managed by
27 // the container. 25 // the container.
28 class Observer { 26 class Observer {
29 public: 27 public:
30 // Invoked on every tick of the timer managed by the container and after 28 // Invoked on every tick of the timer managed by the container and after
31 // all the animations have updated. 29 // all the animations have updated.
32 virtual void AnimationContainerProgressed( 30 virtual void AnimationContainerProgressed(
33 AnimationContainer* container) = 0; 31 AnimationContainer* container) = 0;
34 32
35 // Invoked when no more animations are being managed by this container. 33 // Invoked when no more animations are being managed by this container.
36 virtual void AnimationContainerEmpty(AnimationContainer* container) = 0; 34 virtual void AnimationContainerEmpty(AnimationContainer* container) = 0;
37 }; 35 };
38 36
37 // Interface for the elements the AnimationContainer contains. This is
38 // implemented by Animation.
39 class Element {
40 public:
41 // Sets the start of the animation. This is invoked from
42 // AnimationContainer::Start.
43 virtual void SetStartTime(base::TimeTicks start_time) = 0;
44
45 // Invoked when the animation is to progress.
46 virtual void Step(base::TimeTicks time_now) = 0;
47
48 // Returns the time interval of the animation. If an Element needs to change
49 // this it should first invoke Stop, then Start.
50 virtual base::TimeDelta GetTimerInterval() const = 0;
51
52 protected:
53 virtual ~Element() {}
54 };
55
39 AnimationContainer(); 56 AnimationContainer();
40 57
58 // Invoked by Animation when it needs to start. Starts the timer if necessary.
59 // NOTE: This is invoked by Animation for you, you shouldn't invoke this
60 // directly.
61 void Start(Element* animation);
62
63 // Invoked by Animation when it needs to stop. If there are no more animations
64 // running the timer stops.
65 // NOTE: This is invoked by Animation for you, you shouldn't invoke this
66 // directly.
67 void Stop(Element* animation);
68
41 void set_observer(Observer* observer) { observer_ = observer; } 69 void set_observer(Observer* observer) { observer_ = observer; }
42 70
43 // The time the last animation ran at. 71 // The time the last animation ran at.
44 base::TimeTicks last_tick_time() const { return last_tick_time_; } 72 base::TimeTicks last_tick_time() const { return last_tick_time_; }
45 73
46 // Are there any timers running? 74 // Are there any timers running?
47 bool is_running() const { return !animations_.empty(); } 75 bool is_running() const { return !elements_.empty(); }
48 76
49 private: 77 private:
50 friend class Animation;
51 friend class base::RefCounted<AnimationContainer>; 78 friend class base::RefCounted<AnimationContainer>;
52 79
53 typedef std::set<Animation*> Animations; 80 typedef std::set<Element*> Elements;
54 81
55 ~AnimationContainer(); 82 ~AnimationContainer();
56 83
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. 84 // Timer callback method.
65 void Run(); 85 void Run();
66 86
67 // Sets min_timer_interval_ and restarts the timer. 87 // Sets min_timer_interval_ and restarts the timer.
68 void SetMinTimerInterval(base::TimeDelta delta); 88 void SetMinTimerInterval(base::TimeDelta delta);
69 89
70 // Returns the min timer interval of all the timers. 90 // Returns the min timer interval of all the timers.
71 base::TimeDelta GetMinInterval(); 91 base::TimeDelta GetMinInterval();
72 92
73 // Represents one of two possible values: 93 // Represents one of two possible values:
74 // . If only a single animation has been started and the timer hasn't yet 94 // . If only a single animation has been started and the timer hasn't yet
75 // fired this is the time the animation was added. 95 // fired this is the time the animation was added.
76 // . The time the last animation ran at (::Run was invoked). 96 // . The time the last animation ran at (::Run was invoked).
77 base::TimeTicks last_tick_time_; 97 base::TimeTicks last_tick_time_;
78 98
79 // Set of animations being managed. 99 // Set of elements (animations) being managed.
80 Animations animations_; 100 Elements elements_;
81 101
82 // Minimum interval the timers run at. 102 // Minimum interval the timers run at.
83 base::TimeDelta min_timer_interval_; 103 base::TimeDelta min_timer_interval_;
84 104
85 base::RepeatingTimer<AnimationContainer> timer_; 105 base::RepeatingTimer<AnimationContainer> timer_;
86 106
87 Observer* observer_; 107 Observer* observer_;
88 108
89 DISALLOW_COPY_AND_ASSIGN(AnimationContainer); 109 DISALLOW_COPY_AND_ASSIGN(AnimationContainer);
90 }; 110 };
91 111
92 #endif // APP_ANIMATION_CONTAINER_H_ 112 #endif // APP_ANIMATION_CONTAINER_H_
OLDNEW
« no previous file with comments | « app/animation.cc ('k') | app/animation_container.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698