Chromium Code Reviews| 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/flood_fill_ink_drop_ripple.h" | 5 #include "ui/views/animation/flood_fill_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 "third_party/skia/include/core/SkColor.h" | 10 #include "third_party/skia/include/core/SkColor.h" |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 gfx::Tween::EASE_IN_OUT, animation_observer); | 208 gfx::Tween::EASE_IN_OUT, animation_observer); |
| 209 } | 209 } |
| 210 break; | 210 break; |
| 211 case InkDropState::ACTION_PENDING: { | 211 case InkDropState::ACTION_PENDING: { |
| 212 DCHECK(old_ink_drop_state == InkDropState::HIDDEN); | 212 DCHECK(old_ink_drop_state == InkDropState::HIDDEN); |
| 213 | 213 |
| 214 AnimateToOpacity(visible_opacity_, | 214 AnimateToOpacity(visible_opacity_, |
| 215 GetAnimationDuration(ACTION_PENDING_FADE_IN), | 215 GetAnimationDuration(ACTION_PENDING_FADE_IN), |
| 216 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | 216 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, |
| 217 gfx::Tween::EASE_IN, animation_observer); | 217 gfx::Tween::EASE_IN, animation_observer); |
| 218 AnimateToOpacity(visible_opacity_, | 218 PauseOpacityAnimation(GetAnimationDuration(ACTION_PENDING_TRANSFORM) - |
| 219 GetAnimationDuration(ACTION_PENDING_TRANSFORM) - | 219 GetAnimationDuration(ACTION_PENDING_FADE_IN), |
| 220 GetAnimationDuration(ACTION_PENDING_FADE_IN), | 220 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION, |
| 221 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION, | 221 animation_observer); |
| 222 gfx::Tween::EASE_IN, animation_observer); | |
| 223 | 222 |
| 224 AnimateToTransform(GetMaxSizeTargetTransform(), | 223 AnimateToTransform(GetMaxSizeTargetTransform(), |
| 225 GetAnimationDuration(ACTION_PENDING_TRANSFORM), | 224 GetAnimationDuration(ACTION_PENDING_TRANSFORM), |
| 226 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | 225 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, |
| 227 gfx::Tween::FAST_OUT_SLOW_IN, animation_observer); | 226 gfx::Tween::FAST_OUT_SLOW_IN, animation_observer); |
| 228 break; | 227 break; |
| 229 } | 228 } |
| 230 case InkDropState::ACTION_TRIGGERED: { | 229 case InkDropState::ACTION_TRIGGERED: { |
| 231 DCHECK(old_ink_drop_state == InkDropState::HIDDEN || | 230 DCHECK(old_ink_drop_state == InkDropState::HIDDEN || |
| 232 old_ink_drop_state == InkDropState::ACTION_PENDING); | 231 old_ink_drop_state == InkDropState::ACTION_PENDING); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 253 break; | 252 break; |
| 254 } | 253 } |
| 255 case InkDropState::ALTERNATE_ACTION_TRIGGERED: | 254 case InkDropState::ALTERNATE_ACTION_TRIGGERED: |
| 256 DCHECK(old_ink_drop_state == InkDropState::ALTERNATE_ACTION_PENDING); | 255 DCHECK(old_ink_drop_state == InkDropState::ALTERNATE_ACTION_PENDING); |
| 257 AnimateToOpacity(kHiddenOpacity, GetAnimationDuration( | 256 AnimateToOpacity(kHiddenOpacity, GetAnimationDuration( |
| 258 ALTERNATE_ACTION_TRIGGERED_FADE_OUT), | 257 ALTERNATE_ACTION_TRIGGERED_FADE_OUT), |
| 259 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION, | 258 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION, |
| 260 gfx::Tween::EASE_IN_OUT, animation_observer); | 259 gfx::Tween::EASE_IN_OUT, animation_observer); |
| 261 break; | 260 break; |
| 262 case InkDropState::ACTIVATED: { | 261 case InkDropState::ACTIVATED: { |
| 262 if (old_ink_drop_state == InkDropState::ACTION_PENDING) { | |
| 263 // The final state of pending animation is the same as the final state | |
|
bruthig
2017/01/05 20:20:39
Can this be confirmed/enforced by a test?
mohsen
2017/01/06 19:48:06
Done.
| |
| 264 // of activated animation. We only need to enqueue a zero-length pause | |
| 265 // so that animation observers are notified in order. | |
|
bruthig
2017/01/05 20:20:39
Can this be confirmed/enforced by a test?
mohsen
2017/01/06 19:48:06
Done.
| |
| 266 PauseOpacityAnimation( | |
| 267 base::TimeDelta(), | |
| 268 ui::LayerAnimator::PreemptionStrategy::ENQUEUE_NEW_ANIMATION, | |
| 269 animation_observer); | |
| 270 PauseTransformAnimation( | |
| 271 base::TimeDelta(), | |
| 272 ui::LayerAnimator::PreemptionStrategy::ENQUEUE_NEW_ANIMATION, | |
| 273 animation_observer); | |
| 274 break; | |
| 275 } | |
| 263 AnimateToOpacity(visible_opacity_, | 276 AnimateToOpacity(visible_opacity_, |
| 264 GetAnimationDuration(ACTIVATED_FADE_IN), | 277 GetAnimationDuration(ACTIVATED_FADE_IN), |
| 265 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | 278 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, |
| 266 gfx::Tween::EASE_IN, animation_observer); | 279 gfx::Tween::EASE_IN, animation_observer); |
| 267 AnimateToTransform(GetMaxSizeTargetTransform(), | 280 AnimateToTransform(GetMaxSizeTargetTransform(), |
| 268 GetAnimationDuration(ACTIVATED_TRANSFORM), | 281 GetAnimationDuration(ACTIVATED_TRANSFORM), |
| 269 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | 282 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, |
| 270 gfx::Tween::EASE_IN_OUT, animation_observer); | 283 gfx::Tween::EASE_IN_OUT, animation_observer); |
| 271 break; | 284 break; |
| 272 } | 285 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 306 | 319 |
| 307 ui::LayerAnimationSequence* sequence = | 320 ui::LayerAnimationSequence* sequence = |
| 308 new ui::LayerAnimationSequence(std::move(element)); | 321 new ui::LayerAnimationSequence(std::move(element)); |
| 309 | 322 |
| 310 if (animation_observer) | 323 if (animation_observer) |
| 311 sequence->AddObserver(animation_observer); | 324 sequence->AddObserver(animation_observer); |
| 312 | 325 |
| 313 animator->StartAnimation(sequence); | 326 animator->StartAnimation(sequence); |
| 314 } | 327 } |
| 315 | 328 |
| 329 void FloodFillInkDropRipple::PauseTransformAnimation( | |
| 330 base::TimeDelta duration, | |
| 331 ui::LayerAnimator::PreemptionStrategy preemption_strategy, | |
| 332 ui::LayerAnimationObserver* observer) { | |
| 333 ui::LayerAnimator* animator = painted_layer_.GetAnimator(); | |
| 334 ui::ScopedLayerAnimationSettings animation(animator); | |
| 335 animation.SetPreemptionStrategy(preemption_strategy); | |
| 336 | |
| 337 std::unique_ptr<ui::LayerAnimationElement> element = | |
| 338 ui::LayerAnimationElement::CreatePauseElement( | |
| 339 ui::LayerAnimationElement::TRANSFORM, duration); | |
| 340 | |
| 341 ui::LayerAnimationSequence* sequence = | |
| 342 new ui::LayerAnimationSequence(std::move(element)); | |
| 343 | |
| 344 if (observer) | |
| 345 sequence->AddObserver(observer); | |
| 346 | |
| 347 animator->StartAnimation(sequence); | |
| 348 } | |
| 349 | |
| 316 void FloodFillInkDropRipple::SetOpacity(float opacity) { | 350 void FloodFillInkDropRipple::SetOpacity(float opacity) { |
| 317 root_layer_.SetOpacity(opacity); | 351 root_layer_.SetOpacity(opacity); |
| 318 } | 352 } |
| 319 | 353 |
| 320 void FloodFillInkDropRipple::AnimateToOpacity( | 354 void FloodFillInkDropRipple::AnimateToOpacity( |
| 321 float opacity, | 355 float opacity, |
| 322 base::TimeDelta duration, | 356 base::TimeDelta duration, |
| 323 ui::LayerAnimator::PreemptionStrategy preemption_strategy, | 357 ui::LayerAnimator::PreemptionStrategy preemption_strategy, |
| 324 gfx::Tween::Type tween, | 358 gfx::Tween::Type tween, |
| 325 ui::LayerAnimationObserver* animation_observer) { | 359 ui::LayerAnimationObserver* animation_observer) { |
| 326 ui::LayerAnimator* animator = root_layer_.GetAnimator(); | 360 ui::LayerAnimator* animator = root_layer_.GetAnimator(); |
| 327 ui::ScopedLayerAnimationSettings animation_settings(animator); | 361 ui::ScopedLayerAnimationSettings animation_settings(animator); |
| 328 animation_settings.SetPreemptionStrategy(preemption_strategy); | 362 animation_settings.SetPreemptionStrategy(preemption_strategy); |
| 329 animation_settings.SetTweenType(tween); | 363 animation_settings.SetTweenType(tween); |
| 330 std::unique_ptr<ui::LayerAnimationElement> animation_element = | 364 std::unique_ptr<ui::LayerAnimationElement> animation_element = |
| 331 ui::LayerAnimationElement::CreateOpacityElement(opacity, duration); | 365 ui::LayerAnimationElement::CreateOpacityElement(opacity, duration); |
| 332 ui::LayerAnimationSequence* animation_sequence = | 366 ui::LayerAnimationSequence* animation_sequence = |
| 333 new ui::LayerAnimationSequence(std::move(animation_element)); | 367 new ui::LayerAnimationSequence(std::move(animation_element)); |
| 334 | 368 |
| 335 if (animation_observer) | 369 if (animation_observer) |
| 336 animation_sequence->AddObserver(animation_observer); | 370 animation_sequence->AddObserver(animation_observer); |
| 337 | 371 |
| 338 animator->StartAnimation(animation_sequence); | 372 animator->StartAnimation(animation_sequence); |
| 339 } | 373 } |
| 340 | 374 |
| 375 void FloodFillInkDropRipple::PauseOpacityAnimation( | |
| 376 base::TimeDelta duration, | |
| 377 ui::LayerAnimator::PreemptionStrategy preemption_strategy, | |
| 378 ui::LayerAnimationObserver* observer) { | |
| 379 ui::LayerAnimator* animator = root_layer_.GetAnimator(); | |
| 380 ui::ScopedLayerAnimationSettings animation(animator); | |
| 381 animation.SetPreemptionStrategy(preemption_strategy); | |
| 382 | |
| 383 std::unique_ptr<ui::LayerAnimationElement> element = | |
| 384 ui::LayerAnimationElement::CreatePauseElement( | |
| 385 ui::LayerAnimationElement::OPACITY, duration); | |
| 386 | |
| 387 ui::LayerAnimationSequence* sequence = | |
| 388 new ui::LayerAnimationSequence(std::move(element)); | |
| 389 | |
| 390 if (observer) | |
| 391 sequence->AddObserver(observer); | |
| 392 | |
| 393 animator->StartAnimation(sequence); | |
| 394 } | |
| 395 | |
| 341 gfx::Transform FloodFillInkDropRipple::CalculateTransform( | 396 gfx::Transform FloodFillInkDropRipple::CalculateTransform( |
| 342 float target_radius) const { | 397 float target_radius) const { |
| 343 const float target_scale = target_radius / circle_layer_delegate_.radius(); | 398 const float target_scale = target_radius / circle_layer_delegate_.radius(); |
| 344 | 399 |
| 345 gfx::Transform transform = gfx::Transform(); | 400 gfx::Transform transform = gfx::Transform(); |
| 346 transform.Translate(center_point_.x() - root_layer_.bounds().x(), | 401 transform.Translate(center_point_.x() - root_layer_.bounds().x(), |
| 347 center_point_.y() - root_layer_.bounds().y()); | 402 center_point_.y() - root_layer_.bounds().y()); |
| 348 transform.Scale(target_scale, target_scale); | 403 transform.Scale(target_scale, target_scale); |
| 349 | 404 |
| 350 const gfx::Vector2dF drawn_center_offset = | 405 const gfx::Vector2dF drawn_center_offset = |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 368 (bounds.bottom_right() - point).Length(); | 423 (bounds.bottom_right() - point).Length(); |
| 369 | 424 |
| 370 float largest_distance = | 425 float largest_distance = |
| 371 std::max(distance_to_top_left, distance_to_top_right); | 426 std::max(distance_to_top_left, distance_to_top_right); |
| 372 largest_distance = std::max(largest_distance, distance_to_bottom_left); | 427 largest_distance = std::max(largest_distance, distance_to_bottom_left); |
| 373 largest_distance = std::max(largest_distance, distance_to_bottom_right); | 428 largest_distance = std::max(largest_distance, distance_to_bottom_right); |
| 374 return largest_distance; | 429 return largest_distance; |
| 375 } | 430 } |
| 376 | 431 |
| 377 } // namespace views | 432 } // namespace views |
| OLD | NEW |