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/session_state_animator.h" | 5 #include "ash/wm/session_state_animator.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/shell_window_ids.h" | 8 #include "ash/shell_window_ids.h" |
9 #include "ash/wm/window_animations.h" | 9 #include "ash/wm/window_animations.h" |
10 #include "ui/aura/client/aura_constants.h" | 10 #include "ui/aura/client/aura_constants.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 animator->set_preemption_strategy( | 113 animator->set_preemption_strategy( |
114 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 114 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
115 ui::LayerAnimationSequence* sequence = new ui::LayerAnimationSequence( | 115 ui::LayerAnimationSequence* sequence = new ui::LayerAnimationSequence( |
116 ui::LayerAnimationElement::CreateOpacityElement( | 116 ui::LayerAnimationElement::CreateOpacityElement( |
117 target_opacity, duration)); | 117 target_opacity, duration)); |
118 animator->StartAnimation(sequence); | 118 animator->StartAnimation(sequence); |
119 if (observer) | 119 if (observer) |
120 sequence->AddObserver(observer); | 120 sequence->AddObserver(observer); |
121 } | 121 } |
122 | 122 |
123 // Fades |window| in to full opacity over |duration|. | 123 // Fades |window| in to |opacity| over |duration|. |
124 void FadeInWindow(aura::Window* window, | 124 void StartOpacityAnimationForWindow(aura::Window* window, |
125 base::TimeDelta duration, | 125 float opacity, |
126 ui::LayerAnimationObserver* observer) { | 126 base::TimeDelta duration, |
| 127 ui::LayerAnimationObserver* observer) { |
127 ui::LayerAnimator* animator = window->layer()->GetAnimator(); | 128 ui::LayerAnimator* animator = window->layer()->GetAnimator(); |
128 animator->set_preemption_strategy( | 129 animator->set_preemption_strategy( |
129 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 130 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
130 ui::LayerAnimationSequence* sequence = new ui::LayerAnimationSequence( | 131 ui::LayerAnimationSequence* sequence = new ui::LayerAnimationSequence( |
131 ui::LayerAnimationElement::CreateOpacityElement(1.0, duration)); | 132 ui::LayerAnimationElement::CreateOpacityElement(opacity, duration)); |
132 animator->StartAnimation(sequence); | 133 animator->StartAnimation(sequence); |
133 if (observer) | 134 if (observer) |
134 sequence->AddObserver(observer); | 135 sequence->AddObserver(observer); |
135 } | 136 } |
136 | 137 |
137 // Makes |window| fully transparent instantaneously. | 138 // Makes |window| fully transparent instantaneously. |
138 void HideWindowImmediately(aura::Window* window, | 139 void HideWindowImmediately(aura::Window* window, |
139 ui::LayerAnimationObserver* observer) { | 140 ui::LayerAnimationObserver* observer) { |
140 window->layer()->SetOpacity(0.0); | 141 window->layer()->SetOpacity(0.0); |
141 if (observer) | 142 if (observer) |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 // it does not call NotifyEnded(). | 182 // it does not call NotifyEnded(). |
182 if (observer) { | 183 if (observer) { |
183 ui::LayerAnimationSequence* sequence = new ui::LayerAnimationSequence( | 184 ui::LayerAnimationSequence* sequence = new ui::LayerAnimationSequence( |
184 ui::LayerAnimationElement::CreateOpacityElement( | 185 ui::LayerAnimationElement::CreateOpacityElement( |
185 0.0, base::TimeDelta())); | 186 0.0, base::TimeDelta())); |
186 sequence->AddObserver(observer); | 187 sequence->AddObserver(observer); |
187 layer->GetAnimator()->ScheduleAnimation(sequence); | 188 layer->GetAnimator()->ScheduleAnimation(sequence); |
188 } | 189 } |
189 } | 190 } |
190 | 191 |
191 void ShowWindow(aura::Window* window, | 192 void TransformWindowToBaseState(aura::Window* window, |
192 base::TimeDelta duration, | 193 base::TimeDelta duration, |
193 bool above, | 194 ui::LayerAnimationObserver* observer) { |
194 ui::LayerAnimationObserver* observer) { | |
195 ui::Layer* layer = window->layer(); | 195 ui::Layer* layer = window->layer(); |
196 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator()); | 196 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator()); |
197 | 197 |
198 // Set initial state of animation | |
199 settings.SetTransitionDuration(base::TimeDelta()); | |
200 SetTransformForScaleAnimation(layer, | |
201 above ? LAYER_SCALE_ANIMATION_ABOVE : LAYER_SCALE_ANIMATION_BELOW); | |
202 | |
203 // Animate to target values. | 198 // Animate to target values. |
| 199 settings.SetPreemptionStrategy( |
| 200 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
204 settings.SetTransitionDuration(duration); | 201 settings.SetTransitionDuration(duration); |
205 | 202 |
206 settings.SetTweenType(ui::Tween::EASE_OUT); | 203 settings.SetTweenType(ui::Tween::EASE_OUT); |
207 layer->SetTransform(gfx::Transform()); | 204 layer->SetTransform(gfx::Transform()); |
208 | 205 |
209 settings.SetTweenType(ui::Tween::EASE_IN_OUT); | 206 settings.SetTweenType(ui::Tween::EASE_IN_OUT); |
210 layer->SetOpacity(1.0f); | 207 layer->SetOpacity(1.0f); |
211 | 208 |
212 // A bit of a dirty trick: we need to catch the end of the animation we don't | 209 // A bit of a dirty trick: we need to catch the end of the animation we don't |
213 // control. So we use two facts we know: which animator will be used and the | 210 // control. So we use two facts we know: which animator will be used and the |
214 // target opacity to add "Do nothing" animation sequence. | 211 // target opacity to add "Do nothing" animation sequence. |
215 // Unfortunately, we can not just use empty LayerAnimationSequence, because | 212 // Unfortunately, we can not just use empty LayerAnimationSequence, because |
216 // it does not call NotifyEnded(). | 213 // it does not call NotifyEnded(). |
217 if (observer) { | 214 if (observer) { |
218 ui::LayerAnimationSequence* sequence = new ui::LayerAnimationSequence( | 215 ui::LayerAnimationSequence* sequence = new ui::LayerAnimationSequence( |
219 ui::LayerAnimationElement::CreateOpacityElement( | 216 ui::LayerAnimationElement::CreateOpacityElement( |
220 1.0, base::TimeDelta())); | 217 1.0, base::TimeDelta())); |
221 sequence->AddObserver(observer); | 218 sequence->AddObserver(observer); |
222 layer->GetAnimator()->ScheduleAnimation(sequence); | 219 layer->GetAnimator()->ScheduleAnimation(sequence); |
223 } | 220 } |
224 } | 221 } |
225 | 222 |
| 223 void ShowWindow(aura::Window* window, |
| 224 base::TimeDelta duration, |
| 225 bool above, |
| 226 ui::LayerAnimationObserver* observer) { |
| 227 ui::Layer* layer = window->layer(); |
| 228 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator()); |
| 229 |
| 230 // Set initial state of animation |
| 231 settings.SetPreemptionStrategy( |
| 232 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| 233 settings.SetTransitionDuration(base::TimeDelta()); |
| 234 SetTransformForScaleAnimation(layer, |
| 235 above ? LAYER_SCALE_ANIMATION_ABOVE : LAYER_SCALE_ANIMATION_BELOW); |
| 236 |
| 237 TransformWindowToBaseState(window, duration, observer); |
| 238 } |
| 239 |
226 // Starts grayscale/brightness animation for |window| over |duration|. Target | 240 // Starts grayscale/brightness animation for |window| over |duration|. Target |
227 // value for both grayscale and brightness are specified by |target|. | 241 // value for both grayscale and brightness are specified by |target|. |
228 void StartGrayscaleBrightnessAnimationForWindow( | 242 void StartGrayscaleBrightnessAnimationForWindow( |
229 aura::Window* window, | 243 aura::Window* window, |
230 float target, | 244 float target, |
231 base::TimeDelta duration, | 245 base::TimeDelta duration, |
232 ui::LayerAnimationObserver* observer) { | 246 ui::LayerAnimationObserver* observer) { |
233 ui::LayerAnimator* animator = window->layer()->GetAnimator(); | 247 ui::LayerAnimator* animator = window->layer()->GetAnimator(); |
234 | 248 |
235 std::vector<ui::LayerAnimationSequence*> animations = | 249 std::vector<ui::LayerAnimationSequence*> animations = |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 break; | 306 break; |
293 case SessionStateAnimator::ANIMATION_FULL_CLOSE: | 307 case SessionStateAnimator::ANIMATION_FULL_CLOSE: |
294 if (layer->GetTargetTransform() != GetFastCloseTransform() || | 308 if (layer->GetTargetTransform() != GetFastCloseTransform() || |
295 layer->GetTargetOpacity() > 0.0001) | 309 layer->GetTargetOpacity() > 0.0001) |
296 return false; | 310 return false; |
297 break; | 311 break; |
298 case SessionStateAnimator::ANIMATION_FADE_IN: | 312 case SessionStateAnimator::ANIMATION_FADE_IN: |
299 if (layer->GetTargetOpacity() < 0.9999) | 313 if (layer->GetTargetOpacity() < 0.9999) |
300 return false; | 314 return false; |
301 break; | 315 break; |
| 316 case SessionStateAnimator::ANIMATION_FADE_OUT: |
| 317 if (layer->GetTargetOpacity() > 0.0001) |
| 318 return false; |
| 319 break; |
302 case SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY: | 320 case SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY: |
303 if (layer->GetTargetOpacity() > 0.0001) | 321 if (layer->GetTargetOpacity() > 0.0001) |
304 return false; | 322 return false; |
305 break; | 323 break; |
306 case SessionStateAnimator::ANIMATION_RESTORE: | 324 case SessionStateAnimator::ANIMATION_RESTORE: |
307 if (layer->opacity() < 0.9999 || layer->transform() != gfx::Transform()) | 325 if (layer->opacity() < 0.9999 || layer->transform() != gfx::Transform()) |
308 return false; | 326 return false; |
309 break; | 327 break; |
310 case SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS: | 328 case SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS: |
311 if ((layer->GetTargetBrightness() < 0.9999) || | 329 if ((layer->GetTargetBrightness() < 0.9999) || |
312 (layer->GetTargetGrayscale() < 0.9999)) | 330 (layer->GetTargetGrayscale() < 0.9999)) |
313 return false; | 331 return false; |
314 break; | 332 break; |
315 case SessionStateAnimator::ANIMATION_UNDO_GRAYSCALE_BRIGHTNESS: | 333 case SessionStateAnimator::ANIMATION_UNDO_GRAYSCALE_BRIGHTNESS: |
316 if ((layer->GetTargetBrightness() > 0.0001) || | 334 if ((layer->GetTargetBrightness() > 0.0001) || |
317 (layer->GetTargetGrayscale() > 0.0001)) | 335 (layer->GetTargetGrayscale() > 0.0001)) |
318 return false; | 336 return false; |
319 break; | 337 break; |
320 case SessionStateAnimator::ANIMATION_DROP: | 338 case SessionStateAnimator::ANIMATION_DROP: |
| 339 case SessionStateAnimator::ANIMATION_UNDO_LIFT: |
321 //ToDo(antim) : check other effects | 340 //ToDo(antim) : check other effects |
322 if (layer->GetTargetOpacity() < 0.9999) | 341 if (layer->GetTargetOpacity() < 0.9999) |
323 return false; | 342 return false; |
324 break; | 343 break; |
325 //ToDo(antim) : check other effects | 344 //ToDo(antim) : check other effects |
326 case SessionStateAnimator::ANIMATION_LIFT: | 345 case SessionStateAnimator::ANIMATION_LIFT: |
327 if (layer->GetTargetOpacity() > 0.0001) | 346 if (layer->GetTargetOpacity() > 0.0001) |
328 return false; | 347 return false; |
329 break; | 348 break; |
330 case SessionStateAnimator::ANIMATION_RAISE_TO_SCREEN: | 349 case SessionStateAnimator::ANIMATION_RAISE_TO_SCREEN: |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 if (container_mask & LOCK_SCREEN_CONTAINERS) { | 470 if (container_mask & LOCK_SCREEN_CONTAINERS) { |
452 containers->push_back(Shell::GetContainer( | 471 containers->push_back(Shell::GetContainer( |
453 root_window, | 472 root_window, |
454 internal::kShellWindowId_LockScreenContainersContainer)); | 473 internal::kShellWindowId_LockScreenContainersContainer)); |
455 } | 474 } |
456 if (container_mask & LOCK_SCREEN_RELATED_CONTAINERS) { | 475 if (container_mask & LOCK_SCREEN_RELATED_CONTAINERS) { |
457 containers->push_back(Shell::GetContainer( | 476 containers->push_back(Shell::GetContainer( |
458 root_window, | 477 root_window, |
459 internal::kShellWindowId_LockScreenRelatedContainersContainer)); | 478 internal::kShellWindowId_LockScreenRelatedContainersContainer)); |
460 } | 479 } |
461 if (container_mask & LOCK_SCREEN_SYSTEM_FOREGROUND) { | |
462 containers->push_back(Shell::GetContainer( | |
463 root_window, | |
464 internal::kShellWindowId_PowerButtonAnimationContainer)); | |
465 } | |
466 } | 480 } |
467 | 481 |
468 void SessionStateAnimator::StartAnimation(int container_mask, | 482 void SessionStateAnimator::StartAnimation(int container_mask, |
469 AnimationType type, | 483 AnimationType type, |
470 AnimationSpeed speed) { | 484 AnimationSpeed speed) { |
471 aura::Window::Windows containers; | 485 aura::Window::Windows containers; |
472 GetContainers(container_mask, &containers); | 486 GetContainers(container_mask, &containers); |
473 for (aura::Window::Windows::const_iterator it = containers.begin(); | 487 for (aura::Window::Windows::const_iterator it = containers.begin(); |
474 it != containers.end(); ++it) { | 488 it != containers.end(); ++it) { |
475 RunAnimationForWindow(*it, type, speed, NULL); | 489 RunAnimationForWindow(*it, type, speed, NULL); |
476 } | 490 } |
477 } | 491 } |
478 | 492 |
479 // Apply animation |type| to all containers described by |container_mask|. | 493 // Apply animation |type| to all containers described by |container_mask|. |
480 void SessionStateAnimator::StartAnimationWithCallback( | 494 void SessionStateAnimator::StartAnimationWithCallback( |
481 int container_mask, | 495 int container_mask, |
482 AnimationType type, | 496 AnimationType type, |
483 AnimationSpeed speed, | 497 AnimationSpeed speed, |
484 base::Callback<void(void)>& callback) { | 498 base::Callback<void(void)>& callback) { |
485 aura::Window::Windows containers; | 499 aura::Window::Windows containers; |
486 GetContainers(container_mask, &containers); | 500 GetContainers(container_mask, &containers); |
487 for (aura::Window::Windows::const_iterator it = containers.begin(); | 501 for (aura::Window::Windows::const_iterator it = containers.begin(); |
488 it != containers.end(); ++it) { | 502 it != containers.end(); ++it) { |
489 ui::LayerAnimationObserver* observer = | 503 ui::LayerAnimationObserver* observer = |
490 new CallbackAnimationObserver(callback); | 504 new CallbackAnimationObserver(callback); |
491 RunAnimationForWindow(*it, type, speed, observer); | 505 RunAnimationForWindow(*it, type, speed, observer); |
492 } | 506 } |
493 } | 507 } |
494 | 508 |
| 509 void SessionStateAnimator::StartAnimationWithObserver( |
| 510 int container_mask, |
| 511 AnimationType type, |
| 512 AnimationSpeed speed, |
| 513 ui::LayerAnimationObserver* observer) { |
| 514 aura::Window::Windows containers; |
| 515 GetContainers(container_mask, &containers); |
| 516 for (aura::Window::Windows::const_iterator it = containers.begin(); |
| 517 it != containers.end(); ++it) { |
| 518 RunAnimationForWindow(*it, type, speed, observer); |
| 519 } |
| 520 } |
| 521 |
495 void SessionStateAnimator::StartGlobalAnimation(AnimationType type, | 522 void SessionStateAnimator::StartGlobalAnimation(AnimationType type, |
496 AnimationSpeed speed) { | 523 AnimationSpeed speed) { |
497 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); | 524 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); |
498 RunAnimationForWindow(root_window, type, speed, NULL); | 525 RunAnimationForWindow(root_window, type, speed, NULL); |
499 } | 526 } |
500 | 527 |
501 void SessionStateAnimator::RunAnimationForWindow( | 528 void SessionStateAnimator::RunAnimationForWindow( |
502 aura::Window* window, | 529 aura::Window* window, |
503 AnimationType type, | 530 AnimationType type, |
504 AnimationSpeed speed, | 531 AnimationSpeed speed, |
505 ui::LayerAnimationObserver* observer) { | 532 ui::LayerAnimationObserver* observer) { |
506 base::TimeDelta duration = GetDuration(speed); | 533 base::TimeDelta duration = GetDuration(speed); |
507 | 534 |
508 switch (type) { | 535 switch (type) { |
509 case ANIMATION_PARTIAL_CLOSE: | 536 case ANIMATION_PARTIAL_CLOSE: |
510 StartSlowCloseAnimationForWindow(window, duration, observer); | 537 StartSlowCloseAnimationForWindow(window, duration, observer); |
511 break; | 538 break; |
512 case ANIMATION_UNDO_PARTIAL_CLOSE: | 539 case ANIMATION_UNDO_PARTIAL_CLOSE: |
513 StartUndoSlowCloseAnimationForWindow(window, duration, observer); | 540 StartUndoSlowCloseAnimationForWindow(window, duration, observer); |
514 break; | 541 break; |
515 case ANIMATION_FULL_CLOSE: | 542 case ANIMATION_FULL_CLOSE: |
516 StartFastCloseAnimationForWindow(window, duration, observer); | 543 StartFastCloseAnimationForWindow(window, duration, observer); |
517 break; | 544 break; |
518 case ANIMATION_FADE_IN: | 545 case ANIMATION_FADE_IN: |
519 FadeInWindow(window, duration, observer); | 546 StartOpacityAnimationForWindow(window, 1.0, duration, observer); |
| 547 break; |
| 548 case ANIMATION_FADE_OUT: |
| 549 StartOpacityAnimationForWindow(window, 0.0, duration, observer); |
520 break; | 550 break; |
521 case ANIMATION_HIDE_IMMEDIATELY: | 551 case ANIMATION_HIDE_IMMEDIATELY: |
522 DCHECK_EQ(speed, ANIMATION_SPEED_IMMEDIATE); | 552 DCHECK_EQ(speed, ANIMATION_SPEED_IMMEDIATE); |
523 HideWindowImmediately(window, observer); | 553 HideWindowImmediately(window, observer); |
524 break; | 554 break; |
525 case ANIMATION_RESTORE: | 555 case ANIMATION_RESTORE: |
526 DCHECK_EQ(speed, ANIMATION_SPEED_IMMEDIATE); | 556 DCHECK_EQ(speed, ANIMATION_SPEED_IMMEDIATE); |
527 RestoreWindow(window, observer); | 557 RestoreWindow(window, observer); |
528 break; | 558 break; |
529 case ANIMATION_LIFT: | 559 case ANIMATION_LIFT: |
530 HideWindow(window, duration, true, observer); | 560 HideWindow(window, duration, true, observer); |
531 break; | 561 break; |
532 case ANIMATION_DROP: | 562 case ANIMATION_DROP: |
533 ShowWindow(window, duration, true, observer); | 563 ShowWindow(window, duration, true, observer); |
534 break; | 564 break; |
| 565 case ANIMATION_UNDO_LIFT: |
| 566 TransformWindowToBaseState(window, duration, observer); |
| 567 break; |
535 case ANIMATION_RAISE_TO_SCREEN: | 568 case ANIMATION_RAISE_TO_SCREEN: |
536 ShowWindow(window, duration, false, observer); | 569 ShowWindow(window, duration, false, observer); |
537 break; | 570 break; |
538 case ANIMATION_LOWER_BELOW_SCREEN: | 571 case ANIMATION_LOWER_BELOW_SCREEN: |
539 HideWindow(window, duration, false, observer); | 572 HideWindow(window, duration, false, observer); |
540 break; | 573 break; |
541 case ANIMATION_PARTIAL_FADE_IN: | 574 case ANIMATION_PARTIAL_FADE_IN: |
542 StartPartialFadeAnimation( | 575 StartPartialFadeAnimation( |
543 window, kPartialFadeRatio, duration, observer); | 576 window, kPartialFadeRatio, duration, observer); |
544 break; | 577 break; |
(...skipping 26 matching lines...) Expand all Loading... |
571 foreground_->SetColor(SK_ColorWHITE); | 604 foreground_->SetColor(SK_ColorWHITE); |
572 foreground_->GetWidget()->Show(); | 605 foreground_->GetWidget()->Show(); |
573 } | 606 } |
574 | 607 |
575 void SessionStateAnimator::DropForeground() { | 608 void SessionStateAnimator::DropForeground() { |
576 foreground_.reset(); | 609 foreground_.reset(); |
577 } | 610 } |
578 | 611 |
579 } // namespace internal | 612 } // namespace internal |
580 } // namespace ash | 613 } // namespace ash |
OLD | NEW |