Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: ash/wm/session_state_animator.cc

Issue 11220002: Add new animations in second implementation. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Review fixes Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/wm/session_state_animator.h ('k') | ash/wm/session_state_controller_impl2.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 |target_opacity| over |length| milliseconds.
111 void StartPartialFadeAnimation(aura::Window* window,
112 float target_opacity,
113 base::TimeDelta length,
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, length));
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, base::TimeDelta length) {
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 = length;
156 HideWorkspace(window, details);
157 }
158
159 void LowerWindow(aura::Window* window, base::TimeDelta length) {
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 = length;
166 ShowWorkspace(window, details);
167 }
168
169 // Animation observer that will drop animated foreground once animation is
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
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
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,
366 base::TimeDelta::FromMilliseconds(kSlowCloseAnimMs));
367 break;
368 case ANIMATION_LOWER:
369 LowerWindow(window,
370 base::TimeDelta::FromMilliseconds(kSlowCloseAnimMs));
371 break;
372 case ANIMATION_PARTIAL_FADE_IN:
373 StartPartialFadeAnimation(window, kPartialFadeRatio,
374 base::TimeDelta::FromMilliseconds(kSlowCloseAnimMs),
375 NULL);
376 break;
377 case ANIMATION_UNDO_PARTIAL_FADE_IN:
378 StartPartialFadeAnimation(window, 0.0,
379 base::TimeDelta::FromMilliseconds(kUndoSlowCloseAnimMs),
380 new ForegroundDropAnimationObserver(this));
381 break;
382 case ANIMATION_FULL_FADE_IN:
383 StartPartialFadeAnimation(window, 1.0,
384 base::TimeDelta::FromMilliseconds(kFastCloseAnimMs), NULL);
385 break;
282 default: 386 default:
283 NOTREACHED() << "Unhandled animation type " << type; 387 NOTREACHED() << "Unhandled animation type " << type;
284 } 388 }
285 } 389 }
286 } 390 }
287 391
288 void SessionStateAnimator::OnRootWindowResized(const aura::RootWindow* root, 392 void SessionStateAnimator::OnRootWindowResized(const aura::RootWindow* root,
289 const gfx::Size& new_size) { 393 const gfx::Size& new_size) {
290 if (black_layer_.get()) 394 if (black_layer_.get())
291 black_layer_->SetBounds(gfx::Rect(root->bounds().size())); 395 black_layer_->SetBounds(gfx::Rect(root->bounds().size()));
(...skipping 20 matching lines...) Expand all
312 } 416 }
313 417
314 void SessionStateAnimator::ScheduleDropBlackLayer() { 418 void SessionStateAnimator::ScheduleDropBlackLayer() {
315 hide_black_layer_timer_.Stop(); 419 hide_black_layer_timer_.Stop();
316 hide_black_layer_timer_.Start( 420 hide_black_layer_timer_.Start(
317 FROM_HERE, 421 FROM_HERE,
318 base::TimeDelta::FromMilliseconds(kUndoSlowCloseAnimMs), 422 base::TimeDelta::FromMilliseconds(kUndoSlowCloseAnimMs),
319 this, &SessionStateAnimator::DropBlackLayer); 423 this, &SessionStateAnimator::DropBlackLayer);
320 } 424 }
321 425
426 void SessionStateAnimator::CreateForeground() {
427 if (foreground_.get())
428 return;
429 aura::Window* window = Shell::GetContainer(
430 Shell::GetPrimaryRootWindow(),
431 internal::kShellWindowId_PowerButtonAnimationContainer);
432 HideWindow(window);
433 foreground_.reset(
434 new ColoredWindowController(window, "SessionStateAnimatorForeground"));
435 foreground_->SetColor(SK_ColorWHITE);
436 foreground_->GetWidget()->Show();
437 }
438
439 void SessionStateAnimator::DropForeground() {
440 foreground_.reset();
441 }
442
322 } // namespace internal 443 } // namespace internal
323 } // namespace ash 444 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/session_state_animator.h ('k') | ash/wm/session_state_controller_impl2.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698