| 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_animation.h" | 5 #include "ui/views/animation/square_ink_drop_animation.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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 | 188 |
| 189 SetStateToHidden(); | 189 SetStateToHidden(); |
| 190 } | 190 } |
| 191 | 191 |
| 192 SquareInkDropAnimation::~SquareInkDropAnimation() { | 192 SquareInkDropAnimation::~SquareInkDropAnimation() { |
| 193 // Explicitly aborting all the animations ensures all callbacks are invoked | 193 // Explicitly aborting all the animations ensures all callbacks are invoked |
| 194 // while this instance still exists. | 194 // while this instance still exists. |
| 195 AbortAllAnimations(); | 195 AbortAllAnimations(); |
| 196 } | 196 } |
| 197 | 197 |
| 198 void SquareInkDropAnimation::SnapToActivated() { |
| 199 InkDropAnimation::SnapToActivated(); |
| 200 SetOpacity(kVisibleOpacity); |
| 201 InkDropTransforms transforms; |
| 202 GetActivatedTargetTransforms(&transforms); |
| 203 SetTransforms(transforms); |
| 204 } |
| 205 |
| 198 ui::Layer* SquareInkDropAnimation::GetRootLayer() { | 206 ui::Layer* SquareInkDropAnimation::GetRootLayer() { |
| 199 return &root_layer_; | 207 return &root_layer_; |
| 200 } | 208 } |
| 201 | 209 |
| 202 bool SquareInkDropAnimation::IsVisible() const { | 210 bool SquareInkDropAnimation::IsVisible() const { |
| 203 return root_layer_.visible(); | 211 return root_layer_.visible(); |
| 204 } | 212 } |
| 205 | 213 |
| 206 float SquareInkDropAnimation::GetCurrentOpacity() const { | 214 float SquareInkDropAnimation::GetCurrentOpacity() const { |
| 207 return root_layer_.opacity(); | 215 return root_layer_.opacity(); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 gfx::Tween::EASE_IN, animation_observer); | 270 gfx::Tween::EASE_IN, animation_observer); |
| 263 CalculateCircleTransforms(large_size_, &transforms); | 271 CalculateCircleTransforms(large_size_, &transforms); |
| 264 AnimateToTransforms(transforms, | 272 AnimateToTransforms(transforms, |
| 265 GetAnimationDuration(ACTION_PENDING_TRANSFORM), | 273 GetAnimationDuration(ACTION_PENDING_TRANSFORM), |
| 266 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | 274 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, |
| 267 gfx::Tween::EASE_IN_OUT, animation_observer); | 275 gfx::Tween::EASE_IN_OUT, animation_observer); |
| 268 break; | 276 break; |
| 269 case InkDropState::QUICK_ACTION: { | 277 case InkDropState::QUICK_ACTION: { |
| 270 DCHECK(old_ink_drop_state == InkDropState::HIDDEN || | 278 DCHECK(old_ink_drop_state == InkDropState::HIDDEN || |
| 271 old_ink_drop_state == InkDropState::ACTION_PENDING); | 279 old_ink_drop_state == InkDropState::ACTION_PENDING); |
| 280 if (old_ink_drop_state == InkDropState::HIDDEN) { |
| 281 AnimateStateChange(old_ink_drop_state, InkDropState::ACTION_PENDING, |
| 282 animation_observer); |
| 283 } |
| 272 AnimateToOpacity(kHiddenOpacity, | 284 AnimateToOpacity(kHiddenOpacity, |
| 273 GetAnimationDuration(QUICK_ACTION_FADE_OUT), | 285 GetAnimationDuration(QUICK_ACTION_FADE_OUT), |
| 274 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION, | 286 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION, |
| 275 gfx::Tween::EASE_IN_OUT, animation_observer); | 287 gfx::Tween::EASE_IN_OUT, animation_observer); |
| 276 gfx::Size s = ScaleToRoundedSize(large_size_, kQuickActionBurstScale); | 288 gfx::Size s = ScaleToRoundedSize(large_size_, kQuickActionBurstScale); |
| 277 CalculateCircleTransforms(s, &transforms); | 289 CalculateCircleTransforms(s, &transforms); |
| 278 AnimateToTransforms(transforms, | 290 AnimateToTransforms(transforms, |
| 279 GetAnimationDuration(QUICK_ACTION_TRANSFORM), | 291 GetAnimationDuration(QUICK_ACTION_TRANSFORM), |
| 280 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION, | 292 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION, |
| 281 gfx::Tween::EASE_IN_OUT, animation_observer); | 293 gfx::Tween::EASE_IN_OUT, animation_observer); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 CalculateCircleTransforms(large_size_, &transforms); | 338 CalculateCircleTransforms(large_size_, &transforms); |
| 327 AnimateToTransforms( | 339 AnimateToTransforms( |
| 328 transforms, GetAnimationDuration(ACTIVATED_CIRCLE_TRANSFORM), | 340 transforms, GetAnimationDuration(ACTIVATED_CIRCLE_TRANSFORM), |
| 329 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | 341 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, |
| 330 gfx::Tween::EASE_IN_OUT, animation_observer); | 342 gfx::Tween::EASE_IN_OUT, animation_observer); |
| 331 } else if (old_ink_drop_state == InkDropState::ACTION_PENDING) { | 343 } else if (old_ink_drop_state == InkDropState::ACTION_PENDING) { |
| 332 rect_transform_preemption_strategy = | 344 rect_transform_preemption_strategy = |
| 333 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION; | 345 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION; |
| 334 } | 346 } |
| 335 | 347 |
| 336 CalculateRectTransforms(small_size_, small_corner_radius_, &transforms); | 348 GetActivatedTargetTransforms(&transforms); |
| 337 AnimateToTransforms(transforms, | 349 AnimateToTransforms(transforms, |
| 338 GetAnimationDuration(ACTIVATED_RECT_TRANSFORM), | 350 GetAnimationDuration(ACTIVATED_RECT_TRANSFORM), |
| 339 rect_transform_preemption_strategy, | 351 rect_transform_preemption_strategy, |
| 340 gfx::Tween::EASE_IN_OUT, animation_observer); | 352 gfx::Tween::EASE_IN_OUT, animation_observer); |
| 341 break; | 353 break; |
| 342 } | 354 } |
| 343 case InkDropState::DEACTIVATED: { | 355 case InkDropState::DEACTIVATED: { |
| 344 base::TimeDelta visible_duration = | 356 base::TimeDelta visible_duration = |
| 345 GetAnimationDuration(DEACTIVATED_TRANSFORM) - | 357 GetAnimationDuration(DEACTIVATED_TRANSFORM) - |
| 346 GetAnimationDuration(DEACTIVATED_FADE_OUT); | 358 GetAnimationDuration(DEACTIVATED_FADE_OUT); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 (size.width() - 2.0f * corner_radius) / rect_delegate_width), | 503 (size.width() - 2.0f * corner_radius) / rect_delegate_width), |
| 492 std::max(kMinimumRectScale, size.height() / rect_delegate_height)); | 504 std::max(kMinimumRectScale, size.height() / rect_delegate_height)); |
| 493 } | 505 } |
| 494 | 506 |
| 495 void SquareInkDropAnimation::GetCurrentTransforms( | 507 void SquareInkDropAnimation::GetCurrentTransforms( |
| 496 InkDropTransforms* transforms_out) const { | 508 InkDropTransforms* transforms_out) const { |
| 497 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) | 509 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) |
| 498 (*transforms_out)[i] = painted_layers_[i]->transform(); | 510 (*transforms_out)[i] = painted_layers_[i]->transform(); |
| 499 } | 511 } |
| 500 | 512 |
| 513 void SquareInkDropAnimation::GetActivatedTargetTransforms( |
| 514 InkDropTransforms* transforms_out) const { |
| 515 CalculateRectTransforms(small_size_, small_corner_radius_, transforms_out); |
| 516 } |
| 517 |
| 501 void SquareInkDropAnimation::AddPaintLayer(PaintedShape painted_shape) { | 518 void SquareInkDropAnimation::AddPaintLayer(PaintedShape painted_shape) { |
| 502 ui::LayerDelegate* delegate = nullptr; | 519 ui::LayerDelegate* delegate = nullptr; |
| 503 switch (painted_shape) { | 520 switch (painted_shape) { |
| 504 case TOP_LEFT_CIRCLE: | 521 case TOP_LEFT_CIRCLE: |
| 505 case TOP_RIGHT_CIRCLE: | 522 case TOP_RIGHT_CIRCLE: |
| 506 case BOTTOM_RIGHT_CIRCLE: | 523 case BOTTOM_RIGHT_CIRCLE: |
| 507 case BOTTOM_LEFT_CIRCLE: | 524 case BOTTOM_LEFT_CIRCLE: |
| 508 delegate = circle_layer_delegate_.get(); | 525 delegate = circle_layer_delegate_.get(); |
| 509 break; | 526 break; |
| 510 case HORIZONTAL_RECT: | 527 case HORIZONTAL_RECT: |
| (...skipping 13 matching lines...) Expand all Loading... |
| 524 layer->set_delegate(delegate); | 541 layer->set_delegate(delegate); |
| 525 layer->SetVisible(true); | 542 layer->SetVisible(true); |
| 526 layer->SetOpacity(1.0); | 543 layer->SetOpacity(1.0); |
| 527 layer->SetMasksToBounds(false); | 544 layer->SetMasksToBounds(false); |
| 528 layer->set_name("PAINTED_SHAPE_COUNT:" + ToLayerName(painted_shape)); | 545 layer->set_name("PAINTED_SHAPE_COUNT:" + ToLayerName(painted_shape)); |
| 529 | 546 |
| 530 painted_layers_[painted_shape].reset(layer); | 547 painted_layers_[painted_shape].reset(layer); |
| 531 } | 548 } |
| 532 | 549 |
| 533 } // namespace views | 550 } // namespace views |
| OLD | NEW |