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/window_animations.h" | 5 #include "ash/wm/window_animations.h" |
6 | 6 |
7 #include "ash/animation_timings.h" | |
8 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
9 #include "ash/launcher/launcher.h" | 8 #include "ash/launcher/launcher.h" |
10 #include "ash/shell.h" | 9 #include "ash/shell.h" |
11 #include "base/command_line.h" | 10 #include "base/command_line.h" |
12 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
13 #include "base/logging.h" | 12 #include "base/logging.h" |
14 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
15 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
16 #include "base/time.h" | 15 #include "base/time.h" |
17 #include "ui/aura/client/aura_constants.h" | 16 #include "ui/aura/client/aura_constants.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 WindowVisibilityAnimationTransition prop = window->GetProperty( | 65 WindowVisibilityAnimationTransition prop = window->GetProperty( |
67 internal::kWindowVisibilityAnimationTransitionKey); | 66 internal::kWindowVisibilityAnimationTransitionKey); |
68 return (prop & transition) != 0; | 67 return (prop & transition) != 0; |
69 } | 68 } |
70 | 69 |
71 namespace internal { | 70 namespace internal { |
72 namespace { | 71 namespace { |
73 | 72 |
74 const float kWindowAnimation_HideOpacity = 0.f; | 73 const float kWindowAnimation_HideOpacity = 0.f; |
75 const float kWindowAnimation_ShowOpacity = 1.f; | 74 const float kWindowAnimation_ShowOpacity = 1.f; |
76 const float kWindowAnimation_TranslateX = 3.f; | 75 const float kWindowAnimation_TranslateFactor = -0.025f; |
77 const float kWindowAnimation_TranslateY = -12.f; | 76 const float kWindowAnimation_ScaleFactor = 1.05f; |
78 const float kWindowAnimation_ScaleFactor = .95f; | |
79 const float kWindowAnimation_MinimizeRotate = -5.f; | 77 const float kWindowAnimation_MinimizeRotate = -5.f; |
| 78 |
80 const float kWindowAnimation_Vertical_TranslateY = 15.f; | 79 const float kWindowAnimation_Vertical_TranslateY = 15.f; |
81 | 80 |
82 // Amount windows are scaled during workspace animations. | 81 // Amount windows are scaled during workspace animations. |
83 const float kWorkspaceScale = .95f; | 82 const float kWorkspaceScale = .95f; |
84 | 83 |
85 // Gets/sets the WindowVisibilityAnimationType associated with a window. | 84 // Gets/sets the WindowVisibilityAnimationType associated with a window. |
86 WindowVisibilityAnimationType GetWindowVisibilityAnimationType( | 85 WindowVisibilityAnimationType GetWindowVisibilityAnimationType( |
87 aura::Window* window) { | 86 aura::Window* window) { |
88 WindowVisibilityAnimationType type = | 87 WindowVisibilityAnimationType type = |
89 window->GetProperty(kWindowVisibilityAnimationTypeKey); | 88 window->GetProperty(kWindowVisibilityAnimationTypeKey); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 // Restore the correct visibility value (overridden for the duration of the | 176 // Restore the correct visibility value (overridden for the duration of the |
178 // animation in AnimateHideWindow()). | 177 // animation in AnimateHideWindow()). |
179 layer_->SetVisible(false); | 178 layer_->SetVisible(false); |
180 } | 179 } |
181 | 180 |
182 ui::Layer* layer_; | 181 ui::Layer* layer_; |
183 | 182 |
184 DISALLOW_COPY_AND_ASSIGN(WorkspaceHidingWindowAnimationObserver); | 183 DISALLOW_COPY_AND_ASSIGN(WorkspaceHidingWindowAnimationObserver); |
185 }; | 184 }; |
186 | 185 |
187 base::TimeDelta GetAnimationDurationForWindow(aura::Window* window) { | |
188 int duration = | |
189 window->GetProperty(internal::kWindowVisibilityAnimationDurationKey); | |
190 if (duration > 0) | |
191 return TimeDelta::FromInternalValue(duration); | |
192 return TimeDelta::FromMilliseconds(kStandardTransitionDuration); | |
193 } | |
194 | |
195 // Shows a window using an animation, animating its opacity from 0.f to 1.f, and | 186 // Shows a window using an animation, animating its opacity from 0.f to 1.f, and |
196 // its transform from |start_transform| to |end_transform|. | 187 // its transform from |start_transform| to |end_transform|. |
197 void AnimateShowWindowCommon(aura::Window* window, | 188 void AnimateShowWindowCommon(aura::Window* window, |
198 const ui::Transform& start_transform, | 189 const ui::Transform& start_transform, |
199 const ui::Transform& end_transform) { | 190 const ui::Transform& end_transform) { |
200 window->layer()->set_delegate(window); | 191 window->layer()->set_delegate(window); |
201 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); | 192 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); |
202 window->layer()->SetTransform(start_transform); | 193 window->layer()->SetTransform(start_transform); |
203 | 194 |
204 { | 195 { |
205 // Property sets within this scope will be implicitly animated. | 196 // Property sets within this scope will be implicitly animated. |
206 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); | 197 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); |
207 settings.SetTransitionDuration(GetAnimationDurationForWindow(window)); | 198 int duration = |
| 199 window->GetProperty(internal::kWindowVisibilityAnimationDurationKey); |
| 200 if (duration > 0) |
| 201 settings.SetTransitionDuration(TimeDelta::FromInternalValue(duration)); |
| 202 |
208 window->layer()->SetTransform(end_transform); | 203 window->layer()->SetTransform(end_transform); |
209 window->layer()->SetOpacity(kWindowAnimation_ShowOpacity); | 204 window->layer()->SetOpacity(kWindowAnimation_ShowOpacity); |
210 } | 205 } |
211 } | 206 } |
212 | 207 |
213 // Hides a window using an animation, animating its opacity from 1.f to 0.f, and | 208 // Hides a window using an animation, animating its opacity from 1.f to 0.f, and |
214 // its transform to |end_transform|. | 209 // its transform to |end_transform|. |
215 void AnimateHideWindowCommon(aura::Window* window, | 210 void AnimateHideWindowCommon(aura::Window* window, |
216 const ui::Transform& end_transform) { | 211 const ui::Transform& end_transform) { |
217 window->layer()->set_delegate(NULL); | 212 window->layer()->set_delegate(NULL); |
218 | 213 |
219 // Property sets within this scope will be implicitly animated. | 214 // Property sets within this scope will be implicitly animated. |
220 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); | 215 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); |
221 settings.AddObserver(new HidingWindowAnimationObserver(window)); | 216 settings.AddObserver(new HidingWindowAnimationObserver(window)); |
222 | 217 |
223 settings.SetTransitionDuration(GetAnimationDurationForWindow(window)); | 218 int duration = |
| 219 window->GetProperty(internal::kWindowVisibilityAnimationDurationKey); |
| 220 if (duration > 0) |
| 221 settings.SetTransitionDuration(TimeDelta::FromInternalValue(duration)); |
| 222 |
224 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); | 223 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); |
225 window->layer()->SetTransform(end_transform); | 224 window->layer()->SetTransform(end_transform); |
226 } | 225 } |
227 | 226 |
228 // Show/Hide windows using a shrink animation. | 227 // Show/Hide windows using a shrink animation. |
229 void AnimateShowWindow_Drop(aura::Window* window) { | 228 void AnimateShowWindow_Drop(aura::Window* window) { |
230 ui::Transform transform; | 229 ui::Transform transform; |
231 transform.ConcatScale(kWindowAnimation_ScaleFactor, | 230 transform.ConcatScale(kWindowAnimation_ScaleFactor, |
232 kWindowAnimation_ScaleFactor); | 231 kWindowAnimation_ScaleFactor); |
233 transform.ConcatTranslate(kWindowAnimation_TranslateX, | 232 transform.ConcatTranslate( |
234 kWindowAnimation_TranslateY); | 233 kWindowAnimation_TranslateFactor * window->bounds().width(), |
| 234 kWindowAnimation_TranslateFactor * window->bounds().height()); |
235 AnimateShowWindowCommon(window, transform, ui::Transform()); | 235 AnimateShowWindowCommon(window, transform, ui::Transform()); |
236 } | 236 } |
237 | 237 |
238 void AnimateHideWindow_Drop(aura::Window* window) { | 238 void AnimateHideWindow_Drop(aura::Window* window) { |
239 ui::Transform transform; | 239 ui::Transform transform; |
240 transform.ConcatScale(kWindowAnimation_ScaleFactor, | 240 transform.ConcatScale(kWindowAnimation_ScaleFactor, |
241 kWindowAnimation_ScaleFactor); | 241 kWindowAnimation_ScaleFactor); |
242 // Window keeps dropping vertically when hidden (i.e. doesn't reverse | 242 transform.ConcatTranslate( |
243 // direction) | 243 kWindowAnimation_TranslateFactor * window->bounds().width(), |
244 transform.ConcatTranslate(kWindowAnimation_TranslateX, | 244 kWindowAnimation_TranslateFactor * window->bounds().height()); |
245 -kWindowAnimation_TranslateY); | |
246 AnimateHideWindowCommon(window, transform); | 245 AnimateHideWindowCommon(window, transform); |
247 } | 246 } |
248 | 247 |
249 // Show/Hide windows using a vertical Glenimation. | 248 // Show/Hide windows using a vertical Glenimation. |
250 void AnimateShowWindow_Vertical(aura::Window* window) { | 249 void AnimateShowWindow_Vertical(aura::Window* window) { |
251 ui::Transform transform; | 250 ui::Transform transform; |
252 transform.ConcatTranslate(0, kWindowAnimation_Vertical_TranslateY); | 251 transform.ConcatTranslate(0, kWindowAnimation_Vertical_TranslateY); |
253 AnimateShowWindowCommon(window, transform, ui::Transform()); | 252 AnimateShowWindowCommon(window, transform, ui::Transform()); |
254 } | 253 } |
255 | 254 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 | 292 |
294 void AnimateShowWindow_Workspace(aura::Window* window) { | 293 void AnimateShowWindow_Workspace(aura::Window* window) { |
295 ui::Transform transform(BuildWorkspaceSwitchTransform(window)); | 294 ui::Transform transform(BuildWorkspaceSwitchTransform(window)); |
296 window->layer()->SetVisible(true); | 295 window->layer()->SetVisible(true); |
297 window->layer()->SetOpacity(0.0f); | 296 window->layer()->SetOpacity(0.0f); |
298 window->layer()->SetTransform(transform); | 297 window->layer()->SetTransform(transform); |
299 | 298 |
300 { | 299 { |
301 // Property sets within this scope will be implicitly animated. | 300 // Property sets within this scope will be implicitly animated. |
302 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); | 301 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); |
303 settings.SetTransitionDuration( | |
304 TimeDelta::FromMilliseconds(kSlowTransitionDuration)); | |
305 | 302 |
306 window->layer()->SetTransform(ui::Transform()); | 303 window->layer()->SetTransform(ui::Transform()); |
307 // Opacity animates only during the first half of the animation. | 304 // Opacity animates only during the first half of the animation. |
308 settings.SetTransitionDuration(settings.GetTransitionDuration() / 2); | 305 settings.SetTransitionDuration(settings.GetTransitionDuration() / 2); |
309 window->layer()->SetOpacity(1.0f); | 306 window->layer()->SetOpacity(1.0f); |
310 } | 307 } |
311 } | 308 } |
312 | 309 |
313 void AnimateHideWindow_Workspace(aura::Window* window) { | 310 void AnimateHideWindow_Workspace(aura::Window* window) { |
314 ui::Transform transform(BuildWorkspaceSwitchTransform(window)); | 311 ui::Transform transform(BuildWorkspaceSwitchTransform(window)); |
315 window->layer()->SetOpacity(1.0f); | 312 window->layer()->SetOpacity(1.0f); |
316 window->layer()->SetTransform(ui::Transform()); | 313 window->layer()->SetTransform(ui::Transform()); |
317 | 314 |
318 // Opacity animates from 1 to 0 only over the second half of the animation. To | 315 // Opacity animates from 1 to 0 only over the second half of the animation. To |
319 // get this functionality two animations are schedule for opacity, the first | 316 // get this functionality two animations are schedule for opacity, the first |
320 // from 1 to 1 (which effectively does nothing) the second from 1 to 0. | 317 // from 1 to 1 (which effectively does nothing) the second from 1 to 0. |
321 // Because we're scheduling two animations of the same property we need to | 318 // Because we're scheduling two animations of the same property we need to |
322 // change the preemption strategy. | 319 // change the preemption strategy. |
323 ui::LayerAnimator* animator = window->layer()->GetAnimator(); | 320 ui::LayerAnimator* animator = window->layer()->GetAnimator(); |
324 animator->set_preemption_strategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION); | 321 animator->set_preemption_strategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION); |
325 { | 322 { |
326 // Property sets within this scope will be implicitly animated. | 323 // Property sets within this scope will be implicitly animated. |
327 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); | 324 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); |
328 settings.SetTransitionDuration( | |
329 TimeDelta::FromMilliseconds(kSlowTransitionDuration)); | |
330 // Add an observer that sets visibility of the layer to false once animation | 325 // Add an observer that sets visibility of the layer to false once animation |
331 // completes. | 326 // completes. |
332 settings.AddObserver(new WorkspaceHidingWindowAnimationObserver(window)); | 327 settings.AddObserver(new WorkspaceHidingWindowAnimationObserver(window)); |
333 window->layer()->SetTransform(transform); | 328 window->layer()->SetTransform(transform); |
334 settings.SetTransitionDuration(settings.GetTransitionDuration() / 2); | 329 settings.SetTransitionDuration(settings.GetTransitionDuration() / 2); |
335 window->layer()->SetOpacity(1.0f); | 330 window->layer()->SetOpacity(1.0f); |
336 window->layer()->SetOpacity(0.0f); | 331 window->layer()->SetOpacity(0.0f); |
337 } | 332 } |
338 animator->set_preemption_strategy( | 333 animator->set_preemption_strategy( |
339 ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET); | 334 ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 return AnimateShowWindow(window); | 483 return AnimateShowWindow(window); |
489 } else { | 484 } else { |
490 // Don't start hiding the window again if it's already being hidden. | 485 // Don't start hiding the window again if it's already being hidden. |
491 return window->layer()->GetTargetOpacity() != 0.0f && | 486 return window->layer()->GetTargetOpacity() != 0.0f && |
492 AnimateHideWindow(window); | 487 AnimateHideWindow(window); |
493 } | 488 } |
494 } | 489 } |
495 | 490 |
496 } // namespace internal | 491 } // namespace internal |
497 } // namespace ash | 492 } // namespace ash |
OLD | NEW |