Another take on menu's. This uses the hosting menu scroll view container as a menuba...
[chromium-blink-merge.git] / app / animation.h
blob8433f29620855b472a310e9d608f5d1897a4017e
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.
5 #ifndef APP_ANIMATION_H_
6 #define APP_ANIMATION_H_
7 #pragma once
9 #include "app/animation_container.h"
10 #include "base/ref_counted.h"
11 #include "base/time.h"
13 namespace gfx {
14 class Rect;
17 class Animation;
19 // AnimationDelegate
21 // Implement this interface when you want to receive notifications about the
22 // state of an animation.
23 class AnimationDelegate {
24 public:
25 // Called when an animation has completed.
26 virtual void AnimationEnded(const Animation* animation) {
29 // Called when an animation has progressed.
30 virtual void AnimationProgressed(const Animation* animation) {
33 // Called when an animation has been canceled.
34 virtual void AnimationCanceled(const Animation* animation) {
37 protected:
38 virtual ~AnimationDelegate() {}
41 // Base class used in implementing animations. You only need use this class if
42 // you're implementing a new animation type, otherwise you'll likely want one of
43 // LinearAnimation, SlideAnimation, ThrobAnimation or MultiAnimation.
45 // To subclass override Step, which is invoked as the animation progresses and
46 // GetCurrentValue() to return the value appropriate to the animation.
47 class Animation : public AnimationContainer::Element {
48 public:
49 explicit Animation(base::TimeDelta timer_interval);
50 virtual ~Animation();
52 // Starts the animation. Does nothing if the animation is already running.
53 void Start();
55 // Stops the animation. Does nothing if the animation is not running.
56 void Stop();
58 // Gets the value for the current state, according to the animation
59 // curve in use.
60 virtual double GetCurrentValue() const = 0;
62 // Convenience for returning a value between |start| and |target| based on
63 // the current value. This is (target - start) * GetCurrentValue() + start.
64 double CurrentValueBetween(double start, double target) const;
65 int CurrentValueBetween(int start, int target) const;
66 gfx::Rect CurrentValueBetween(const gfx::Rect& start_bounds,
67 const gfx::Rect& target_bounds) const;
69 // Sets the delegate.
70 void set_delegate(AnimationDelegate* delegate) { delegate_ = delegate; }
72 // Sets the container used to manage the timer. A value of NULL results in
73 // creating a new AnimationContainer.
74 void SetContainer(AnimationContainer* container);
76 bool is_animating() const { return is_animating_; }
78 base::TimeDelta timer_interval() const { return timer_interval_; }
80 // Returns true if rich animations should be rendered.
81 // Looks at session type (e.g. remote desktop) and accessibility settings
82 // to give guidance for heavy animations such as "start download" arrow.
83 static bool ShouldRenderRichAnimation();
85 protected:
86 // Invoked from Start to allow subclasses to prepare for the animation.
87 virtual void AnimationStarted() {}
89 // Invoked from Stop after we're removed from the container but before the
90 // delegate has been invoked.
91 virtual void AnimationStopped() {}
93 // Invoked from stop to determine if cancel should be invoked. If this returns
94 // true the delegate is notified the animation was canceled, otherwise the
95 // delegate is notified the animation stopped.
96 virtual bool ShouldSendCanceledFromStop() { return false; }
98 AnimationContainer* container() { return container_.get(); }
99 base::TimeTicks start_time() const { return start_time_; }
100 AnimationDelegate* delegate() { return delegate_; }
102 // AnimationContainer::Element overrides
103 virtual void SetStartTime(base::TimeTicks start_time);
104 virtual void Step(base::TimeTicks time_now) = 0;
105 virtual base::TimeDelta GetTimerInterval() const { return timer_interval_; }
107 private:
108 // Interval for the animation.
109 const base::TimeDelta timer_interval_;
111 // If true we're running.
112 bool is_animating_;
114 // Our delegate; may be null.
115 AnimationDelegate* delegate_;
117 // Container we're in. If non-null we're animating.
118 scoped_refptr<AnimationContainer> container_;
120 // Time we started at.
121 base::TimeTicks start_time_;
123 DISALLOW_COPY_AND_ASSIGN(Animation);
126 #endif // APP_ANIMATION_H_