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 "ash/wm/workspace/workspace_animations.h" | |
11 #include "ui/aura/client/aura_constants.h" | 10 #include "ui/aura/client/aura_constants.h" |
12 #include "ui/aura/root_window.h" | 11 #include "ui/aura/root_window.h" |
13 #include "ui/compositor/layer_animation_observer.h" | 12 #include "ui/compositor/layer_animation_observer.h" |
14 #include "ui/compositor/layer_animation_sequence.h" | 13 #include "ui/compositor/layer_animation_sequence.h" |
14 #include "ui/compositor/scoped_layer_animation_settings.h" | |
15 #include "ui/views/widget/widget.h" | 15 #include "ui/views/widget/widget.h" |
16 | 16 |
17 namespace ash { | 17 namespace ash { |
18 namespace internal { | 18 namespace internal { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 // Slightly-smaller size that we scale the screen down to for the pre-lock and | 22 // Slightly-smaller size that we scale the screen down to for the pre-lock and |
23 // pre-shutdown states. | 23 // pre-shutdown states. |
24 const float kSlowCloseSizeRatio = 0.95f; | 24 const float kSlowCloseSizeRatio = 0.95f; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 // instantaneously. | 146 // instantaneously. |
147 void RestoreWindow(aura::Window* window, ui::LayerAnimationObserver* observer) { | 147 void RestoreWindow(aura::Window* window, ui::LayerAnimationObserver* observer) { |
148 window->layer()->SetTransform(gfx::Transform()); | 148 window->layer()->SetTransform(gfx::Transform()); |
149 window->layer()->SetOpacity(1.0); | 149 window->layer()->SetOpacity(1.0); |
150 if (observer) | 150 if (observer) |
151 observer->OnLayerAnimationEnded(NULL); | 151 observer->OnLayerAnimationEnded(NULL); |
152 } | 152 } |
153 | 153 |
154 void HideWindow(aura::Window* window, | 154 void HideWindow(aura::Window* window, |
155 base::TimeDelta duration, | 155 base::TimeDelta duration, |
156 WorkspaceAnimationDirection direction, | 156 bool above, |
157 ui::LayerAnimationObserver* observer) { | 157 ui::LayerAnimationObserver* observer) { |
158 WorkspaceAnimationDetails details; | 158 ui::Layer* layer = window->layer(); |
159 details.direction = direction; | 159 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator()); |
160 details.animate = true; | 160 |
161 details.animate_scale = true; | 161 settings.SetTransitionDuration(duration); |
162 details.animate_opacity = true; | 162 |
163 details.duration = duration; | 163 settings.SetTweenType(ui::Tween::EASE_OUT); |
164 HideWorkspace(window, details); | 164 ApplyAshWindowAnimationScale(layer, |
165 above ? ASH_WINDOW_SCALE_ABOVE : ASH_WINDOW_SCALE_BELOW); | |
166 | |
167 settings.SetTweenType(ui::Tween::EASE_IN_OUT); | |
168 layer->SetOpacity(0.0f); | |
169 | |
170 // After the animation completes snap the transform back to the identity, | |
171 // otherwise any one that asks for screen bounds gets a slightly scaled | |
172 // version. | |
173 settings.SetPreemptionStrategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION); | |
174 settings.SetTransitionDuration(base::TimeDelta()); | |
175 layer->SetTransform(gfx::Transform()); | |
176 | |
165 // A bit of a dirty trick: we need to catch the end of the animation we don't | 177 // A bit of a dirty trick: we need to catch the end of the animation we don't |
166 // control. So we use two facts we know: which animator will be used and the | 178 // control. So we use two facts we know: which animator will be used and the |
167 // target opacity to add "Do nothing" animation sequence. | 179 // target opacity to add "Do nothing" animation sequence. |
168 // Unfortunately, we can not just use empty LayerAnimationSequence, because | 180 // Unfortunately, we can not just use empty LayerAnimationSequence, because |
169 // it does not call NotifyEnded(). | 181 // it does not call NotifyEnded(). |
170 ui::LayerAnimationSequence* sequence = new ui::LayerAnimationSequence( | 182 if (observer) { |
171 ui::LayerAnimationElement::CreateOpacityElement( | 183 ui::LayerAnimationSequence* sequence = new ui::LayerAnimationSequence( |
172 0.0, base::TimeDelta())); | 184 ui::LayerAnimationElement::CreateOpacityElement( |
173 if (observer) | 185 0.0, base::TimeDelta())); |
174 sequence->AddObserver(observer); | 186 sequence->AddObserver(observer); |
175 window->layer()->GetAnimator()->ScheduleAnimation(sequence); | 187 layer->GetAnimator()->ScheduleAnimation(sequence); |
188 } | |
176 } | 189 } |
177 | 190 |
178 void ShowWindow(aura::Window* window, | 191 void ShowWindow(aura::Window* window, |
179 base::TimeDelta length, | 192 base::TimeDelta duration, |
180 WorkspaceAnimationDirection direction, | 193 bool above, |
181 ui::LayerAnimationObserver* observer) { | 194 ui::LayerAnimationObserver* observer) { |
182 WorkspaceAnimationDetails details; | 195 ui::Layer* layer = window->layer(); |
183 details.direction = direction; | 196 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator()); |
184 details.animate = true; | 197 |
185 details.animate_scale = true; | 198 // Set initial state of animation |
186 details.animate_opacity = true; | 199 settings.SetTransitionDuration(base::TimeDelta()); |
187 details.duration = length; | 200 ApplyAshWindowAnimationScale(layer, |
188 ShowWorkspace(window, details); | 201 above ? ASH_WINDOW_SCALE_ABOVE : ASH_WINDOW_SCALE_BELOW); |
202 | |
203 // Animate to target values. | |
204 settings.SetTransitionDuration(duration); | |
205 | |
206 settings.SetTweenType(ui::Tween::EASE_OUT); | |
207 layer->SetTransform(gfx::Transform()); | |
208 | |
209 settings.SetTweenType(ui::Tween::EASE_IN_OUT); | |
210 layer->SetOpacity(1.0f); | |
211 | |
189 // A bit of a dirty trick: we need to catch the end of the animation we don't | 212 // A bit of a dirty trick: we need to catch the end of the animation we don't |
190 // control. So we use two facts we know: which animator will be used and the | 213 // control. So we use two facts we know: which animator will be used and the |
191 // target opacity to add "Do nothing" animation sequence. | 214 // target opacity to add "Do nothing" animation sequence. |
192 // Unfortunately, we can not just use empty LayerAnimationSequence, because | 215 // Unfortunately, we can not just use empty LayerAnimationSequence, because |
193 // it does not call NotifyEnded(). | 216 // it does not call NotifyEnded(). |
194 ui::LayerAnimationSequence* sequence = new ui::LayerAnimationSequence( | 217 if (observer) { |
195 ui::LayerAnimationElement::CreateOpacityElement( | 218 ui::LayerAnimationSequence* sequence = new ui::LayerAnimationSequence( |
196 1.0, base::TimeDelta())); | 219 ui::LayerAnimationElement::CreateOpacityElement( |
197 if (observer) | 220 1.0, base::TimeDelta())); |
198 sequence->AddObserver(observer); | 221 sequence->AddObserver(observer); |
Daniel Erat
2012/11/30 14:33:08
fix indenting
| |
199 window->layer()->GetAnimator()->ScheduleAnimation(sequence); | 222 layer->GetAnimator()->ScheduleAnimation(sequence); |
223 } | |
200 } | 224 } |
201 | 225 |
202 // Starts grayscale/brightness animation for |window| over |duration|. Target | 226 // Starts grayscale/brightness animation for |window| over |duration|. Target |
203 // value for both grayscale and brightness are specified by |target|. | 227 // value for both grayscale and brightness are specified by |target|. |
204 void StartGrayscaleBrightnessAnimationForWindow( | 228 void StartGrayscaleBrightnessAnimationForWindow( |
205 aura::Window* window, | 229 aura::Window* window, |
206 float target, | 230 float target, |
207 base::TimeDelta duration, | 231 base::TimeDelta duration, |
208 ui::LayerAnimationObserver* observer) { | 232 ui::LayerAnimationObserver* observer) { |
209 ui::LayerAnimator* animator = window->layer()->GetAnimator(); | 233 ui::LayerAnimator* animator = window->layer()->GetAnimator(); |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
367 case ANIMATION_SPEED_UNDOABLE: | 391 case ANIMATION_SPEED_UNDOABLE: |
368 return base::TimeDelta::FromMilliseconds(400); | 392 return base::TimeDelta::FromMilliseconds(400); |
369 case ANIMATION_SPEED_REVERT: | 393 case ANIMATION_SPEED_REVERT: |
370 return base::TimeDelta::FromMilliseconds(100); | 394 return base::TimeDelta::FromMilliseconds(100); |
371 case ANIMATION_SPEED_FAST: | 395 case ANIMATION_SPEED_FAST: |
372 return base::TimeDelta::FromMilliseconds(150); | 396 return base::TimeDelta::FromMilliseconds(150); |
373 case ANIMATION_SPEED_SHOW_LOCK_SCREEN: | 397 case ANIMATION_SPEED_SHOW_LOCK_SCREEN: |
374 return base::TimeDelta::FromMilliseconds(200); | 398 return base::TimeDelta::FromMilliseconds(200); |
375 case ANIMATION_SPEED_MOVE_WINDOWS: | 399 case ANIMATION_SPEED_MOVE_WINDOWS: |
376 return base::TimeDelta::FromMilliseconds(400); | 400 return base::TimeDelta::FromMilliseconds(400); |
401 case ANIMATION_SPEED_UNDO_MOVE_WINDOWS: | |
402 return base::TimeDelta::FromMilliseconds(600); | |
377 case ANIMATION_SPEED_SHUTDOWN: | 403 case ANIMATION_SPEED_SHUTDOWN: |
378 return base::TimeDelta::FromMilliseconds(1000); | 404 return base::TimeDelta::FromMilliseconds(1000); |
379 case ANIMATION_SPEED_REVERT_SHUTDOWN: | 405 case ANIMATION_SPEED_REVERT_SHUTDOWN: |
380 return base::TimeDelta::FromMilliseconds(400); | 406 return base::TimeDelta::FromMilliseconds(1500); |
381 } | 407 } |
382 // Satisfy compilers that do not understand that we will return from switch | 408 // Satisfy compilers that do not understand that we will return from switch |
383 // above anyway. | 409 // above anyway. |
384 DCHECK(false) << "Unhandled animation speed " << speed; | 410 DCHECK(false) << "Unhandled animation speed " << speed; |
385 return base::TimeDelta(); | 411 return base::TimeDelta(); |
386 } | 412 } |
387 | 413 |
388 // Fills |containers| with the containers described by |container_mask|. | 414 // Fills |containers| with the containers described by |container_mask|. |
389 void SessionStateAnimator::GetContainers(int container_mask, | 415 void SessionStateAnimator::GetContainers(int container_mask, |
390 aura::Window::Windows* containers) { | 416 aura::Window::Windows* containers) { |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
494 break; | 520 break; |
495 case ANIMATION_HIDE_IMMEDIATELY: | 521 case ANIMATION_HIDE_IMMEDIATELY: |
496 DCHECK_EQ(speed, ANIMATION_SPEED_IMMEDIATE); | 522 DCHECK_EQ(speed, ANIMATION_SPEED_IMMEDIATE); |
497 HideWindowImmediately(window, observer); | 523 HideWindowImmediately(window, observer); |
498 break; | 524 break; |
499 case ANIMATION_RESTORE: | 525 case ANIMATION_RESTORE: |
500 DCHECK_EQ(speed, ANIMATION_SPEED_IMMEDIATE); | 526 DCHECK_EQ(speed, ANIMATION_SPEED_IMMEDIATE); |
501 RestoreWindow(window, observer); | 527 RestoreWindow(window, observer); |
502 break; | 528 break; |
503 case ANIMATION_LIFT: | 529 case ANIMATION_LIFT: |
504 HideWindow(window, duration, WORKSPACE_ANIMATE_UP, observer); | 530 HideWindow(window, duration, true, observer); |
505 break; | 531 break; |
506 case ANIMATION_DROP: | 532 case ANIMATION_DROP: |
507 ShowWindow(window, duration, WORKSPACE_ANIMATE_DOWN, observer); | 533 ShowWindow(window, duration, true, observer); |
508 break; | 534 break; |
509 case ANIMATION_RAISE_TO_SCREEN: | 535 case ANIMATION_RAISE_TO_SCREEN: |
510 ShowWindow(window, duration, WORKSPACE_ANIMATE_UP, observer); | 536 ShowWindow(window, duration, false, observer); |
511 break; | 537 break; |
512 case ANIMATION_LOWER_BELOW_SCREEN: | 538 case ANIMATION_LOWER_BELOW_SCREEN: |
513 HideWindow(window, duration, WORKSPACE_ANIMATE_DOWN, observer); | 539 HideWindow(window, duration, false, observer); |
514 break; | 540 break; |
515 case ANIMATION_PARTIAL_FADE_IN: | 541 case ANIMATION_PARTIAL_FADE_IN: |
516 StartPartialFadeAnimation( | 542 StartPartialFadeAnimation( |
517 window, kPartialFadeRatio, duration, observer); | 543 window, kPartialFadeRatio, duration, observer); |
518 break; | 544 break; |
519 case ANIMATION_UNDO_PARTIAL_FADE_IN: | 545 case ANIMATION_UNDO_PARTIAL_FADE_IN: |
520 StartPartialFadeAnimation(window, 0.0, duration, observer); | 546 StartPartialFadeAnimation(window, 0.0, duration, observer); |
521 break; | 547 break; |
522 case ANIMATION_FULL_FADE_IN: | 548 case ANIMATION_FULL_FADE_IN: |
523 StartPartialFadeAnimation(window, 1.0, duration, observer); | 549 StartPartialFadeAnimation(window, 1.0, duration, observer); |
(...skipping 21 matching lines...) Expand all Loading... | |
545 foreground_->SetColor(SK_ColorWHITE); | 571 foreground_->SetColor(SK_ColorWHITE); |
546 foreground_->GetWidget()->Show(); | 572 foreground_->GetWidget()->Show(); |
547 } | 573 } |
548 | 574 |
549 void SessionStateAnimator::DropForeground() { | 575 void SessionStateAnimator::DropForeground() { |
550 foreground_.reset(); | 576 foreground_.reset(); |
551 } | 577 } |
552 | 578 |
553 } // namespace internal | 579 } // namespace internal |
554 } // namespace ash | 580 } // namespace ash |
OLD | NEW |