Revert of Add Masonry to key_silk_cases. (patchset #3 id:40001 of https://codereview...
[chromium-blink-merge.git] / ui / gfx / animation / animation.h
blobd7d7d3a3b08b27cf64b989adcc265ae6f8ca0f2b
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_H_
6 #define UI_GFX_ANIMATION_ANIMATION_H_
8 #include "base/compiler_specific.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/time/time.h"
11 #include "ui/gfx/animation/animation_container_element.h"
13 namespace gfx {
14 class Rect;
17 namespace gfx {
19 class AnimationContainer;
20 class AnimationDelegate;
22 // Base class used in implementing animations. You only need use this class if
23 // you're implementing a new animation type, otherwise you'll likely want one of
24 // LinearAnimation, SlideAnimation, ThrobAnimation or MultiAnimation.
26 // To subclass override Step, which is invoked as the animation progresses and
27 // GetCurrentValue() to return the value appropriate to the animation.
28 class GFX_EXPORT Animation : public AnimationContainerElement {
29 public:
30 explicit Animation(base::TimeDelta timer_interval);
31 ~Animation() override;
33 // Starts the animation. Does nothing if the animation is already running.
34 void Start();
36 // Stops the animation. Does nothing if the animation is not running.
37 void Stop();
39 // Gets the value for the current state, according to the animation
40 // curve in use.
41 virtual double GetCurrentValue() const = 0;
43 // Convenience for returning a value between |start| and |target| based on
44 // the current value. This is (target - start) * GetCurrentValue() + start.
45 double CurrentValueBetween(double start, double target) const;
46 int CurrentValueBetween(int start, int target) const;
47 gfx::Rect CurrentValueBetween(const gfx::Rect& start_bounds,
48 const gfx::Rect& target_bounds) const;
50 // Sets the delegate.
51 void set_delegate(AnimationDelegate* delegate) { delegate_ = delegate; }
53 // Sets the container used to manage the timer. A value of NULL results in
54 // creating a new AnimationContainer.
55 void SetContainer(AnimationContainer* container);
57 bool is_animating() const { return is_animating_; }
59 base::TimeDelta timer_interval() const { return timer_interval_; }
61 // Returns true if rich animations should be rendered.
62 // Looks at session type (e.g. remote desktop) and accessibility settings
63 // to give guidance for heavy animations such as "start download" arrow.
64 static bool ShouldRenderRichAnimation();
66 protected:
67 // Invoked from Start to allow subclasses to prepare for the animation.
68 virtual void AnimationStarted() {}
70 // Invoked from Stop after we're removed from the container but before the
71 // delegate has been invoked.
72 virtual void AnimationStopped() {}
74 // Invoked from stop to determine if cancel should be invoked. If this returns
75 // true the delegate is notified the animation was canceled, otherwise the
76 // delegate is notified the animation stopped.
77 virtual bool ShouldSendCanceledFromStop();
79 AnimationContainer* container() { return container_.get(); }
80 base::TimeTicks start_time() const { return start_time_; }
81 AnimationDelegate* delegate() { return delegate_; }
83 // AnimationContainer::Element overrides
84 void SetStartTime(base::TimeTicks start_time) override;
85 void Step(base::TimeTicks time_now) override = 0;
86 base::TimeDelta GetTimerInterval() const override;
88 private:
89 // Interval for the animation.
90 const base::TimeDelta timer_interval_;
92 // If true we're running.
93 bool is_animating_;
95 // Our delegate; may be null.
96 AnimationDelegate* delegate_;
98 // Container we're in. If non-null we're animating.
99 scoped_refptr<AnimationContainer> container_;
101 // Time we started at.
102 base::TimeTicks start_time_;
104 DISALLOW_COPY_AND_ASSIGN(Animation);
107 } // namespace gfx
109 #endif // UI_GFX_ANIMATION_ANIMATION_H_