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 "ash/wm/window_animations.h" | 5 #include "ash/wm/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 16 matching lines...) Expand all Loading... |
27 #include "ui/aura/window_observer.h" | 27 #include "ui/aura/window_observer.h" |
28 #include "ui/aura/window_property.h" | 28 #include "ui/aura/window_property.h" |
29 #include "ui/compositor/compositor_observer.h" | 29 #include "ui/compositor/compositor_observer.h" |
30 #include "ui/compositor/layer.h" | 30 #include "ui/compositor/layer.h" |
31 #include "ui/compositor/layer_animation_observer.h" | 31 #include "ui/compositor/layer_animation_observer.h" |
32 #include "ui/compositor/layer_animation_sequence.h" | 32 #include "ui/compositor/layer_animation_sequence.h" |
33 #include "ui/compositor/layer_animator.h" | 33 #include "ui/compositor/layer_animator.h" |
34 #include "ui/compositor/scoped_layer_animation_settings.h" | 34 #include "ui/compositor/scoped_layer_animation_settings.h" |
35 #include "ui/gfx/interpolated_transform.h" | 35 #include "ui/gfx/interpolated_transform.h" |
36 #include "ui/gfx/screen.h" | 36 #include "ui/gfx/screen.h" |
| 37 #include "ui/gfx/vector3d_f.h" |
37 #include "ui/views/view.h" | 38 #include "ui/views/view.h" |
38 #include "ui/views/widget/widget.h" | 39 #include "ui/views/widget/widget.h" |
39 | 40 |
40 DECLARE_WINDOW_PROPERTY_TYPE(int) | 41 DECLARE_WINDOW_PROPERTY_TYPE(int) |
41 DECLARE_WINDOW_PROPERTY_TYPE(ash::WindowVisibilityAnimationType) | 42 DECLARE_WINDOW_PROPERTY_TYPE(ash::WindowVisibilityAnimationType) |
42 DECLARE_WINDOW_PROPERTY_TYPE(ash::WindowVisibilityAnimationTransition) | 43 DECLARE_WINDOW_PROPERTY_TYPE(ash::WindowVisibilityAnimationTransition) |
43 DECLARE_WINDOW_PROPERTY_TYPE(float) | 44 DECLARE_WINDOW_PROPERTY_TYPE(float) |
44 DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(ASH_EXPORT, bool) | 45 DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(ASH_EXPORT, bool) |
45 | 46 |
46 using aura::Window; | 47 using aura::Window; |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 | 273 |
273 base::TimeDelta duration = GetWindowVisibilityAnimationDuration(window); | 274 base::TimeDelta duration = GetWindowVisibilityAnimationDuration(window); |
274 if (duration.ToInternalValue() > 0) | 275 if (duration.ToInternalValue() > 0) |
275 settings.SetTransitionDuration(duration); | 276 settings.SetTransitionDuration(duration); |
276 | 277 |
277 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); | 278 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); |
278 window->layer()->SetTransform(end_transform); | 279 window->layer()->SetTransform(end_transform); |
279 window->layer()->SetVisible(false); | 280 window->layer()->SetVisible(false); |
280 } | 281 } |
281 | 282 |
| 283 static gfx::Transform GetScaleForWindow(aura::Window* window) { |
| 284 gfx::Rect bounds = window->bounds(); |
| 285 gfx::Transform scale = gfx::GetScaleTransform( |
| 286 gfx::Point(kWindowAnimation_TranslateFactor * bounds.width(), |
| 287 kWindowAnimation_TranslateFactor * bounds.height()), |
| 288 kWindowAnimation_ScaleFactor); |
| 289 return scale; |
| 290 } |
| 291 |
282 // Show/Hide windows using a shrink animation. | 292 // Show/Hide windows using a shrink animation. |
283 void AnimateShowWindow_Drop(aura::Window* window) { | 293 void AnimateShowWindow_Drop(aura::Window* window) { |
284 gfx::Transform transform; | 294 AnimateShowWindowCommon(window, GetScaleForWindow(window), gfx::Transform()); |
285 transform.ConcatScale(kWindowAnimation_ScaleFactor, | |
286 kWindowAnimation_ScaleFactor); | |
287 gfx::Rect bounds = window->bounds(); | |
288 transform.ConcatTranslate( | |
289 kWindowAnimation_TranslateFactor * bounds.width(), | |
290 kWindowAnimation_TranslateFactor * bounds.height()); | |
291 AnimateShowWindowCommon(window, transform, gfx::Transform()); | |
292 } | 295 } |
293 | 296 |
294 void AnimateHideWindow_Drop(aura::Window* window) { | 297 void AnimateHideWindow_Drop(aura::Window* window) { |
295 gfx::Transform transform; | 298 AnimateHideWindowCommon(window, GetScaleForWindow(window)); |
296 transform.ConcatScale(kWindowAnimation_ScaleFactor, | |
297 kWindowAnimation_ScaleFactor); | |
298 gfx::Rect bounds = window->bounds(); | |
299 transform.ConcatTranslate( | |
300 kWindowAnimation_TranslateFactor * bounds.width(), | |
301 kWindowAnimation_TranslateFactor * bounds.height()); | |
302 AnimateHideWindowCommon(window, transform); | |
303 } | 299 } |
304 | 300 |
305 // Show/Hide windows using a vertical Glenimation. | 301 // Show/Hide windows using a vertical Glenimation. |
306 void AnimateShowWindow_Vertical(aura::Window* window) { | 302 void AnimateShowWindow_Vertical(aura::Window* window) { |
307 gfx::Transform transform; | 303 gfx::Transform transform; |
308 transform.ConcatTranslate(0, window->GetProperty( | 304 transform.Translate(0, window->GetProperty( |
309 kWindowVisibilityAnimationVerticalPositionKey)); | 305 kWindowVisibilityAnimationVerticalPositionKey)); |
310 AnimateShowWindowCommon(window, transform, gfx::Transform()); | 306 AnimateShowWindowCommon(window, transform, gfx::Transform()); |
311 } | 307 } |
312 | 308 |
313 void AnimateHideWindow_Vertical(aura::Window* window) { | 309 void AnimateHideWindow_Vertical(aura::Window* window) { |
314 gfx::Transform transform; | 310 gfx::Transform transform; |
315 transform.ConcatTranslate(0, window->GetProperty( | 311 transform.Translate(0, window->GetProperty( |
316 kWindowVisibilityAnimationVerticalPositionKey)); | 312 kWindowVisibilityAnimationVerticalPositionKey)); |
317 AnimateHideWindowCommon(window, transform); | 313 AnimateHideWindowCommon(window, transform); |
318 } | 314 } |
319 | 315 |
320 // Show/Hide windows using a fade. | 316 // Show/Hide windows using a fade. |
321 void AnimateShowWindow_Fade(aura::Window* window) { | 317 void AnimateShowWindow_Fade(aura::Window* window) { |
322 AnimateShowWindowCommon(window, gfx::Transform(), gfx::Transform()); | 318 AnimateShowWindowCommon(window, gfx::Transform(), gfx::Transform()); |
323 } | 319 } |
324 | 320 |
325 void AnimateHideWindow_Fade(aura::Window* window) { | 321 void AnimateHideWindow_Fade(aura::Window* window) { |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 ui::LayerAnimationElement::CreateOpacityElement( | 491 ui::LayerAnimationElement::CreateOpacityElement( |
496 show ? kWindowAnimation_ShowOpacity : kWindowAnimation_HideOpacity, | 492 show ? kWindowAnimation_ShowOpacity : kWindowAnimation_HideOpacity, |
497 duration * kWindowAnimation_Rotate_OpacityDurationPercent / 100)); | 493 duration * kWindowAnimation_Rotate_OpacityDurationPercent / 100)); |
498 opacity->set_tween_type(ui::Tween::EASE_IN_OUT); | 494 opacity->set_tween_type(ui::Tween::EASE_IN_OUT); |
499 window->layer()->GetAnimator()->ScheduleAnimation( | 495 window->layer()->GetAnimator()->ScheduleAnimation( |
500 new ui::LayerAnimationSequence(opacity.release())); | 496 new ui::LayerAnimationSequence(opacity.release())); |
501 | 497 |
502 float xcenter = window->bounds().width() * 0.5; | 498 float xcenter = window->bounds().width() * 0.5; |
503 | 499 |
504 gfx::Transform transform; | 500 gfx::Transform transform; |
505 transform.ConcatTranslate(-xcenter, 0); | 501 transform.Translate(xcenter, 0); |
506 transform.ConcatPerspectiveDepth(kWindowAnimation_Rotate_PerspectiveDepth); | 502 transform.ApplyPerspectiveDepth(kWindowAnimation_Rotate_PerspectiveDepth); |
507 transform.ConcatTranslate(xcenter, 0); | 503 transform.Translate(-xcenter, 0); |
508 scoped_ptr<ui::InterpolatedTransform> perspective( | 504 scoped_ptr<ui::InterpolatedTransform> perspective( |
509 new ui::InterpolatedConstantTransform(transform)); | 505 new ui::InterpolatedConstantTransform(transform)); |
510 | 506 |
511 scoped_ptr<ui::InterpolatedTransform> scale( | 507 scoped_ptr<ui::InterpolatedTransform> scale( |
512 new ui::InterpolatedScale(1, kWindowAnimation_Rotate_ScaleFactor)); | 508 new ui::InterpolatedScale(1, kWindowAnimation_Rotate_ScaleFactor)); |
513 scoped_ptr<ui::InterpolatedTransform> scale_about_pivot( | 509 scoped_ptr<ui::InterpolatedTransform> scale_about_pivot( |
514 new ui::InterpolatedTransformAboutPivot( | 510 new ui::InterpolatedTransformAboutPivot( |
515 gfx::Point(xcenter, kWindowAnimation_Rotate_TranslateY), | 511 gfx::Point(xcenter, kWindowAnimation_Rotate_TranslateY), |
516 scale.release())); | 512 scale.release())); |
517 | 513 |
518 scoped_ptr<ui::InterpolatedTransform> translation( | 514 scoped_ptr<ui::InterpolatedTransform> translation( |
519 new ui::InterpolatedTranslation(gfx::Point(), gfx::Point( | 515 new ui::InterpolatedTranslation(gfx::Point(), gfx::Point( |
520 0, kWindowAnimation_Rotate_TranslateY))); | 516 0, kWindowAnimation_Rotate_TranslateY))); |
521 | 517 |
522 scoped_ptr<ui::InterpolatedTransform> rotation( | 518 scoped_ptr<ui::InterpolatedTransform> rotation( |
523 new ui::InterpolatedAxisAngleRotation( | 519 new ui::InterpolatedAxisAngleRotation( |
524 gfx::Point3F(1, 0, 0), 0, kWindowAnimation_Rotate_DegreesX)); | 520 gfx::Vector3dF(1, 0, 0), 0, kWindowAnimation_Rotate_DegreesX)); |
525 | 521 |
526 scale_about_pivot->SetChild(perspective.release()); | 522 scale_about_pivot->SetChild(perspective.release()); |
527 translation->SetChild(scale_about_pivot.release()); | 523 translation->SetChild(scale_about_pivot.release()); |
528 rotation->SetChild(translation.release()); | 524 rotation->SetChild(translation.release()); |
529 rotation->SetReversed(show); | 525 rotation->SetReversed(show); |
530 | 526 |
531 scoped_ptr<ui::LayerAnimationElement> transition( | 527 scoped_ptr<ui::LayerAnimationElement> transition( |
532 ui::LayerAnimationElement::CreateInterpolatedTransformElement( | 528 ui::LayerAnimationElement::CreateInterpolatedTransformElement( |
533 rotation.release(), duration)); | 529 rotation.release(), duration)); |
534 | 530 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 | 681 |
686 // Animation observer owns the old layer and deletes itself. | 682 // Animation observer owns the old layer and deletes itself. |
687 settings.AddObserver(new internal::CrossFadeObserver(window, old_layer)); | 683 settings.AddObserver(new internal::CrossFadeObserver(window, old_layer)); |
688 settings.SetTransitionDuration(duration); | 684 settings.SetTransitionDuration(duration); |
689 settings.SetTweenType(tween_type); | 685 settings.SetTweenType(tween_type); |
690 gfx::Transform out_transform; | 686 gfx::Transform out_transform; |
691 float scale_x = static_cast<float>(new_bounds.width()) / | 687 float scale_x = static_cast<float>(new_bounds.width()) / |
692 static_cast<float>(old_bounds.width()); | 688 static_cast<float>(old_bounds.width()); |
693 float scale_y = static_cast<float>(new_bounds.height()) / | 689 float scale_y = static_cast<float>(new_bounds.height()) / |
694 static_cast<float>(old_bounds.height()); | 690 static_cast<float>(old_bounds.height()); |
695 out_transform.ConcatScale(scale_x, scale_y); | 691 out_transform.Translate(new_bounds.x() - old_bounds.x(), |
696 out_transform.ConcatTranslate(new_bounds.x() - old_bounds.x(), | 692 new_bounds.y() - old_bounds.y()); |
697 new_bounds.y() - old_bounds.y()); | 693 out_transform.Scale(scale_x, scale_y); |
698 old_layer->SetTransform(out_transform); | 694 old_layer->SetTransform(out_transform); |
699 if (old_on_top) { | 695 if (old_on_top) { |
700 // The old layer is on top, and should fade out. The new layer below will | 696 // The old layer is on top, and should fade out. The new layer below will |
701 // stay opaque to block the desktop. | 697 // stay opaque to block the desktop. |
702 old_layer->SetOpacity(0.f); | 698 old_layer->SetOpacity(0.f); |
703 } | 699 } |
704 // In tests |old_layer| is deleted here, as animations have zero duration. | 700 // In tests |old_layer| is deleted here, as animations have zero duration. |
705 old_layer = NULL; | 701 old_layer = NULL; |
706 } | 702 } |
707 | 703 |
708 // Set the new layer's current transform, such that the user sees a scaled | 704 // Set the new layer's current transform, such that the user sees a scaled |
709 // version of the window with the original bounds at the original position. | 705 // version of the window with the original bounds at the original position. |
710 gfx::Transform in_transform; | 706 gfx::Transform in_transform; |
711 const float scale_x = static_cast<float>(old_bounds.width()) / | 707 const float scale_x = static_cast<float>(old_bounds.width()) / |
712 static_cast<float>(new_bounds.width()); | 708 static_cast<float>(new_bounds.width()); |
713 const float scale_y = static_cast<float>(old_bounds.height()) / | 709 const float scale_y = static_cast<float>(old_bounds.height()) / |
714 static_cast<float>(new_bounds.height()); | 710 static_cast<float>(new_bounds.height()); |
715 in_transform.ConcatScale(scale_x, scale_y); | 711 in_transform.Translate(old_bounds.x() - new_bounds.x(), |
716 in_transform.ConcatTranslate(old_bounds.x() - new_bounds.x(), | |
717 old_bounds.y() - new_bounds.y()); | 712 old_bounds.y() - new_bounds.y()); |
| 713 in_transform.Scale(scale_x, scale_y); |
718 window->layer()->SetTransform(in_transform); | 714 window->layer()->SetTransform(in_transform); |
719 if (!old_on_top) { | 715 if (!old_on_top) { |
720 // The new layer is on top and should fade in. The old layer below will | 716 // The new layer is on top and should fade in. The old layer below will |
721 // stay opaque and block the desktop. | 717 // stay opaque and block the desktop. |
722 window->layer()->SetOpacity(0.f); | 718 window->layer()->SetOpacity(0.f); |
723 } | 719 } |
724 { | 720 { |
725 // Animate the new layer to the identity transform, so the window goes to | 721 // Animate the new layer to the identity transform, so the window goes to |
726 // its newly set bounds. | 722 // its newly set bounds. |
727 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); | 723 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
885 | 881 |
886 std::vector<ui::LayerAnimationSequence*> animations; | 882 std::vector<ui::LayerAnimationSequence*> animations; |
887 animations.push_back(brightness_sequence.release()); | 883 animations.push_back(brightness_sequence.release()); |
888 animations.push_back(grayscale_sequence.release()); | 884 animations.push_back(grayscale_sequence.release()); |
889 | 885 |
890 return animations; | 886 return animations; |
891 } | 887 } |
892 | 888 |
893 } // namespace internal | 889 } // namespace internal |
894 } // namespace ash | 890 } // namespace ash |
OLD | NEW |