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

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: Added shutdown animations 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
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"
10 #include "ui/compositor/layer_animation_sequence.h" 12 #include "ui/compositor/layer_animation_sequence.h"
13 #include "ui/compositor/layer_animation_observer.h"
Daniel Erat 2012/10/22 17:45:48 keep this list alphabetized
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 //ToDo (antrim) : comment
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 a |target_opacity| for a |lengthMs| milliseconds.
Daniel Erat 2012/10/22 17:45:48 s/lengthMs/length_ms/
111 void StartPartialFadeAnimation(aura::Window* window, float target_opacity,
Daniel Erat 2012/10/22 17:45:48 one argument per line
112 int length_ms,
Daniel Erat 2012/10/22 17:45:48 use base::TimeDelta instead of int
113 ui::LayerAnimationObserver* observer) {
114 ui::LayerAnimator* animator = window->layer()->GetAnimator();
115 animator->set_preemption_strategy(
116 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
117 ui::LayerAnimationSequence* sequence = new ui::LayerAnimationSequence(
118 ui::LayerAnimationElement::CreateOpacityElement(
119 target_opacity, base::TimeDelta::FromMilliseconds(length_ms)));
120 animator->StartAnimation(sequence);
121 if (observer)
122 sequence->AddObserver(observer);
123 }
124
103 // Fades |window| in to full opacity. 125 // Fades |window| in to full opacity.
104 void FadeInWindow(aura::Window* window) { 126 void FadeInWindow(aura::Window* window) {
105 ui::LayerAnimator* animator = window->layer()->GetAnimator(); 127 ui::LayerAnimator* animator = window->layer()->GetAnimator();
106 animator->set_preemption_strategy( 128 animator->set_preemption_strategy(
107 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 129 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
108 animator->StartAnimation( 130 animator->StartAnimation(
109 new ui::LayerAnimationSequence( 131 new ui::LayerAnimationSequence(
110 ui::LayerAnimationElement::CreateOpacityElement( 132 ui::LayerAnimationElement::CreateOpacityElement(
111 1.0, base::TimeDelta::FromMilliseconds(kLockFadeInAnimMs)))); 133 1.0, base::TimeDelta::FromMilliseconds(kLockFadeInAnimMs))));
112 } 134 }
113 135
114 // Makes |window| fully transparent instantaneously. 136 // Makes |window| fully transparent instantaneously.
115 void HideWindow(aura::Window* window) { 137 void HideWindow(aura::Window* window) {
116 window->layer()->SetOpacity(0.0); 138 window->layer()->SetOpacity(0.0);
117 } 139 }
118 140
119 // Restores |window| to its original position and scale and full opacity 141 // Restores |window| to its original position and scale and full opacity
120 // instantaneously. 142 // instantaneously.
121 void RestoreWindow(aura::Window* window) { 143 void RestoreWindow(aura::Window* window) {
122 window->layer()->SetTransform(gfx::Transform()); 144 window->layer()->SetTransform(gfx::Transform());
123 window->layer()->SetOpacity(1.0); 145 window->layer()->SetOpacity(1.0);
124 } 146 }
125 147
148 void LiftUpWindow(aura::Window* window, int length_ms) {
Daniel Erat 2012/10/22 17:45:48 pass in base::TimeDelta here instead of int
149 WorkspaceAnimationDetails details;
150 details.direction = WORKSPACE_ANIMATE_UP;
151 details.animate = true;
152 details.animate_scale = true;
153 details.animate_opacity = true;
154 details.duration = base::TimeDelta::FromMilliseconds(length_ms);
155 HideWorkspace(window, details);
156 }
157
158 void PutDownWindow(aura::Window* window, int length_ms) {
Daniel Erat 2012/10/22 17:45:48 ditto
159 WorkspaceAnimationDetails details;
160 details.direction = WORKSPACE_ANIMATE_DOWN;
161 details.animate = true;
162 details.animate_scale = true;
163 details.animate_opacity = true;
164 details.duration = base::TimeDelta::FromMilliseconds(length_ms);
165 ShowWorkspace(window, details);
166 }
167
168 //ToDo(antrim) : comment.
169 class ForegroundDropAnimationObserver : public ui::LayerAnimationObserver {
170 public:
171 explicit ForegroundDropAnimationObserver(SessionStateAnimator* animator)
172 : animator_(animator) {
173 }
174 virtual ~ForegroundDropAnimationObserver() {
175 }
176
177 private:
178 // Overridden from ui::LayerAnimationObserver:
179 virtual void OnLayerAnimationEnded(ui::LayerAnimationSequence* seq)
180 OVERRIDE {
181 //Drop foreground once animation is over.
Daniel Erat 2012/10/22 17:45:48 add space between "//" and "Drop"
182 animator_->DropForeground();
183 delete this;
184 }
185
186 virtual void OnLayerAnimationAborted(ui::LayerAnimationSequence* seq)
187 OVERRIDE {
188 //Drop foreground once animation is over.
Daniel Erat 2012/10/22 17:45:48 same here
189 animator_->DropForeground();
190 delete this;
191 }
192
193 virtual void OnLayerAnimationScheduled(ui::LayerAnimationSequence* seq)
194 OVERRIDE {}
195
196 SessionStateAnimator* animator_;
197
198 DISALLOW_COPY_AND_ASSIGN(ForegroundDropAnimationObserver);
199 };
200
126 } // namespace 201 } // namespace
127 202
128 void SessionStateAnimator::TestApi::TriggerHideBlackLayerTimeout() { 203 void SessionStateAnimator::TestApi::TriggerHideBlackLayerTimeout() {
129 animator_->DropBlackLayer(); 204 animator_->DropBlackLayer();
130 animator_->hide_black_layer_timer_.Stop(); 205 animator_->hide_black_layer_timer_.Stop();
131 } 206 }
132 207
133 bool SessionStateAnimator::TestApi::ContainersAreAnimated( 208 bool SessionStateAnimator::TestApi::ContainersAreAnimated(
134 int container_mask, AnimationType type) const { 209 int container_mask, AnimationType type) const {
135 aura::Window::Windows containers; 210 aura::Window::Windows containers;
136 animator_->GetContainers(container_mask, &containers); 211 animator_->GetContainers(container_mask, &containers);
137 for (aura::Window::Windows::const_iterator it = containers.begin(); 212 for (aura::Window::Windows::const_iterator it = containers.begin();
138 it != containers.end(); ++it) { 213 it != containers.end(); ++it) {
139 aura::Window* window = *it; 214 aura::Window* window = *it;
140 ui::Layer* layer = window->layer(); 215 ui::Layer* layer = window->layer();
141 216
142 switch (type) { 217 switch (type) {
143 case ANIMATION_SLOW_CLOSE: 218 case ANIMATION_PARTIAL_CLOSE:
144 if (layer->GetTargetTransform() != GetSlowCloseTransform()) 219 if (layer->GetTargetTransform() != GetSlowCloseTransform())
145 return false; 220 return false;
146 break; 221 break;
147 case ANIMATION_UNDO_SLOW_CLOSE: 222 case ANIMATION_UNDO_PARTIAL_CLOSE:
148 if (layer->GetTargetTransform() != gfx::Transform()) 223 if (layer->GetTargetTransform() != gfx::Transform())
149 return false; 224 return false;
150 break; 225 break;
151 case ANIMATION_FAST_CLOSE: 226 case ANIMATION_FULL_CLOSE:
152 if (layer->GetTargetTransform() != GetFastCloseTransform() || 227 if (layer->GetTargetTransform() != GetFastCloseTransform() ||
153 layer->GetTargetOpacity() > 0.0001) 228 layer->GetTargetOpacity() > 0.0001)
154 return false; 229 return false;
155 break; 230 break;
156 case ANIMATION_FADE_IN: 231 case ANIMATION_FADE_IN:
157 if (layer->GetTargetOpacity() < 0.9999) 232 if (layer->GetTargetOpacity() < 0.9999)
158 return false; 233 return false;
159 break; 234 break;
160 case ANIMATION_HIDE: 235 case ANIMATION_HIDE:
161 if (layer->GetTargetOpacity() > 0.0001) 236 if (layer->GetTargetOpacity() > 0.0001)
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 if (container_mask & LOCK_SCREEN_CONTAINERS) { 317 if (container_mask & LOCK_SCREEN_CONTAINERS) {
243 containers->push_back(Shell::GetContainer( 318 containers->push_back(Shell::GetContainer(
244 root_window, 319 root_window,
245 internal::kShellWindowId_LockScreenContainersContainer)); 320 internal::kShellWindowId_LockScreenContainersContainer));
246 } 321 }
247 if (container_mask & LOCK_SCREEN_RELATED_CONTAINERS) { 322 if (container_mask & LOCK_SCREEN_RELATED_CONTAINERS) {
248 containers->push_back(Shell::GetContainer( 323 containers->push_back(Shell::GetContainer(
249 root_window, 324 root_window,
250 internal::kShellWindowId_LockScreenRelatedContainersContainer)); 325 internal::kShellWindowId_LockScreenRelatedContainersContainer));
251 } 326 }
327 if (container_mask & LOCK_SCREEN_SYSTEM_FOREGROUND) {
328 containers->push_back(Shell::GetContainer(
329 root_window,
330 internal::kShellWindowId_TopmostContainer));
331 }
252 } 332 }
253 333
254 // Apply animation |type| to all containers described by |container_mask|. 334 // Apply animation |type| to all containers described by |container_mask|.
255 void SessionStateAnimator::StartAnimation(int container_mask, 335 void SessionStateAnimator::StartAnimation(int container_mask,
256 AnimationType type) { 336 AnimationType type) {
257 aura::Window::Windows containers; 337 aura::Window::Windows containers;
258 GetContainers(container_mask, &containers); 338 GetContainers(container_mask, &containers);
259 339
260 for (aura::Window::Windows::const_iterator it = containers.begin(); 340 for (aura::Window::Windows::const_iterator it = containers.begin();
261 it != containers.end(); ++it) { 341 it != containers.end(); ++it) {
262 aura::Window* window = *it; 342 aura::Window* window = *it;
263 switch (type) { 343 switch (type) {
264 case ANIMATION_SLOW_CLOSE: 344 case ANIMATION_PARTIAL_CLOSE:
265 StartSlowCloseAnimationForWindow(window); 345 StartSlowCloseAnimationForWindow(window);
266 break; 346 break;
267 case ANIMATION_UNDO_SLOW_CLOSE: 347 case ANIMATION_UNDO_PARTIAL_CLOSE:
268 StartUndoSlowCloseAnimationForWindow(window); 348 StartUndoSlowCloseAnimationForWindow(window);
269 break; 349 break;
270 case ANIMATION_FAST_CLOSE: 350 case ANIMATION_FULL_CLOSE:
271 StartFastCloseAnimationForWindow(window); 351 StartFastCloseAnimationForWindow(window);
272 break; 352 break;
273 case ANIMATION_FADE_IN: 353 case ANIMATION_FADE_IN:
274 FadeInWindow(window); 354 FadeInWindow(window);
275 break; 355 break;
276 case ANIMATION_HIDE: 356 case ANIMATION_HIDE:
277 HideWindow(window); 357 HideWindow(window);
278 break; 358 break;
279 case ANIMATION_RESTORE: 359 case ANIMATION_RESTORE:
280 RestoreWindow(window); 360 RestoreWindow(window);
281 break; 361 break;
362 case ANIMATION_LIFT_UP:
363 LiftUpWindow(window, kSlowCloseAnimMs);
364 break;
365 case ANIMATION_PUT_DOWN:
366 PutDownWindow(window, kSlowCloseAnimMs);
367 break;
368 case ANIMATION_PARTIAL_FADE_IN:
369 StartPartialFadeAnimation(window, kPartialFadeRatio, kSlowCloseAnimMs,
370 NULL);
371 break;
372 case ANIMATION_UNDO_PARTIAL_FADE_IN:
373 StartPartialFadeAnimation(window, 0.0, kUndoSlowCloseAnimMs,
374 new ForegroundDropAnimationObserver(this));
375 break;
376 case ANIMATION_FULL_FADE_IN:
377 StartPartialFadeAnimation(window, 1.0, kFastCloseAnimMs, NULL);
378 break;
282 default: 379 default:
283 NOTREACHED() << "Unhandled animation type " << type; 380 NOTREACHED() << "Unhandled animation type " << type;
284 } 381 }
285 } 382 }
286 } 383 }
287 384
288 void SessionStateAnimator::OnRootWindowResized(const aura::RootWindow* root, 385 void SessionStateAnimator::OnRootWindowResized(const aura::RootWindow* root,
289 const gfx::Size& new_size) { 386 const gfx::Size& new_size) {
290 if (black_layer_.get()) 387 if (black_layer_.get())
291 black_layer_->SetBounds(gfx::Rect(root->bounds().size())); 388 black_layer_->SetBounds(gfx::Rect(root->bounds().size()));
(...skipping 20 matching lines...) Expand all
312 } 409 }
313 410
314 void SessionStateAnimator::ScheduleDropBlackLayer() { 411 void SessionStateAnimator::ScheduleDropBlackLayer() {
315 hide_black_layer_timer_.Stop(); 412 hide_black_layer_timer_.Stop();
316 hide_black_layer_timer_.Start( 413 hide_black_layer_timer_.Start(
317 FROM_HERE, 414 FROM_HERE,
318 base::TimeDelta::FromMilliseconds(kUndoSlowCloseAnimMs), 415 base::TimeDelta::FromMilliseconds(kUndoSlowCloseAnimMs),
319 this, &SessionStateAnimator::DropBlackLayer); 416 this, &SessionStateAnimator::DropBlackLayer);
320 } 417 }
321 418
419 void SessionStateAnimator::CreateForeground() {
420 LOG(ERROR) << "SessionStateAnimator::CreateForeground()";
Daniel Erat 2012/10/22 17:45:48 delete this
421 if (!foreground_.get()) {
Daniel Erat 2012/10/22 17:45:48 nit: little bit cleaner to just do: if (foregro
422 aura::Window* window = Shell::GetContainer(
423 Shell::GetPrimaryRootWindow(),
424 internal::kShellWindowId_TopmostContainer);
425 HideWindow(window);
426 foreground_.reset(new ColoredWindowController(window, "WhiteForeground"));
Daniel Erat 2012/10/22 17:45:48 "SessionStateAnimatorForeground"?
427 foreground_->SetColor(SK_ColorWHITE);
428 foreground_->GetWidget()->Show();
429 }
430 }
431
432 void SessionStateAnimator::DropForeground() {
433 foreground_.reset();
434 }
435
322 } // namespace internal 436 } // namespace internal
323 } // namespace ash 437 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698