cc: Initialize wait_for_beginframe_interval in tests.
[chromium-blink-merge.git] / ash / wm / overview / scoped_overview_animation_settings.cc
blobe0cf9776e9cbe09039d7aafdd716cc5d22ce2735
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
3 // found in the LICENSE file.
5 #include "ash/wm/overview/scoped_overview_animation_settings.h"
7 #include "ash/wm/overview/overview_animation_type.h"
8 #include "base/time/time.h"
9 #include "ui/aura/window.h"
10 #include "ui/compositor/layer.h"
11 #include "ui/gfx/animation/tween.h"
13 namespace ash {
15 namespace {
17 // The time duration for transformation animations.
18 const int kTransitionMilliseconds = 200;
20 // The time duration for widgets to fade in.
21 const int kFadeInMilliseconds = 80;
23 base::TimeDelta GetAnimationDuration(OverviewAnimationType animation_type) {
24 switch (animation_type) {
25 case OVERVIEW_ANIMATION_NONE:
26 return base::TimeDelta();
27 case OVERVIEW_ANIMATION_ENTER_OVERVIEW_MODE_FADE_IN:
28 return base::TimeDelta::FromMilliseconds(kFadeInMilliseconds);
29 case OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS:
30 case OVERVIEW_ANIMATION_RESTORE_WINDOW:
31 case OVERVIEW_ANIMATION_HIDE_WINDOW:
32 return base::TimeDelta::FromMilliseconds(kTransitionMilliseconds);
34 NOTREACHED();
35 return base::TimeDelta();
38 } // namespace
40 ScopedOverviewAnimationSettings::ScopedOverviewAnimationSettings(
41 OverviewAnimationType animation_type,
42 aura::Window* window)
43 : animation_settings_(window->layer()->GetAnimator()) {
45 switch (animation_type) {
46 case OVERVIEW_ANIMATION_NONE:
47 animation_settings_.SetPreemptionStrategy(
48 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
49 break;
50 case OVERVIEW_ANIMATION_ENTER_OVERVIEW_MODE_FADE_IN:
51 window->layer()->GetAnimator()->SchedulePauseForProperties(
52 GetAnimationDuration(
53 OverviewAnimationType::OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS),
54 ui::LayerAnimationElement::OPACITY);
55 animation_settings_.SetPreemptionStrategy(
56 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
57 break;
58 case OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS:
59 case OVERVIEW_ANIMATION_RESTORE_WINDOW:
60 animation_settings_.SetPreemptionStrategy(
61 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
62 animation_settings_.SetTweenType(gfx::Tween::FAST_OUT_SLOW_IN);
63 break;
64 case OVERVIEW_ANIMATION_HIDE_WINDOW:
65 animation_settings_.SetPreemptionStrategy(
66 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
67 break;
69 animation_settings_.SetTransitionDuration(
70 GetAnimationDuration(animation_type));
73 ScopedOverviewAnimationSettings::~ScopedOverviewAnimationSettings() {
76 } // namespace ash