Revert of Add Masonry to key_silk_cases. (patchset #3 id:40001 of https://codereview...
[chromium-blink-merge.git] / ui / gfx / animation / animation_container.h
blobbb59f8f0cc75451659baaa18fe5b8edf23679bdd
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
3 // found in the LICENSE file.
5 #ifndef UI_GFX_ANIMATION_ANIMATION_CONTAINER_H_
6 #define UI_GFX_ANIMATION_ANIMATION_CONTAINER_H_
8 #include <set>
10 #include "base/memory/ref_counted.h"
11 #include "base/time/time.h"
12 #include "base/timer/timer.h"
13 #include "ui/gfx/gfx_export.h"
15 namespace gfx {
17 class AnimationContainerElement;
18 class AnimationContainerObserver;
20 // AnimationContainer is used by Animation to manage the underlying timer.
21 // Internally each Animation creates a single AnimationContainer. You can
22 // group a set of Animations into the same AnimationContainer by way of
23 // Animation::SetContainer. Grouping a set of Animations into the same
24 // AnimationContainer ensures they all update and start at the same time.
26 // AnimationContainer is ref counted. Each Animation contained within the
27 // AnimationContainer own it.
28 class GFX_EXPORT AnimationContainer
29 : public base::RefCounted<AnimationContainer> {
30 public:
31 AnimationContainer();
33 // 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
35 // directly.
36 void Start(AnimationContainerElement* animation);
38 // Invoked by Animation when it needs to stop. If there are no more animations
39 // running the timer stops.
40 // NOTE: This is invoked by Animation for you, you shouldn't invoke this
41 // directly.
42 void Stop(AnimationContainerElement* animation);
44 void set_observer(AnimationContainerObserver* observer) {
45 observer_ = observer;
48 // The time the last animation ran at.
49 base::TimeTicks last_tick_time() const { return last_tick_time_; }
51 // Are there any timers running?
52 bool is_running() const { return !elements_.empty(); }
54 private:
55 friend class base::RefCounted<AnimationContainer>;
57 typedef std::set<AnimationContainerElement*> Elements;
59 ~AnimationContainer();
61 // Timer callback method.
62 void Run();
64 // Sets min_timer_interval_ and restarts the timer.
65 void SetMinTimerInterval(base::TimeDelta delta);
67 // Returns the min timer interval of all the timers.
68 base::TimeDelta GetMinInterval();
70 // Represents one of two possible values:
71 // . If only a single animation has been started and the timer hasn't yet
72 // fired this is the time the animation was added.
73 // . The time the last animation ran at (::Run was invoked).
74 base::TimeTicks last_tick_time_;
76 // Set of elements (animations) being managed.
77 Elements elements_;
79 // Minimum interval the timers run at.
80 base::TimeDelta min_timer_interval_;
82 base::RepeatingTimer<AnimationContainer> timer_;
84 AnimationContainerObserver* observer_;
86 DISALLOW_COPY_AND_ASSIGN(AnimationContainer);
89 } // namespace gfx
91 #endif // UI_GFX_ANIMATION_ANIMATION_CONTAINER_H_