OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/wm/core/window_animations.h" | 5 #include "ui/wm/core/window_animations.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <vector> | 10 #include <vector> |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 | 344 |
345 // Show/Hide windows using a fade. | 345 // Show/Hide windows using a fade. |
346 void AnimateShowWindow_Fade(aura::Window* window) { | 346 void AnimateShowWindow_Fade(aura::Window* window) { |
347 AnimateShowWindowCommon(window, gfx::Transform(), gfx::Transform()); | 347 AnimateShowWindowCommon(window, gfx::Transform(), gfx::Transform()); |
348 } | 348 } |
349 | 349 |
350 void AnimateHideWindow_Fade(aura::Window* window) { | 350 void AnimateHideWindow_Fade(aura::Window* window) { |
351 AnimateHideWindowCommon(window, gfx::Transform()); | 351 AnimateHideWindowCommon(window, gfx::Transform()); |
352 } | 352 } |
353 | 353 |
354 ui::LayerAnimationElement* CreateGrowShrinkElement( | 354 std::unique_ptr<ui::LayerAnimationElement> CreateGrowShrinkElement( |
355 aura::Window* window, bool grow) { | 355 aura::Window* window, |
356 std::unique_ptr<ui::InterpolatedTransform> scale( | 356 bool grow) { |
357 new ui::InterpolatedScale(gfx::Point3F(kWindowAnimation_Bounce_Scale, | 357 std::unique_ptr<ui::InterpolatedTransform> scale = |
358 kWindowAnimation_Bounce_Scale, 1), | 358 base::MakeUnique<ui::InterpolatedScale>( |
359 gfx::Point3F(1, 1, 1))); | 359 gfx::Point3F(kWindowAnimation_Bounce_Scale, |
360 std::unique_ptr<ui::InterpolatedTransform> scale_about_pivot( | 360 kWindowAnimation_Bounce_Scale, 1), |
361 new ui::InterpolatedTransformAboutPivot( | 361 gfx::Point3F(1, 1, 1)); |
| 362 std::unique_ptr<ui::InterpolatedTransform> scale_about_pivot = |
| 363 base::MakeUnique<ui::InterpolatedTransformAboutPivot>( |
362 gfx::Point(window->bounds().width() * 0.5, | 364 gfx::Point(window->bounds().width() * 0.5, |
363 window->bounds().height() * 0.5), | 365 window->bounds().height() * 0.5), |
364 scale.release())); | 366 std::move(scale)); |
365 scale_about_pivot->SetReversed(grow); | 367 scale_about_pivot->SetReversed(grow); |
366 std::unique_ptr<ui::LayerAnimationElement> transition( | 368 std::unique_ptr<ui::LayerAnimationElement> transition = |
367 ui::LayerAnimationElement::CreateInterpolatedTransformElement( | 369 ui::LayerAnimationElement::CreateInterpolatedTransformElement( |
368 scale_about_pivot.release(), | 370 std::move(scale_about_pivot), |
369 base::TimeDelta::FromMilliseconds( | 371 base::TimeDelta::FromMilliseconds( |
370 kWindowAnimation_Bounce_DurationMS * | 372 kWindowAnimation_Bounce_DurationMS * |
371 kWindowAnimation_Bounce_GrowShrinkDurationPercent / 100))); | 373 kWindowAnimation_Bounce_GrowShrinkDurationPercent / 100)); |
372 transition->set_tween_type(grow ? gfx::Tween::EASE_OUT : gfx::Tween::EASE_IN); | 374 transition->set_tween_type(grow ? gfx::Tween::EASE_OUT : gfx::Tween::EASE_IN); |
373 return transition.release(); | 375 return transition; |
374 } | 376 } |
375 | 377 |
376 void AnimateBounce(aura::Window* window) { | 378 void AnimateBounce(aura::Window* window) { |
377 ui::ScopedLayerAnimationSettings scoped_settings( | 379 ui::ScopedLayerAnimationSettings scoped_settings( |
378 window->layer()->GetAnimator()); | 380 window->layer()->GetAnimator()); |
379 scoped_settings.SetPreemptionStrategy( | 381 scoped_settings.SetPreemptionStrategy( |
380 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); | 382 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); |
381 std::unique_ptr<ui::LayerAnimationSequence> sequence( | 383 std::unique_ptr<ui::LayerAnimationSequence> sequence = |
382 new ui::LayerAnimationSequence); | 384 base::MakeUnique<ui::LayerAnimationSequence>(); |
383 sequence->AddElement(CreateGrowShrinkElement(window, true)); | 385 sequence->AddElement(CreateGrowShrinkElement(window, true)); |
384 sequence->AddElement(ui::LayerAnimationElement::CreatePauseElement( | 386 sequence->AddElement(ui::LayerAnimationElement::CreatePauseElement( |
385 ui::LayerAnimationElement::BOUNDS, | 387 ui::LayerAnimationElement::BOUNDS, |
386 base::TimeDelta::FromMilliseconds( | 388 base::TimeDelta::FromMilliseconds( |
387 kWindowAnimation_Bounce_DurationMS * | 389 kWindowAnimation_Bounce_DurationMS * |
388 (100 - 2 * kWindowAnimation_Bounce_GrowShrinkDurationPercent) / | 390 (100 - 2 * kWindowAnimation_Bounce_GrowShrinkDurationPercent) / |
389 100))); | 391 100))); |
390 sequence->AddElement(CreateGrowShrinkElement(window, false)); | 392 sequence->AddElement(CreateGrowShrinkElement(window, false)); |
391 window->layer()->GetAnimator()->StartAnimation(sequence.release()); | 393 window->layer()->GetAnimator()->StartAnimation(sequence.release()); |
392 } | 394 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 kWindowAnimation_Rotate_DurationMS); | 431 kWindowAnimation_Rotate_DurationMS); |
430 | 432 |
431 RotateHidingWindowAnimationObserver* observer = NULL; | 433 RotateHidingWindowAnimationObserver* observer = NULL; |
432 | 434 |
433 if (!show) { | 435 if (!show) { |
434 observer = new RotateHidingWindowAnimationObserver(window); | 436 observer = new RotateHidingWindowAnimationObserver(window); |
435 window->layer()->GetAnimator()->SchedulePauseForProperties( | 437 window->layer()->GetAnimator()->SchedulePauseForProperties( |
436 duration * (100 - kWindowAnimation_Rotate_OpacityDurationPercent) / 100, | 438 duration * (100 - kWindowAnimation_Rotate_OpacityDurationPercent) / 100, |
437 ui::LayerAnimationElement::OPACITY); | 439 ui::LayerAnimationElement::OPACITY); |
438 } | 440 } |
439 std::unique_ptr<ui::LayerAnimationElement> opacity( | 441 std::unique_ptr<ui::LayerAnimationElement> opacity = |
440 ui::LayerAnimationElement::CreateOpacityElement( | 442 ui::LayerAnimationElement::CreateOpacityElement( |
441 show ? kWindowAnimation_ShowOpacity : kWindowAnimation_HideOpacity, | 443 show ? kWindowAnimation_ShowOpacity : kWindowAnimation_HideOpacity, |
442 duration * kWindowAnimation_Rotate_OpacityDurationPercent / 100)); | 444 duration * kWindowAnimation_Rotate_OpacityDurationPercent / 100); |
443 opacity->set_tween_type(gfx::Tween::EASE_IN_OUT); | 445 opacity->set_tween_type(gfx::Tween::EASE_IN_OUT); |
444 window->layer()->GetAnimator()->ScheduleAnimation( | 446 window->layer()->GetAnimator()->ScheduleAnimation( |
445 new ui::LayerAnimationSequence(opacity.release())); | 447 new ui::LayerAnimationSequence(std::move(opacity))); |
446 | 448 |
447 float xcenter = window->bounds().width() * 0.5; | 449 float xcenter = window->bounds().width() * 0.5; |
448 | 450 |
449 gfx::Transform transform; | 451 gfx::Transform transform; |
450 transform.Translate(xcenter, 0); | 452 transform.Translate(xcenter, 0); |
451 transform.ApplyPerspectiveDepth(kWindowAnimation_Rotate_PerspectiveDepth); | 453 transform.ApplyPerspectiveDepth(kWindowAnimation_Rotate_PerspectiveDepth); |
452 transform.Translate(-xcenter, 0); | 454 transform.Translate(-xcenter, 0); |
453 std::unique_ptr<ui::InterpolatedTransform> perspective( | 455 std::unique_ptr<ui::InterpolatedTransform> perspective = |
454 new ui::InterpolatedConstantTransform(transform)); | 456 base::MakeUnique<ui::InterpolatedConstantTransform>(transform); |
455 | 457 |
456 std::unique_ptr<ui::InterpolatedTransform> scale( | 458 std::unique_ptr<ui::InterpolatedTransform> scale = |
457 new ui::InterpolatedScale(1, kWindowAnimation_Rotate_ScaleFactor)); | 459 base::MakeUnique<ui::InterpolatedScale>( |
458 std::unique_ptr<ui::InterpolatedTransform> scale_about_pivot( | 460 1, kWindowAnimation_Rotate_ScaleFactor); |
459 new ui::InterpolatedTransformAboutPivot( | 461 std::unique_ptr<ui::InterpolatedTransform> scale_about_pivot = |
| 462 base::MakeUnique<ui::InterpolatedTransformAboutPivot>( |
460 gfx::Point(xcenter, kWindowAnimation_Rotate_TranslateY), | 463 gfx::Point(xcenter, kWindowAnimation_Rotate_TranslateY), |
461 scale.release())); | 464 std::move(scale)); |
462 | 465 |
463 std::unique_ptr<ui::InterpolatedTransform> translation( | 466 std::unique_ptr<ui::InterpolatedTransform> translation = |
464 new ui::InterpolatedTranslation( | 467 base::MakeUnique<ui::InterpolatedTranslation>( |
465 gfx::PointF(), gfx::PointF(0, kWindowAnimation_Rotate_TranslateY))); | 468 gfx::PointF(), gfx::PointF(0, kWindowAnimation_Rotate_TranslateY)); |
466 | 469 |
467 std::unique_ptr<ui::InterpolatedTransform> rotation( | 470 std::unique_ptr<ui::InterpolatedTransform> rotation = |
468 new ui::InterpolatedAxisAngleRotation(gfx::Vector3dF(1, 0, 0), 0, | 471 base::MakeUnique<ui::InterpolatedAxisAngleRotation>( |
469 kWindowAnimation_Rotate_DegreesX)); | 472 gfx::Vector3dF(1, 0, 0), 0, kWindowAnimation_Rotate_DegreesX); |
470 | 473 |
471 scale_about_pivot->SetChild(perspective.release()); | 474 scale_about_pivot->SetChild(std::move(perspective)); |
472 translation->SetChild(scale_about_pivot.release()); | 475 translation->SetChild(std::move(scale_about_pivot)); |
473 rotation->SetChild(translation.release()); | 476 rotation->SetChild(std::move(translation)); |
474 rotation->SetReversed(show); | 477 rotation->SetReversed(show); |
475 | 478 |
476 std::unique_ptr<ui::LayerAnimationElement> transition( | 479 std::unique_ptr<ui::LayerAnimationElement> transition = |
477 ui::LayerAnimationElement::CreateInterpolatedTransformElement( | 480 ui::LayerAnimationElement::CreateInterpolatedTransformElement( |
478 rotation.release(), duration)); | 481 std::move(rotation), duration); |
479 ui::LayerAnimationSequence* last_sequence = | 482 ui::LayerAnimationSequence* last_sequence = |
480 new ui::LayerAnimationSequence(transition.release()); | 483 new ui::LayerAnimationSequence(std::move(transition)); |
481 window->layer()->GetAnimator()->ScheduleAnimation(last_sequence); | 484 window->layer()->GetAnimator()->ScheduleAnimation(last_sequence); |
482 | 485 |
483 if (observer) { | 486 if (observer) { |
484 observer->SetLastSequence(last_sequence); | 487 observer->SetLastSequence(last_sequence); |
485 observer->DetachAndRecreateLayers(); | 488 observer->DetachAndRecreateLayers(); |
486 } | 489 } |
487 } | 490 } |
488 | 491 |
489 void AnimateShowWindow_Rotate(aura::Window* window) { | 492 void AnimateShowWindow_Rotate(aura::Window* window) { |
490 AddLayerAnimationsForRotate(window, true); | 493 AddLayerAnimationsForRotate(window, true); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 // being accessed via Remote Desktop. | 663 // being accessed via Remote Desktop. |
661 if (ui::ScopedAnimationDurationScaleMode::duration_scale_mode() == | 664 if (ui::ScopedAnimationDurationScaleMode::duration_scale_mode() == |
662 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION) | 665 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION) |
663 return false; | 666 return false; |
664 | 667 |
665 // Let the user decide whether or not to play the animation. | 668 // Let the user decide whether or not to play the animation. |
666 return !gfx::Animation::ShouldRenderRichAnimation(); | 669 return !gfx::Animation::ShouldRenderRichAnimation(); |
667 } | 670 } |
668 | 671 |
669 } // namespace wm | 672 } // namespace wm |
OLD | NEW |