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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 kWindowAnimation_Vertical_TranslateY); | 62 kWindowAnimation_Vertical_TranslateY); |
63 | 63 |
64 namespace { | 64 namespace { |
65 | 65 |
66 const int kDefaultAnimationDurationForMenuMS = 150; | 66 const int kDefaultAnimationDurationForMenuMS = 150; |
67 | 67 |
68 // Durations for the cross-fade animation, in milliseconds. | 68 // Durations for the cross-fade animation, in milliseconds. |
69 const float kCrossFadeDurationMinMs = 100.f; | 69 const float kCrossFadeDurationMinMs = 100.f; |
70 const float kCrossFadeDurationMaxMs = 400.f; | 70 const float kCrossFadeDurationMaxMs = 400.f; |
71 | 71 |
| 72 // Durations for the brightness/grayscale fade animation, in milliseconds. |
| 73 const int kBrightnessGrayscaleFadeDurationMs = 2000; |
| 74 |
| 75 // Brightness/grayscale values for hide/show window animations. |
| 76 const float kWindowAnimation_HideBrightnessGrayscale = 1.f; |
| 77 const float kWindowAnimation_ShowBrightnessGrayscale = 0.f; |
| 78 |
72 const float kWindowAnimation_HideOpacity = 0.f; | 79 const float kWindowAnimation_HideOpacity = 0.f; |
73 const float kWindowAnimation_ShowOpacity = 1.f; | 80 const float kWindowAnimation_ShowOpacity = 1.f; |
74 const float kWindowAnimation_TranslateFactor = -0.025f; | 81 const float kWindowAnimation_TranslateFactor = -0.025f; |
75 const float kWindowAnimation_ScaleFactor = 1.05f; | 82 const float kWindowAnimation_ScaleFactor = 1.05f; |
76 const float kWindowAnimation_MinimizeRotate = -5.f; | 83 const float kWindowAnimation_MinimizeRotate = -5.f; |
77 | 84 |
78 // Amount windows are scaled during workspace animations. | 85 // Amount windows are scaled during workspace animations. |
79 const float kWorkspaceScale = .95f; | 86 const float kWorkspaceScale = .95f; |
80 | 87 |
81 int64 Round64(float f) { | 88 int64 Round64(float f) { |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 window->layer()->set_delegate(NULL); | 465 window->layer()->set_delegate(NULL); |
459 | 466 |
460 // Property sets within this scope will be implicitly animated. | 467 // Property sets within this scope will be implicitly animated. |
461 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); | 468 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); |
462 settings.AddObserver(new HidingWindowAnimationObserver(window)); | 469 settings.AddObserver(new HidingWindowAnimationObserver(window)); |
463 window->layer()->SetVisible(false); | 470 window->layer()->SetVisible(false); |
464 | 471 |
465 AddLayerAnimationsForMinimize(window, false); | 472 AddLayerAnimationsForMinimize(window, false); |
466 } | 473 } |
467 | 474 |
| 475 void AnimateShowHideWindowCommon_BrightnessGrayscale(aura::Window* window, |
| 476 bool show) { |
| 477 window->layer()->set_delegate(window); |
| 478 |
| 479 float start_value, end_value; |
| 480 if (show) { |
| 481 start_value = kWindowAnimation_HideBrightnessGrayscale; |
| 482 end_value = kWindowAnimation_ShowBrightnessGrayscale; |
| 483 } else { |
| 484 start_value = kWindowAnimation_ShowBrightnessGrayscale; |
| 485 end_value = kWindowAnimation_HideBrightnessGrayscale; |
| 486 } |
| 487 |
| 488 window->layer()->SetLayerBrightness(start_value); |
| 489 window->layer()->SetLayerGrayscale(start_value); |
| 490 if (show) { |
| 491 window->layer()->SetOpacity(kWindowAnimation_ShowOpacity); |
| 492 window->layer()->SetVisible(true); |
| 493 } |
| 494 |
| 495 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); |
| 496 settings.SetTransitionDuration( |
| 497 base::TimeDelta::FromMilliseconds(kBrightnessGrayscaleFadeDurationMs)); |
| 498 if (!show) |
| 499 settings.AddObserver(new HidingWindowAnimationObserver(window)); |
| 500 |
| 501 scoped_ptr<ui::LayerAnimationSequence> brightness_sequence( |
| 502 new ui::LayerAnimationSequence()); |
| 503 scoped_ptr<ui::LayerAnimationSequence> grayscale_sequence( |
| 504 new ui::LayerAnimationSequence()); |
| 505 |
| 506 brightness_sequence->AddElement( |
| 507 ui::LayerAnimationElement::CreateBrightnessElement( |
| 508 end_value, |
| 509 base::TimeDelta::FromMilliseconds( |
| 510 kBrightnessGrayscaleFadeDurationMs))); |
| 511 grayscale_sequence->AddElement( |
| 512 ui::LayerAnimationElement::CreateGrayscaleElement( |
| 513 end_value, |
| 514 base::TimeDelta::FromMilliseconds( |
| 515 kBrightnessGrayscaleFadeDurationMs))); |
| 516 |
| 517 std::vector<ui::LayerAnimationSequence*> animations; |
| 518 animations.push_back(brightness_sequence.release()); |
| 519 animations.push_back(grayscale_sequence.release()); |
| 520 window->layer()->GetAnimator()->ScheduleTogether(animations); |
| 521 if (!show) { |
| 522 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); |
| 523 window->layer()->SetVisible(false); |
| 524 } |
| 525 } |
| 526 |
| 527 void AnimateShowWindow_BrightnessGrayscale(aura::Window* window) { |
| 528 AnimateShowHideWindowCommon_BrightnessGrayscale(window, true); |
| 529 } |
| 530 |
| 531 void AnimateHideWindow_BrightnessGrayscale(aura::Window* window) { |
| 532 AnimateShowHideWindowCommon_BrightnessGrayscale(window, false); |
| 533 } |
| 534 |
468 bool AnimateShowWindow(aura::Window* window) { | 535 bool AnimateShowWindow(aura::Window* window) { |
469 if (!HasWindowVisibilityAnimationTransition(window, ANIMATE_SHOW)) | 536 if (!HasWindowVisibilityAnimationTransition(window, ANIMATE_SHOW)) |
470 return false; | 537 return false; |
471 | 538 |
472 switch (GetWindowVisibilityAnimationType(window)) { | 539 switch (GetWindowVisibilityAnimationType(window)) { |
473 case WINDOW_VISIBILITY_ANIMATION_TYPE_DROP: | 540 case WINDOW_VISIBILITY_ANIMATION_TYPE_DROP: |
474 AnimateShowWindow_Drop(window); | 541 AnimateShowWindow_Drop(window); |
475 return true; | 542 return true; |
476 case WINDOW_VISIBILITY_ANIMATION_TYPE_VERTICAL: | 543 case WINDOW_VISIBILITY_ANIMATION_TYPE_VERTICAL: |
477 AnimateShowWindow_Vertical(window); | 544 AnimateShowWindow_Vertical(window); |
478 return true; | 545 return true; |
479 case WINDOW_VISIBILITY_ANIMATION_TYPE_FADE: | 546 case WINDOW_VISIBILITY_ANIMATION_TYPE_FADE: |
480 AnimateShowWindow_Fade(window); | 547 AnimateShowWindow_Fade(window); |
481 return true; | 548 return true; |
482 case WINDOW_VISIBILITY_ANIMATION_TYPE_WORKSPACE_SHOW: | 549 case WINDOW_VISIBILITY_ANIMATION_TYPE_WORKSPACE_SHOW: |
483 AnimateShowWindow_Workspace(window); | 550 AnimateShowWindow_Workspace(window); |
484 return true; | 551 return true; |
485 case WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE: | 552 case WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE: |
486 AnimateShowWindow_Minimize(window); | 553 AnimateShowWindow_Minimize(window); |
487 return true; | 554 return true; |
| 555 case WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE: |
| 556 AnimateShowWindow_BrightnessGrayscale(window); |
| 557 return true; |
488 default: | 558 default: |
489 NOTREACHED(); | 559 NOTREACHED(); |
490 return false; | 560 return false; |
491 } | 561 } |
492 } | 562 } |
493 | 563 |
494 bool AnimateHideWindow(aura::Window* window) { | 564 bool AnimateHideWindow(aura::Window* window) { |
495 if (!HasWindowVisibilityAnimationTransition(window, ANIMATE_HIDE)) | 565 if (!HasWindowVisibilityAnimationTransition(window, ANIMATE_HIDE)) |
496 return false; | 566 return false; |
497 | 567 |
498 switch (GetWindowVisibilityAnimationType(window)) { | 568 switch (GetWindowVisibilityAnimationType(window)) { |
499 case WINDOW_VISIBILITY_ANIMATION_TYPE_DROP: | 569 case WINDOW_VISIBILITY_ANIMATION_TYPE_DROP: |
500 AnimateHideWindow_Drop(window); | 570 AnimateHideWindow_Drop(window); |
501 return true; | 571 return true; |
502 case WINDOW_VISIBILITY_ANIMATION_TYPE_VERTICAL: | 572 case WINDOW_VISIBILITY_ANIMATION_TYPE_VERTICAL: |
503 AnimateHideWindow_Vertical(window); | 573 AnimateHideWindow_Vertical(window); |
504 return true; | 574 return true; |
505 case WINDOW_VISIBILITY_ANIMATION_TYPE_FADE: | 575 case WINDOW_VISIBILITY_ANIMATION_TYPE_FADE: |
506 AnimateHideWindow_Fade(window); | 576 AnimateHideWindow_Fade(window); |
507 return true; | 577 return true; |
508 case WINDOW_VISIBILITY_ANIMATION_TYPE_WORKSPACE_HIDE: | 578 case WINDOW_VISIBILITY_ANIMATION_TYPE_WORKSPACE_HIDE: |
509 AnimateHideWindow_Workspace(window); | 579 AnimateHideWindow_Workspace(window); |
510 return true; | 580 return true; |
511 case WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE: | 581 case WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE: |
512 AnimateHideWindow_Minimize(window); | 582 AnimateHideWindow_Minimize(window); |
513 return true; | 583 return true; |
| 584 case WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE: |
| 585 AnimateHideWindow_BrightnessGrayscale(window); |
| 586 return true; |
514 default: | 587 default: |
515 NOTREACHED(); | 588 NOTREACHED(); |
516 return false; | 589 return false; |
517 } | 590 } |
518 } | 591 } |
519 | 592 |
520 // Recreates a fresh layer for |window| and all its child windows. Does not | 593 // Recreates a fresh layer for |window| and all its child windows. Does not |
521 // recreate shadows or other non-window layers. Returns the old layer and its | 594 // recreate shadows or other non-window layers. Returns the old layer and its |
522 // children, maintaining the hierarchy. | 595 // children, maintaining the hierarchy. |
523 Layer* RecreateWindowLayers(Window* window) { | 596 Layer* RecreateWindowLayers(Window* window) { |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
778 AnimateHideWindow(window); | 851 AnimateHideWindow(window); |
779 } | 852 } |
780 } | 853 } |
781 | 854 |
782 void SetDelayedOldLayerDeletionInCrossFadeForTest(bool value) { | 855 void SetDelayedOldLayerDeletionInCrossFadeForTest(bool value) { |
783 delayed_old_layer_deletion_in_cross_fade_for_test_ = value; | 856 delayed_old_layer_deletion_in_cross_fade_for_test_ = value; |
784 } | 857 } |
785 | 858 |
786 } // namespace internal | 859 } // namespace internal |
787 } // namespace ash | 860 } // namespace ash |
OLD | NEW |