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 // The opacity of the ink drop when it is visible. |
37 const float kVisibleOpacity = 0.14f; | 40 const float kVisibleOpacity = 0.09f; |
38 | 41 |
39 // The opacity of the ink drop when it is not visible. | 42 // The opacity of the ink drop when it is not visible. |
40 const float kHiddenOpacity = 0.0f; | 43 const float kHiddenOpacity = 0.0f; |
41 | 44 |
42 // Durations for the different InkDropState animations in milliseconds. | 45 // All the sub animations that are used to animate each of the InkDropStates. |
43 const int kHiddenStateAnimationDurationMs = 1; | 46 // These are used to get time durations with |
44 const int kActionPendingStateAnimationDurationMs = 500; | 47 // GetAnimationDuration(InkDropSubAnimations). Note that in general a sub |
45 const int kQuickActionStateAnimationDurationMs = 250; | 48 // animation defines the duration for either a transformation animation or an |
46 const int kSlowActionPendingStateAnimationDurationMs = 500; | 49 // opacity animation but there are some exceptions where an entire InkDropState |
47 const int kSlowActionStateAnimationDurationMs = 250; | 50 // animation consists of only 1 sub animation and it defines the duration for |
48 const int kActivatedStateAnimationDurationMs = 125; | 51 // both the transformation and opacity animations. |
49 const int kDeactivatedStateAnimationDurationMs = 250; | 52 enum InkDropSubAnimations { |
| 53 // Multi-purpose sub animation that is used for all InkDropState animations |
| 54 // that fade out. It defines the portion of the animation where the ripple |
| 55 // shape should be in it's final form and should pause at full opacity before |
| 56 // fading out. |
| 57 OPACITY_PAUSE_BEFORE_FADE_OUT, |
| 58 |
| 59 // HIDDEN sub animations. |
| 60 |
| 61 // The HIDDEN animation consists of a single sub animation that is fading out |
| 62 // to a hidden opacity. |
| 63 HIDDEN_FADE_OUT, |
| 64 |
| 65 // ACTION_PENDING sub animations. |
| 66 |
| 67 // The ACTION_PENDING sub animation that fades in to the visible opacity. |
| 68 ACTION_PENDING_FADE_IN, |
| 69 |
| 70 // The ACTION_PENDING sub animation that transforms the shape to a |
| 71 // |large_size_| circle. |
| 72 ACTION_PENDING_TRANSFORM, |
| 73 |
| 74 // QUICK_ACTION sub animations. |
| 75 |
| 76 // The QUICK_ACTION sub animation that is fading in to a visible opacity. |
| 77 QUICK_ACTION_FADE_IN, |
| 78 |
| 79 // The QUICK_ACTION sub animation that is fading out to a hidden opacity. |
| 80 QUICK_ACTION_FADE_OUT, |
| 81 |
| 82 // The QUICK_ACTION sub animation that transforms the shape to a |large_size_| |
| 83 // circle. |
| 84 QUICK_ACTION_TRANSFORM, |
| 85 |
| 86 // The SLOW_ACTION_PENDING animation has only one sub animation which animates |
| 87 // to a |small_size_| rounded rectangle at visible opacity. |
| 88 SLOW_ACTION_PENDING, |
| 89 |
| 90 // SLOW_ACTION sub animations. |
| 91 |
| 92 // The SLOW_ACTION sub animation that is fading out to a hidden opacity. |
| 93 SLOW_ACTION_FADE_OUT, |
| 94 |
| 95 // The SLOW_ACTION sub animation that transforms the shape to a |large_size_| |
| 96 // rounded rectangle. |
| 97 SLOW_ACTION_TRANSFORM, |
| 98 |
| 99 // ACTIVATED sub animations. |
| 100 |
| 101 // The ACTIVATED sub animation that is fading in to a visible opacity. |
| 102 ACTIVATED_FADE_IN, |
| 103 |
| 104 // The ACTIVATED sub animation that transforms the shape to a |small_size_| |
| 105 // rounded rectangle. |
| 106 ACTIVATED_TRANSFORM, |
| 107 |
| 108 // DEACTIVATED sub animations. |
| 109 |
| 110 // The DEACTIVATED sub animation that is fading out to a hidden opacity. |
| 111 DEACTIVATED_FADE_OUT, |
| 112 |
| 113 // The DEACTIVATED sub animation that transforms the shape to a |large_size_| |
| 114 // rounded rectangle. |
| 115 DEACTIVATED_TRANSFORM, |
| 116 }; |
| 117 |
| 118 // Duration constants for InkDropStateSubAnimations. See the |
| 119 // InkDropStateSubAnimations enum documentation for more info. |
| 120 const int kOpacityPauseBeforeFadeDurationMs = 100; |
| 121 const int kHiddenFadeOutDurationMs = 100; |
| 122 const int kActionPendingFadeInDurationMs = 100; |
| 123 const int kActionPendingTransformDurationMs = 300; |
| 124 const int kQuickActionFadeInDurationMs = 100; |
| 125 const int kQuickActionFadeOutDurationMs = 100; |
| 126 const int kQuickActionTransformDurationMs = 300; |
| 127 const int kSlowActionPendingDurationMs = 100; |
| 128 const int kSlowActionFadeOutDurationMs = 100; |
| 129 const int kSlowActionTransformDurationMs = 250; |
| 130 const int kActivatedFadeInDurationMs = 75; |
| 131 const int kActivatedTransformDurationMs = 150; |
| 132 const int kDeactivatedFadeOutDurationMs = 100; |
| 133 const int kDeactivatedTransformDurationMs = 100; |
50 | 134 |
51 // A multiplicative factor used to slow down InkDropState animations. | 135 // A multiplicative factor used to slow down InkDropState animations. |
52 const int kSlowAnimationDurationFactor = 3; | 136 const int kSlowAnimationDurationFactor = 3; |
53 | 137 |
54 // Checks CommandLine switches to determine if the visual feedback should have | 138 // Checks CommandLine switches to determine if the visual feedback should have |
55 // a fast animations speed. | 139 // a fast animations speed. |
56 bool UseFastAnimations() { | 140 bool UseFastAnimations() { |
57 static bool fast = | 141 static bool fast = |
58 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 142 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
59 (::switches::kMaterialDesignInkDropAnimationSpeed)) != | 143 (::switches::kMaterialDesignInkDropAnimationSpeed)) != |
60 ::switches::kMaterialDesignInkDropAnimationSpeedSlow; | 144 ::switches::kMaterialDesignInkDropAnimationSpeedSlow; |
61 return fast; | 145 return fast; |
62 } | 146 } |
63 | 147 |
64 // Returns the InkDropState animation duration for the given |state|. | 148 // Returns the InkDropState sub animation duration for the given |state|. |
65 base::TimeDelta GetAnimationDuration(views::InkDropState state) { | 149 base::TimeDelta GetAnimationDuration(InkDropSubAnimations state) { |
66 int duration = 0; | 150 int duration = 0; |
67 switch (state) { | 151 switch (state) { |
68 case views::InkDropState::HIDDEN: | 152 case OPACITY_PAUSE_BEFORE_FADE_OUT: |
69 duration = kHiddenStateAnimationDurationMs; | 153 duration = kOpacityPauseBeforeFadeDurationMs; |
70 break; | 154 break; |
71 case views::InkDropState::ACTION_PENDING: | 155 case HIDDEN_FADE_OUT: |
72 duration = kActionPendingStateAnimationDurationMs; | 156 duration = kHiddenFadeOutDurationMs; |
73 break; | 157 break; |
74 case views::InkDropState::QUICK_ACTION: | 158 case ACTION_PENDING_FADE_IN: |
75 duration = kQuickActionStateAnimationDurationMs; | 159 duration = kActionPendingFadeInDurationMs; |
76 break; | 160 break; |
77 case views::InkDropState::SLOW_ACTION_PENDING: | 161 case ACTION_PENDING_TRANSFORM: |
78 duration = kSlowActionPendingStateAnimationDurationMs; | 162 duration = kActionPendingTransformDurationMs; |
79 break; | 163 break; |
80 case views::InkDropState::SLOW_ACTION: | 164 case QUICK_ACTION_FADE_IN: |
81 duration = kSlowActionStateAnimationDurationMs; | 165 duration = kQuickActionFadeInDurationMs; |
82 break; | 166 break; |
83 case views::InkDropState::ACTIVATED: | 167 case QUICK_ACTION_FADE_OUT: |
84 duration = kActivatedStateAnimationDurationMs; | 168 duration = kQuickActionFadeOutDurationMs; |
85 break; | 169 break; |
86 case views::InkDropState::DEACTIVATED: | 170 case QUICK_ACTION_TRANSFORM: |
87 duration = kDeactivatedStateAnimationDurationMs; | 171 duration = kQuickActionTransformDurationMs; |
| 172 break; |
| 173 case SLOW_ACTION_PENDING: |
| 174 duration = kSlowActionPendingDurationMs; |
| 175 break; |
| 176 case SLOW_ACTION_TRANSFORM: |
| 177 duration = kSlowActionTransformDurationMs; |
| 178 break; |
| 179 case SLOW_ACTION_FADE_OUT: |
| 180 duration = kSlowActionFadeOutDurationMs; |
| 181 break; |
| 182 case ACTIVATED_FADE_IN: |
| 183 duration = kActivatedFadeInDurationMs; |
| 184 break; |
| 185 case ACTIVATED_TRANSFORM: |
| 186 duration = kActivatedTransformDurationMs; |
| 187 break; |
| 188 case DEACTIVATED_FADE_OUT: |
| 189 duration = kDeactivatedFadeOutDurationMs; |
| 190 break; |
| 191 case DEACTIVATED_TRANSFORM: |
| 192 duration = kDeactivatedTransformDurationMs; |
88 break; | 193 break; |
89 } | 194 } |
90 | |
91 return base::TimeDelta::FromMilliseconds( | 195 return base::TimeDelta::FromMilliseconds( |
92 (UseFastAnimations() ? 1 : kSlowAnimationDurationFactor) * duration); | 196 (UseFastAnimations() ? 1 : kSlowAnimationDurationFactor) * duration); |
93 } | 197 } |
94 | 198 |
95 // Calculates a Transform for a circle layer. The transform will be set up to | 199 // 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 | 200 // 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|. | 201 // to the target point defined by |target_center_x| and |target_center_y|. |
98 gfx::Transform CalculateCircleTransform(const gfx::Point& drawn_center_point, | 202 gfx::Transform CalculateCircleTransform(const gfx::Point& drawn_center_point, |
99 float scale, | 203 float scale, |
100 float target_center_x, | 204 float target_center_x, |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 | 279 |
176 void InkDropAnimation::SetCenterPoint(const gfx::Point& center_point) { | 280 void InkDropAnimation::SetCenterPoint(const gfx::Point& center_point) { |
177 gfx::Transform transform; | 281 gfx::Transform transform; |
178 transform.Translate(center_point.x(), center_point.y()); | 282 transform.Translate(center_point.x(), center_point.y()); |
179 root_layer_->SetTransform(transform); | 283 root_layer_->SetTransform(transform); |
180 } | 284 } |
181 | 285 |
182 void InkDropAnimation::AnimateToStateInternal( | 286 void InkDropAnimation::AnimateToStateInternal( |
183 InkDropState ink_drop_state, | 287 InkDropState ink_drop_state, |
184 ui::LayerAnimationObserver* animation_observer) { | 288 ui::LayerAnimationObserver* animation_observer) { |
| 289 if (ink_drop_state_ == InkDropState::HIDDEN) { |
| 290 // The HIDDEN state animations might still be in progress and we don't want |
| 291 // to start the new ink drop sequence from that shape so snap the state to |
| 292 // hidden. |
| 293 AbortAllAnimations(); |
| 294 SetStateToHidden(); |
| 295 } |
| 296 |
185 ink_drop_state_ = ink_drop_state; | 297 ink_drop_state_ = ink_drop_state; |
186 | 298 |
187 if (ink_drop_state_ == InkDropState::HIDDEN) { | |
188 // Animating to the HIDDEN state doesn't actually use any | |
189 // LayerAnimationSequences so we need to explicitly abort any running ones | |
190 // so that observers receive an InkDropAnimationEnded() event for the | |
191 // running animation prior to receiving an InkDropAnimationStarted() event | |
192 // for the HIDDEN 'animation'. | |
193 AbortAllAnimations(); | |
194 root_layer_->SetVisible(false); | |
195 SetStateToHidden(); | |
196 return; | |
197 } | |
198 | |
199 InkDropTransforms transforms; | 299 InkDropTransforms transforms; |
200 root_layer_->SetVisible(true); | 300 root_layer_->SetVisible(true); |
201 | 301 |
202 switch (ink_drop_state_) { | 302 switch (ink_drop_state_) { |
203 case InkDropState::HIDDEN: | 303 case InkDropState::HIDDEN: |
204 // This case is handled above in a short circuit return. | 304 // Only the opacity is animated so we have to explicitly abort the other |
| 305 // running animations so that the LayerAnimationObservers are notified in |
| 306 // the proper order. |
| 307 AbortAllAnimations(); |
| 308 if (GetCurrentOpacity() != kHiddenOpacity) { |
| 309 AnimateToOpacity(kHiddenOpacity, GetAnimationDuration(HIDDEN_FADE_OUT), |
| 310 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, |
| 311 gfx::Tween::EASE_IN_OUT, animation_observer); |
| 312 } |
205 break; | 313 break; |
206 case InkDropState::ACTION_PENDING: | 314 case InkDropState::ACTION_PENDING: |
| 315 AnimateToOpacity(kVisibleOpacity, |
| 316 GetAnimationDuration(ACTION_PENDING_FADE_IN), |
| 317 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, |
| 318 gfx::Tween::EASE_IN, animation_observer); |
207 CalculateCircleTransforms(large_size_, &transforms); | 319 CalculateCircleTransforms(large_size_, &transforms); |
208 AnimateToTransforms(transforms, kVisibleOpacity, | 320 AnimateToTransforms(transforms, |
209 GetAnimationDuration(InkDropState::ACTION_PENDING), | 321 GetAnimationDuration(ACTION_PENDING_TRANSFORM), |
210 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | 322 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, |
211 animation_observer); | 323 gfx::Tween::EASE_OUT, animation_observer); |
212 break; | 324 break; |
213 case InkDropState::QUICK_ACTION: | 325 case InkDropState::QUICK_ACTION: { |
| 326 const float fade_in_ratio = 1.0f - GetCurrentOpacity() / kVisibleOpacity; |
| 327 const base::TimeDelta fade_in_duration = |
| 328 GetAnimationDuration(QUICK_ACTION_FADE_IN) * fade_in_ratio; |
| 329 |
| 330 const base::TimeDelta fade_out_duration = |
| 331 GetAnimationDuration(QUICK_ACTION_FADE_OUT); |
| 332 |
| 333 GetCurrentTransforms(&transforms); |
| 334 const float transformation_ratio = |
| 335 1.0f - CalculateDistanceEstimateToQuickAction(transforms); |
| 336 const base::TimeDelta transformation_duration = |
| 337 GetAnimationDuration(QUICK_ACTION_TRANSFORM) * transformation_ratio; |
| 338 |
| 339 const base::TimeDelta visible_duration = |
| 340 transformation_duration - fade_in_duration + |
| 341 GetAnimationDuration(OPACITY_PAUSE_BEFORE_FADE_OUT); |
| 342 |
| 343 if (fade_in_duration.InMilliseconds() > 0) { |
| 344 AnimateToOpacity(kVisibleOpacity, fade_in_duration, |
| 345 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, |
| 346 gfx::Tween::EASE_IN, animation_observer); |
| 347 } |
| 348 |
| 349 AnimateToOpacity(kVisibleOpacity, visible_duration, |
| 350 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION, |
| 351 gfx::Tween::LINEAR, animation_observer); |
| 352 AnimateToOpacity(kHiddenOpacity, fade_out_duration, |
| 353 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION, |
| 354 gfx::Tween::EASE_OUT, animation_observer); |
214 CalculateCircleTransforms(large_size_, &transforms); | 355 CalculateCircleTransforms(large_size_, &transforms); |
215 AnimateToTransforms(transforms, kHiddenOpacity, | 356 AnimateToTransforms(transforms, transformation_duration, |
216 GetAnimationDuration(InkDropState::QUICK_ACTION), | |
217 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | 357 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, |
218 animation_observer); | 358 gfx::Tween::EASE_OUT, animation_observer); |
219 break; | 359 break; |
| 360 } |
220 case InkDropState::SLOW_ACTION_PENDING: | 361 case InkDropState::SLOW_ACTION_PENDING: |
| 362 AnimateToOpacity(kVisibleOpacity, |
| 363 GetAnimationDuration(SLOW_ACTION_PENDING), |
| 364 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, |
| 365 gfx::Tween::EASE_IN, animation_observer); |
221 CalculateRectTransforms(small_size_, small_corner_radius_, &transforms); | 366 CalculateRectTransforms(small_size_, small_corner_radius_, &transforms); |
222 AnimateToTransforms( | 367 AnimateToTransforms(transforms, GetAnimationDuration(SLOW_ACTION_PENDING), |
223 transforms, kVisibleOpacity, | 368 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, |
224 GetAnimationDuration(InkDropState::SLOW_ACTION_PENDING), | 369 gfx::Tween::EASE_IN_OUT, animation_observer); |
225 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | |
226 animation_observer); | |
227 break; | 370 break; |
228 case InkDropState::SLOW_ACTION: | 371 case InkDropState::SLOW_ACTION: |
| 372 AnimateToOpacity(kVisibleOpacity, |
| 373 GetAnimationDuration(SLOW_ACTION_TRANSFORM) + |
| 374 GetAnimationDuration(OPACITY_PAUSE_BEFORE_FADE_OUT), |
| 375 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, |
| 376 gfx::Tween::EASE_IN, animation_observer); |
| 377 AnimateToOpacity(kHiddenOpacity, |
| 378 GetAnimationDuration(SLOW_ACTION_FADE_OUT), |
| 379 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION, |
| 380 gfx::Tween::EASE_IN_OUT, animation_observer); |
229 CalculateRectTransforms(large_size_, large_corner_radius_, &transforms); | 381 CalculateRectTransforms(large_size_, large_corner_radius_, &transforms); |
230 AnimateToTransforms(transforms, kHiddenOpacity, | 382 AnimateToTransforms(transforms, |
231 GetAnimationDuration(InkDropState::SLOW_ACTION), | 383 GetAnimationDuration(SLOW_ACTION_TRANSFORM), |
232 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | 384 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, |
233 animation_observer); | 385 gfx::Tween::EASE_IN_OUT, animation_observer); |
234 break; | 386 break; |
235 case InkDropState::ACTIVATED: | 387 case InkDropState::ACTIVATED: |
| 388 AnimateToOpacity(kVisibleOpacity, GetAnimationDuration(ACTIVATED_FADE_IN), |
| 389 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, |
| 390 gfx::Tween::EASE_IN, animation_observer); |
236 CalculateRectTransforms(small_size_, small_corner_radius_, &transforms); | 391 CalculateRectTransforms(small_size_, small_corner_radius_, &transforms); |
237 AnimateToTransforms(transforms, kVisibleOpacity, | 392 AnimateToTransforms(transforms, GetAnimationDuration(ACTIVATED_TRANSFORM), |
238 GetAnimationDuration(InkDropState::ACTIVATED), | |
239 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | 393 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, |
240 animation_observer); | 394 gfx::Tween::EASE_OUT, animation_observer); |
241 break; | 395 break; |
242 case InkDropState::DEACTIVATED: | 396 case InkDropState::DEACTIVATED: |
| 397 AnimateToOpacity(kVisibleOpacity, |
| 398 GetAnimationDuration(DEACTIVATED_TRANSFORM) + |
| 399 GetAnimationDuration(OPACITY_PAUSE_BEFORE_FADE_OUT), |
| 400 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, |
| 401 gfx::Tween::EASE_IN, animation_observer); |
| 402 AnimateToOpacity(kHiddenOpacity, |
| 403 GetAnimationDuration(DEACTIVATED_FADE_OUT), |
| 404 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION, |
| 405 gfx::Tween::EASE_IN_OUT, animation_observer); |
243 CalculateRectTransforms(large_size_, large_corner_radius_, &transforms); | 406 CalculateRectTransforms(large_size_, large_corner_radius_, &transforms); |
244 AnimateToTransforms(transforms, kHiddenOpacity, | 407 AnimateToTransforms(transforms, |
245 GetAnimationDuration(InkDropState::DEACTIVATED), | 408 GetAnimationDuration(DEACTIVATED_TRANSFORM), |
246 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | 409 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, |
247 animation_observer); | 410 gfx::Tween::EASE_IN_OUT, animation_observer); |
248 break; | 411 break; |
249 } | 412 } |
250 } | 413 } |
251 | 414 |
252 void InkDropAnimation::AnimateToTransforms( | 415 void InkDropAnimation::AnimateToTransforms( |
253 const InkDropTransforms transforms, | 416 const InkDropTransforms transforms, |
254 float opacity, | |
255 base::TimeDelta duration, | 417 base::TimeDelta duration, |
256 ui::LayerAnimator::PreemptionStrategy preemption_strategy, | 418 ui::LayerAnimator::PreemptionStrategy preemption_strategy, |
| 419 gfx::Tween::Type tween, |
257 ui::LayerAnimationObserver* animation_observer) { | 420 ui::LayerAnimationObserver* animation_observer) { |
258 ui::LayerAnimator* root_animator = root_layer_->GetAnimator(); | |
259 ui::ScopedLayerAnimationSettings root_animation(root_animator); | |
260 root_animation.SetPreemptionStrategy(preemption_strategy); | |
261 ui::LayerAnimationElement* root_element = | |
262 ui::LayerAnimationElement::CreateOpacityElement(opacity, duration); | |
263 ui::LayerAnimationSequence* root_sequence = | |
264 new ui::LayerAnimationSequence(root_element); | |
265 | |
266 if (animation_observer) | |
267 root_sequence->AddObserver(animation_observer); | |
268 | |
269 root_animator->StartAnimation(root_sequence); | |
270 | |
271 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) { | 421 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) { |
272 ui::LayerAnimator* animator = painted_layers_[i]->GetAnimator(); | 422 ui::LayerAnimator* animator = painted_layers_[i]->GetAnimator(); |
273 ui::ScopedLayerAnimationSettings animation(animator); | 423 ui::ScopedLayerAnimationSettings animation(animator); |
274 animation.SetPreemptionStrategy(preemption_strategy); | 424 animation.SetPreemptionStrategy(preemption_strategy); |
| 425 animation.SetTweenType(tween); |
275 ui::LayerAnimationElement* element = | 426 ui::LayerAnimationElement* element = |
276 ui::LayerAnimationElement::CreateTransformElement(transforms[i], | 427 ui::LayerAnimationElement::CreateTransformElement(transforms[i], |
277 duration); | 428 duration); |
278 ui::LayerAnimationSequence* sequence = | 429 ui::LayerAnimationSequence* sequence = |
279 new ui::LayerAnimationSequence(element); | 430 new ui::LayerAnimationSequence(element); |
280 | 431 |
281 if (animation_observer) | 432 if (animation_observer) |
282 sequence->AddObserver(animation_observer); | 433 sequence->AddObserver(animation_observer); |
283 | 434 |
284 animator->StartAnimation(sequence); | 435 animator->StartAnimation(sequence); |
285 } | 436 } |
286 } | 437 } |
287 | 438 |
288 void InkDropAnimation::SetStateToHidden() { | 439 void InkDropAnimation::SetStateToHidden() { |
289 InkDropTransforms transforms; | 440 InkDropTransforms transforms; |
290 // Using a size of 0x0 creates visual anomalies. | 441 // Using a size of 0x0 creates visual anomalies. |
291 CalculateCircleTransforms(gfx::Size(1, 1), &transforms); | 442 CalculateCircleTransforms(gfx::Size(1, 1), &transforms); |
292 SetTransforms(transforms); | 443 SetTransforms(transforms); |
293 SetOpacity(kHiddenOpacity); | 444 SetOpacity(kHiddenOpacity); |
| 445 root_layer_->SetVisible(false); |
294 } | 446 } |
295 | 447 |
296 void InkDropAnimation::SetTransforms(const InkDropTransforms transforms) { | 448 void InkDropAnimation::SetTransforms(const InkDropTransforms transforms) { |
297 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) | 449 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) |
298 painted_layers_[i]->SetTransform(transforms[i]); | 450 painted_layers_[i]->SetTransform(transforms[i]); |
299 } | 451 } |
300 | 452 |
| 453 float InkDropAnimation::GetCurrentOpacity() const { |
| 454 return root_layer_->opacity(); |
| 455 } |
| 456 |
301 void InkDropAnimation::SetOpacity(float opacity) { | 457 void InkDropAnimation::SetOpacity(float opacity) { |
302 root_layer_->SetOpacity(opacity); | 458 root_layer_->SetOpacity(opacity); |
303 } | 459 } |
304 | 460 |
| 461 void InkDropAnimation::AnimateToOpacity( |
| 462 float opacity, |
| 463 base::TimeDelta duration, |
| 464 ui::LayerAnimator::PreemptionStrategy preemption_strategy, |
| 465 gfx::Tween::Type tween, |
| 466 ui::LayerAnimationObserver* animation_observer) { |
| 467 ui::LayerAnimator* animator = root_layer_->GetAnimator(); |
| 468 ui::ScopedLayerAnimationSettings animation_settings(animator); |
| 469 animation_settings.SetPreemptionStrategy(preemption_strategy); |
| 470 animation_settings.SetTweenType(tween); |
| 471 ui::LayerAnimationElement* animation_element = |
| 472 ui::LayerAnimationElement::CreateOpacityElement(opacity, duration); |
| 473 ui::LayerAnimationSequence* animation_sequence = |
| 474 new ui::LayerAnimationSequence(animation_element); |
| 475 |
| 476 if (animation_observer) |
| 477 animation_sequence->AddObserver(animation_observer); |
| 478 |
| 479 animator->StartAnimation(animation_sequence); |
| 480 } |
| 481 |
305 void InkDropAnimation::CalculateCircleTransforms( | 482 void InkDropAnimation::CalculateCircleTransforms( |
306 const gfx::Size& size, | 483 const gfx::Size& size, |
307 InkDropTransforms* transforms_out) const { | 484 InkDropTransforms* transforms_out) const { |
308 CalculateRectTransforms(size, std::min(size.width(), size.height()) / 2.0f, | 485 CalculateRectTransforms(size, std::min(size.width(), size.height()) / 2.0f, |
309 transforms_out); | 486 transforms_out); |
310 } | 487 } |
311 | 488 |
312 void InkDropAnimation::CalculateRectTransforms( | 489 void InkDropAnimation::CalculateRectTransforms( |
313 const gfx::Size& size, | 490 const gfx::Size& size, |
314 float corner_radius, | 491 float corner_radius, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 std::max(kMinimumRectScale, | 533 std::max(kMinimumRectScale, |
357 (size.height() - 2.0f * corner_radius) / rect_delegate_height)); | 534 (size.height() - 2.0f * corner_radius) / rect_delegate_height)); |
358 | 535 |
359 (*transforms_out)[VERTICAL_RECT] = CalculateRectTransform( | 536 (*transforms_out)[VERTICAL_RECT] = CalculateRectTransform( |
360 ToRoundedPoint(rect_layer_delegate_->GetCenterPoint()), | 537 ToRoundedPoint(rect_layer_delegate_->GetCenterPoint()), |
361 std::max(kMinimumRectScale, | 538 std::max(kMinimumRectScale, |
362 (size.width() - 2.0f * corner_radius) / rect_delegate_width), | 539 (size.width() - 2.0f * corner_radius) / rect_delegate_width), |
363 std::max(kMinimumRectScale, size.height() / rect_delegate_height)); | 540 std::max(kMinimumRectScale, size.height() / rect_delegate_height)); |
364 } | 541 } |
365 | 542 |
366 void InkDropAnimation::GetCurrentTansforms( | 543 void InkDropAnimation::GetCurrentTransforms( |
367 InkDropTransforms* transforms_out) const { | 544 InkDropTransforms* transforms_out) const { |
368 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) | 545 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) |
369 (*transforms_out)[i] = painted_layers_[i]->GetTargetTransform(); | 546 (*transforms_out)[i] = painted_layers_[i]->transform(); |
370 } | 547 } |
371 | 548 |
372 void InkDropAnimation::AddPaintLayer(PaintedShape painted_shape) { | 549 void InkDropAnimation::AddPaintLayer(PaintedShape painted_shape) { |
373 ui::LayerDelegate* delegate = nullptr; | 550 ui::LayerDelegate* delegate = nullptr; |
374 switch (painted_shape) { | 551 switch (painted_shape) { |
375 case TOP_LEFT_CIRCLE: | 552 case TOP_LEFT_CIRCLE: |
376 case TOP_RIGHT_CIRCLE: | 553 case TOP_RIGHT_CIRCLE: |
377 case BOTTOM_RIGHT_CIRCLE: | 554 case BOTTOM_RIGHT_CIRCLE: |
378 case BOTTOM_LEFT_CIRCLE: | 555 case BOTTOM_LEFT_CIRCLE: |
379 delegate = circle_layer_delegate_.get(); | 556 delegate = circle_layer_delegate_.get(); |
(...skipping 19 matching lines...) Expand all Loading... |
399 | 576 |
400 painted_layers_[painted_shape].reset(layer); | 577 painted_layers_[painted_shape].reset(layer); |
401 } | 578 } |
402 | 579 |
403 void InkDropAnimation::AbortAllAnimations() { | 580 void InkDropAnimation::AbortAllAnimations() { |
404 root_layer_->GetAnimator()->AbortAllAnimations(); | 581 root_layer_->GetAnimator()->AbortAllAnimations(); |
405 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) | 582 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) |
406 painted_layers_[i]->GetAnimator()->AbortAllAnimations(); | 583 painted_layers_[i]->GetAnimator()->AbortAllAnimations(); |
407 } | 584 } |
408 | 585 |
| 586 float InkDropAnimation::CalculateDistanceEstimateToQuickAction( |
| 587 const InkDropTransforms& transforms) const { |
| 588 gfx::Point3F circle_center_point = |
| 589 gfx::Point3F(circle_layer_delegate_->GetCenterPoint()); |
| 590 |
| 591 gfx::Point3F circle_top_point( |
| 592 circle_center_point.x(), |
| 593 circle_center_point.y() - circle_layer_delegate_->radius(), 0); |
| 594 |
| 595 transforms[TOP_LEFT_CIRCLE].TransformPoint(&circle_center_point); |
| 596 transforms[TOP_LEFT_CIRCLE].TransformPoint(&circle_top_point); |
| 597 |
| 598 // Calculate the ratio of how far the transformed circle's center point is |
| 599 // from the destination compared to how far it can be. |
| 600 const float center_point_distance_estimate = |
| 601 1.0f - |
| 602 gfx::Vector3dF(circle_center_point.x(), circle_center_point.y(), 0) |
| 603 .Length() / |
| 604 (gfx::Vector3dF(large_size_.width(), large_size_.height(), 0) |
| 605 .Length() / |
| 606 2.0f); |
| 607 |
| 608 // Calculate the ratio of how far the transformed circle's topmost point is |
| 609 // from the destination compared to how far it can be. |
| 610 const float top_point_distance_estimate = |
| 611 -circle_top_point.y() / (large_size_.height() / 2.0f); |
| 612 |
| 613 return std::min(center_point_distance_estimate, top_point_distance_estimate); |
| 614 } |
| 615 |
409 void InkDropAnimation::AnimationStartedCallback( | 616 void InkDropAnimation::AnimationStartedCallback( |
410 InkDropState ink_drop_state, | 617 InkDropState ink_drop_state, |
411 const ui::CallbackLayerAnimationObserver& observer) { | 618 const ui::CallbackLayerAnimationObserver& observer) { |
412 FOR_EACH_OBSERVER(InkDropAnimationObserver, observers_, | 619 FOR_EACH_OBSERVER(InkDropAnimationObserver, observers_, |
413 InkDropAnimationStarted(ink_drop_state)); | 620 InkDropAnimationStarted(ink_drop_state)); |
414 } | 621 } |
415 | 622 |
416 bool InkDropAnimation::AnimationEndedCallback( | 623 bool InkDropAnimation::AnimationEndedCallback( |
417 InkDropState ink_drop_state, | 624 InkDropState ink_drop_state, |
418 const ui::CallbackLayerAnimationObserver& observer) { | 625 const ui::CallbackLayerAnimationObserver& observer) { |
| 626 if (ink_drop_state == InkDropState::HIDDEN) |
| 627 SetStateToHidden(); |
| 628 |
419 FOR_EACH_OBSERVER( | 629 FOR_EACH_OBSERVER( |
420 InkDropAnimationObserver, observers_, | 630 InkDropAnimationObserver, observers_, |
421 InkDropAnimationEnded(ink_drop_state, | 631 InkDropAnimationEnded(ink_drop_state, |
422 observer.aborted_count() | 632 observer.aborted_count() |
423 ? InkDropAnimationObserver::PRE_EMPTED | 633 ? InkDropAnimationObserver::PRE_EMPTED |
424 : InkDropAnimationObserver::SUCCESS)); | 634 : InkDropAnimationObserver::SUCCESS)); |
425 return true; | 635 return true; |
426 } | 636 } |
427 | 637 |
428 } // namespace views | 638 } // namespace views |
OLD | NEW |