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

Side by Side Diff: ui/views/animation/ink_drop_animation.cc

Issue 1422593003: Made material design ink drop QUICK_ACTION animation more visible. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merged in changes to https://codereview.chromium.org/1390113006/ Created 4 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
OLDNEW
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.14f;
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 enum InkDropSubAnimations {
44 const int kActionPendingStateAnimationDurationMs = 500; 47 // The ACTION_PENDING animation has only one sub animation which animates to a
45 const int kQuickActionStateAnimationDurationMs = 250; 48 // |large_size_| circle at visible opacity.
46 const int kSlowActionPendingStateAnimationDurationMs = 500; 49 ACTION_PENDING,
47 const int kSlowActionStateAnimationDurationMs = 250; 50
48 const int kActivatedStateAnimationDurationMs = 125; 51 // The QUICK_ACTION animation consists of the two sub animations:
49 const int kDeactivatedStateAnimationDurationMs = 250; 52 // QUICK_ACTION_VISIBLE, QUICK_ACTION_FADE_OUT. The final frame of the
53 // animation is a |large_size_| circle at hidden opacity.
54
55 // The portion of the QUICK_ACTION animation that is at visible opacity.
56 QUICK_ACTION_VISIBLE,
57
58 // The portion of the QUICK_ACTION animation that is at fading out to a hidden
59 // opacity.
60 QUICK_ACTION_FADE_OUT,
61
62 // The SLOW_ACTION_PENDING animation has only one sub animation which animates
63 // to a |small_size_| rounded rectangle at visible opacity.
64 SLOW_ACTION_PENDING,
65
66 // The SLOW_ACTION animation consists of the two sub animations:
67 // SLOW_ACTION_VISIBLE, SLOW_ACTION_FADE_OUT. The final frame of the
68 // animation is a |large_size_| rounded rectangle at hidden opacity.
69
70 // The portion of the SLOW_ACTION animation that is at visible opacity.
71 SLOW_ACTION_VISIBLE,
72
73 // The portion of the SLOW_ACTION animation that is fading out to a hidden
74 // opacity.
75 SLOW_ACTION_FADE_OUT,
76
77 // The ACTIVATED animation has only one sub animation which animates to a
78 // |small_size_| rounded rectangle at visible opacity.
79 ACTIVATED,
80
81 // The DEACTIVATED animation consists of the two sub animations:
82 // DEACTIVATED_VISIBLE, DEACTIVATED_FADE_OUT. The final frame of the
83 // animation is a |large_size_| rounded rectangle at hidden opacity.
84
85 // The portion of the DEACTIVATED animation that is at visible opacity.
86 DEACTIVATED_VISIBLE,
87
88 // The portion of the DEACTIVATED animation that is fading out to a hidden
89 // opacity.
90 DEACTIVATED_FADE_OUT,
91 };
92
93 // The time taken to animate the ACTION_PENDING animation.
94 const int kActionPendingAnimationDurationMs = 500;
95
96 // The time taken to animate the visible portion of the QUICK_ACTION animation.
97 const int kQuickActionVisibleAnimationDurationMs = 200;
98
99 // The time taken to animate the fade out portion of the QUICK_ACTION animation.
100 const int kQuickActionFadeOutAnimationDurationMs = 100;
101
102 // The time taken to animate the SLOW_ACTION_PENDING animation.
103 const int kSlowActionPendingAnimationDurationMs = 100;
104
105 // The time taken to animate the visible portion of the SLOW_ACTION animation.
106 const int kSlowActionVisibleAnimationDurationMs = 150;
107
108 // The time taken to animate the fade out portion of the SLOW_ACTION animation.
109 const int kSlowActionFadeOutAnimationDurationMs = 100;
110
111 // The time taken to animate the ACTIVATED animation.
112 const int kActivatedAnimationDurationMs = 125;
113
114 // The time taken to animate the visible portion of the DEACTIVATED animation.
115 const int kDeactivatedVisibleAnimationDurationMs = 150;
116
117 // The time taken to animate the fade out portion of the DEACTIVATED animation.
118 const int kDeactivatedFadeOutAnimationDurationMs = 100;
50 119
51 // A multiplicative factor used to slow down InkDropState animations. 120 // A multiplicative factor used to slow down InkDropState animations.
52 const int kSlowAnimationDurationFactor = 3; 121 const int kSlowAnimationDurationFactor = 3;
53 122
54 // Checks CommandLine switches to determine if the visual feedback should have 123 // Checks CommandLine switches to determine if the visual feedback should have
55 // a fast animations speed. 124 // a fast animations speed.
56 bool UseFastAnimations() { 125 bool UseFastAnimations() {
57 static bool fast = 126 static bool fast =
58 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 127 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
59 (::switches::kMaterialDesignInkDropAnimationSpeed)) != 128 (::switches::kMaterialDesignInkDropAnimationSpeed)) !=
60 ::switches::kMaterialDesignInkDropAnimationSpeedSlow; 129 ::switches::kMaterialDesignInkDropAnimationSpeedSlow;
61 return fast; 130 return fast;
62 } 131 }
63 132
64 // Returns the InkDropState animation duration for the given |state|. 133 // Returns the InkDropState animation duration for the given |state|.
65 base::TimeDelta GetAnimationDuration(views::InkDropState state) { 134 base::TimeDelta GetAnimationDuration(InkDropSubAnimations state) {
66 int duration = 0; 135 int duration = 0;
67 switch (state) { 136 switch (state) {
68 case views::InkDropState::HIDDEN: 137 case ACTION_PENDING:
69 duration = kHiddenStateAnimationDurationMs; 138 duration = kActionPendingAnimationDurationMs;
70 break; 139 break;
71 case views::InkDropState::ACTION_PENDING: 140 case QUICK_ACTION_VISIBLE:
72 duration = kActionPendingStateAnimationDurationMs; 141 duration = kQuickActionVisibleAnimationDurationMs;
73 break; 142 break;
74 case views::InkDropState::QUICK_ACTION: 143 case QUICK_ACTION_FADE_OUT:
75 duration = kQuickActionStateAnimationDurationMs; 144 duration = kQuickActionFadeOutAnimationDurationMs;
76 break; 145 break;
77 case views::InkDropState::SLOW_ACTION_PENDING: 146 case SLOW_ACTION_PENDING:
78 duration = kSlowActionPendingStateAnimationDurationMs; 147 duration = kSlowActionPendingAnimationDurationMs;
79 break; 148 break;
80 case views::InkDropState::SLOW_ACTION: 149 case SLOW_ACTION_VISIBLE:
81 duration = kSlowActionStateAnimationDurationMs; 150 duration = kSlowActionVisibleAnimationDurationMs;
82 break; 151 break;
83 case views::InkDropState::ACTIVATED: 152 case SLOW_ACTION_FADE_OUT:
84 duration = kActivatedStateAnimationDurationMs; 153 duration = kSlowActionFadeOutAnimationDurationMs;
85 break; 154 break;
86 case views::InkDropState::DEACTIVATED: 155 case ACTIVATED:
87 duration = kDeactivatedStateAnimationDurationMs; 156 duration = kActivatedAnimationDurationMs;
157 break;
158 case DEACTIVATED_VISIBLE:
159 duration = kDeactivatedVisibleAnimationDurationMs;
160 break;
161 case DEACTIVATED_FADE_OUT:
162 duration = kDeactivatedFadeOutAnimationDurationMs;
88 break; 163 break;
89 } 164 }
90
91 return base::TimeDelta::FromMilliseconds( 165 return base::TimeDelta::FromMilliseconds(
92 (UseFastAnimations() ? 1 : kSlowAnimationDurationFactor) * duration); 166 (UseFastAnimations() ? 1 : kSlowAnimationDurationFactor) * duration);
93 } 167 }
94 168
95 // Calculates a Transform for a circle layer. The transform will be set up to 169 // 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 170 // 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|. 171 // to the target point defined by |target_center_x| and |target_center_y|.
98 gfx::Transform CalculateCircleTransform(const gfx::Point& drawn_center_point, 172 gfx::Transform CalculateCircleTransform(const gfx::Point& drawn_center_point,
99 float scale, 173 float scale,
100 float target_center_x, 174 float target_center_x,
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 case PAINTED_SHAPE_COUNT: 272 case PAINTED_SHAPE_COUNT:
199 NOTREACHED() << "The PAINTED_SHAPE_COUNT value should never be used."; 273 NOTREACHED() << "The PAINTED_SHAPE_COUNT value should never be used.";
200 return "PAINTED_SHAPE_COUNT"; 274 return "PAINTED_SHAPE_COUNT";
201 } 275 }
202 return "UNKNOWN"; 276 return "UNKNOWN";
203 } 277 }
204 278
205 void InkDropAnimation::AnimateToStateInternal( 279 void InkDropAnimation::AnimateToStateInternal(
206 InkDropState ink_drop_state, 280 InkDropState ink_drop_state,
207 ui::LayerAnimationObserver* animation_observer) { 281 ui::LayerAnimationObserver* animation_observer) {
282 const InkDropState previous_ink_drop_state_ = ink_drop_state_;
208 ink_drop_state_ = ink_drop_state; 283 ink_drop_state_ = ink_drop_state;
209 284
210 if (ink_drop_state_ == InkDropState::HIDDEN) { 285 if (ink_drop_state_ == InkDropState::HIDDEN) {
211 // Animating to the HIDDEN state doesn't actually use any 286 // Animating to the HIDDEN state doesn't actually use any
212 // LayerAnimationSequences so we need to explicitly abort any running ones 287 // LayerAnimationSequences so we need to explicitly abort any running ones
213 // so that observers receive an InkDropAnimationEnded() event for the 288 // so that observers receive an InkDropAnimationEnded() event for the
214 // running animation prior to receiving an InkDropAnimationStarted() event 289 // running animation prior to receiving an InkDropAnimationStarted() event
215 // for the HIDDEN 'animation'. 290 // for the HIDDEN 'animation'.
216 AbortAllAnimations(); 291 AbortAllAnimations();
217 root_layer_->SetVisible(false);
218 SetStateToHidden(); 292 SetStateToHidden();
219 return; 293 return;
220 } 294 }
221 295
222 InkDropTransforms transforms; 296 InkDropTransforms transforms;
223 root_layer_->SetVisible(true); 297 root_layer_->SetVisible(true);
224 298
225 switch (ink_drop_state_) { 299 switch (ink_drop_state_) {
226 case InkDropState::HIDDEN: 300 case InkDropState::HIDDEN:
227 // This case is handled above in a short circuit return. 301 // This case is handled above in a short circuit return.
228 break; 302 break;
229 case InkDropState::ACTION_PENDING: 303 case InkDropState::ACTION_PENDING:
304 AnimateToOpacity(kVisibleOpacity, GetAnimationDuration(ACTION_PENDING),
305 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
306 animation_observer);
230 CalculateCircleTransforms(large_size_, &transforms); 307 CalculateCircleTransforms(large_size_, &transforms);
231 AnimateToTransforms(transforms, kVisibleOpacity, 308 AnimateToTransforms(transforms, GetAnimationDuration(ACTION_PENDING),
232 GetAnimationDuration(InkDropState::ACTION_PENDING),
233 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, 309 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
234 animation_observer); 310 animation_observer);
235 break; 311 break;
236 case InkDropState::QUICK_ACTION: 312 case InkDropState::QUICK_ACTION: {
313 float visible_duration_ratio = 1.0f;
314
315 // If the previous state is ACTION_PENDING we don't want the QUICK_ACTION
316 // to take the full duration because the expanding ripple noticably
317 // changes speed.
318 if (previous_ink_drop_state_ == InkDropState::ACTION_PENDING) {
319 GetCurrentTransforms(&transforms);
320 visible_duration_ratio =
321 visible_duration_ratio -
322 CalculateDistanceEstimateToQuickAction(transforms);
323 }
324
325 const base::TimeDelta visible_duration =
326 GetAnimationDuration(QUICK_ACTION_VISIBLE) * visible_duration_ratio;
327
328 ui::LayerAnimator::PreemptionStrategy fade_out_preemption_strategy =
329 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET;
330
331 base::TimeDelta total_effective_duration =
332 GetAnimationDuration(QUICK_ACTION_FADE_OUT);
333
334 if (visible_duration.InMilliseconds() > 0) {
335 fade_out_preemption_strategy = ui::LayerAnimator::ENQUEUE_NEW_ANIMATION;
336 total_effective_duration += visible_duration;
337 AnimateToOpacity(kVisibleOpacity, visible_duration,
338 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
339 animation_observer);
340 }
341
342 AnimateToOpacity(kHiddenOpacity,
343 GetAnimationDuration(QUICK_ACTION_FADE_OUT),
344 fade_out_preemption_strategy, animation_observer);
237 CalculateCircleTransforms(large_size_, &transforms); 345 CalculateCircleTransforms(large_size_, &transforms);
238 AnimateToTransforms(transforms, kHiddenOpacity, 346 AnimateToTransforms(transforms, total_effective_duration,
239 GetAnimationDuration(InkDropState::QUICK_ACTION),
240 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, 347 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
241 animation_observer); 348 animation_observer);
242 break; 349 break;
350 }
243 case InkDropState::SLOW_ACTION_PENDING: 351 case InkDropState::SLOW_ACTION_PENDING:
352 AnimateToOpacity(kVisibleOpacity,
353 GetAnimationDuration(SLOW_ACTION_PENDING),
354 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
355 animation_observer);
244 CalculateRectTransforms(small_size_, small_corner_radius_, &transforms); 356 CalculateRectTransforms(small_size_, small_corner_radius_, &transforms);
245 AnimateToTransforms( 357 AnimateToTransforms(transforms, GetAnimationDuration(SLOW_ACTION_PENDING),
246 transforms, kVisibleOpacity, 358 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
247 GetAnimationDuration(InkDropState::SLOW_ACTION_PENDING), 359 animation_observer);
248 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
249 animation_observer);
250 break; 360 break;
251 case InkDropState::SLOW_ACTION: 361 case InkDropState::SLOW_ACTION:
362 AnimateToOpacity(kVisibleOpacity,
363 GetAnimationDuration(SLOW_ACTION_VISIBLE),
364 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
365 animation_observer);
366 AnimateToOpacity(
367 kHiddenOpacity, GetAnimationDuration(SLOW_ACTION_FADE_OUT),
368 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION, animation_observer);
252 CalculateRectTransforms(large_size_, large_corner_radius_, &transforms); 369 CalculateRectTransforms(large_size_, large_corner_radius_, &transforms);
253 AnimateToTransforms(transforms, kHiddenOpacity, 370 AnimateToTransforms(transforms,
254 GetAnimationDuration(InkDropState::SLOW_ACTION), 371 GetAnimationDuration(SLOW_ACTION_VISIBLE) +
372 GetAnimationDuration(SLOW_ACTION_FADE_OUT),
255 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, 373 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
256 animation_observer); 374 animation_observer);
257 break; 375 break;
258 case InkDropState::ACTIVATED: 376 case InkDropState::ACTIVATED:
377 AnimateToOpacity(kVisibleOpacity, GetAnimationDuration(ACTIVATED),
378 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
379 animation_observer);
259 CalculateRectTransforms(small_size_, small_corner_radius_, &transforms); 380 CalculateRectTransforms(small_size_, small_corner_radius_, &transforms);
260 AnimateToTransforms(transforms, kVisibleOpacity, 381 AnimateToTransforms(transforms, GetAnimationDuration(ACTIVATED),
261 GetAnimationDuration(InkDropState::ACTIVATED),
262 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, 382 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
263 animation_observer); 383 animation_observer);
264 break; 384 break;
265 case InkDropState::DEACTIVATED: 385 case InkDropState::DEACTIVATED:
386 AnimateToOpacity(kVisibleOpacity,
387 GetAnimationDuration(DEACTIVATED_VISIBLE),
388 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
389 animation_observer);
390 AnimateToOpacity(
391 kHiddenOpacity, GetAnimationDuration(DEACTIVATED_FADE_OUT),
392 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION, animation_observer);
266 CalculateRectTransforms(large_size_, large_corner_radius_, &transforms); 393 CalculateRectTransforms(large_size_, large_corner_radius_, &transforms);
267 AnimateToTransforms(transforms, kHiddenOpacity, 394 AnimateToTransforms(transforms,
268 GetAnimationDuration(InkDropState::DEACTIVATED), 395 GetAnimationDuration(DEACTIVATED_VISIBLE) +
396 GetAnimationDuration(DEACTIVATED_FADE_OUT),
269 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, 397 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
270 animation_observer); 398 animation_observer);
271 break; 399 break;
272 } 400 }
273 } 401 }
274 402
275 void InkDropAnimation::AnimateToTransforms( 403 void InkDropAnimation::AnimateToTransforms(
276 const InkDropTransforms transforms, 404 const InkDropTransforms transforms,
277 float opacity,
278 base::TimeDelta duration, 405 base::TimeDelta duration,
279 ui::LayerAnimator::PreemptionStrategy preemption_strategy, 406 ui::LayerAnimator::PreemptionStrategy preemption_strategy,
280 ui::LayerAnimationObserver* animation_observer) { 407 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) { 408 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) {
295 ui::LayerAnimator* animator = painted_layers_[i]->GetAnimator(); 409 ui::LayerAnimator* animator = painted_layers_[i]->GetAnimator();
296 ui::ScopedLayerAnimationSettings animation(animator); 410 ui::ScopedLayerAnimationSettings animation(animator);
297 animation.SetPreemptionStrategy(preemption_strategy); 411 animation.SetPreemptionStrategy(preemption_strategy);
298 ui::LayerAnimationElement* element = 412 ui::LayerAnimationElement* element =
299 ui::LayerAnimationElement::CreateTransformElement(transforms[i], 413 ui::LayerAnimationElement::CreateTransformElement(transforms[i],
300 duration); 414 duration);
301 ui::LayerAnimationSequence* sequence = 415 ui::LayerAnimationSequence* sequence =
302 new ui::LayerAnimationSequence(element); 416 new ui::LayerAnimationSequence(element);
303 417
304 if (animation_observer) 418 if (animation_observer)
305 sequence->AddObserver(animation_observer); 419 sequence->AddObserver(animation_observer);
306 420
307 animator->StartAnimation(sequence); 421 animator->StartAnimation(sequence);
308 } 422 }
309 } 423 }
310 424
311 void InkDropAnimation::SetStateToHidden() { 425 void InkDropAnimation::SetStateToHidden() {
312 InkDropTransforms transforms; 426 InkDropTransforms transforms;
313 // Using a size of 0x0 creates visual anomalies. 427 // Using a size of 0x0 creates visual anomalies.
314 CalculateCircleTransforms(gfx::Size(1, 1), &transforms); 428 CalculateCircleTransforms(gfx::Size(1, 1), &transforms);
315 SetTransforms(transforms); 429 SetTransforms(transforms);
316 SetOpacity(kHiddenOpacity); 430 SetOpacity(kHiddenOpacity);
431 root_layer_->SetVisible(false);
317 } 432 }
318 433
319 void InkDropAnimation::SetTransforms(const InkDropTransforms transforms) { 434 void InkDropAnimation::SetTransforms(const InkDropTransforms transforms) {
320 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) 435 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i)
321 painted_layers_[i]->SetTransform(transforms[i]); 436 painted_layers_[i]->SetTransform(transforms[i]);
322 } 437 }
323 438
324 void InkDropAnimation::SetOpacity(float opacity) { 439 void InkDropAnimation::SetOpacity(float opacity) {
325 root_layer_->SetOpacity(opacity); 440 root_layer_->SetOpacity(opacity);
326 } 441 }
327 442
443 void InkDropAnimation::AnimateToOpacity(
444 float opacity,
445 base::TimeDelta duration,
446 ui::LayerAnimator::PreemptionStrategy preemption_strategy,
447 ui::LayerAnimationObserver* animation_observer) {
448 ui::LayerAnimator* animator = root_layer_->GetAnimator();
449 ui::ScopedLayerAnimationSettings animation_settings(animator);
450 animation_settings.SetPreemptionStrategy(preemption_strategy);
451 ui::LayerAnimationElement* animation_element =
452 ui::LayerAnimationElement::CreateOpacityElement(opacity, duration);
453 ui::LayerAnimationSequence* animation_sequence =
454 new ui::LayerAnimationSequence(animation_element);
455
456 if (animation_observer)
457 animation_sequence->AddObserver(animation_observer);
458
459 animator->StartAnimation(animation_sequence);
460 }
461
328 void InkDropAnimation::CalculateCircleTransforms( 462 void InkDropAnimation::CalculateCircleTransforms(
329 const gfx::Size& size, 463 const gfx::Size& size,
330 InkDropTransforms* transforms_out) const { 464 InkDropTransforms* transforms_out) const {
331 CalculateRectTransforms(size, std::min(size.width(), size.height()) / 2.0f, 465 CalculateRectTransforms(size, std::min(size.width(), size.height()) / 2.0f,
332 transforms_out); 466 transforms_out);
333 } 467 }
334 468
335 void InkDropAnimation::CalculateRectTransforms( 469 void InkDropAnimation::CalculateRectTransforms(
336 const gfx::Size& size, 470 const gfx::Size& size,
337 float corner_radius, 471 float corner_radius,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 std::max(kMinimumRectScale, 513 std::max(kMinimumRectScale,
380 (size.height() - 2.0f * corner_radius) / rect_delegate_height)); 514 (size.height() - 2.0f * corner_radius) / rect_delegate_height));
381 515
382 (*transforms_out)[VERTICAL_RECT] = CalculateRectTransform( 516 (*transforms_out)[VERTICAL_RECT] = CalculateRectTransform(
383 ToRoundedPoint(rect_layer_delegate_->GetCenterPoint()), 517 ToRoundedPoint(rect_layer_delegate_->GetCenterPoint()),
384 std::max(kMinimumRectScale, 518 std::max(kMinimumRectScale,
385 (size.width() - 2.0f * corner_radius) / rect_delegate_width), 519 (size.width() - 2.0f * corner_radius) / rect_delegate_width),
386 std::max(kMinimumRectScale, size.height() / rect_delegate_height)); 520 std::max(kMinimumRectScale, size.height() / rect_delegate_height));
387 } 521 }
388 522
389 void InkDropAnimation::GetCurrentTansforms( 523 void InkDropAnimation::GetCurrentTransforms(
390 InkDropTransforms* transforms_out) const { 524 InkDropTransforms* transforms_out) const {
391 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) 525 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i)
392 (*transforms_out)[i] = painted_layers_[i]->GetTargetTransform(); 526 (*transforms_out)[i] = painted_layers_[i]->transform();
393 } 527 }
394 528
395 void InkDropAnimation::AddPaintLayer(PaintedShape painted_shape) { 529 void InkDropAnimation::AddPaintLayer(PaintedShape painted_shape) {
396 ui::LayerDelegate* delegate = nullptr; 530 ui::LayerDelegate* delegate = nullptr;
397 switch (painted_shape) { 531 switch (painted_shape) {
398 case TOP_LEFT_CIRCLE: 532 case TOP_LEFT_CIRCLE:
399 case TOP_RIGHT_CIRCLE: 533 case TOP_RIGHT_CIRCLE:
400 case BOTTOM_RIGHT_CIRCLE: 534 case BOTTOM_RIGHT_CIRCLE:
401 case BOTTOM_LEFT_CIRCLE: 535 case BOTTOM_LEFT_CIRCLE:
402 delegate = circle_layer_delegate_.get(); 536 delegate = circle_layer_delegate_.get();
(...skipping 20 matching lines...) Expand all
423 557
424 painted_layers_[painted_shape].reset(layer); 558 painted_layers_[painted_shape].reset(layer);
425 } 559 }
426 560
427 void InkDropAnimation::AbortAllAnimations() { 561 void InkDropAnimation::AbortAllAnimations() {
428 root_layer_->GetAnimator()->AbortAllAnimations(); 562 root_layer_->GetAnimator()->AbortAllAnimations();
429 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) 563 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i)
430 painted_layers_[i]->GetAnimator()->AbortAllAnimations(); 564 painted_layers_[i]->GetAnimator()->AbortAllAnimations();
431 } 565 }
432 566
567 float InkDropAnimation::CalculateDistanceEstimateToQuickAction(
568 const InkDropTransforms& transforms) const {
569 gfx::Point3F circle_center_point =
570 gfx::Point3F(circle_layer_delegate_->GetCenterPoint());
571
572 gfx::Point3F circle_top_point(
573 circle_center_point.x(),
574 circle_center_point.y() - circle_layer_delegate_->radius(), 0);
575
576 transforms[TOP_LEFT_CIRCLE].TransformPoint(&circle_center_point);
577 transforms[TOP_LEFT_CIRCLE].TransformPoint(&circle_top_point);
578
579 // Calculate the ratio of how far the transformed circle's center point is
580 // from the destination compared to how far it can be.
581 const float center_point_distance_estimate =
582 1.0f -
583 gfx::Vector3dF(circle_center_point.x(), circle_center_point.y(), 0)
584 .Length() /
585 (gfx::Vector3dF(static_cast<float>(large_size_.width()),
586 static_cast<float>(large_size_.height()), 0)
587 .Length() /
588 2.0f);
589
590 // Calculate the ratio of how far the transformed circle's topmost point is
591 // from the destination compared to how far it can be.
592 const float top_point_distance_estimate =
593 circle_top_point.y() / (large_size_.height() / 2.0f);
594
595 return std::min(center_point_distance_estimate, top_point_distance_estimate);
596 }
597
433 void InkDropAnimation::AnimationStartedCallback( 598 void InkDropAnimation::AnimationStartedCallback(
434 InkDropState ink_drop_state, 599 InkDropState ink_drop_state,
435 const ui::CallbackLayerAnimationObserver& observer) { 600 const ui::CallbackLayerAnimationObserver& observer) {
436 FOR_EACH_OBSERVER(InkDropAnimationObserver, observers_, 601 FOR_EACH_OBSERVER(InkDropAnimationObserver, observers_,
437 InkDropAnimationStarted(ink_drop_state)); 602 InkDropAnimationStarted(ink_drop_state));
438 } 603 }
439 604
440 bool InkDropAnimation::AnimationEndedCallback( 605 bool InkDropAnimation::AnimationEndedCallback(
441 InkDropState ink_drop_state, 606 InkDropState ink_drop_state,
442 const ui::CallbackLayerAnimationObserver& observer) { 607 const ui::CallbackLayerAnimationObserver& observer) {
443 FOR_EACH_OBSERVER( 608 FOR_EACH_OBSERVER(
444 InkDropAnimationObserver, observers_, 609 InkDropAnimationObserver, observers_,
445 InkDropAnimationEnded(ink_drop_state, 610 InkDropAnimationEnded(ink_drop_state,
446 observer.aborted_count() 611 observer.aborted_count()
447 ? InkDropAnimationObserver::PRE_EMPTED 612 ? InkDropAnimationObserver::PRE_EMPTED
448 : InkDropAnimationObserver::SUCCESS)); 613 : InkDropAnimationObserver::SUCCESS));
449 return true; 614 return true;
450 } 615 }
451 616
452 } // namespace views 617 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/animation/ink_drop_animation.h ('k') | ui/views/animation/ink_drop_painted_layer_delegates.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698