OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 #include "ui/gfx/compositor/layer_animator.h" | 5 #include "ui/gfx/compositor/layer_animation_manager.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "ui/base/animation/animation_container.h" | 9 #include "ui/base/animation/animation_container.h" |
10 #include "ui/base/animation/animation.h" | 10 #include "ui/base/animation/animation.h" |
11 #include "ui/base/animation/tween.h" | 11 #include "ui/base/animation/tween.h" |
12 #include "ui/gfx/compositor/compositor.h" | 12 #include "ui/gfx/compositor/compositor.h" |
13 #include "ui/gfx/compositor/layer.h" | 13 #include "ui/gfx/compositor/layer.h" |
14 #include "ui/gfx/compositor/layer_animator_delegate.h" | 14 #include "ui/gfx/compositor/layer_animator_delegate.h" |
15 #include "ui/gfx/transform.h" | 15 #include "ui/gfx/transform.h" |
(...skipping 10 matching lines...) Expand all Loading... |
26 SkMScalar GetMatrixElement(const SkMatrix44& matrix, int index) { | 26 SkMScalar GetMatrixElement(const SkMatrix44& matrix, int index) { |
27 int row = index / 4; | 27 int row = index / 4; |
28 int col = index % 4; | 28 int col = index % 4; |
29 return matrix.get(row, col); | 29 return matrix.get(row, col); |
30 } | 30 } |
31 | 31 |
32 } // anonymous namespace | 32 } // anonymous namespace |
33 | 33 |
34 namespace ui { | 34 namespace ui { |
35 | 35 |
36 LayerAnimator::LayerAnimator(Layer* layer) | 36 LayerAnimationManager::LayerAnimationManager(Layer* layer) |
37 : layer_(layer), | 37 : layer_(layer), |
38 got_initial_tick_(false) { | 38 got_initial_tick_(false) { |
39 } | 39 } |
40 | 40 |
41 LayerAnimator::~LayerAnimator() { | 41 LayerAnimationManager::~LayerAnimationManager() { |
42 } | 42 } |
43 | 43 |
44 void LayerAnimator::SetAnimation(Animation* animation) { | 44 void LayerAnimationManager::SetAnimation(Animation* animation) { |
45 animation_.reset(animation); | 45 animation_.reset(animation); |
46 if (animation_.get()) { | 46 if (animation_.get()) { |
47 static ui::AnimationContainer* container = NULL; | 47 static ui::AnimationContainer* container = NULL; |
48 if (!container) { | 48 if (!container) { |
49 container = new AnimationContainer; | 49 container = new AnimationContainer; |
50 container->AddRef(); | 50 container->AddRef(); |
51 } | 51 } |
52 animation_->set_delegate(this); | 52 animation_->set_delegate(this); |
53 animation_->SetContainer(container); | 53 animation_->SetContainer(container); |
54 got_initial_tick_ = false; | 54 got_initial_tick_ = false; |
55 } | 55 } |
56 } | 56 } |
57 | 57 |
58 void LayerAnimator::AnimateToPoint(const gfx::Point& target) { | 58 void LayerAnimationManager::AnimateToPoint(const gfx::Point& target) { |
59 StopAnimating(LOCATION); | 59 StopAnimating(LOCATION); |
60 const gfx::Rect& layer_bounds = layer_->bounds(); | 60 const gfx::Rect& layer_bounds = layer_->bounds(); |
61 if (target == layer_bounds.origin()) | 61 if (target == layer_bounds.origin()) |
62 return; // Already there. | 62 return; // Already there. |
63 | 63 |
64 Params& element = elements_[LOCATION]; | 64 Params& element = elements_[LOCATION]; |
65 element.location.target_x = target.x(); | 65 element.location.target_x = target.x(); |
66 element.location.target_y = target.y(); | 66 element.location.target_y = target.y(); |
67 element.location.start_x = layer_bounds.origin().x(); | 67 element.location.start_x = layer_bounds.origin().x(); |
68 element.location.start_y = layer_bounds.origin().y(); | 68 element.location.start_y = layer_bounds.origin().y(); |
69 } | 69 } |
70 | 70 |
71 void LayerAnimator::AnimateTransform(const Transform& transform) { | 71 void LayerAnimationManager::AnimateTransform(const Transform& transform) { |
72 StopAnimating(TRANSFORM); | 72 StopAnimating(TRANSFORM); |
73 const Transform& layer_transform = layer_->transform(); | 73 const Transform& layer_transform = layer_->transform(); |
74 if (transform == layer_transform) | 74 if (transform == layer_transform) |
75 return; // Already there. | 75 return; // Already there. |
76 | 76 |
77 Params& element = elements_[TRANSFORM]; | 77 Params& element = elements_[TRANSFORM]; |
78 for (int i = 0; i < 16; ++i) { | 78 for (int i = 0; i < 16; ++i) { |
79 element.transform.start[i] = | 79 element.transform.start[i] = |
80 GetMatrixElement(layer_transform.matrix(), i); | 80 GetMatrixElement(layer_transform.matrix(), i); |
81 element.transform.target[i] = | 81 element.transform.target[i] = |
82 GetMatrixElement(transform.matrix(), i); | 82 GetMatrixElement(transform.matrix(), i); |
83 } | 83 } |
84 } | 84 } |
85 | 85 |
86 void LayerAnimator::AnimateOpacity(float target_opacity) { | 86 void LayerAnimationManager::AnimateOpacity(float target_opacity) { |
87 StopAnimating(OPACITY); | 87 StopAnimating(OPACITY); |
88 if (layer_->opacity() == target_opacity) | 88 if (layer_->opacity() == target_opacity) |
89 return; | 89 return; |
90 | 90 |
91 Params& element = elements_[OPACITY]; | 91 Params& element = elements_[OPACITY]; |
92 element.opacity.start = layer_->opacity(); | 92 element.opacity.start = layer_->opacity(); |
93 element.opacity.target = target_opacity; | 93 element.opacity.target = target_opacity; |
94 } | 94 } |
95 | 95 |
96 gfx::Point LayerAnimator::GetTargetPoint() { | 96 gfx::Point LayerAnimationManager::GetTargetPoint() { |
97 return IsAnimating(LOCATION) ? | 97 return IsAnimating(LOCATION) ? |
98 gfx::Point(elements_[LOCATION].location.target_x, | 98 gfx::Point(elements_[LOCATION].location.target_x, |
99 elements_[LOCATION].location.target_y) : | 99 elements_[LOCATION].location.target_y) : |
100 layer_->bounds().origin(); | 100 layer_->bounds().origin(); |
101 } | 101 } |
102 | 102 |
103 float LayerAnimator::GetTargetOpacity() { | 103 float LayerAnimationManager::GetTargetOpacity() { |
104 return IsAnimating(OPACITY) ? | 104 return IsAnimating(OPACITY) ? |
105 elements_[OPACITY].opacity.target : layer_->opacity(); | 105 elements_[OPACITY].opacity.target : layer_->opacity(); |
106 } | 106 } |
107 | 107 |
108 ui::Transform LayerAnimator::GetTargetTransform() { | 108 ui::Transform LayerAnimationManager::GetTargetTransform() { |
109 if (IsAnimating(TRANSFORM)) { | 109 if (IsAnimating(TRANSFORM)) { |
110 Transform transform; | 110 Transform transform; |
111 for (int i = 0; i < 16; ++i) { | 111 for (int i = 0; i < 16; ++i) { |
112 SetMatrixElement(transform.matrix(), i, | 112 SetMatrixElement(transform.matrix(), i, |
113 elements_[TRANSFORM].transform.target[i]); | 113 elements_[TRANSFORM].transform.target[i]); |
114 } | 114 } |
115 return transform; | 115 return transform; |
116 } | 116 } |
117 return layer_->transform(); | 117 return layer_->transform(); |
118 } | 118 } |
119 | 119 |
120 bool LayerAnimator::IsAnimating(AnimationProperty property) const { | 120 bool LayerAnimationManager::IsAnimating(AnimationProperty property) const { |
121 return elements_.count(property) > 0; | 121 return elements_.count(property) > 0; |
122 } | 122 } |
123 | 123 |
124 bool LayerAnimator::IsRunning() const { | 124 bool LayerAnimationManager::IsRunning() const { |
125 return animation_.get() && animation_->is_animating(); | 125 return animation_.get() && animation_->is_animating(); |
126 } | 126 } |
127 | 127 |
128 void LayerAnimator::AnimationProgressed(const ui::Animation* animation) { | 128 void LayerAnimationManager::AnimationProgressed( |
| 129 const ui::Animation* animation) { |
129 got_initial_tick_ = true; | 130 got_initial_tick_ = true; |
130 for (Elements::const_iterator i = elements_.begin(); i != elements_.end(); | 131 for (Elements::const_iterator i = elements_.begin(); i != elements_.end(); |
131 ++i) { | 132 ++i) { |
132 switch (i->first) { | 133 switch (i->first) { |
133 case LOCATION: { | 134 case LOCATION: { |
134 const gfx::Rect& current_bounds(layer_->bounds()); | 135 const gfx::Rect& current_bounds(layer_->bounds()); |
135 gfx::Rect new_bounds = animation_->CurrentValueBetween( | 136 gfx::Rect new_bounds = animation_->CurrentValueBetween( |
136 gfx::Rect(gfx::Point(i->second.location.start_x, | 137 gfx::Rect(gfx::Point(i->second.location.start_x, |
137 i->second.location.start_y), | 138 i->second.location.start_y), |
138 current_bounds.size()), | 139 current_bounds.size()), |
(...skipping 22 matching lines...) Expand all Loading... |
161 break; | 162 break; |
162 } | 163 } |
163 | 164 |
164 default: | 165 default: |
165 NOTREACHED(); | 166 NOTREACHED(); |
166 } | 167 } |
167 } | 168 } |
168 layer_->ScheduleDraw(); | 169 layer_->ScheduleDraw(); |
169 } | 170 } |
170 | 171 |
171 void LayerAnimator::AnimationEnded(const ui::Animation* animation) { | 172 void LayerAnimationManager::AnimationEnded(const ui::Animation* animation) { |
172 AnimationProgressed(animation); | 173 AnimationProgressed(animation); |
173 if (layer_->delegate()) | |
174 layer_->delegate()->OnLayerAnimationEnded(animation); | |
175 } | 174 } |
176 | 175 |
177 void LayerAnimator::StopAnimating(AnimationProperty property) { | 176 void LayerAnimationManager::StopAnimating(AnimationProperty property) { |
178 if (!IsAnimating(property)) | 177 if (!IsAnimating(property)) |
179 return; | 178 return; |
180 | 179 |
181 elements_.erase(property); | 180 elements_.erase(property); |
182 } | 181 } |
183 | 182 |
184 LayerAnimatorDelegate* LayerAnimator::delegate() { | 183 LayerAnimatorDelegate* LayerAnimationManager::delegate() { |
185 return static_cast<LayerAnimatorDelegate*>(layer_); | 184 return static_cast<LayerAnimatorDelegate*>(layer_); |
186 } | 185 } |
187 | 186 |
188 } // namespace ui | 187 } // namespace ui |
OLD | NEW |