OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ash/wm/workspace/workspace_animations.h" | |
6 | |
7 #include "ash/wm/window_animations.h" | |
8 #include "ui/aura/window.h" | |
9 #include "ui/compositor/layer.h" | |
10 #include "ui/compositor/scoped_layer_animation_settings.h" | |
11 #include "ui/views/corewm/window_animations.h" | |
12 | |
13 namespace ash { | |
14 namespace internal { | |
15 | |
16 const int kWorkspaceSwitchTimeMS = 200; | |
17 | |
18 namespace { | |
19 | |
20 // Tween type used when showing/hiding workspaces. | |
21 const ui::Tween::Type kWorkspaceTweenType = ui::Tween::EASE_OUT; | |
22 | |
23 // If |details.duration| is not-empty it is returned, otherwise | |
24 // |kWorkspaceSwitchTimeMS| is returned. | |
25 base::TimeDelta DurationForWorkspaceShowOrHide( | |
26 const WorkspaceAnimationDetails& details) { | |
27 return details.duration == base::TimeDelta() ? | |
28 base::TimeDelta::FromMilliseconds(kWorkspaceSwitchTimeMS) : | |
29 details.duration; | |
30 } | |
31 | |
32 } // namespace | |
33 | |
34 WorkspaceAnimationDetails::WorkspaceAnimationDetails() | |
35 : direction(WORKSPACE_ANIMATE_UP), | |
36 animate(false), | |
37 animate_opacity(false), | |
38 animate_scale(false), | |
39 pause_time_ms(0) { | |
40 } | |
41 | |
42 WorkspaceAnimationDetails::~WorkspaceAnimationDetails() { | |
43 } | |
44 | |
45 void ShowWorkspace(aura::Window* window, | |
46 const WorkspaceAnimationDetails& details) { | |
47 window->Show(); | |
48 | |
49 if (!details.animate || views::corewm::WindowAnimationsDisabled(NULL)) { | |
50 window->layer()->SetOpacity(1.0f); | |
51 window->layer()->SetTransform(gfx::Transform()); | |
52 return; | |
53 } | |
54 | |
55 window->layer()->SetOpacity(details.animate_opacity ? 0.0f : 1.0f); | |
56 if (details.animate_scale) { | |
57 SetTransformForScaleAnimation(window->layer(), | |
58 details.direction == WORKSPACE_ANIMATE_UP ? | |
59 LAYER_SCALE_ANIMATION_BELOW : LAYER_SCALE_ANIMATION_BELOW); | |
60 } else { | |
61 window->layer()->SetTransform(gfx::Transform()); | |
62 } | |
63 | |
64 // In order for pause to work we need to stop animations. | |
65 window->layer()->GetAnimator()->StopAnimating(); | |
66 | |
67 { | |
68 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); | |
69 | |
70 if (details.pause_time_ms > 0) { | |
71 settings.SetPreemptionStrategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION); | |
72 window->layer()->GetAnimator()->SchedulePauseForProperties( | |
73 base::TimeDelta::FromMilliseconds(details.pause_time_ms), | |
74 ui::LayerAnimationElement::TRANSFORM, | |
75 ui::LayerAnimationElement::OPACITY, | |
76 ui::LayerAnimationElement::BRIGHTNESS, | |
77 ui::LayerAnimationElement::VISIBILITY, | |
78 -1); | |
79 } | |
80 | |
81 settings.SetTweenType(kWorkspaceTweenType); | |
82 settings.SetTransitionDuration(DurationForWorkspaceShowOrHide(details)); | |
83 window->layer()->SetTransform(gfx::Transform()); | |
84 window->layer()->SetOpacity(1.0f); | |
85 } | |
86 } | |
87 | |
88 void HideWorkspace(aura::Window* window, | |
89 const WorkspaceAnimationDetails& details) { | |
90 window->layer()->SetTransform(gfx::Transform()); | |
91 window->layer()->SetOpacity(1.0f); | |
92 window->layer()->GetAnimator()->StopAnimating(); | |
93 | |
94 if (!details.animate || views::corewm::WindowAnimationsDisabled(NULL)) { | |
95 window->Hide(); | |
96 return; | |
97 } | |
98 | |
99 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); | |
100 if (details.pause_time_ms > 0) { | |
101 settings.SetPreemptionStrategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION); | |
102 window->layer()->GetAnimator()->SchedulePauseForProperties( | |
103 base::TimeDelta::FromMilliseconds(details.pause_time_ms), | |
104 ui::LayerAnimationElement::TRANSFORM, | |
105 ui::LayerAnimationElement::OPACITY, | |
106 ui::LayerAnimationElement::BRIGHTNESS, | |
107 ui::LayerAnimationElement::VISIBILITY, | |
108 -1); | |
109 } | |
110 | |
111 settings.SetTransitionDuration(DurationForWorkspaceShowOrHide(details)); | |
112 settings.SetTweenType(kWorkspaceTweenType); | |
113 if (details.animate_scale) { | |
114 SetTransformForScaleAnimation(window->layer(), | |
115 details.direction == WORKSPACE_ANIMATE_UP ? | |
116 LAYER_SCALE_ANIMATION_ABOVE : LAYER_SCALE_ANIMATION_BELOW); | |
117 } else { | |
118 window->layer()->SetTransform(gfx::Transform()); | |
119 } | |
120 | |
121 // NOTE: Hide() must be before SetOpacity(), else | |
122 // VisibilityController::UpdateLayerVisibility doesn't pass the false to the | |
123 // layer so that the layer and window end up out of sync and confused. | |
124 window->Hide(); | |
125 | |
126 if (details.animate_opacity) | |
127 window->layer()->SetOpacity(0.0f); | |
128 | |
129 // After the animation completes snap the transform back to the identity, | |
130 // otherwise any one that asks for screen bounds gets a slightly scaled | |
131 // version. | |
132 settings.SetPreemptionStrategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION); | |
133 settings.SetTransitionDuration(base::TimeDelta()); | |
134 window->layer()->SetTransform(gfx::Transform()); | |
135 } | |
136 | |
137 } // namespace internal | |
138 } // namespace ash | |
OLD | NEW |