OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/views/animation/ink_drop_animation.h" | 5 #include "ui/views/animation/ink_drop_animation.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "third_party/skia/include/core/SkColor.h" | 11 #include "third_party/skia/include/core/SkColor.h" |
12 #include "ui/base/ui_base_switches.h" | 12 #include "ui/base/ui_base_switches.h" |
13 #include "ui/compositor/callback_layer_animation_observer.h" | 13 #include "ui/compositor/callback_layer_animation_observer.h" |
14 #include "ui/compositor/layer.h" | 14 #include "ui/compositor/layer.h" |
15 #include "ui/compositor/layer_animation_sequence.h" | 15 #include "ui/compositor/layer_animation_sequence.h" |
16 #include "ui/compositor/scoped_layer_animation_settings.h" | 16 #include "ui/compositor/scoped_layer_animation_settings.h" |
17 #include "ui/gfx/geometry/point3_f.h" | |
17 #include "ui/gfx/geometry/point_conversions.h" | 18 #include "ui/gfx/geometry/point_conversions.h" |
19 #include "ui/gfx/geometry/point_f.h" | |
20 #include "ui/gfx/geometry/vector3d_f.h" | |
18 #include "ui/gfx/transform_util.h" | 21 #include "ui/gfx/transform_util.h" |
19 #include "ui/views/animation/ink_drop_animation_observer.h" | 22 #include "ui/views/animation/ink_drop_animation_observer.h" |
20 #include "ui/views/animation/ink_drop_painted_layer_delegates.h" | 23 #include "ui/views/animation/ink_drop_painted_layer_delegates.h" |
21 #include "ui/views/view.h" | 24 #include "ui/views/view.h" |
22 | 25 |
23 namespace { | 26 namespace { |
24 | 27 |
25 // The minimum scale factor to use when scaling rectangle layers. Smaller values | 28 // The minimum scale factor to use when scaling rectangle layers. Smaller values |
26 // were causing visual anomalies. | 29 // were causing visual anomalies. |
27 const float kMinimumRectScale = 0.0001f; | 30 const float kMinimumRectScale = 0.0001f; |
28 | 31 |
29 // The minimum scale factor to use when scaling circle layers. Smaller values | 32 // The minimum scale factor to use when scaling circle layers. Smaller values |
30 // were causing visual anomalies. | 33 // were causing visual anomalies. |
31 const float kMinimumCircleScale = 0.001f; | 34 const float kMinimumCircleScale = 0.001f; |
32 | 35 |
33 // The ink drop color. | 36 // The ink drop color. |
34 const SkColor kInkDropColor = SK_ColorBLACK; | 37 const SkColor kInkDropColor = SK_ColorBLACK; |
35 | 38 |
36 // The opacity of the ink drop when it is visible. | 39 // All the sub animations that are used to animate each of the InkDropStates. |
37 const float kVisibleOpacity = 0.14f; | 40 // These are used to get time durations with |
41 // GetAnimationDuration(InkDropSubAnimations). Note that in general a sub | |
42 // animation defines the duration for either a transformation animation or an | |
43 // opacity animation but there are some exceptions where an entire InkDropState | |
44 // animation consists of only 1 sub animation and it defines the duration for | |
45 // both the transformation and opacity animations. | |
46 enum InkDropSubAnimations { | |
47 // HIDDEN sub animations. | |
38 | 48 |
39 // The opacity of the ink drop when it is not visible. | 49 // The HIDDEN sub animation that is fading out to a hidden opacity. |
40 const float kHiddenOpacity = 0.0f; | 50 HIDDEN_FADE_OUT, |
41 | 51 |
42 // Durations for the different InkDropState animations in milliseconds. | 52 // The HIDDEN sub animation that transforms the shape to a |small_size_| |
43 const int kHiddenStateAnimationDurationMs = 1; | 53 // circle. |
44 const int kActionPendingStateAnimationDurationMs = 500; | 54 HIDDEN_TRANSFORM, |
45 const int kQuickActionStateAnimationDurationMs = 250; | 55 |
46 const int kSlowActionPendingStateAnimationDurationMs = 500; | 56 // ACTION_PENDING sub animations. |
47 const int kSlowActionStateAnimationDurationMs = 250; | 57 |
48 const int kActivatedStateAnimationDurationMs = 125; | 58 // The ACTION_PENDING sub animation that fades in to the visible opacity. |
49 const int kDeactivatedStateAnimationDurationMs = 250; | 59 ACTION_PENDING_FADE_IN, |
60 | |
61 // The ACTION_PENDING sub animation that transforms the shape to a | |
62 // |large_size_| circle. | |
63 ACTION_PENDING_TRANSFORM, | |
64 | |
65 // QUICK_ACTION sub animations. | |
66 | |
67 // The QUICK_ACTION sub animation that is fading out to a hidden opacity. | |
68 QUICK_ACTION_FADE_OUT, | |
69 | |
70 // The QUICK_ACTION sub animation that transforms the shape to a |large_size_| | |
71 // circle. | |
72 QUICK_ACTION_TRANSFORM, | |
73 | |
74 // SLOW_ACTION_PENDING sub animations. | |
75 | |
76 // The SLOW_ACTION_PENDING animation has only one sub animation which animates | |
77 // to a |small_size_| rounded rectangle at visible opacity. | |
78 SLOW_ACTION_PENDING, | |
79 | |
80 // SLOW_ACTION sub animations. | |
81 | |
82 // The SLOW_ACTION sub animation that is fading out to a hidden opacity. | |
83 SLOW_ACTION_FADE_OUT, | |
84 | |
85 // The SLOW_ACTION sub animation that transforms the shape to a |large_size_| | |
86 // rounded rectangle. | |
87 SLOW_ACTION_TRANSFORM, | |
88 | |
89 // ACTIVATED sub animations. | |
90 | |
91 // The ACTIVATED sub animation that transforms the shape to a |large_size_| | |
92 // circle. This is used when the ink drop is in a HIDDEN state prior to | |
93 // animating to the ACTIVATED state. | |
94 ACTIVATED_CIRCLE_TRANSFORM, | |
95 | |
96 // The ACTIVATED sub animation that transforms the shape to a |small_size_| | |
97 // rounded rectangle. | |
98 ACTIVATED_RECT_TRANSFORM, | |
99 | |
100 // DEACTIVATED sub animations. | |
101 | |
102 // The DEACTIVATED sub animation that is fading out to a hidden opacity. | |
103 DEACTIVATED_FADE_OUT, | |
104 | |
105 // The DEACTIVATED sub animation that transforms the shape to a |large_size_| | |
106 // rounded rectangle. | |
107 DEACTIVATED_TRANSFORM, | |
108 }; | |
109 | |
110 // The scale factor used to burst the QUICK_ACTION bubble as it fades out. | |
111 const float kQuickActionBurstScale = 1.3f; | |
50 | 112 |
51 // A multiplicative factor used to slow down InkDropState animations. | 113 // A multiplicative factor used to slow down InkDropState animations. |
52 const int kSlowAnimationDurationFactor = 3; | 114 const int kSlowAnimationDurationFactor = 3; |
53 | 115 |
54 // Checks CommandLine switches to determine if the visual feedback should have | 116 // Checks CommandLine switches to determine if the visual feedback should have |
55 // a fast animations speed. | 117 // a fast animations speed. |
56 bool UseFastAnimations() { | 118 bool UseFastAnimations() { |
57 static bool fast = | 119 static bool fast = |
58 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 120 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
59 (::switches::kMaterialDesignInkDropAnimationSpeed)) != | 121 (::switches::kMaterialDesignInkDropAnimationSpeed)) != |
60 ::switches::kMaterialDesignInkDropAnimationSpeedSlow; | 122 ::switches::kMaterialDesignInkDropAnimationSpeedSlow; |
61 return fast; | 123 return fast; |
62 } | 124 } |
63 | 125 |
64 // Returns the InkDropState animation duration for the given |state|. | 126 // Duration constants for InkDropStateSubAnimations. See the |
65 base::TimeDelta GetAnimationDuration(views::InkDropState state) { | 127 // InkDropStateSubAnimations enum documentation for more info. |
66 int duration = 0; | 128 int kDurationTableInMs[] = { |
varkha
2016/01/29 00:11:59
nit: I think kAnimationDurationInMs[idx] would be
bruthig
2016/01/29 15:27:09
Done.
| |
67 switch (state) { | 129 150, // HIDDEN_FADE_OUT |
68 case views::InkDropState::HIDDEN: | 130 200, // HIDDEN_TRANSFORM |
69 duration = kHiddenStateAnimationDurationMs; | 131 0, // ACTION_PENDING_FADE_IN |
70 break; | 132 160, // ACTION_PENDING_TRANSFORM |
71 case views::InkDropState::ACTION_PENDING: | 133 150, // QUICK_ACTION_FADE_OUT |
72 duration = kActionPendingStateAnimationDurationMs; | 134 160, // QUICK_ACTION_TRANSFORM |
73 break; | 135 200, // SLOW_ACTION_PENDING |
74 case views::InkDropState::QUICK_ACTION: | 136 150, // SLOW_ACTION_FADE_OUT |
75 duration = kQuickActionStateAnimationDurationMs; | 137 200, // SLOW_ACTION_TRANSFORM |
76 break; | 138 200, // ACTIVATED_CIRCLE_TRANSFORM |
77 case views::InkDropState::SLOW_ACTION_PENDING: | 139 160, // ACTIVATED_RECT_TRANSFORM |
78 duration = kSlowActionPendingStateAnimationDurationMs; | 140 150, // DEACTIVATED_FADE_OUT |
79 break; | 141 200, // DEACTIVATED_TRANSFORM |
80 case views::InkDropState::SLOW_ACTION: | 142 }; |
81 duration = kSlowActionStateAnimationDurationMs; | |
82 break; | |
83 case views::InkDropState::ACTIVATED: | |
84 duration = kActivatedStateAnimationDurationMs; | |
85 break; | |
86 case views::InkDropState::DEACTIVATED: | |
87 duration = kDeactivatedStateAnimationDurationMs; | |
88 break; | |
89 } | |
90 | 143 |
144 // Returns the InkDropState sub animation duration for the given |state|. | |
145 base::TimeDelta GetAnimationDuration(InkDropSubAnimations state) { | |
91 return base::TimeDelta::FromMilliseconds( | 146 return base::TimeDelta::FromMilliseconds( |
92 (UseFastAnimations() ? 1 : kSlowAnimationDurationFactor) * duration); | 147 (UseFastAnimations() ? 1 : kSlowAnimationDurationFactor) * |
148 kDurationTableInMs[state]); | |
93 } | 149 } |
94 | 150 |
95 // Calculates a Transform for a circle layer. The transform will be set up to | 151 // Calculates a Transform for a circle layer. The transform will be set up to |
96 // translate the |drawn_center_point| to the origin, scale, and then translate | 152 // translate the |drawn_center_point| to the origin, scale, and then translate |
97 // to the target point defined by |target_center_x| and |target_center_y|. | 153 // to the target point defined by |target_center_x| and |target_center_y|. |
98 gfx::Transform CalculateCircleTransform(const gfx::Point& drawn_center_point, | 154 gfx::Transform CalculateCircleTransform(const gfx::Point& drawn_center_point, |
99 float scale, | 155 float scale, |
100 float target_center_x, | 156 float target_center_x, |
101 float target_center_y) { | 157 float target_center_y) { |
102 gfx::Transform transform; | 158 gfx::Transform transform; |
(...skipping 12 matching lines...) Expand all Loading... | |
115 gfx::Transform transform; | 171 gfx::Transform transform; |
116 transform.Scale(x_scale, y_scale); | 172 transform.Scale(x_scale, y_scale); |
117 transform.Translate(-drawn_center_point.x(), -drawn_center_point.y()); | 173 transform.Translate(-drawn_center_point.x(), -drawn_center_point.y()); |
118 return transform; | 174 return transform; |
119 } | 175 } |
120 | 176 |
121 } // namespace | 177 } // namespace |
122 | 178 |
123 namespace views { | 179 namespace views { |
124 | 180 |
181 const float InkDropAnimation::kVisibleOpacity = 0.11f; | |
182 const float InkDropAnimation::kHiddenOpacity = 0.0f; | |
183 | |
125 InkDropAnimation::InkDropAnimation(const gfx::Size& large_size, | 184 InkDropAnimation::InkDropAnimation(const gfx::Size& large_size, |
126 int large_corner_radius, | 185 int large_corner_radius, |
127 const gfx::Size& small_size, | 186 const gfx::Size& small_size, |
128 int small_corner_radius) | 187 int small_corner_radius) |
129 : large_size_(large_size), | 188 : large_size_(large_size), |
130 large_corner_radius_(large_corner_radius), | 189 large_corner_radius_(large_corner_radius), |
131 small_size_(small_size), | 190 small_size_(small_size), |
132 small_corner_radius_(small_corner_radius), | 191 small_corner_radius_(small_corner_radius), |
133 circle_layer_delegate_(new CircleLayerDelegate( | 192 circle_layer_delegate_(new CircleLayerDelegate( |
134 kInkDropColor, | 193 kInkDropColor, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 AnimateToStateInternal(ink_drop_state, animation_observer); | 233 AnimateToStateInternal(ink_drop_state, animation_observer); |
175 animation_observer->SetActive(); | 234 animation_observer->SetActive(); |
176 } | 235 } |
177 | 236 |
178 void InkDropAnimation::SetCenterPoint(const gfx::Point& center_point) { | 237 void InkDropAnimation::SetCenterPoint(const gfx::Point& center_point) { |
179 gfx::Transform transform; | 238 gfx::Transform transform; |
180 transform.Translate(center_point.x(), center_point.y()); | 239 transform.Translate(center_point.x(), center_point.y()); |
181 root_layer_->SetTransform(transform); | 240 root_layer_->SetTransform(transform); |
182 } | 241 } |
183 | 242 |
243 void InkDropAnimation::HideImmediately() { | |
244 AbortAllAnimations(); | |
245 SetStateToHidden(); | |
246 ink_drop_state_ = InkDropState::HIDDEN; | |
247 } | |
248 | |
184 std::string InkDropAnimation::ToLayerName(PaintedShape painted_shape) { | 249 std::string InkDropAnimation::ToLayerName(PaintedShape painted_shape) { |
185 switch (painted_shape) { | 250 switch (painted_shape) { |
186 case TOP_LEFT_CIRCLE: | 251 case TOP_LEFT_CIRCLE: |
187 return "TOP_LEFT_CIRCLE"; | 252 return "TOP_LEFT_CIRCLE"; |
188 case TOP_RIGHT_CIRCLE: | 253 case TOP_RIGHT_CIRCLE: |
189 return "TOP_RIGHT_CIRCLE"; | 254 return "TOP_RIGHT_CIRCLE"; |
190 case BOTTOM_RIGHT_CIRCLE: | 255 case BOTTOM_RIGHT_CIRCLE: |
191 return "BOTTOM_RIGHT_CIRCLE"; | 256 return "BOTTOM_RIGHT_CIRCLE"; |
192 case BOTTOM_LEFT_CIRCLE: | 257 case BOTTOM_LEFT_CIRCLE: |
193 return "BOTTOM_LEFT_CIRCLE"; | 258 return "BOTTOM_LEFT_CIRCLE"; |
194 case HORIZONTAL_RECT: | 259 case HORIZONTAL_RECT: |
195 return "HORIZONTAL_RECT"; | 260 return "HORIZONTAL_RECT"; |
196 case VERTICAL_RECT: | 261 case VERTICAL_RECT: |
197 return "VERTICAL_RECT"; | 262 return "VERTICAL_RECT"; |
198 case PAINTED_SHAPE_COUNT: | 263 case PAINTED_SHAPE_COUNT: |
199 NOTREACHED() << "The PAINTED_SHAPE_COUNT value should never be used."; | 264 NOTREACHED() << "The PAINTED_SHAPE_COUNT value should never be used."; |
200 return "PAINTED_SHAPE_COUNT"; | 265 return "PAINTED_SHAPE_COUNT"; |
201 } | 266 } |
202 return "UNKNOWN"; | 267 return "UNKNOWN"; |
203 } | 268 } |
204 | 269 |
205 void InkDropAnimation::AnimateToStateInternal( | 270 void InkDropAnimation::AnimateToStateInternal( |
206 InkDropState ink_drop_state, | 271 InkDropState ink_drop_state, |
207 ui::LayerAnimationObserver* animation_observer) { | 272 ui::LayerAnimationObserver* animation_observer) { |
273 InkDropState previous_ink_drop_state = ink_drop_state_; | |
208 ink_drop_state_ = ink_drop_state; | 274 ink_drop_state_ = ink_drop_state; |
209 | 275 |
210 if (ink_drop_state_ == InkDropState::HIDDEN) { | |
211 // Animating to the HIDDEN state doesn't actually use any | |
212 // LayerAnimationSequences so we need to explicitly abort any running ones | |
213 // so that observers receive an InkDropAnimationEnded() event for the | |
214 // running animation prior to receiving an InkDropAnimationStarted() event | |
215 // for the HIDDEN 'animation'. | |
216 AbortAllAnimations(); | |
217 root_layer_->SetVisible(false); | |
218 SetStateToHidden(); | |
219 return; | |
220 } | |
221 | |
222 InkDropTransforms transforms; | 276 InkDropTransforms transforms; |
223 root_layer_->SetVisible(true); | 277 root_layer_->SetVisible(true); |
224 | 278 |
225 switch (ink_drop_state_) { | 279 switch (ink_drop_state_) { |
226 case InkDropState::HIDDEN: | 280 case InkDropState::HIDDEN: |
227 // This case is handled above in a short circuit return. | 281 if (GetCurrentOpacity() == kHiddenOpacity) { |
282 AbortAllAnimations(); | |
283 break; | |
284 } else { | |
285 AnimateToOpacity(kHiddenOpacity, GetAnimationDuration(HIDDEN_FADE_OUT), | |
286 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | |
287 gfx::Tween::EASE_IN_OUT, animation_observer); | |
288 CalculateCircleTransforms(small_size_, &transforms); | |
289 AnimateToTransforms( | |
290 transforms, GetAnimationDuration(HIDDEN_TRANSFORM), | |
291 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | |
292 gfx::Tween::EASE_IN_OUT, animation_observer); | |
293 } | |
228 break; | 294 break; |
229 case InkDropState::ACTION_PENDING: | 295 case InkDropState::ACTION_PENDING: |
296 DCHECK(previous_ink_drop_state == InkDropState::HIDDEN); | |
297 AnimateToOpacity(kVisibleOpacity, | |
298 GetAnimationDuration(ACTION_PENDING_FADE_IN), | |
299 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | |
300 gfx::Tween::EASE_IN, animation_observer); | |
301 AnimateToOpacity(kVisibleOpacity, | |
302 GetAnimationDuration(ACTION_PENDING_TRANSFORM), | |
303 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | |
304 gfx::Tween::EASE_IN, animation_observer); | |
230 CalculateCircleTransforms(large_size_, &transforms); | 305 CalculateCircleTransforms(large_size_, &transforms); |
231 AnimateToTransforms(transforms, kVisibleOpacity, | 306 AnimateToTransforms(transforms, |
232 GetAnimationDuration(InkDropState::ACTION_PENDING), | 307 GetAnimationDuration(ACTION_PENDING_TRANSFORM), |
233 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | 308 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, |
234 animation_observer); | 309 gfx::Tween::EASE_IN_OUT, animation_observer); |
235 break; | 310 break; |
236 case InkDropState::QUICK_ACTION: | 311 case InkDropState::QUICK_ACTION: { |
237 CalculateCircleTransforms(large_size_, &transforms); | 312 DCHECK(previous_ink_drop_state == InkDropState::HIDDEN || |
238 AnimateToTransforms(transforms, kHiddenOpacity, | 313 previous_ink_drop_state == InkDropState::ACTION_PENDING); |
239 GetAnimationDuration(InkDropState::QUICK_ACTION), | 314 AnimateToOpacity(kHiddenOpacity, |
315 GetAnimationDuration(QUICK_ACTION_FADE_OUT), | |
316 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION, | |
317 gfx::Tween::EASE_IN_OUT, animation_observer); | |
318 gfx::Size s = ScaleToRoundedSize(large_size_, kQuickActionBurstScale); | |
319 CalculateCircleTransforms(s, &transforms); | |
320 AnimateToTransforms(transforms, | |
321 GetAnimationDuration(QUICK_ACTION_TRANSFORM), | |
322 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION, | |
323 gfx::Tween::EASE_IN_OUT, animation_observer); | |
324 break; | |
325 } | |
326 case InkDropState::SLOW_ACTION_PENDING: | |
327 DCHECK(previous_ink_drop_state == InkDropState::ACTION_PENDING); | |
328 AnimateToOpacity(kVisibleOpacity, | |
329 GetAnimationDuration(SLOW_ACTION_PENDING), | |
330 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | |
331 gfx::Tween::EASE_IN, animation_observer); | |
332 CalculateRectTransforms(small_size_, small_corner_radius_, &transforms); | |
333 AnimateToTransforms(transforms, GetAnimationDuration(SLOW_ACTION_PENDING), | |
240 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | 334 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, |
241 animation_observer); | 335 gfx::Tween::EASE_IN_OUT, animation_observer); |
242 break; | 336 break; |
243 case InkDropState::SLOW_ACTION_PENDING: | 337 case InkDropState::SLOW_ACTION: { |
338 DCHECK(previous_ink_drop_state == InkDropState::SLOW_ACTION_PENDING); | |
339 base::TimeDelta visible_duration = | |
340 GetAnimationDuration(SLOW_ACTION_TRANSFORM) - | |
341 GetAnimationDuration(SLOW_ACTION_FADE_OUT); | |
342 AnimateToOpacity(kVisibleOpacity, visible_duration, | |
343 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | |
344 gfx::Tween::EASE_IN_OUT, animation_observer); | |
345 AnimateToOpacity(kHiddenOpacity, | |
346 GetAnimationDuration(SLOW_ACTION_FADE_OUT), | |
347 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION, | |
348 gfx::Tween::EASE_IN_OUT, animation_observer); | |
349 CalculateRectTransforms(large_size_, large_corner_radius_, &transforms); | |
350 AnimateToTransforms(transforms, | |
351 GetAnimationDuration(SLOW_ACTION_TRANSFORM), | |
352 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | |
353 gfx::Tween::EASE_IN_OUT, animation_observer); | |
354 break; | |
355 } | |
356 case InkDropState::ACTIVATED: { | |
357 // Animate the opacity so that it cancels any opacity animations already | |
358 // in progress. | |
359 AnimateToOpacity(kVisibleOpacity, base::TimeDelta(), | |
360 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | |
361 gfx::Tween::EASE_IN_OUT, animation_observer); | |
362 | |
363 ui::LayerAnimator::PreemptionStrategy rect_transform_preemption_strategy = | |
364 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET; | |
365 if (previous_ink_drop_state == InkDropState::HIDDEN) { | |
366 rect_transform_preemption_strategy = | |
367 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION; | |
368 CalculateCircleTransforms(large_size_, &transforms); | |
369 AnimateToTransforms( | |
370 transforms, GetAnimationDuration(ACTIVATED_CIRCLE_TRANSFORM), | |
371 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | |
372 gfx::Tween::EASE_IN_OUT, animation_observer); | |
373 } else if (previous_ink_drop_state == InkDropState::ACTION_PENDING) { | |
374 rect_transform_preemption_strategy = | |
375 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION; | |
376 } | |
377 | |
244 CalculateRectTransforms(small_size_, small_corner_radius_, &transforms); | 378 CalculateRectTransforms(small_size_, small_corner_radius_, &transforms); |
245 AnimateToTransforms( | 379 AnimateToTransforms(transforms, |
246 transforms, kVisibleOpacity, | 380 GetAnimationDuration(ACTIVATED_RECT_TRANSFORM), |
247 GetAnimationDuration(InkDropState::SLOW_ACTION_PENDING), | 381 rect_transform_preemption_strategy, |
248 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | 382 gfx::Tween::EASE_IN_OUT, animation_observer); |
249 animation_observer); | |
250 break; | 383 break; |
251 case InkDropState::SLOW_ACTION: | 384 } |
385 case InkDropState::DEACTIVATED: { | |
386 base::TimeDelta visible_duration = | |
387 GetAnimationDuration(DEACTIVATED_TRANSFORM) - | |
388 GetAnimationDuration(DEACTIVATED_FADE_OUT); | |
389 AnimateToOpacity(kVisibleOpacity, visible_duration, | |
390 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | |
391 gfx::Tween::EASE_IN_OUT, animation_observer); | |
252 CalculateRectTransforms(large_size_, large_corner_radius_, &transforms); | 392 CalculateRectTransforms(large_size_, large_corner_radius_, &transforms); |
253 AnimateToTransforms(transforms, kHiddenOpacity, | 393 AnimateToOpacity(kHiddenOpacity, |
254 GetAnimationDuration(InkDropState::SLOW_ACTION), | 394 GetAnimationDuration(DEACTIVATED_FADE_OUT), |
395 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION, | |
396 gfx::Tween::EASE_IN_OUT, animation_observer); | |
397 CalculateRectTransforms(large_size_, large_corner_radius_, &transforms); | |
398 AnimateToTransforms(transforms, | |
399 GetAnimationDuration(DEACTIVATED_TRANSFORM), | |
255 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | 400 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, |
256 animation_observer); | 401 gfx::Tween::EASE_IN_OUT, animation_observer); |
257 break; | 402 break; |
258 case InkDropState::ACTIVATED: | 403 } |
259 CalculateRectTransforms(small_size_, small_corner_radius_, &transforms); | |
260 AnimateToTransforms(transforms, kVisibleOpacity, | |
261 GetAnimationDuration(InkDropState::ACTIVATED), | |
262 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | |
263 animation_observer); | |
264 break; | |
265 case InkDropState::DEACTIVATED: | |
266 CalculateRectTransforms(large_size_, large_corner_radius_, &transforms); | |
267 AnimateToTransforms(transforms, kHiddenOpacity, | |
268 GetAnimationDuration(InkDropState::DEACTIVATED), | |
269 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | |
270 animation_observer); | |
271 break; | |
272 } | 404 } |
273 } | 405 } |
274 | 406 |
275 void InkDropAnimation::AnimateToTransforms( | 407 void InkDropAnimation::AnimateToTransforms( |
276 const InkDropTransforms transforms, | 408 const InkDropTransforms transforms, |
277 float opacity, | |
278 base::TimeDelta duration, | 409 base::TimeDelta duration, |
279 ui::LayerAnimator::PreemptionStrategy preemption_strategy, | 410 ui::LayerAnimator::PreemptionStrategy preemption_strategy, |
411 gfx::Tween::Type tween, | |
280 ui::LayerAnimationObserver* animation_observer) { | 412 ui::LayerAnimationObserver* animation_observer) { |
281 ui::LayerAnimator* root_animator = root_layer_->GetAnimator(); | |
282 ui::ScopedLayerAnimationSettings root_animation(root_animator); | |
283 root_animation.SetPreemptionStrategy(preemption_strategy); | |
284 ui::LayerAnimationElement* root_element = | |
285 ui::LayerAnimationElement::CreateOpacityElement(opacity, duration); | |
286 ui::LayerAnimationSequence* root_sequence = | |
287 new ui::LayerAnimationSequence(root_element); | |
288 | |
289 if (animation_observer) | |
290 root_sequence->AddObserver(animation_observer); | |
291 | |
292 root_animator->StartAnimation(root_sequence); | |
293 | |
294 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) { | 413 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) { |
295 ui::LayerAnimator* animator = painted_layers_[i]->GetAnimator(); | 414 ui::LayerAnimator* animator = painted_layers_[i]->GetAnimator(); |
296 ui::ScopedLayerAnimationSettings animation(animator); | 415 ui::ScopedLayerAnimationSettings animation(animator); |
297 animation.SetPreemptionStrategy(preemption_strategy); | 416 animation.SetPreemptionStrategy(preemption_strategy); |
417 animation.SetTweenType(tween); | |
298 ui::LayerAnimationElement* element = | 418 ui::LayerAnimationElement* element = |
299 ui::LayerAnimationElement::CreateTransformElement(transforms[i], | 419 ui::LayerAnimationElement::CreateTransformElement(transforms[i], |
300 duration); | 420 duration); |
301 ui::LayerAnimationSequence* sequence = | 421 ui::LayerAnimationSequence* sequence = |
302 new ui::LayerAnimationSequence(element); | 422 new ui::LayerAnimationSequence(element); |
303 | 423 |
304 if (animation_observer) | 424 if (animation_observer) |
305 sequence->AddObserver(animation_observer); | 425 sequence->AddObserver(animation_observer); |
306 | 426 |
307 animator->StartAnimation(sequence); | 427 animator->StartAnimation(sequence); |
308 } | 428 } |
309 } | 429 } |
310 | 430 |
311 void InkDropAnimation::SetStateToHidden() { | 431 void InkDropAnimation::SetStateToHidden() { |
312 InkDropTransforms transforms; | 432 InkDropTransforms transforms; |
313 // Using a size of 0x0 creates visual anomalies. | 433 // Using a size of 0x0 creates visual anomalies. |
314 CalculateCircleTransforms(gfx::Size(1, 1), &transforms); | 434 CalculateCircleTransforms(gfx::Size(1, 1), &transforms); |
315 SetTransforms(transforms); | 435 SetTransforms(transforms); |
316 SetOpacity(kHiddenOpacity); | 436 SetOpacity(kHiddenOpacity); |
437 root_layer_->SetVisible(false); | |
317 } | 438 } |
318 | 439 |
319 void InkDropAnimation::SetTransforms(const InkDropTransforms transforms) { | 440 void InkDropAnimation::SetTransforms(const InkDropTransforms transforms) { |
320 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) | 441 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) |
321 painted_layers_[i]->SetTransform(transforms[i]); | 442 painted_layers_[i]->SetTransform(transforms[i]); |
322 } | 443 } |
323 | 444 |
445 float InkDropAnimation::GetCurrentOpacity() const { | |
446 return root_layer_->opacity(); | |
447 } | |
448 | |
324 void InkDropAnimation::SetOpacity(float opacity) { | 449 void InkDropAnimation::SetOpacity(float opacity) { |
325 root_layer_->SetOpacity(opacity); | 450 root_layer_->SetOpacity(opacity); |
326 } | 451 } |
327 | 452 |
453 void InkDropAnimation::AnimateToOpacity( | |
454 float opacity, | |
455 base::TimeDelta duration, | |
456 ui::LayerAnimator::PreemptionStrategy preemption_strategy, | |
457 gfx::Tween::Type tween, | |
458 ui::LayerAnimationObserver* animation_observer) { | |
459 ui::LayerAnimator* animator = root_layer_->GetAnimator(); | |
460 ui::ScopedLayerAnimationSettings animation_settings(animator); | |
461 animation_settings.SetPreemptionStrategy(preemption_strategy); | |
462 animation_settings.SetTweenType(tween); | |
463 ui::LayerAnimationElement* animation_element = | |
464 ui::LayerAnimationElement::CreateOpacityElement(opacity, duration); | |
465 ui::LayerAnimationSequence* animation_sequence = | |
466 new ui::LayerAnimationSequence(animation_element); | |
467 | |
468 if (animation_observer) | |
469 animation_sequence->AddObserver(animation_observer); | |
470 | |
471 animator->StartAnimation(animation_sequence); | |
472 } | |
473 | |
328 void InkDropAnimation::CalculateCircleTransforms( | 474 void InkDropAnimation::CalculateCircleTransforms( |
329 const gfx::Size& size, | 475 const gfx::Size& size, |
330 InkDropTransforms* transforms_out) const { | 476 InkDropTransforms* transforms_out) const { |
331 CalculateRectTransforms(size, std::min(size.width(), size.height()) / 2.0f, | 477 CalculateRectTransforms(size, std::min(size.width(), size.height()) / 2.0f, |
332 transforms_out); | 478 transforms_out); |
333 } | 479 } |
334 | 480 |
335 void InkDropAnimation::CalculateRectTransforms( | 481 void InkDropAnimation::CalculateRectTransforms( |
336 const gfx::Size& size, | 482 const gfx::Size& size, |
337 float corner_radius, | 483 float corner_radius, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
379 std::max(kMinimumRectScale, | 525 std::max(kMinimumRectScale, |
380 (size.height() - 2.0f * corner_radius) / rect_delegate_height)); | 526 (size.height() - 2.0f * corner_radius) / rect_delegate_height)); |
381 | 527 |
382 (*transforms_out)[VERTICAL_RECT] = CalculateRectTransform( | 528 (*transforms_out)[VERTICAL_RECT] = CalculateRectTransform( |
383 ToRoundedPoint(rect_layer_delegate_->GetCenterPoint()), | 529 ToRoundedPoint(rect_layer_delegate_->GetCenterPoint()), |
384 std::max(kMinimumRectScale, | 530 std::max(kMinimumRectScale, |
385 (size.width() - 2.0f * corner_radius) / rect_delegate_width), | 531 (size.width() - 2.0f * corner_radius) / rect_delegate_width), |
386 std::max(kMinimumRectScale, size.height() / rect_delegate_height)); | 532 std::max(kMinimumRectScale, size.height() / rect_delegate_height)); |
387 } | 533 } |
388 | 534 |
389 void InkDropAnimation::GetCurrentTansforms( | 535 void InkDropAnimation::GetCurrentTransforms( |
390 InkDropTransforms* transforms_out) const { | 536 InkDropTransforms* transforms_out) const { |
391 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) | 537 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) |
392 (*transforms_out)[i] = painted_layers_[i]->GetTargetTransform(); | 538 (*transforms_out)[i] = painted_layers_[i]->transform(); |
393 } | 539 } |
394 | 540 |
395 void InkDropAnimation::AddPaintLayer(PaintedShape painted_shape) { | 541 void InkDropAnimation::AddPaintLayer(PaintedShape painted_shape) { |
396 ui::LayerDelegate* delegate = nullptr; | 542 ui::LayerDelegate* delegate = nullptr; |
397 switch (painted_shape) { | 543 switch (painted_shape) { |
398 case TOP_LEFT_CIRCLE: | 544 case TOP_LEFT_CIRCLE: |
399 case TOP_RIGHT_CIRCLE: | 545 case TOP_RIGHT_CIRCLE: |
400 case BOTTOM_RIGHT_CIRCLE: | 546 case BOTTOM_RIGHT_CIRCLE: |
401 case BOTTOM_LEFT_CIRCLE: | 547 case BOTTOM_LEFT_CIRCLE: |
402 delegate = circle_layer_delegate_.get(); | 548 delegate = circle_layer_delegate_.get(); |
(...skipping 30 matching lines...) Expand all Loading... | |
433 void InkDropAnimation::AnimationStartedCallback( | 579 void InkDropAnimation::AnimationStartedCallback( |
434 InkDropState ink_drop_state, | 580 InkDropState ink_drop_state, |
435 const ui::CallbackLayerAnimationObserver& observer) { | 581 const ui::CallbackLayerAnimationObserver& observer) { |
436 FOR_EACH_OBSERVER(InkDropAnimationObserver, observers_, | 582 FOR_EACH_OBSERVER(InkDropAnimationObserver, observers_, |
437 InkDropAnimationStarted(ink_drop_state)); | 583 InkDropAnimationStarted(ink_drop_state)); |
438 } | 584 } |
439 | 585 |
440 bool InkDropAnimation::AnimationEndedCallback( | 586 bool InkDropAnimation::AnimationEndedCallback( |
441 InkDropState ink_drop_state, | 587 InkDropState ink_drop_state, |
442 const ui::CallbackLayerAnimationObserver& observer) { | 588 const ui::CallbackLayerAnimationObserver& observer) { |
589 if (ink_drop_state == InkDropState::HIDDEN) | |
590 SetStateToHidden(); | |
591 | |
443 FOR_EACH_OBSERVER( | 592 FOR_EACH_OBSERVER( |
444 InkDropAnimationObserver, observers_, | 593 InkDropAnimationObserver, observers_, |
445 InkDropAnimationEnded(ink_drop_state, | 594 InkDropAnimationEnded(ink_drop_state, |
446 observer.aborted_count() | 595 observer.aborted_count() |
447 ? InkDropAnimationObserver::PRE_EMPTED | 596 ? InkDropAnimationObserver::PRE_EMPTED |
448 : InkDropAnimationObserver::SUCCESS)); | 597 : InkDropAnimationObserver::SUCCESS)); |
449 return true; | 598 return true; |
450 } | 599 } |
451 | 600 |
452 } // namespace views | 601 } // namespace views |
OLD | NEW |