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 "ui/aura/window.h" | 7 #include "ui/aura/window.h" |
8 #include "ui/compositor/layer.h" | 8 #include "ui/compositor/layer.h" |
9 #include "ui/compositor/scoped_layer_animation_settings.h" | 9 #include "ui/compositor/scoped_layer_animation_settings.h" |
10 #include "ui/views/corewm/window_animations.h" | 10 #include "ui/views/corewm/window_animations.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
54 : direction(WORKSPACE_ANIMATE_UP), | 54 : direction(WORKSPACE_ANIMATE_UP), |
55 animate(false), | 55 animate(false), |
56 animate_opacity(false), | 56 animate_opacity(false), |
57 animate_scale(false), | 57 animate_scale(false), |
58 pause_time_ms(0) { | 58 pause_time_ms(0) { |
59 } | 59 } |
60 | 60 |
61 WorkspaceAnimationDetails::~WorkspaceAnimationDetails() { | 61 WorkspaceAnimationDetails::~WorkspaceAnimationDetails() { |
62 } | 62 } |
63 | 63 |
64 void SetWorkspaceAnimationStartParameters( | |
65 aura::Window* window, | |
66 const WorkspaceAnimationDetails& details, | |
67 bool show, | |
68 bool force) { | |
69 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); | |
70 settings.SetTweenType(kWorkspaceTweenType); | |
71 if (details.animate_scale || force) { | |
sky
2012/11/29 19:06:51
Why do we need both force and scale?
| |
72 if (show) { | |
73 ApplyWorkspaceScale(window->layer(), | |
74 details.direction == WORKSPACE_ANIMATE_UP ? | |
75 WORKSPACE_SCALE_BELOW : WORKSPACE_SCALE_ABOVE); | |
76 } else { | |
77 // Identity transform at the beginning of hide animation. | |
78 window->layer()->SetTransform(gfx::Transform()); | |
79 } | |
80 } | |
81 if (details.animate_opacity || force) { | |
82 if (show) { | |
83 window->layer()->SetOpacity(0.0f); | |
84 } else { | |
85 window->layer()->SetOpacity(1.0f); | |
86 } | |
87 } | |
88 } | |
89 | |
90 void SetWorkspaceAnimationTargetParameters( | |
91 aura::Window* window, | |
92 const WorkspaceAnimationDetails& details, | |
93 bool show, | |
94 bool force) { | |
95 if (details.animate_scale || force) { | |
96 if (show) { | |
97 // Identity transform at the end of show animation. | |
98 window->layer()->SetTransform(gfx::Transform()); | |
99 } else { | |
100 ApplyWorkspaceScale(window->layer(), | |
101 details.direction == WORKSPACE_ANIMATE_UP ? | |
102 WORKSPACE_SCALE_ABOVE : WORKSPACE_SCALE_BELOW); | |
103 } | |
104 } | |
105 if (details.animate_opacity || force) { | |
106 if (show) { | |
107 window->layer()->SetOpacity(1.0f); | |
108 } else { | |
109 window->layer()->SetOpacity(0.0f); | |
110 } | |
111 } | |
112 } | |
113 | |
64 void ShowWorkspace(aura::Window* window, | 114 void ShowWorkspace(aura::Window* window, |
65 const WorkspaceAnimationDetails& details) { | 115 const WorkspaceAnimationDetails& details) { |
66 window->Show(); | 116 window->Show(); |
117 const bool show = true; | |
118 const bool force = true; | |
119 const bool noforce = false; | |
67 | 120 |
68 if (!details.animate || views::corewm::WindowAnimationsDisabled(NULL)) { | 121 if (!details.animate || views::corewm::WindowAnimationsDisabled(NULL)) { |
69 window->layer()->SetOpacity(1.0f); | 122 SetWorkspaceAnimationTargetParameters(window, details, show, force); |
70 window->layer()->SetTransform(gfx::Transform()); | |
71 return; | 123 return; |
72 } | 124 } |
73 | 125 |
74 window->layer()->SetOpacity(details.animate_opacity ? 0.0f : 1.0f); | 126 SetWorkspaceAnimationStartParameters(window, details, show, noforce); |
75 if (details.animate_scale) { | 127 // In order for pause to work we need to stop animations. |
76 ApplyWorkspaceScale(window->layer(), | |
77 details.direction == WORKSPACE_ANIMATE_UP ? | |
78 WORKSPACE_SCALE_BELOW : WORKSPACE_SCALE_ABOVE); | |
79 } else { | |
80 window->layer()->SetTransform(gfx::Transform()); | |
81 } | |
82 | |
83 // In order for pause to work we need to stop animations. | |
84 window->layer()->GetAnimator()->StopAnimating(); | 128 window->layer()->GetAnimator()->StopAnimating(); |
85 | 129 |
86 { | 130 { |
87 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); | 131 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); |
88 | 132 |
89 if (details.pause_time_ms > 0) { | 133 if (details.pause_time_ms > 0) { |
90 settings.SetPreemptionStrategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION); | 134 settings.SetPreemptionStrategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION); |
91 window->layer()->GetAnimator()->SchedulePauseForProperties( | 135 window->layer()->GetAnimator()->SchedulePauseForProperties( |
92 base::TimeDelta::FromMilliseconds(details.pause_time_ms), | 136 base::TimeDelta::FromMilliseconds(details.pause_time_ms), |
93 ui::LayerAnimationElement::TRANSFORM, | 137 ui::LayerAnimationElement::TRANSFORM, |
94 ui::LayerAnimationElement::OPACITY, | 138 ui::LayerAnimationElement::OPACITY, |
95 ui::LayerAnimationElement::BRIGHTNESS, | 139 ui::LayerAnimationElement::BRIGHTNESS, |
96 ui::LayerAnimationElement::VISIBILITY, | 140 ui::LayerAnimationElement::VISIBILITY, |
97 -1); | 141 -1); |
98 } | 142 } |
99 | 143 |
100 settings.SetTweenType(kWorkspaceTweenType); | |
101 settings.SetTransitionDuration(DurationForWorkspaceShowOrHide(details)); | 144 settings.SetTransitionDuration(DurationForWorkspaceShowOrHide(details)); |
102 window->layer()->SetTransform(gfx::Transform()); | 145 SetWorkspaceAnimationTargetParameters(window, details, show, force); |
103 window->layer()->SetOpacity(1.0f); | |
104 } | 146 } |
105 } | 147 } |
106 | 148 |
107 void HideWorkspace(aura::Window* window, | 149 void HideWorkspace(aura::Window* window, |
108 const WorkspaceAnimationDetails& details) { | 150 const WorkspaceAnimationDetails& details) { |
109 window->layer()->SetTransform(gfx::Transform()); | 151 const bool hide = false; |
110 window->layer()->SetOpacity(1.0f); | 152 const bool force = true; |
153 const bool noforce = true; | |
154 | |
155 SetWorkspaceAnimationStartParameters(window, details, hide, force); | |
111 window->layer()->GetAnimator()->StopAnimating(); | 156 window->layer()->GetAnimator()->StopAnimating(); |
112 | 157 |
113 if (!details.animate || views::corewm::WindowAnimationsDisabled(NULL)) { | 158 if (!details.animate || views::corewm::WindowAnimationsDisabled(NULL)) { |
114 window->Hide(); | 159 window->Hide(); |
115 return; | 160 return; |
116 } | 161 } |
117 | 162 |
118 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); | 163 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); |
119 if (details.pause_time_ms > 0) { | 164 if (details.pause_time_ms > 0) { |
120 settings.SetPreemptionStrategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION); | 165 settings.SetPreemptionStrategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION); |
121 window->layer()->GetAnimator()->SchedulePauseForProperties( | 166 window->layer()->GetAnimator()->SchedulePauseForProperties( |
122 base::TimeDelta::FromMilliseconds(details.pause_time_ms), | 167 base::TimeDelta::FromMilliseconds(details.pause_time_ms), |
123 ui::LayerAnimationElement::TRANSFORM, | 168 ui::LayerAnimationElement::TRANSFORM, |
124 ui::LayerAnimationElement::OPACITY, | 169 ui::LayerAnimationElement::OPACITY, |
125 ui::LayerAnimationElement::BRIGHTNESS, | 170 ui::LayerAnimationElement::BRIGHTNESS, |
126 ui::LayerAnimationElement::VISIBILITY, | 171 ui::LayerAnimationElement::VISIBILITY, |
127 -1); | 172 -1); |
128 } | 173 } |
129 | 174 |
130 settings.SetTransitionDuration(DurationForWorkspaceShowOrHide(details)); | 175 settings.SetTransitionDuration(DurationForWorkspaceShowOrHide(details)); |
131 settings.SetTweenType(kWorkspaceTweenType); | |
132 if (details.animate_scale) { | |
133 ApplyWorkspaceScale(window->layer(), | |
134 details.direction == WORKSPACE_ANIMATE_UP ? | |
135 WORKSPACE_SCALE_ABOVE : WORKSPACE_SCALE_BELOW); | |
136 } else { | |
137 window->layer()->SetTransform(gfx::Transform()); | |
138 } | |
139 | 176 |
140 // NOTE: Hide() must be before SetOpacity(), else | 177 // NOTE: Hide() must be before SetOpacity(), else |
141 // VisibilityController::UpdateLayerVisibility doesn't pass the false to the | 178 // VisibilityController::UpdateLayerVisibility doesn't pass the false to the |
142 // layer so that the layer and window end up out of sync and confused. | 179 // layer so that the layer and window end up out of sync and confused. |
143 window->Hide(); | 180 window->Hide(); |
144 | 181 |
145 if (details.animate_opacity) | 182 SetWorkspaceAnimationTargetParameters(window, details, hide, noforce); |
146 window->layer()->SetOpacity(0.0f); | |
147 | 183 |
148 // After the animation completes snap the transform back to the identity, | 184 // After the animation completes snap the transform back to the identity, |
149 // otherwise any one that asks for screen bounds gets a slightly scaled | 185 // otherwise any one that asks for screen bounds gets a slightly scaled |
150 // version. | 186 // version. |
151 settings.SetPreemptionStrategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION); | 187 settings.SetPreemptionStrategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION); |
152 settings.SetTransitionDuration(base::TimeDelta()); | 188 settings.SetTransitionDuration(base::TimeDelta()); |
153 window->layer()->SetTransform(gfx::Transform()); | 189 window->layer()->SetTransform(gfx::Transform()); |
154 } | 190 } |
155 | 191 |
156 } // namespace internal | 192 } // namespace internal |
157 } // namespace ash | 193 } // namespace ash |
OLD | NEW |