| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/square_ink_drop_ripple.h" | 5 #include "ui/views/animation/square_ink_drop_ripple.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "ui/compositor/layer.h" | 10 #include "ui/compositor/layer.h" |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 gfx::Tween::EASE_IN, animation_observer); | 290 gfx::Tween::EASE_IN, animation_observer); |
| 291 AnimateToOpacity(visible_opacity_, | 291 AnimateToOpacity(visible_opacity_, |
| 292 GetAnimationDuration(ACTION_PENDING_TRANSFORM), | 292 GetAnimationDuration(ACTION_PENDING_TRANSFORM), |
| 293 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | 293 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, |
| 294 gfx::Tween::EASE_IN, animation_observer); | 294 gfx::Tween::EASE_IN, animation_observer); |
| 295 CalculateCircleTransforms(large_size_, &transforms); | 295 CalculateCircleTransforms(large_size_, &transforms); |
| 296 AnimateToTransforms(transforms, | 296 AnimateToTransforms(transforms, |
| 297 GetAnimationDuration(ACTION_PENDING_TRANSFORM), | 297 GetAnimationDuration(ACTION_PENDING_TRANSFORM), |
| 298 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | 298 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, |
| 299 gfx::Tween::EASE_IN_OUT, animation_observer); | 299 gfx::Tween::EASE_IN_OUT, animation_observer); |
| 300 AnimateCenterPoint(target_center_point_, | |
| 301 GetAnimationDuration(ACTION_PENDING_TRANSFORM), | |
| 302 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | |
| 303 gfx::Tween::EASE_IN, animation_observer); | |
| 304 break; | 300 break; |
| 305 case InkDropState::ACTION_TRIGGERED: { | 301 case InkDropState::ACTION_TRIGGERED: { |
| 306 DCHECK(old_ink_drop_state == InkDropState::HIDDEN || | 302 DCHECK(old_ink_drop_state == InkDropState::HIDDEN || |
| 307 old_ink_drop_state == InkDropState::ACTION_PENDING) | 303 old_ink_drop_state == InkDropState::ACTION_PENDING) |
| 308 << " old_ink_drop_state=" << ToString(old_ink_drop_state); | 304 << " old_ink_drop_state=" << ToString(old_ink_drop_state); |
| 309 if (old_ink_drop_state == InkDropState::HIDDEN) { | 305 if (old_ink_drop_state == InkDropState::HIDDEN) { |
| 310 AnimateStateChange(old_ink_drop_state, InkDropState::ACTION_PENDING, | 306 AnimateStateChange(old_ink_drop_state, InkDropState::ACTION_PENDING, |
| 311 animation_observer); | 307 animation_observer); |
| 312 } | 308 } |
| 313 AnimateToOpacity(kHiddenOpacity, | 309 AnimateToOpacity(kHiddenOpacity, |
| 314 GetAnimationDuration(ACTION_TRIGGERED_FADE_OUT), | 310 GetAnimationDuration(ACTION_TRIGGERED_FADE_OUT), |
| 315 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION, | 311 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION, |
| 316 gfx::Tween::EASE_IN_OUT, animation_observer); | 312 gfx::Tween::EASE_IN_OUT, animation_observer); |
| 317 gfx::Size s = ScaleToRoundedSize(large_size_, kQuickActionBurstScale); | 313 gfx::Size s = ScaleToRoundedSize(large_size_, kQuickActionBurstScale); |
| 318 CalculateCircleTransforms(s, &transforms); | 314 CalculateCircleTransforms(s, &transforms); |
| 319 AnimateToTransforms(transforms, | 315 AnimateToTransforms(transforms, |
| 320 GetAnimationDuration(ACTION_TRIGGERED_TRANSFORM), | 316 GetAnimationDuration(ACTION_TRIGGERED_TRANSFORM), |
| 321 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION, | 317 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION, |
| 322 gfx::Tween::EASE_IN_OUT, animation_observer); | 318 gfx::Tween::EASE_IN_OUT, animation_observer); |
| 323 AnimateCenterPoint(target_center_point_, | |
| 324 GetAnimationDuration(ACTION_TRIGGERED_TRANSFORM), | |
| 325 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION, | |
| 326 gfx::Tween::EASE_IN, animation_observer); | |
| 327 break; | 319 break; |
| 328 } | 320 } |
| 329 case InkDropState::ALTERNATE_ACTION_PENDING: | 321 case InkDropState::ALTERNATE_ACTION_PENDING: |
| 330 DCHECK_EQ(InkDropState::ACTION_PENDING, old_ink_drop_state) | 322 DCHECK_EQ(InkDropState::ACTION_PENDING, old_ink_drop_state) |
| 331 << " old_ink_drop_state=" << ToString(old_ink_drop_state); | 323 << " old_ink_drop_state=" << ToString(old_ink_drop_state); |
| 332 AnimateToOpacity(visible_opacity_, | 324 AnimateToOpacity(visible_opacity_, |
| 333 GetAnimationDuration(ALTERNATE_ACTION_PENDING), | 325 GetAnimationDuration(ALTERNATE_ACTION_PENDING), |
| 334 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | 326 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, |
| 335 gfx::Tween::EASE_IN, animation_observer); | 327 gfx::Tween::EASE_IN, animation_observer); |
| 336 CalculateRectTransforms(small_size_, small_corner_radius_, &transforms); | 328 CalculateRectTransforms(small_size_, small_corner_radius_, &transforms); |
| 337 AnimateToTransforms(transforms, | 329 AnimateToTransforms(transforms, |
| 338 GetAnimationDuration(ALTERNATE_ACTION_PENDING), | 330 GetAnimationDuration(ALTERNATE_ACTION_PENDING), |
| 339 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | 331 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, |
| 340 gfx::Tween::EASE_IN_OUT, animation_observer); | 332 gfx::Tween::EASE_IN_OUT, animation_observer); |
| 341 AnimateCenterPoint(target_center_point_, | |
| 342 GetAnimationDuration(ALTERNATE_ACTION_PENDING), | |
| 343 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | |
| 344 gfx::Tween::EASE_IN, animation_observer); | |
| 345 break; | 333 break; |
| 346 case InkDropState::ALTERNATE_ACTION_TRIGGERED: { | 334 case InkDropState::ALTERNATE_ACTION_TRIGGERED: { |
| 347 DCHECK_EQ(InkDropState::ALTERNATE_ACTION_PENDING, old_ink_drop_state) | 335 DCHECK_EQ(InkDropState::ALTERNATE_ACTION_PENDING, old_ink_drop_state) |
| 348 << " old_ink_drop_state=" << ToString(old_ink_drop_state); | 336 << " old_ink_drop_state=" << ToString(old_ink_drop_state); |
| 349 base::TimeDelta visible_duration = | 337 base::TimeDelta visible_duration = |
| 350 GetAnimationDuration(ALTERNATE_ACTION_TRIGGERED_TRANSFORM) - | 338 GetAnimationDuration(ALTERNATE_ACTION_TRIGGERED_TRANSFORM) - |
| 351 GetAnimationDuration(ALTERNATE_ACTION_TRIGGERED_FADE_OUT); | 339 GetAnimationDuration(ALTERNATE_ACTION_TRIGGERED_FADE_OUT); |
| 352 AnimateToOpacity(visible_opacity_, visible_duration, | 340 AnimateToOpacity(visible_opacity_, visible_duration, |
| 353 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | 341 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, |
| 354 gfx::Tween::EASE_IN_OUT, animation_observer); | 342 gfx::Tween::EASE_IN_OUT, animation_observer); |
| 355 AnimateToOpacity(kHiddenOpacity, GetAnimationDuration( | 343 AnimateToOpacity(kHiddenOpacity, GetAnimationDuration( |
| 356 ALTERNATE_ACTION_TRIGGERED_FADE_OUT), | 344 ALTERNATE_ACTION_TRIGGERED_FADE_OUT), |
| 357 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION, | 345 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION, |
| 358 gfx::Tween::EASE_IN_OUT, animation_observer); | 346 gfx::Tween::EASE_IN_OUT, animation_observer); |
| 359 CalculateRectTransforms(large_size_, large_corner_radius_, &transforms); | 347 CalculateRectTransforms(large_size_, large_corner_radius_, &transforms); |
| 360 AnimateToTransforms(transforms, GetAnimationDuration( | 348 AnimateToTransforms(transforms, GetAnimationDuration( |
| 361 ALTERNATE_ACTION_TRIGGERED_TRANSFORM), | 349 ALTERNATE_ACTION_TRIGGERED_TRANSFORM), |
| 362 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | 350 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, |
| 363 gfx::Tween::EASE_IN_OUT, animation_observer); | 351 gfx::Tween::EASE_IN_OUT, animation_observer); |
| 364 AnimateCenterPoint( | |
| 365 target_center_point_, | |
| 366 GetAnimationDuration(ALTERNATE_ACTION_TRIGGERED_TRANSFORM), | |
| 367 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | |
| 368 gfx::Tween::EASE_IN, animation_observer); | |
| 369 break; | 352 break; |
| 370 } | 353 } |
| 371 case InkDropState::ACTIVATED: { | 354 case InkDropState::ACTIVATED: { |
| 372 // Animate the opacity so that it cancels any opacity animations already | 355 // Animate the opacity so that it cancels any opacity animations already |
| 373 // in progress. | 356 // in progress. |
| 374 AnimateToOpacity(visible_opacity_, base::TimeDelta(), | 357 AnimateToOpacity(visible_opacity_, base::TimeDelta(), |
| 375 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | 358 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, |
| 376 gfx::Tween::EASE_IN_OUT, animation_observer); | 359 gfx::Tween::EASE_IN_OUT, animation_observer); |
| 377 | 360 |
| 378 ui::LayerAnimator::PreemptionStrategy rect_transform_preemption_strategy = | 361 ui::LayerAnimator::PreemptionStrategy rect_transform_preemption_strategy = |
| 379 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET; | 362 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET; |
| 380 if (old_ink_drop_state == InkDropState::HIDDEN) { | 363 if (old_ink_drop_state == InkDropState::HIDDEN) { |
| 381 rect_transform_preemption_strategy = | 364 rect_transform_preemption_strategy = |
| 382 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION; | 365 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION; |
| 383 CalculateCircleTransforms(large_size_, &transforms); | 366 CalculateCircleTransforms(large_size_, &transforms); |
| 384 AnimateToTransforms( | 367 AnimateToTransforms( |
| 385 transforms, GetAnimationDuration(ACTIVATED_CIRCLE_TRANSFORM), | 368 transforms, GetAnimationDuration(ACTIVATED_CIRCLE_TRANSFORM), |
| 386 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | 369 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, |
| 387 gfx::Tween::EASE_IN_OUT, animation_observer); | 370 gfx::Tween::EASE_IN_OUT, animation_observer); |
| 388 AnimateCenterPoint(target_center_point_, | |
| 389 GetAnimationDuration(ACTIVATED_CIRCLE_TRANSFORM), | |
| 390 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | |
| 391 gfx::Tween::EASE_IN, animation_observer); | |
| 392 } else if (old_ink_drop_state == InkDropState::ACTION_PENDING) { | 371 } else if (old_ink_drop_state == InkDropState::ACTION_PENDING) { |
| 393 rect_transform_preemption_strategy = | 372 rect_transform_preemption_strategy = |
| 394 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION; | 373 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION; |
| 395 } | 374 } |
| 396 | 375 |
| 397 GetActivatedTargetTransforms(&transforms); | 376 GetActivatedTargetTransforms(&transforms); |
| 398 AnimateToTransforms(transforms, | 377 AnimateToTransforms(transforms, |
| 399 GetAnimationDuration(ACTIVATED_RECT_TRANSFORM), | 378 GetAnimationDuration(ACTIVATED_RECT_TRANSFORM), |
| 400 rect_transform_preemption_strategy, | 379 rect_transform_preemption_strategy, |
| 401 gfx::Tween::EASE_IN_OUT, animation_observer); | 380 gfx::Tween::EASE_IN_OUT, animation_observer); |
| 402 AnimateCenterPoint(target_center_point_, | |
| 403 GetAnimationDuration(ACTIVATED_RECT_TRANSFORM), | |
| 404 rect_transform_preemption_strategy, | |
| 405 gfx::Tween::EASE_IN, animation_observer); | |
| 406 break; | 381 break; |
| 407 } | 382 } |
| 408 case InkDropState::DEACTIVATED: { | 383 case InkDropState::DEACTIVATED: { |
| 409 base::TimeDelta visible_duration = | 384 base::TimeDelta visible_duration = |
| 410 GetAnimationDuration(DEACTIVATED_TRANSFORM) - | 385 GetAnimationDuration(DEACTIVATED_TRANSFORM) - |
| 411 GetAnimationDuration(DEACTIVATED_FADE_OUT); | 386 GetAnimationDuration(DEACTIVATED_FADE_OUT); |
| 412 AnimateToOpacity(visible_opacity_, visible_duration, | 387 AnimateToOpacity(visible_opacity_, visible_duration, |
| 413 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | 388 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, |
| 414 gfx::Tween::EASE_IN_OUT, animation_observer); | 389 gfx::Tween::EASE_IN_OUT, animation_observer); |
| 415 AnimateToOpacity(kHiddenOpacity, | 390 AnimateToOpacity(kHiddenOpacity, |
| 416 GetAnimationDuration(DEACTIVATED_FADE_OUT), | 391 GetAnimationDuration(DEACTIVATED_FADE_OUT), |
| 417 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION, | 392 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION, |
| 418 gfx::Tween::EASE_IN_OUT, animation_observer); | 393 gfx::Tween::EASE_IN_OUT, animation_observer); |
| 419 GetDeactivatedTargetTransforms(&transforms); | 394 GetDeactivatedTargetTransforms(&transforms); |
| 420 AnimateToTransforms(transforms, | 395 AnimateToTransforms(transforms, |
| 421 GetAnimationDuration(DEACTIVATED_TRANSFORM), | 396 GetAnimationDuration(DEACTIVATED_TRANSFORM), |
| 422 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | 397 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, |
| 423 gfx::Tween::EASE_IN_OUT, animation_observer); | 398 gfx::Tween::EASE_IN_OUT, animation_observer); |
| 424 AnimateCenterPoint(target_center_point_, | |
| 425 GetAnimationDuration(DEACTIVATED_TRANSFORM), | |
| 426 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | |
| 427 gfx::Tween::EASE_IN, animation_observer); | |
| 428 break; | 399 break; |
| 429 } | 400 } |
| 430 } | 401 } |
| 431 } | 402 } |
| 432 | 403 |
| 433 void SquareInkDropRipple::SetStateToHidden() { | 404 void SquareInkDropRipple::SetStateToHidden() { |
| 434 InkDropTransforms transforms; | 405 InkDropTransforms transforms; |
| 435 // Use non-zero size to avoid visual anomalies. | 406 // Use non-zero size to avoid visual anomalies. |
| 436 CalculateCircleTransforms(gfx::Size(1, 1), &transforms); | 407 CalculateCircleTransforms(gfx::Size(1, 1), &transforms); |
| 437 SetTransforms(transforms); | 408 SetTransforms(transforms); |
| 438 root_layer_.SetOpacity(InkDropRipple::kHiddenOpacity); | 409 root_layer_.SetOpacity(InkDropRipple::kHiddenOpacity); |
| 439 root_layer_.SetVisible(false); | 410 root_layer_.SetVisible(false); |
| 440 } | 411 } |
| 441 | 412 |
| 442 void SquareInkDropRipple::AbortAllAnimations() { | 413 void SquareInkDropRipple::AbortAllAnimations() { |
| 443 root_layer_.GetAnimator()->AbortAllAnimations(); | 414 root_layer_.GetAnimator()->AbortAllAnimations(); |
| 444 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) | 415 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) |
| 445 painted_layers_[i]->GetAnimator()->AbortAllAnimations(); | 416 painted_layers_[i]->GetAnimator()->AbortAllAnimations(); |
| 446 } | 417 } |
| 447 | 418 |
| 448 void SquareInkDropRipple::AnimateCenterPoint( | |
| 449 const gfx::Point& center_point, | |
| 450 base::TimeDelta duration, | |
| 451 ui::LayerAnimator::PreemptionStrategy preemption_strategy, | |
| 452 gfx::Tween::Type tween, | |
| 453 ui::LayerAnimationObserver* observer) { | |
| 454 ui::LayerAnimator* animator = root_layer_.GetAnimator(); | |
| 455 ui::ScopedLayerAnimationSettings animation(animator); | |
| 456 animation.SetPreemptionStrategy(preemption_strategy); | |
| 457 animation.SetTweenType(tween); | |
| 458 gfx::Transform transform; | |
| 459 transform.Translate(target_center_point_.x(), target_center_point_.y()); | |
| 460 std::unique_ptr<ui::LayerAnimationElement> element = | |
| 461 ui::LayerAnimationElement::CreateTransformElement(transform, duration); | |
| 462 ui::LayerAnimationSequence* sequence = | |
| 463 new ui::LayerAnimationSequence(std::move(element)); | |
| 464 | |
| 465 if (observer) | |
| 466 sequence->AddObserver(observer); | |
| 467 | |
| 468 animator->StartAnimation(sequence); | |
| 469 } | |
| 470 | |
| 471 void SquareInkDropRipple::AnimateToTransforms( | 419 void SquareInkDropRipple::AnimateToTransforms( |
| 472 const InkDropTransforms transforms, | 420 const InkDropTransforms transforms, |
| 473 base::TimeDelta duration, | 421 base::TimeDelta duration, |
| 474 ui::LayerAnimator::PreemptionStrategy preemption_strategy, | 422 ui::LayerAnimator::PreemptionStrategy preemption_strategy, |
| 475 gfx::Tween::Type tween, | 423 gfx::Tween::Type tween, |
| 476 ui::LayerAnimationObserver* animation_observer) { | 424 ui::LayerAnimationObserver* animation_observer) { |
| 477 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) { | 425 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) { |
| 478 ui::LayerAnimator* animator = painted_layers_[i]->GetAnimator(); | 426 ui::LayerAnimator* animator = painted_layers_[i]->GetAnimator(); |
| 479 ui::ScopedLayerAnimationSettings animation(animator); | 427 ui::ScopedLayerAnimationSettings animation(animator); |
| 480 animation.SetPreemptionStrategy(preemption_strategy); | 428 animation.SetPreemptionStrategy(preemption_strategy); |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 layer->set_delegate(delegate); | 593 layer->set_delegate(delegate); |
| 646 layer->SetVisible(true); | 594 layer->SetVisible(true); |
| 647 layer->SetOpacity(1.0); | 595 layer->SetOpacity(1.0); |
| 648 layer->SetMasksToBounds(false); | 596 layer->SetMasksToBounds(false); |
| 649 layer->set_name("PAINTED_SHAPE_COUNT:" + ToLayerName(painted_shape)); | 597 layer->set_name("PAINTED_SHAPE_COUNT:" + ToLayerName(painted_shape)); |
| 650 | 598 |
| 651 painted_layers_[painted_shape].reset(layer); | 599 painted_layers_[painted_shape].reset(layer); |
| 652 } | 600 } |
| 653 | 601 |
| 654 } // namespace views | 602 } // namespace views |
| OLD | NEW |