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/workspace/workspace_animations.h" | |
10 #include "ui/aura/client/aura_constants.h" | |
9 #include "ui/aura/root_window.h" | 11 #include "ui/aura/root_window.h" |
12 #include "ui/compositor/layer_animation_observer.h" | |
10 #include "ui/compositor/layer_animation_sequence.h" | 13 #include "ui/compositor/layer_animation_sequence.h" |
14 #include "ui/views/widget/widget.h" | |
11 | 15 |
12 namespace ash { | 16 namespace ash { |
13 namespace internal { | 17 namespace internal { |
14 | 18 |
15 namespace { | 19 namespace { |
16 | 20 |
17 // Amount of time taken to scale the snapshot of the screen down to a | 21 // Amount of time taken to scale the snapshot of the screen down to a |
18 // slightly-smaller size once the user starts holding the power button. Used | 22 // slightly-smaller size once the user starts holding the power button. Used |
19 // for both the pre-lock and pre-shutdown animations. | 23 // for both the pre-lock and pre-shutdown animations. |
20 const int kSlowCloseAnimMs = 400; | 24 const int kSlowCloseAnimMs = 400; |
21 | 25 |
22 // Amount of time taken to scale the snapshot of the screen back to its original | 26 // Amount of time taken to scale the snapshot of the screen back to its original |
23 // size when the button is released. | 27 // size when the button is released. |
24 const int kUndoSlowCloseAnimMs = 100; | 28 const int kUndoSlowCloseAnimMs = 100; |
25 | 29 |
26 // Amount of time taken to scale the snapshot down to a point in the center of | 30 // Amount of time taken to scale the snapshot down to a point in the center of |
27 // the screen once the screen has been locked or we've been notified that the | 31 // the screen once the screen has been locked or we've been notified that the |
28 // system is shutting down. | 32 // system is shutting down. |
29 const int kFastCloseAnimMs = 150; | 33 const int kFastCloseAnimMs = 150; |
30 | 34 |
31 // Amount of time taken to make the lock window fade in when the screen is | 35 // Amount of time taken to make the lock window fade in when the screen is |
32 // locked. | 36 // locked. |
33 const int kLockFadeInAnimMs = 200; | 37 const int kLockFadeInAnimMs = 200; |
34 | 38 |
35 // Slightly-smaller size that we scale the screen down to for the pre-lock and | 39 // Slightly-smaller size that we scale the screen down to for the pre-lock and |
36 // pre-shutdown states. | 40 // pre-shutdown states. |
37 const float kSlowCloseSizeRatio = 0.95f; | 41 const float kSlowCloseSizeRatio = 0.95f; |
38 | 42 |
43 // Maximum opacity of white layer when animating pre-shutdown state. | |
44 const float kPartialFadeRatio = 0.3f; | |
45 | |
39 // Returns the transform that should be applied to containers for the slow-close | 46 // Returns the transform that should be applied to containers for the slow-close |
40 // animation. | 47 // animation. |
41 gfx::Transform GetSlowCloseTransform() { | 48 gfx::Transform GetSlowCloseTransform() { |
42 gfx::Size root_size = Shell::GetPrimaryRootWindow()->bounds().size(); | 49 gfx::Size root_size = Shell::GetPrimaryRootWindow()->bounds().size(); |
43 gfx::Transform transform; | 50 gfx::Transform transform; |
44 transform.SetScale(kSlowCloseSizeRatio, kSlowCloseSizeRatio); | 51 transform.SetScale(kSlowCloseSizeRatio, kSlowCloseSizeRatio); |
45 transform.ConcatTranslate( | 52 transform.ConcatTranslate( |
46 floor(0.5 * (1.0 - kSlowCloseSizeRatio) * root_size.width() + 0.5), | 53 floor(0.5 * (1.0 - kSlowCloseSizeRatio) * root_size.width() + 0.5), |
47 floor(0.5 * (1.0 - kSlowCloseSizeRatio) * root_size.height() + 0.5)); | 54 floor(0.5 * (1.0 - kSlowCloseSizeRatio) * root_size.height() + 0.5)); |
48 return transform; | 55 return transform; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 new ui::LayerAnimationSequence( | 100 new ui::LayerAnimationSequence( |
94 ui::LayerAnimationElement::CreateTransformElement( | 101 ui::LayerAnimationElement::CreateTransformElement( |
95 GetFastCloseTransform(), | 102 GetFastCloseTransform(), |
96 base::TimeDelta::FromMilliseconds(kFastCloseAnimMs)))); | 103 base::TimeDelta::FromMilliseconds(kFastCloseAnimMs)))); |
97 animator->StartAnimation( | 104 animator->StartAnimation( |
98 new ui::LayerAnimationSequence( | 105 new ui::LayerAnimationSequence( |
99 ui::LayerAnimationElement::CreateOpacityElement( | 106 ui::LayerAnimationElement::CreateOpacityElement( |
100 0.0, base::TimeDelta::FromMilliseconds(kFastCloseAnimMs)))); | 107 0.0, base::TimeDelta::FromMilliseconds(kFastCloseAnimMs)))); |
101 } | 108 } |
102 | 109 |
110 // Fades |window| to a |target_opacity| for a |lengthMs| milliseconds. | |
Daniel Erat
2012/10/23 16:02:11
nit: s/to a/to/, s/for a/over/, s/lengthMs/length_
| |
111 void StartPartialFadeAnimation(aura::Window* window, | |
112 float target_opacity, | |
113 int length_ms, | |
Daniel Erat
2012/10/23 16:02:11
use base::TimeDelta instead
Denis Kuznetsov (DE-MUC)
2012/10/23 16:07:30
What is the reason for that?
It will require base:
Daniel Erat
2012/10/23 16:13:03
It makes the units obvious to anyone who's reading
| |
114 ui::LayerAnimationObserver* observer) { | |
115 ui::LayerAnimator* animator = window->layer()->GetAnimator(); | |
116 animator->set_preemption_strategy( | |
117 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
118 ui::LayerAnimationSequence* sequence = new ui::LayerAnimationSequence( | |
119 ui::LayerAnimationElement::CreateOpacityElement( | |
120 target_opacity, base::TimeDelta::FromMilliseconds(length_ms))); | |
121 animator->StartAnimation(sequence); | |
122 if (observer) | |
123 sequence->AddObserver(observer); | |
124 } | |
125 | |
103 // Fades |window| in to full opacity. | 126 // Fades |window| in to full opacity. |
104 void FadeInWindow(aura::Window* window) { | 127 void FadeInWindow(aura::Window* window) { |
105 ui::LayerAnimator* animator = window->layer()->GetAnimator(); | 128 ui::LayerAnimator* animator = window->layer()->GetAnimator(); |
106 animator->set_preemption_strategy( | 129 animator->set_preemption_strategy( |
107 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 130 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
108 animator->StartAnimation( | 131 animator->StartAnimation( |
109 new ui::LayerAnimationSequence( | 132 new ui::LayerAnimationSequence( |
110 ui::LayerAnimationElement::CreateOpacityElement( | 133 ui::LayerAnimationElement::CreateOpacityElement( |
111 1.0, base::TimeDelta::FromMilliseconds(kLockFadeInAnimMs)))); | 134 1.0, base::TimeDelta::FromMilliseconds(kLockFadeInAnimMs)))); |
112 } | 135 } |
113 | 136 |
114 // Makes |window| fully transparent instantaneously. | 137 // Makes |window| fully transparent instantaneously. |
115 void HideWindow(aura::Window* window) { | 138 void HideWindow(aura::Window* window) { |
116 window->layer()->SetOpacity(0.0); | 139 window->layer()->SetOpacity(0.0); |
117 } | 140 } |
118 | 141 |
119 // Restores |window| to its original position and scale and full opacity | 142 // Restores |window| to its original position and scale and full opacity |
120 // instantaneously. | 143 // instantaneously. |
121 void RestoreWindow(aura::Window* window) { | 144 void RestoreWindow(aura::Window* window) { |
122 window->layer()->SetTransform(gfx::Transform()); | 145 window->layer()->SetTransform(gfx::Transform()); |
123 window->layer()->SetOpacity(1.0); | 146 window->layer()->SetOpacity(1.0); |
124 } | 147 } |
125 | 148 |
149 void RaiseWindow(aura::Window* window, int length_ms) { | |
Daniel Erat
2012/10/23 16:02:11
base::TimeDelta
| |
150 WorkspaceAnimationDetails details; | |
151 details.direction = WORKSPACE_ANIMATE_UP; | |
152 details.animate = true; | |
153 details.animate_scale = true; | |
154 details.animate_opacity = true; | |
155 details.duration = base::TimeDelta::FromMilliseconds(length_ms); | |
156 HideWorkspace(window, details); | |
157 } | |
158 | |
159 void LowerWindow(aura::Window* window, int length_ms) { | |
Daniel Erat
2012/10/23 16:02:11
base::TimeDelta
| |
160 WorkspaceAnimationDetails details; | |
161 details.direction = WORKSPACE_ANIMATE_DOWN; | |
162 details.animate = true; | |
163 details.animate_scale = true; | |
164 details.animate_opacity = true; | |
165 details.duration = base::TimeDelta::FromMilliseconds(length_ms); | |
166 ShowWorkspace(window, details); | |
167 } | |
168 | |
169 // Animation observer that would drop animated Foreground once animation is | |
Daniel Erat
2012/10/23 16:02:11
nit: s/would/will/, s/Foreground/foreground/
| |
170 // finished. It is used in when undoing shutdown animation. | |
171 class ForegroundDropAnimationObserver : public ui::LayerAnimationObserver { | |
172 public: | |
173 explicit ForegroundDropAnimationObserver(SessionStateAnimator* animator) | |
174 : animator_(animator) { | |
175 } | |
176 virtual ~ForegroundDropAnimationObserver() { | |
177 } | |
178 | |
179 private: | |
180 // Overridden from ui::LayerAnimationObserver: | |
181 virtual void OnLayerAnimationEnded(ui::LayerAnimationSequence* seq) | |
182 OVERRIDE { | |
183 // Drop foreground once animation is over. | |
184 animator_->DropForeground(); | |
185 delete this; | |
186 } | |
187 | |
188 virtual void OnLayerAnimationAborted(ui::LayerAnimationSequence* seq) | |
189 OVERRIDE { | |
190 // Drop foreground once animation is over. | |
191 animator_->DropForeground(); | |
192 delete this; | |
193 } | |
194 | |
195 virtual void OnLayerAnimationScheduled(ui::LayerAnimationSequence* seq) | |
196 OVERRIDE {} | |
197 | |
198 SessionStateAnimator* animator_; | |
199 | |
200 DISALLOW_COPY_AND_ASSIGN(ForegroundDropAnimationObserver); | |
201 }; | |
202 | |
126 } // namespace | 203 } // namespace |
127 | 204 |
128 void SessionStateAnimator::TestApi::TriggerHideBlackLayerTimeout() { | 205 void SessionStateAnimator::TestApi::TriggerHideBlackLayerTimeout() { |
129 animator_->DropBlackLayer(); | 206 animator_->DropBlackLayer(); |
130 animator_->hide_black_layer_timer_.Stop(); | 207 animator_->hide_black_layer_timer_.Stop(); |
131 } | 208 } |
132 | 209 |
133 bool SessionStateAnimator::TestApi::ContainersAreAnimated( | 210 bool SessionStateAnimator::TestApi::ContainersAreAnimated( |
134 int container_mask, AnimationType type) const { | 211 int container_mask, AnimationType type) const { |
135 aura::Window::Windows containers; | 212 aura::Window::Windows containers; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
242 if (container_mask & LOCK_SCREEN_CONTAINERS) { | 319 if (container_mask & LOCK_SCREEN_CONTAINERS) { |
243 containers->push_back(Shell::GetContainer( | 320 containers->push_back(Shell::GetContainer( |
244 root_window, | 321 root_window, |
245 internal::kShellWindowId_LockScreenContainersContainer)); | 322 internal::kShellWindowId_LockScreenContainersContainer)); |
246 } | 323 } |
247 if (container_mask & LOCK_SCREEN_RELATED_CONTAINERS) { | 324 if (container_mask & LOCK_SCREEN_RELATED_CONTAINERS) { |
248 containers->push_back(Shell::GetContainer( | 325 containers->push_back(Shell::GetContainer( |
249 root_window, | 326 root_window, |
250 internal::kShellWindowId_LockScreenRelatedContainersContainer)); | 327 internal::kShellWindowId_LockScreenRelatedContainersContainer)); |
251 } | 328 } |
329 if (container_mask & LOCK_SCREEN_SYSTEM_FOREGROUND) { | |
330 containers->push_back(Shell::GetContainer( | |
331 root_window, | |
332 internal::kShellWindowId_PowerButtonAnimationContainer)); | |
333 } | |
252 } | 334 } |
253 | 335 |
254 // Apply animation |type| to all containers described by |container_mask|. | 336 // Apply animation |type| to all containers described by |container_mask|. |
255 void SessionStateAnimator::StartAnimation(int container_mask, | 337 void SessionStateAnimator::StartAnimation(int container_mask, |
256 AnimationType type) { | 338 AnimationType type) { |
257 aura::Window::Windows containers; | 339 aura::Window::Windows containers; |
258 GetContainers(container_mask, &containers); | 340 GetContainers(container_mask, &containers); |
259 | 341 |
260 for (aura::Window::Windows::const_iterator it = containers.begin(); | 342 for (aura::Window::Windows::const_iterator it = containers.begin(); |
261 it != containers.end(); ++it) { | 343 it != containers.end(); ++it) { |
(...skipping 10 matching lines...) Expand all Loading... | |
272 break; | 354 break; |
273 case ANIMATION_FADE_IN: | 355 case ANIMATION_FADE_IN: |
274 FadeInWindow(window); | 356 FadeInWindow(window); |
275 break; | 357 break; |
276 case ANIMATION_HIDE: | 358 case ANIMATION_HIDE: |
277 HideWindow(window); | 359 HideWindow(window); |
278 break; | 360 break; |
279 case ANIMATION_RESTORE: | 361 case ANIMATION_RESTORE: |
280 RestoreWindow(window); | 362 RestoreWindow(window); |
281 break; | 363 break; |
364 case ANIMATION_RAISE: | |
365 RaiseWindow(window, kSlowCloseAnimMs); | |
366 break; | |
367 case ANIMATION_LOWER: | |
368 LowerWindow(window, kSlowCloseAnimMs); | |
369 break; | |
370 case ANIMATION_PARTIAL_FADE_IN: | |
371 StartPartialFadeAnimation(window, kPartialFadeRatio, kSlowCloseAnimMs, | |
372 NULL); | |
373 break; | |
374 case ANIMATION_UNDO_PARTIAL_FADE_IN: | |
375 StartPartialFadeAnimation(window, 0.0, kUndoSlowCloseAnimMs, | |
376 new ForegroundDropAnimationObserver(this)); | |
377 break; | |
378 case ANIMATION_FULL_FADE_IN: | |
379 StartPartialFadeAnimation(window, 1.0, kFastCloseAnimMs, NULL); | |
380 break; | |
282 default: | 381 default: |
283 NOTREACHED() << "Unhandled animation type " << type; | 382 NOTREACHED() << "Unhandled animation type " << type; |
284 } | 383 } |
285 } | 384 } |
286 } | 385 } |
287 | 386 |
288 void SessionStateAnimator::OnRootWindowResized(const aura::RootWindow* root, | 387 void SessionStateAnimator::OnRootWindowResized(const aura::RootWindow* root, |
289 const gfx::Size& new_size) { | 388 const gfx::Size& new_size) { |
290 if (black_layer_.get()) | 389 if (black_layer_.get()) |
291 black_layer_->SetBounds(gfx::Rect(root->bounds().size())); | 390 black_layer_->SetBounds(gfx::Rect(root->bounds().size())); |
(...skipping 20 matching lines...) Expand all Loading... | |
312 } | 411 } |
313 | 412 |
314 void SessionStateAnimator::ScheduleDropBlackLayer() { | 413 void SessionStateAnimator::ScheduleDropBlackLayer() { |
315 hide_black_layer_timer_.Stop(); | 414 hide_black_layer_timer_.Stop(); |
316 hide_black_layer_timer_.Start( | 415 hide_black_layer_timer_.Start( |
317 FROM_HERE, | 416 FROM_HERE, |
318 base::TimeDelta::FromMilliseconds(kUndoSlowCloseAnimMs), | 417 base::TimeDelta::FromMilliseconds(kUndoSlowCloseAnimMs), |
319 this, &SessionStateAnimator::DropBlackLayer); | 418 this, &SessionStateAnimator::DropBlackLayer); |
320 } | 419 } |
321 | 420 |
421 void SessionStateAnimator::CreateForeground() { | |
422 if (foreground_.get()) | |
423 return; | |
424 aura::Window* window = Shell::GetContainer( | |
425 Shell::GetPrimaryRootWindow(), | |
426 internal::kShellWindowId_PowerButtonAnimationContainer); | |
427 HideWindow(window); | |
428 foreground_.reset( | |
429 new ColoredWindowController(window, "SessionStateAnimatorForeground")); | |
430 foreground_->SetColor(SK_ColorWHITE); | |
431 foreground_->GetWidget()->Show(); | |
432 } | |
433 | |
434 void SessionStateAnimator::DropForeground() { | |
435 foreground_.reset(); | |
436 } | |
437 | |
322 } // namespace internal | 438 } // namespace internal |
323 } // namespace ash | 439 } // namespace ash |
OLD | NEW |