| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/overview/scoped_overview_animation_settings_aura.h" | 5 #include "ash/wm/overview/scoped_overview_animation_settings_aura.h" |
| 6 | 6 |
| 7 #include "ash/common/material_design/material_design_controller.h" | |
| 8 #include "base/time/time.h" | 7 #include "base/time/time.h" |
| 9 #include "ui/aura/window.h" | 8 #include "ui/aura/window.h" |
| 10 #include "ui/compositor/layer.h" | 9 #include "ui/compositor/layer.h" |
| 11 #include "ui/compositor/layer_animation_observer.h" | 10 #include "ui/compositor/layer_animation_observer.h" |
| 12 #include "ui/compositor/scoped_layer_animation_settings.h" | 11 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 13 #include "ui/gfx/animation/tween.h" | 12 #include "ui/gfx/animation/tween.h" |
| 14 | 13 |
| 15 namespace ash { | 14 namespace ash { |
| 16 | 15 |
| 17 namespace { | 16 namespace { |
| 18 | 17 |
| 19 // The time duration for transformation animations. | 18 // The time duration for transformation animations. |
| 20 const int kTransitionMilliseconds = 300; | 19 const int kTransitionMilliseconds = 300; |
| 21 | 20 |
| 22 // The time duration for fading out when closing an item. Only used with | 21 // The time duration for fading out when closing an item. |
| 23 // Material Design. | 22 const int kCloseFadeOutMilliseconds = 50; |
| 24 const int kCloseFadeOutMillisecondsMd = 50; | |
| 25 | 23 |
| 26 // The time duration for scaling down when an item is closed. Only used with | 24 // The time duration for scaling down when an item is closed. |
| 27 // Material Design. | 25 const int kCloseScaleMilliseconds = 100; |
| 28 const int kCloseScaleMillisecondsMd = 100; | |
| 29 | 26 |
| 30 // The time duration for widgets to fade in. | 27 // The time duration for widgets to fade in. |
| 31 const int kFadeInMilliseconds = 60; | 28 const int kFadeInMilliseconds = 60; |
| 32 | 29 |
| 33 // The time duration for widgets to fade out. | 30 // The time duration for widgets to fade out. |
| 34 const int kFadeOutDelayMilliseconds = kTransitionMilliseconds * 1 / 5; | 31 const int kFadeOutDelayMilliseconds = kTransitionMilliseconds * 1 / 5; |
| 35 const int kFadeOutMilliseconds = kTransitionMilliseconds * 3 / 5; | 32 const int kFadeOutMilliseconds = kTransitionMilliseconds * 3 / 5; |
| 36 | 33 |
| 37 base::TimeDelta GetAnimationDuration(OverviewAnimationType animation_type) { | 34 base::TimeDelta GetAnimationDuration(OverviewAnimationType animation_type) { |
| 38 const bool material = ash::MaterialDesignController::IsOverviewMaterial(); | |
| 39 switch (animation_type) { | 35 switch (animation_type) { |
| 40 case OVERVIEW_ANIMATION_NONE: | 36 case OVERVIEW_ANIMATION_NONE: |
| 41 return base::TimeDelta(); | 37 return base::TimeDelta(); |
| 42 case OVERVIEW_ANIMATION_ENTER_OVERVIEW_MODE_FADE_IN: | 38 case OVERVIEW_ANIMATION_ENTER_OVERVIEW_MODE_FADE_IN: |
| 43 return base::TimeDelta::FromMilliseconds( | 39 return base::TimeDelta::FromMilliseconds(kFadeInMilliseconds); |
| 44 material ? kFadeInMilliseconds : kTransitionMilliseconds); | |
| 45 case OVERVIEW_ANIMATION_EXIT_OVERVIEW_MODE_FADE_OUT: | 40 case OVERVIEW_ANIMATION_EXIT_OVERVIEW_MODE_FADE_OUT: |
| 46 return base::TimeDelta::FromMilliseconds(kFadeOutMilliseconds); | 41 return base::TimeDelta::FromMilliseconds(kFadeOutMilliseconds); |
| 47 case OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS: | 42 case OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS: |
| 48 case OVERVIEW_ANIMATION_RESTORE_WINDOW: | 43 case OVERVIEW_ANIMATION_RESTORE_WINDOW: |
| 49 return base::TimeDelta::FromMilliseconds(kTransitionMilliseconds); | 44 return base::TimeDelta::FromMilliseconds(kTransitionMilliseconds); |
| 50 case OVERVIEW_ANIMATION_CLOSING_SELECTOR_ITEM: | 45 case OVERVIEW_ANIMATION_CLOSING_SELECTOR_ITEM: |
| 51 return base::TimeDelta::FromMilliseconds(kCloseScaleMillisecondsMd); | 46 return base::TimeDelta::FromMilliseconds(kCloseScaleMilliseconds); |
| 52 case OVERVIEW_ANIMATION_CLOSE_SELECTOR_ITEM: | 47 case OVERVIEW_ANIMATION_CLOSE_SELECTOR_ITEM: |
| 53 return base::TimeDelta::FromMilliseconds(kCloseFadeOutMillisecondsMd); | 48 return base::TimeDelta::FromMilliseconds(kCloseFadeOutMilliseconds); |
| 54 } | 49 } |
| 55 NOTREACHED(); | 50 NOTREACHED(); |
| 56 return base::TimeDelta(); | 51 return base::TimeDelta(); |
| 57 } | 52 } |
| 58 | 53 |
| 59 } // namespace | 54 } // namespace |
| 60 | 55 |
| 61 ScopedOverviewAnimationSettingsAura::ScopedOverviewAnimationSettingsAura( | 56 ScopedOverviewAnimationSettingsAura::ScopedOverviewAnimationSettingsAura( |
| 62 OverviewAnimationType animation_type, | 57 OverviewAnimationType animation_type, |
| 63 aura::Window* window) | 58 aura::Window* window) |
| 64 : animation_settings_(new ui::ScopedLayerAnimationSettings( | 59 : animation_settings_(new ui::ScopedLayerAnimationSettings( |
| 65 window->layer()->GetAnimator())) { | 60 window->layer()->GetAnimator())) { |
| 66 const bool material = ash::MaterialDesignController::IsOverviewMaterial(); | |
| 67 switch (animation_type) { | 61 switch (animation_type) { |
| 68 case OVERVIEW_ANIMATION_NONE: | 62 case OVERVIEW_ANIMATION_NONE: |
| 69 animation_settings_->SetPreemptionStrategy( | 63 animation_settings_->SetPreemptionStrategy( |
| 70 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); | 64 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); |
| 71 break; | 65 break; |
| 72 case OVERVIEW_ANIMATION_ENTER_OVERVIEW_MODE_FADE_IN: | 66 case OVERVIEW_ANIMATION_ENTER_OVERVIEW_MODE_FADE_IN: |
| 73 if (material) { | 67 animation_settings_->SetTweenType(gfx::Tween::EASE_IN); |
| 74 animation_settings_->SetTweenType(gfx::Tween::EASE_IN); | |
| 75 } else { | |
| 76 window->layer()->GetAnimator()->SchedulePauseForProperties( | |
| 77 GetAnimationDuration(OverviewAnimationType:: | |
| 78 OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS), | |
| 79 ui::LayerAnimationElement::OPACITY); | |
| 80 } | |
| 81 animation_settings_->SetPreemptionStrategy( | 68 animation_settings_->SetPreemptionStrategy( |
| 82 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); | 69 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); |
| 83 break; | 70 break; |
| 84 case OVERVIEW_ANIMATION_EXIT_OVERVIEW_MODE_FADE_OUT: | 71 case OVERVIEW_ANIMATION_EXIT_OVERVIEW_MODE_FADE_OUT: |
| 85 window->layer()->GetAnimator()->SchedulePauseForProperties( | 72 window->layer()->GetAnimator()->SchedulePauseForProperties( |
| 86 base::TimeDelta::FromMilliseconds(kFadeOutDelayMilliseconds), | 73 base::TimeDelta::FromMilliseconds(kFadeOutDelayMilliseconds), |
| 87 ui::LayerAnimationElement::OPACITY); | 74 ui::LayerAnimationElement::OPACITY); |
| 88 animation_settings_->SetTweenType(gfx::Tween::EASE_OUT); | 75 animation_settings_->SetTweenType(gfx::Tween::EASE_OUT); |
| 89 animation_settings_->SetPreemptionStrategy( | 76 animation_settings_->SetPreemptionStrategy( |
| 90 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); | 77 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); |
| 91 break; | 78 break; |
| 92 case OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS: | 79 case OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS: |
| 93 case OVERVIEW_ANIMATION_RESTORE_WINDOW: | 80 case OVERVIEW_ANIMATION_RESTORE_WINDOW: |
| 94 animation_settings_->SetPreemptionStrategy( | 81 animation_settings_->SetPreemptionStrategy( |
| 95 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 82 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| 96 animation_settings_->SetTweenType( | 83 animation_settings_->SetTweenType(gfx::Tween::EASE_OUT); |
| 97 material ? gfx::Tween::EASE_OUT : gfx::Tween::FAST_OUT_SLOW_IN); | |
| 98 break; | 84 break; |
| 99 case OVERVIEW_ANIMATION_CLOSING_SELECTOR_ITEM: | 85 case OVERVIEW_ANIMATION_CLOSING_SELECTOR_ITEM: |
| 100 case OVERVIEW_ANIMATION_CLOSE_SELECTOR_ITEM: | 86 case OVERVIEW_ANIMATION_CLOSE_SELECTOR_ITEM: |
| 101 animation_settings_->SetPreemptionStrategy( | 87 animation_settings_->SetPreemptionStrategy( |
| 102 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION); | 88 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION); |
| 103 animation_settings_->SetTweenType(gfx::Tween::EASE_OUT); | 89 animation_settings_->SetTweenType(gfx::Tween::EASE_OUT); |
| 104 break; | 90 break; |
| 105 } | 91 } |
| 106 animation_settings_->SetTransitionDuration( | 92 animation_settings_->SetTransitionDuration( |
| 107 GetAnimationDuration(animation_type)); | 93 GetAnimationDuration(animation_type)); |
| 108 } | 94 } |
| 109 | 95 |
| 110 ScopedOverviewAnimationSettingsAura::~ScopedOverviewAnimationSettingsAura() {} | 96 ScopedOverviewAnimationSettingsAura::~ScopedOverviewAnimationSettingsAura() {} |
| 111 | 97 |
| 112 void ScopedOverviewAnimationSettingsAura::AddObserver( | 98 void ScopedOverviewAnimationSettingsAura::AddObserver( |
| 113 ui::ImplicitAnimationObserver* observer) { | 99 ui::ImplicitAnimationObserver* observer) { |
| 114 animation_settings_->AddObserver(observer); | 100 animation_settings_->AddObserver(observer); |
| 115 } | 101 } |
| 116 | 102 |
| 117 } // namespace ash | 103 } // namespace ash |
| OLD | NEW |