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/workspace/workspace_animations.h" | 5 #include "ash/wm/workspace/workspace_animations.h" |
6 | 6 |
| 7 #include "ash/wm/window_animations.h" |
7 #include "ui/aura/window.h" | 8 #include "ui/aura/window.h" |
8 #include "ui/compositor/layer.h" | 9 #include "ui/compositor/layer.h" |
9 #include "ui/compositor/scoped_layer_animation_settings.h" | 10 #include "ui/compositor/scoped_layer_animation_settings.h" |
10 #include "ui/views/corewm/window_animations.h" | 11 #include "ui/views/corewm/window_animations.h" |
11 | 12 |
12 namespace ash { | 13 namespace ash { |
13 namespace internal { | 14 namespace internal { |
14 | 15 |
15 const int kWorkspaceSwitchTimeMS = 200; | 16 const int kWorkspaceSwitchTimeMS = 200; |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 // Tween type used when showing/hiding workspaces. | 20 // Tween type used when showing/hiding workspaces. |
20 const ui::Tween::Type kWorkspaceTweenType = ui::Tween::EASE_OUT; | 21 const ui::Tween::Type kWorkspaceTweenType = ui::Tween::EASE_OUT; |
21 | 22 |
22 // Scales for workspaces above/below current workspace. | |
23 const float kWorkspaceScaleAbove = 1.1f; | |
24 const float kWorkspaceScaleBelow = .9f; | |
25 | |
26 enum WorkspaceScaleType { | |
27 WORKSPACE_SCALE_ABOVE, | |
28 WORKSPACE_SCALE_BELOW, | |
29 }; | |
30 | |
31 // Applies the specified WorkspaceScaleType. | |
32 void ApplyWorkspaceScale(ui::Layer* layer, WorkspaceScaleType type) { | |
33 const float scale = type == WORKSPACE_SCALE_ABOVE ? kWorkspaceScaleAbove : | |
34 kWorkspaceScaleBelow; | |
35 gfx::Transform transform; | |
36 transform.Translate(-layer->bounds().width() * (scale - 1.0f) / 2, | |
37 -layer->bounds().height() * (scale - 1.0f) / 2); | |
38 transform.Scale(scale, scale); | |
39 layer->SetTransform(transform); | |
40 } | |
41 | |
42 // If |details.duration| is not-empty it is returned, otherwise | 23 // If |details.duration| is not-empty it is returned, otherwise |
43 // |kWorkspaceSwitchTimeMS| is returned. | 24 // |kWorkspaceSwitchTimeMS| is returned. |
44 base::TimeDelta DurationForWorkspaceShowOrHide( | 25 base::TimeDelta DurationForWorkspaceShowOrHide( |
45 const WorkspaceAnimationDetails& details) { | 26 const WorkspaceAnimationDetails& details) { |
46 return details.duration == base::TimeDelta() ? | 27 return details.duration == base::TimeDelta() ? |
47 base::TimeDelta::FromMilliseconds(kWorkspaceSwitchTimeMS) : | 28 base::TimeDelta::FromMilliseconds(kWorkspaceSwitchTimeMS) : |
48 details.duration; | 29 details.duration; |
49 } | 30 } |
50 | 31 |
51 } // namespace | 32 } // namespace |
(...skipping 14 matching lines...) Expand all Loading... |
66 window->Show(); | 47 window->Show(); |
67 | 48 |
68 if (!details.animate || views::corewm::WindowAnimationsDisabled(NULL)) { | 49 if (!details.animate || views::corewm::WindowAnimationsDisabled(NULL)) { |
69 window->layer()->SetOpacity(1.0f); | 50 window->layer()->SetOpacity(1.0f); |
70 window->layer()->SetTransform(gfx::Transform()); | 51 window->layer()->SetTransform(gfx::Transform()); |
71 return; | 52 return; |
72 } | 53 } |
73 | 54 |
74 window->layer()->SetOpacity(details.animate_opacity ? 0.0f : 1.0f); | 55 window->layer()->SetOpacity(details.animate_opacity ? 0.0f : 1.0f); |
75 if (details.animate_scale) { | 56 if (details.animate_scale) { |
76 ApplyWorkspaceScale(window->layer(), | 57 ApplyAshWindowAnimationScale(window->layer(), |
77 details.direction == WORKSPACE_ANIMATE_UP ? | 58 details.direction == WORKSPACE_ANIMATE_UP ? |
78 WORKSPACE_SCALE_BELOW : WORKSPACE_SCALE_ABOVE); | 59 ASH_WINDOW_SCALE_BELOW : ASH_WINDOW_SCALE_ABOVE); |
79 } else { | 60 } else { |
80 window->layer()->SetTransform(gfx::Transform()); | 61 window->layer()->SetTransform(gfx::Transform()); |
81 } | 62 } |
82 | 63 |
83 // In order for pause to work we need to stop animations. | 64 // In order for pause to work we need to stop animations. |
84 window->layer()->GetAnimator()->StopAnimating(); | 65 window->layer()->GetAnimator()->StopAnimating(); |
85 | 66 |
86 { | 67 { |
87 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); | 68 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); |
88 | 69 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 ui::LayerAnimationElement::TRANSFORM, | 104 ui::LayerAnimationElement::TRANSFORM, |
124 ui::LayerAnimationElement::OPACITY, | 105 ui::LayerAnimationElement::OPACITY, |
125 ui::LayerAnimationElement::BRIGHTNESS, | 106 ui::LayerAnimationElement::BRIGHTNESS, |
126 ui::LayerAnimationElement::VISIBILITY, | 107 ui::LayerAnimationElement::VISIBILITY, |
127 -1); | 108 -1); |
128 } | 109 } |
129 | 110 |
130 settings.SetTransitionDuration(DurationForWorkspaceShowOrHide(details)); | 111 settings.SetTransitionDuration(DurationForWorkspaceShowOrHide(details)); |
131 settings.SetTweenType(kWorkspaceTweenType); | 112 settings.SetTweenType(kWorkspaceTweenType); |
132 if (details.animate_scale) { | 113 if (details.animate_scale) { |
133 ApplyWorkspaceScale(window->layer(), | 114 ApplyAshWindowAnimationScale(window->layer(), |
134 details.direction == WORKSPACE_ANIMATE_UP ? | 115 details.direction == WORKSPACE_ANIMATE_UP ? |
135 WORKSPACE_SCALE_ABOVE : WORKSPACE_SCALE_BELOW); | 116 ASH_WINDOW_SCALE_ABOVE : ASH_WINDOW_SCALE_BELOW); |
136 } else { | 117 } else { |
137 window->layer()->SetTransform(gfx::Transform()); | 118 window->layer()->SetTransform(gfx::Transform()); |
138 } | 119 } |
139 | 120 |
140 // NOTE: Hide() must be before SetOpacity(), else | 121 // NOTE: Hide() must be before SetOpacity(), else |
141 // VisibilityController::UpdateLayerVisibility doesn't pass the false to the | 122 // VisibilityController::UpdateLayerVisibility doesn't pass the false to the |
142 // layer so that the layer and window end up out of sync and confused. | 123 // layer so that the layer and window end up out of sync and confused. |
143 window->Hide(); | 124 window->Hide(); |
144 | 125 |
145 if (details.animate_opacity) | 126 if (details.animate_opacity) |
146 window->layer()->SetOpacity(0.0f); | 127 window->layer()->SetOpacity(0.0f); |
147 | 128 |
148 // After the animation completes snap the transform back to the identity, | 129 // After the animation completes snap the transform back to the identity, |
149 // otherwise any one that asks for screen bounds gets a slightly scaled | 130 // otherwise any one that asks for screen bounds gets a slightly scaled |
150 // version. | 131 // version. |
151 settings.SetPreemptionStrategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION); | 132 settings.SetPreemptionStrategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION); |
152 settings.SetTransitionDuration(base::TimeDelta()); | 133 settings.SetTransitionDuration(base::TimeDelta()); |
153 window->layer()->SetTransform(gfx::Transform()); | 134 window->layer()->SetTransform(gfx::Transform()); |
154 } | 135 } |
155 | 136 |
156 } // namespace internal | 137 } // namespace internal |
157 } // namespace ash | 138 } // namespace ash |
OLD | NEW |