Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(210)

Side by Side Diff: views/animation/bounds_animator.h

Issue 6154001: Move animation code to new ui/base/animation directory.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/ui.gyp ('k') | views/animation/bounds_animator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 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 VIEWS_ANIMATION_BOUNDS_ANIMATOR_H_ 5 #ifndef VIEWS_ANIMATION_BOUNDS_ANIMATOR_H_
6 #define VIEWS_ANIMATION_BOUNDS_ANIMATOR_H_ 6 #define VIEWS_ANIMATION_BOUNDS_ANIMATOR_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 10
11 #include "app/animation_container_observer.h"
12 #include "app/animation_delegate.h"
13 #include "base/ref_counted.h" 11 #include "base/ref_counted.h"
14 #include "gfx/rect.h" 12 #include "gfx/rect.h"
13 #include "ui/base/animation/animation_container_observer.h"
14 #include "ui/base/animation/animation_delegate.h"
15 15
16 class AnimationContainer; 16 namespace ui {
17 class SlideAnimation; 17 class SlideAnimation;
18 }
18 19
19 namespace views { 20 namespace views {
20 21
21 class BoundsAnimator; 22 class BoundsAnimator;
22 class View; 23 class View;
23 24
24 class BoundsAnimatorObserver { 25 class BoundsAnimatorObserver {
25 public: 26 public:
26 // Invoked when all animations are complete. 27 // Invoked when all animations are complete.
27 virtual void OnBoundsAnimatorDone(BoundsAnimator* animator) = 0; 28 virtual void OnBoundsAnimatorDone(BoundsAnimator* animator) = 0;
28 }; 29 };
29 30
30 // Bounds animator is responsible for animating the bounds of a view from the 31 // Bounds animator is responsible for animating the bounds of a view from the
31 // the views current location and size to a target position and size. To use 32 // the views current location and size to a target position and size. To use
32 // BoundsAnimator invoke AnimateViewTo for the set of views you want to 33 // BoundsAnimator invoke AnimateViewTo for the set of views you want to
33 // animate. 34 // animate.
34 // 35 //
35 // BoundsAnimator internally creates an animation for each view. If you need 36 // BoundsAnimator internally creates an animation for each view. If you need
36 // a specific animation invoke SetAnimationForView after invoking AnimateViewTo. 37 // a specific animation invoke SetAnimationForView after invoking AnimateViewTo.
37 // You can attach an AnimationDelegate to the individual animation for a view 38 // You can attach an AnimationDelegate to the individual animation for a view
38 // by way of SetAnimationDelegate. Additionally you can attach an observer to 39 // by way of SetAnimationDelegate. Additionally you can attach an observer to
39 // the BoundsAnimator that is notified when all animations are complete. 40 // the BoundsAnimator that is notified when all animations are complete.
40 class BoundsAnimator : public AnimationDelegate, 41 class BoundsAnimator : public ui::AnimationDelegate,
41 public AnimationContainerObserver { 42 public ui::AnimationContainerObserver {
42 public: 43 public:
43 // If |delete_when_done| is set to true in |SetAnimationDelegate| the 44 // If |delete_when_done| is set to true in |SetAnimationDelegate| the
44 // |AnimationDelegate| must subclass this class. 45 // |AnimationDelegate| must subclass this class.
45 class OwnedAnimationDelegate : public AnimationDelegate { 46 class OwnedAnimationDelegate : public ui::AnimationDelegate {
46 public: 47 public:
47 virtual ~OwnedAnimationDelegate() {} 48 virtual ~OwnedAnimationDelegate() {}
48 }; 49 };
49 50
50 explicit BoundsAnimator(View* view); 51 explicit BoundsAnimator(View* view);
51 ~BoundsAnimator(); 52 ~BoundsAnimator();
52 53
53 // Starts animating |view| from its current bounds to |target|. If there is 54 // Starts animating |view| from its current bounds to |target|. If there is
54 // already an animation running for the view it's stopped and a new one 55 // already an animation running for the view it's stopped and a new one
55 // started. If an AnimationDelegate has been set for |view| it is removed 56 // started. If an AnimationDelegate has been set for |view| it is removed
56 // (after being notified that the animation was canceled). 57 // (after being notified that the animation was canceled).
57 void AnimateViewTo(View* view, const gfx::Rect& target); 58 void AnimateViewTo(View* view, const gfx::Rect& target);
58 59
59 // Sets the animation for the specified view. BoundsAnimator takes ownership 60 // Sets the animation for the specified view. BoundsAnimator takes ownership
60 // of the specified animation. 61 // of the specified animation.
61 void SetAnimationForView(View* view, SlideAnimation* animation); 62 void SetAnimationForView(View* view, ui::SlideAnimation* animation);
62 63
63 // Returns the animation for the specified view. BoundsAnimator owns the 64 // Returns the animation for the specified view. BoundsAnimator owns the
64 // returned Animation. 65 // returned Animation.
65 const SlideAnimation* GetAnimationForView(View* view); 66 const ui::SlideAnimation* GetAnimationForView(View* view);
66 67
67 // Stops animating the specified view. If the view was scheduled for deletion 68 // Stops animating the specified view. If the view was scheduled for deletion
68 // it is deleted. This does nothing if |view| is not currently animating. 69 // it is deleted. This does nothing if |view| is not currently animating.
69 void StopAnimatingView(View* view); 70 void StopAnimatingView(View* view);
70 71
71 // Sets the delegate for the animation created for the specified view. If 72 // Sets the delegate for the animation created for the specified view. If
72 // |delete_when_done| is true the |delegate| is deleted when done and 73 // |delete_when_done| is true the |delegate| is deleted when done and
73 // |delegate| must subclass OwnedAnimationDelegate. 74 // |delegate| must subclass OwnedAnimationDelegate.
74 void SetAnimationDelegate(View* view, 75 void SetAnimationDelegate(View* view,
75 AnimationDelegate* delegate, 76 ui::AnimationDelegate* delegate,
76 bool delete_when_done); 77 bool delete_when_done);
77 78
78 // Returns true if BoundsAnimator is animating the bounds of |view|. 79 // Returns true if BoundsAnimator is animating the bounds of |view|.
79 bool IsAnimating(View* view) const; 80 bool IsAnimating(View* view) const;
80 81
81 // Returns true if BoundsAnimator is animating any view. 82 // Returns true if BoundsAnimator is animating any view.
82 bool IsAnimating() const; 83 bool IsAnimating() const;
83 84
84 // Cancels all animations, leaving the views at their current location and 85 // Cancels all animations, leaving the views at their current location and
85 // size. Any views marked for deletion are deleted. 86 // size. Any views marked for deletion are deleted.
86 void Cancel(); 87 void Cancel();
87 88
88 void set_observer(BoundsAnimatorObserver* observer) { 89 void set_observer(BoundsAnimatorObserver* observer) {
89 observer_ = observer; 90 observer_ = observer;
90 } 91 }
91 92
92 protected: 93 protected:
93 // Creates the animation to use for animating views. 94 // Creates the animation to use for animating views.
94 virtual SlideAnimation* CreateAnimation(); 95 virtual ui::SlideAnimation* CreateAnimation();
95 96
96 private: 97 private:
97 // Tracks data about the view being animated. 98 // Tracks data about the view being animated.
98 struct Data { 99 struct Data {
99 Data() 100 Data()
100 : delete_delegate_when_done(false), 101 : delete_delegate_when_done(false),
101 animation(NULL), 102 animation(NULL),
102 delegate(NULL) {} 103 delegate(NULL) {}
103 104
104 // If true the delegate is deleted when done. 105 // If true the delegate is deleted when done.
105 bool delete_delegate_when_done; 106 bool delete_delegate_when_done;
106 107
107 // The initial bounds. 108 // The initial bounds.
108 gfx::Rect start_bounds; 109 gfx::Rect start_bounds;
109 110
110 // Target bounds. 111 // Target bounds.
111 gfx::Rect target_bounds; 112 gfx::Rect target_bounds;
112 113
113 // The animation. We own this. 114 // The animation. We own this.
114 SlideAnimation* animation; 115 ui::SlideAnimation* animation;
115 116
116 // Additional delegate for the animation, may be null. 117 // Additional delegate for the animation, may be null.
117 AnimationDelegate* delegate; 118 ui::AnimationDelegate* delegate;
118 }; 119 };
119 120
120 // Used by AnimationEndedOrCanceled. 121 // Used by AnimationEndedOrCanceled.
121 enum AnimationEndType { 122 enum AnimationEndType {
122 ANIMATION_ENDED, 123 ANIMATION_ENDED,
123 ANIMATION_CANCELED 124 ANIMATION_CANCELED
124 }; 125 };
125 126
126 typedef std::map<View*, Data> ViewToDataMap; 127 typedef std::map<View*, Data> ViewToDataMap;
127 128
128 typedef std::map<const Animation*, View*> AnimationToViewMap; 129 typedef std::map<const ui::Animation*, View*> AnimationToViewMap;
129 130
130 // Removes references to |view| and its animation. This does NOT delete the 131 // Removes references to |view| and its animation. This does NOT delete the
131 // animation or delegate. 132 // animation or delegate.
132 void RemoveFromMaps(View* view); 133 void RemoveFromMaps(View* view);
133 134
134 // Does the necessary cleanup for |data|. If |send_cancel| is true and a 135 // Does the necessary cleanup for |data|. If |send_cancel| is true and a
135 // delegate has been installed on |data| AnimationCanceled is invoked on it. 136 // delegate has been installed on |data| AnimationCanceled is invoked on it.
136 void CleanupData(bool send_cancel, Data* data, View* view); 137 void CleanupData(bool send_cancel, Data* data, View* view);
137 138
138 // Used when changing the animation for a view. This resets the maps for 139 // Used when changing the animation for a view. This resets the maps for
139 // the animation used by view and returns the current animation. Ownership 140 // the animation used by view and returns the current animation. Ownership
140 // of the returned animation passes to the caller. 141 // of the returned animation passes to the caller.
141 Animation* ResetAnimationForView(View* view); 142 ui::Animation* ResetAnimationForView(View* view);
142 143
143 // Invoked from AnimationEnded and AnimationCanceled. 144 // Invoked from AnimationEnded and AnimationCanceled.
144 void AnimationEndedOrCanceled(const Animation* animation, 145 void AnimationEndedOrCanceled(const ui::Animation* animation,
145 AnimationEndType type); 146 AnimationEndType type);
146 147
147 // AnimationDelegate overrides. 148 // ui::AnimationDelegate overrides.
148 virtual void AnimationProgressed(const Animation* animation); 149 virtual void AnimationProgressed(const ui::Animation* animation);
149 virtual void AnimationEnded(const Animation* animation); 150 virtual void AnimationEnded(const ui::Animation* animation);
150 virtual void AnimationCanceled(const Animation* animation); 151 virtual void AnimationCanceled(const ui::Animation* animation);
151 152
152 // AnimationContainerObserver overrides. 153 // ui::AnimationContainerObserver overrides.
153 virtual void AnimationContainerProgressed(AnimationContainer* container); 154 virtual void AnimationContainerProgressed(ui::AnimationContainer* container);
154 virtual void AnimationContainerEmpty(AnimationContainer* container); 155 virtual void AnimationContainerEmpty(ui::AnimationContainer* container);
155 156
156 // Parent of all views being animated. 157 // Parent of all views being animated.
157 View* parent_; 158 View* parent_;
158 159
159 BoundsAnimatorObserver* observer_; 160 BoundsAnimatorObserver* observer_;
160 161
161 // All animations we create up with the same container. 162 // All animations we create up with the same container.
162 scoped_refptr<AnimationContainer> container_; 163 scoped_refptr<ui::AnimationContainer> container_;
163 164
164 // Maps from view being animated to info about the view. 165 // Maps from view being animated to info about the view.
165 ViewToDataMap data_; 166 ViewToDataMap data_;
166 167
167 // Makes from animation to view. 168 // Makes from animation to view.
168 AnimationToViewMap animation_to_view_; 169 AnimationToViewMap animation_to_view_;
169 170
170 // As the animations we created update (AnimationProgressed is invoked) this 171 // As the animations we created update (AnimationProgressed is invoked) this
171 // is updated. When all the animations have completed for a given tick of 172 // is updated. When all the animations have completed for a given tick of
172 // the timer (AnimationContainerProgressed is invoked) the parent_ is asked 173 // the timer (AnimationContainerProgressed is invoked) the parent_ is asked
173 // to repaint these bounds. 174 // to repaint these bounds.
174 gfx::Rect repaint_bounds_; 175 gfx::Rect repaint_bounds_;
175 176
176 DISALLOW_COPY_AND_ASSIGN(BoundsAnimator); 177 DISALLOW_COPY_AND_ASSIGN(BoundsAnimator);
177 }; 178 };
178 179
179 } // namespace views 180 } // namespace views
180 181
181 #endif // VIEWS_ANIMATION_BOUNDS_ANIMATOR_H_ 182 #endif // VIEWS_ANIMATION_BOUNDS_ANIMATOR_H_
OLDNEW
« no previous file with comments | « ui/ui.gyp ('k') | views/animation/bounds_animator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698