| OLD | NEW |
| (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 #pragma once | |
| 8 | |
| 9 #include <set> | |
| 10 | |
| 11 #include "base/ref_counted.h" | |
| 12 #include "base/time.h" | |
| 13 #include "base/timer.h" | |
| 14 | |
| 15 class AnimationContainerElement; | |
| 16 class AnimationContainerObserver; | |
| 17 | |
| 18 // AnimationContainer is used by Animation to manage the underlying timer. | |
| 19 // Internally each Animation creates a single AnimationContainer. You can | |
| 20 // group a set of Animations into the same AnimationContainer by way of | |
| 21 // Animation::SetContainer. Grouping a set of Animations into the same | |
| 22 // AnimationContainer ensures they all update and start at the same time. | |
| 23 // | |
| 24 // AnimationContainer is ref counted. Each Animation contained within the | |
| 25 // AnimationContainer own it. | |
| 26 class AnimationContainer : public base::RefCounted<AnimationContainer> { | |
| 27 public: | |
| 28 AnimationContainer(); | |
| 29 | |
| 30 // Invoked by Animation when it needs to start. Starts the timer if necessary. | |
| 31 // NOTE: This is invoked by Animation for you, you shouldn't invoke this | |
| 32 // directly. | |
| 33 void Start(AnimationContainerElement* animation); | |
| 34 | |
| 35 // Invoked by Animation when it needs to stop. If there are no more animations | |
| 36 // running the timer stops. | |
| 37 // NOTE: This is invoked by Animation for you, you shouldn't invoke this | |
| 38 // directly. | |
| 39 void Stop(AnimationContainerElement* animation); | |
| 40 | |
| 41 void set_observer(AnimationContainerObserver* observer) { | |
| 42 observer_ = observer; | |
| 43 } | |
| 44 | |
| 45 // The time the last animation ran at. | |
| 46 base::TimeTicks last_tick_time() const { return last_tick_time_; } | |
| 47 | |
| 48 // Are there any timers running? | |
| 49 bool is_running() const { return !elements_.empty(); } | |
| 50 | |
| 51 private: | |
| 52 friend class base::RefCounted<AnimationContainer>; | |
| 53 | |
| 54 typedef std::set<AnimationContainerElement*> Elements; | |
| 55 | |
| 56 ~AnimationContainer(); | |
| 57 | |
| 58 // Timer callback method. | |
| 59 void Run(); | |
| 60 | |
| 61 // Sets min_timer_interval_ and restarts the timer. | |
| 62 void SetMinTimerInterval(base::TimeDelta delta); | |
| 63 | |
| 64 // Returns the min timer interval of all the timers. | |
| 65 base::TimeDelta GetMinInterval(); | |
| 66 | |
| 67 // Represents one of two possible values: | |
| 68 // . If only a single animation has been started and the timer hasn't yet | |
| 69 // fired this is the time the animation was added. | |
| 70 // . The time the last animation ran at (::Run was invoked). | |
| 71 base::TimeTicks last_tick_time_; | |
| 72 | |
| 73 // Set of elements (animations) being managed. | |
| 74 Elements elements_; | |
| 75 | |
| 76 // Minimum interval the timers run at. | |
| 77 base::TimeDelta min_timer_interval_; | |
| 78 | |
| 79 base::RepeatingTimer<AnimationContainer> timer_; | |
| 80 | |
| 81 AnimationContainerObserver* observer_; | |
| 82 | |
| 83 DISALLOW_COPY_AND_ASSIGN(AnimationContainer); | |
| 84 }; | |
| 85 | |
| 86 #endif // APP_ANIMATION_CONTAINER_H_ | |
| OLD | NEW |