OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 UI_BASE_ANIMATION_ANIMATION_CONTAINER_H_ | 5 #ifndef UI_BASE_ANIMATION_ANIMATION_CONTAINER_H_ |
6 #define UI_BASE_ANIMATION_ANIMATION_CONTAINER_H_ | 6 #define UI_BASE_ANIMATION_ANIMATION_CONTAINER_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/time.h" | 11 #include "base/time.h" |
12 #include "base/timer.h" | 12 #include "base/timer.h" |
13 #include "ui/base/ui_export.h" | 13 #include "ui/base/ui_export.h" |
14 | 14 |
15 namespace ui { | 15 namespace ui { |
16 | 16 |
17 class AnimationContainerElement; | 17 class AnimationContainerElement; |
18 class AnimationContainerObserver; | 18 class AnimationContainerObserver; |
19 | 19 |
| 20 namespace test { |
| 21 class AnimationContainerTestHelper; |
| 22 } |
| 23 |
20 // AnimationContainer is used by Animation to manage the underlying timer. | 24 // AnimationContainer is used by Animation to manage the underlying timer. |
21 // Internally each Animation creates a single AnimationContainer. You can | 25 // Internally each Animation creates a single AnimationContainer. You can |
22 // group a set of Animations into the same AnimationContainer by way of | 26 // group a set of Animations into the same AnimationContainer by way of |
23 // Animation::SetContainer. Grouping a set of Animations into the same | 27 // Animation::SetContainer. Grouping a set of Animations into the same |
24 // AnimationContainer ensures they all update and start at the same time. | 28 // AnimationContainer ensures they all update and start at the same time. |
25 // | 29 // |
26 // AnimationContainer is ref counted. Each Animation contained within the | 30 // AnimationContainer is ref counted. Each Animation contained within the |
27 // AnimationContainer own it. | 31 // AnimationContainer own it. |
28 class UI_EXPORT AnimationContainer | 32 class UI_EXPORT AnimationContainer |
29 : public base::RefCounted<AnimationContainer> { | 33 : public base::RefCounted<AnimationContainer> { |
30 public: | 34 public: |
31 AnimationContainer(); | 35 AnimationContainer(); |
32 | 36 |
33 // Invoked by Animation when it needs to start. Starts the timer if necessary. | 37 // Invoked by Animation when it needs to start. Starts the timer if necessary. |
34 // NOTE: This is invoked by Animation for you, you shouldn't invoke this | 38 // NOTE: This is invoked by Animation for you, you shouldn't invoke this |
35 // directly. | 39 // directly. |
36 void Start(AnimationContainerElement* animation); | 40 void Start(AnimationContainerElement* animation); |
37 | 41 |
38 // Invoked by Animation when it needs to stop. If there are no more animations | 42 // Invoked by Animation when it needs to stop. If there are no more animations |
39 // running the timer stops. | 43 // running the timer stops. |
40 // NOTE: This is invoked by Animation for you, you shouldn't invoke this | 44 // NOTE: This is invoked by Animation for you, you shouldn't invoke this |
41 // directly. | 45 // directly. |
42 void Stop(AnimationContainerElement* animation); | 46 void Stop(AnimationContainerElement* animation); |
43 | 47 |
| 48 // Returns current time. |
| 49 base::TimeTicks GetCurrentTime(); |
| 50 |
44 void set_observer(AnimationContainerObserver* observer) { | 51 void set_observer(AnimationContainerObserver* observer) { |
45 observer_ = observer; | 52 observer_ = observer; |
46 } | 53 } |
47 | 54 |
48 // The time the last animation ran at. | 55 // The time the last animation ran at. |
49 base::TimeTicks last_tick_time() const { return last_tick_time_; } | 56 base::TimeTicks last_tick_time() const { return last_tick_time_; } |
50 | 57 |
51 // Are there any timers running? | 58 // Are there any timers running? |
52 bool is_running() const { return !elements_.empty(); } | 59 bool is_running() const { return !elements_.empty(); } |
53 | 60 |
54 private: | 61 private: |
55 friend class base::RefCounted<AnimationContainer>; | 62 friend class base::RefCounted<AnimationContainer>; |
| 63 friend class test::AnimationContainerTestHelper; |
56 | 64 |
57 typedef std::set<AnimationContainerElement*> Elements; | 65 typedef std::set<AnimationContainerElement*> Elements; |
58 | 66 |
59 ~AnimationContainer(); | 67 ~AnimationContainer(); |
60 | 68 |
61 // Timer callback method. | 69 // Timer callback method. |
62 void Run(); | 70 void Run(); |
63 | 71 |
64 // Sets min_timer_interval_ and restarts the timer. | 72 // Sets min_timer_interval_ and restarts the timer. |
65 void SetMinTimerInterval(base::TimeDelta delta); | 73 void SetMinTimerInterval(base::TimeDelta delta); |
(...skipping 10 matching lines...) Expand all Loading... |
76 // Set of elements (animations) being managed. | 84 // Set of elements (animations) being managed. |
77 Elements elements_; | 85 Elements elements_; |
78 | 86 |
79 // Minimum interval the timers run at. | 87 // Minimum interval the timers run at. |
80 base::TimeDelta min_timer_interval_; | 88 base::TimeDelta min_timer_interval_; |
81 | 89 |
82 base::RepeatingTimer<AnimationContainer> timer_; | 90 base::RepeatingTimer<AnimationContainer> timer_; |
83 | 91 |
84 AnimationContainerObserver* observer_; | 92 AnimationContainerObserver* observer_; |
85 | 93 |
| 94 // Used for testing : indicates that "Time" is controlled by |
| 95 // AnimationContainerTestHelper. |
| 96 bool test_timing_enabled_; |
| 97 |
| 98 // Current time for tests. |
| 99 base::TimeTicks test_time_; |
| 100 |
86 DISALLOW_COPY_AND_ASSIGN(AnimationContainer); | 101 DISALLOW_COPY_AND_ASSIGN(AnimationContainer); |
87 }; | 102 }; |
88 | 103 |
89 } // namespace ui | 104 } // namespace ui |
90 | 105 |
91 #endif // UI_BASE_ANIMATION_ANIMATION_CONTAINER_H_ | 106 #endif // UI_BASE_ANIMATION_ANIMATION_CONTAINER_H_ |
OLD | NEW |