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

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

Issue 11453012: Fix black background when locking with fullscreen window: (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Mock TimeTicks::Now() Created 8 years 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/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
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)
142 observer->OnLayerAnimationEnded(NULL); 143 observer->OnLayerAnimationEnded(NULL);
143 } 144 }
144 145
145 // Restores |window| to its original position and scale and full opacity 146 // Restores |window| to its original position and scale and full opacity
146 // instantaneously. 147 // instantaneously.
147 void RestoreWindow(aura::Window* window, ui::LayerAnimationObserver* observer) { 148 void RestoreWindow(aura::Window* window, ui::LayerAnimationObserver* observer) {
148 window->layer()->SetTransform(gfx::Transform()); 149 window->layer()->SetTransform(gfx::Transform());
149 window->layer()->SetOpacity(1.0); 150 window->layer()->SetOpacity(1.0);
150 if (observer) 151 if (observer)
151 observer->OnLayerAnimationEnded(NULL); 152 observer->OnLayerAnimationEnded(NULL);
152 } 153 }
153 154
154 void HideWindow(aura::Window* window, 155 void HideWindow(aura::Window* window,
155 base::TimeDelta duration, 156 base::TimeDelta duration,
156 bool above, 157 bool above,
157 ui::LayerAnimationObserver* observer) { 158 ui::LayerAnimationObserver* observer) {
158 ui::Layer* layer = window->layer(); 159 ui::Layer* layer = window->layer();
159 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator()); 160 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator());
160 161
162 settings.SetPreemptionStrategy(
163 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
161 settings.SetTransitionDuration(duration); 164 settings.SetTransitionDuration(duration);
162 165
163 settings.SetTweenType(ui::Tween::EASE_OUT); 166 settings.SetTweenType(ui::Tween::EASE_OUT);
164 SetTransformForScaleAnimation(layer, 167 SetTransformForScaleAnimation(layer,
165 above ? LAYER_SCALE_ANIMATION_ABOVE : LAYER_SCALE_ANIMATION_BELOW); 168 above ? LAYER_SCALE_ANIMATION_ABOVE : LAYER_SCALE_ANIMATION_BELOW);
166 169
167 settings.SetTweenType(ui::Tween::EASE_IN_OUT); 170 settings.SetTweenType(ui::Tween::EASE_IN_OUT);
168 layer->SetOpacity(0.0f); 171 layer->SetOpacity(0.0f);
169 172
170 // After the animation completes snap the transform back to the identity, 173 // After the animation completes snap the transform back to the identity,
(...skipping 10 matching lines...) Expand all
181 // it does not call NotifyEnded(). 184 // it does not call NotifyEnded().
182 if (observer) { 185 if (observer) {
183 ui::LayerAnimationSequence* sequence = new ui::LayerAnimationSequence( 186 ui::LayerAnimationSequence* sequence = new ui::LayerAnimationSequence(
184 ui::LayerAnimationElement::CreateOpacityElement( 187 ui::LayerAnimationElement::CreateOpacityElement(
185 0.0, base::TimeDelta())); 188 0.0, base::TimeDelta()));
186 sequence->AddObserver(observer); 189 sequence->AddObserver(observer);
187 layer->GetAnimator()->ScheduleAnimation(sequence); 190 layer->GetAnimator()->ScheduleAnimation(sequence);
188 } 191 }
189 } 192 }
190 193
191 void ShowWindow(aura::Window* window, 194 void TransformWindowToBaseState(aura::Window* window,
192 base::TimeDelta duration, 195 base::TimeDelta duration,
193 bool above, 196 ui::LayerAnimationObserver* observer) {
194 ui::LayerAnimationObserver* observer) {
195 ui::Layer* layer = window->layer(); 197 ui::Layer* layer = window->layer();
196 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator()); 198 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator());
197 199
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. 200 // Animate to target values.
201 settings.SetPreemptionStrategy(
202 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
204 settings.SetTransitionDuration(duration); 203 settings.SetTransitionDuration(duration);
205 204
206 settings.SetTweenType(ui::Tween::EASE_OUT); 205 settings.SetTweenType(ui::Tween::EASE_OUT);
207 layer->SetTransform(gfx::Transform()); 206 layer->SetTransform(gfx::Transform());
208 207
209 settings.SetTweenType(ui::Tween::EASE_IN_OUT); 208 settings.SetTweenType(ui::Tween::EASE_IN_OUT);
210 layer->SetOpacity(1.0f); 209 layer->SetOpacity(1.0f);
211 210
212 // A bit of a dirty trick: we need to catch the end of the animation we don't 211 // 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 212 // control. So we use two facts we know: which animator will be used and the
214 // target opacity to add "Do nothing" animation sequence. 213 // target opacity to add "Do nothing" animation sequence.
215 // Unfortunately, we can not just use empty LayerAnimationSequence, because 214 // Unfortunately, we can not just use empty LayerAnimationSequence, because
216 // it does not call NotifyEnded(). 215 // it does not call NotifyEnded().
217 if (observer) { 216 if (observer) {
218 ui::LayerAnimationSequence* sequence = new ui::LayerAnimationSequence( 217 ui::LayerAnimationSequence* sequence = new ui::LayerAnimationSequence(
219 ui::LayerAnimationElement::CreateOpacityElement( 218 ui::LayerAnimationElement::CreateOpacityElement(
220 1.0, base::TimeDelta())); 219 1.0, base::TimeDelta()));
221 sequence->AddObserver(observer); 220 sequence->AddObserver(observer);
222 layer->GetAnimator()->ScheduleAnimation(sequence); 221 layer->GetAnimator()->ScheduleAnimation(sequence);
223 } 222 }
224 } 223 }
225 224
225 void ShowWindow(aura::Window* window,
226 base::TimeDelta duration,
227 bool above,
228 ui::LayerAnimationObserver* observer) {
229 ui::Layer* layer = window->layer();
230 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator());
231
232 // Set initial state of animation
233 settings.SetPreemptionStrategy(
234 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
235 settings.SetTransitionDuration(base::TimeDelta());
236 SetTransformForScaleAnimation(layer,
237 above ? LAYER_SCALE_ANIMATION_ABOVE : LAYER_SCALE_ANIMATION_BELOW);
238
239 TransformWindowToBaseState(window, duration, observer);
240 }
241
226 // Starts grayscale/brightness animation for |window| over |duration|. Target 242 // Starts grayscale/brightness animation for |window| over |duration|. Target
227 // value for both grayscale and brightness are specified by |target|. 243 // value for both grayscale and brightness are specified by |target|.
228 void StartGrayscaleBrightnessAnimationForWindow( 244 void StartGrayscaleBrightnessAnimationForWindow(
229 aura::Window* window, 245 aura::Window* window,
230 float target, 246 float target,
231 base::TimeDelta duration, 247 base::TimeDelta duration,
232 ui::LayerAnimationObserver* observer) { 248 ui::LayerAnimationObserver* observer) {
233 ui::LayerAnimator* animator = window->layer()->GetAnimator(); 249 ui::LayerAnimator* animator = window->layer()->GetAnimator();
234 250
235 std::vector<ui::LayerAnimationSequence*> animations = 251 std::vector<ui::LayerAnimationSequence*> animations =
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 break; 308 break;
293 case SessionStateAnimator::ANIMATION_FULL_CLOSE: 309 case SessionStateAnimator::ANIMATION_FULL_CLOSE:
294 if (layer->GetTargetTransform() != GetFastCloseTransform() || 310 if (layer->GetTargetTransform() != GetFastCloseTransform() ||
295 layer->GetTargetOpacity() > 0.0001) 311 layer->GetTargetOpacity() > 0.0001)
296 return false; 312 return false;
297 break; 313 break;
298 case SessionStateAnimator::ANIMATION_FADE_IN: 314 case SessionStateAnimator::ANIMATION_FADE_IN:
299 if (layer->GetTargetOpacity() < 0.9999) 315 if (layer->GetTargetOpacity() < 0.9999)
300 return false; 316 return false;
301 break; 317 break;
318 case SessionStateAnimator::ANIMATION_FADE_OUT:
319 if (layer->GetTargetOpacity() > 0.0001)
320 return false;
321 break;
302 case SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY: 322 case SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY:
303 if (layer->GetTargetOpacity() > 0.0001) 323 if (layer->GetTargetOpacity() > 0.0001)
304 return false; 324 return false;
305 break; 325 break;
306 case SessionStateAnimator::ANIMATION_RESTORE: 326 case SessionStateAnimator::ANIMATION_RESTORE:
307 if (layer->opacity() < 0.9999 || layer->transform() != gfx::Transform()) 327 if (layer->opacity() < 0.9999 || layer->transform() != gfx::Transform())
308 return false; 328 return false;
309 break; 329 break;
310 case SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS: 330 case SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS:
311 if ((layer->GetTargetBrightness() < 0.9999) || 331 if ((layer->GetTargetBrightness() < 0.9999) ||
312 (layer->GetTargetGrayscale() < 0.9999)) 332 (layer->GetTargetGrayscale() < 0.9999))
313 return false; 333 return false;
314 break; 334 break;
315 case SessionStateAnimator::ANIMATION_UNDO_GRAYSCALE_BRIGHTNESS: 335 case SessionStateAnimator::ANIMATION_UNDO_GRAYSCALE_BRIGHTNESS:
316 if ((layer->GetTargetBrightness() > 0.0001) || 336 if ((layer->GetTargetBrightness() > 0.0001) ||
317 (layer->GetTargetGrayscale() > 0.0001)) 337 (layer->GetTargetGrayscale() > 0.0001))
318 return false; 338 return false;
319 break; 339 break;
320 case SessionStateAnimator::ANIMATION_DROP: 340 case SessionStateAnimator::ANIMATION_DROP:
341 case SessionStateAnimator::ANIMATION_UNDO_LIFT:
321 //ToDo(antim) : check other effects 342 //ToDo(antim) : check other effects
322 if (layer->GetTargetOpacity() < 0.9999) 343 if (layer->GetTargetOpacity() < 0.9999)
323 return false; 344 return false;
324 break; 345 break;
325 //ToDo(antim) : check other effects 346 //ToDo(antim) : check other effects
326 case SessionStateAnimator::ANIMATION_LIFT: 347 case SessionStateAnimator::ANIMATION_LIFT:
327 if (layer->GetTargetOpacity() > 0.0001) 348 if (layer->GetTargetOpacity() > 0.0001)
328 return false; 349 return false;
329 break; 350 break;
330 case SessionStateAnimator::ANIMATION_RAISE_TO_SCREEN: 351 case SessionStateAnimator::ANIMATION_RAISE_TO_SCREEN:
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 if (container_mask & LOCK_SCREEN_CONTAINERS) { 472 if (container_mask & LOCK_SCREEN_CONTAINERS) {
452 containers->push_back(Shell::GetContainer( 473 containers->push_back(Shell::GetContainer(
453 root_window, 474 root_window,
454 internal::kShellWindowId_LockScreenContainersContainer)); 475 internal::kShellWindowId_LockScreenContainersContainer));
455 } 476 }
456 if (container_mask & LOCK_SCREEN_RELATED_CONTAINERS) { 477 if (container_mask & LOCK_SCREEN_RELATED_CONTAINERS) {
457 containers->push_back(Shell::GetContainer( 478 containers->push_back(Shell::GetContainer(
458 root_window, 479 root_window,
459 internal::kShellWindowId_LockScreenRelatedContainersContainer)); 480 internal::kShellWindowId_LockScreenRelatedContainersContainer));
460 } 481 }
461 if (container_mask & LOCK_SCREEN_SYSTEM_FOREGROUND) {
462 containers->push_back(Shell::GetContainer(
463 root_window,
464 internal::kShellWindowId_PowerButtonAnimationContainer));
465 }
466 } 482 }
467 483
468 void SessionStateAnimator::StartAnimation(int container_mask, 484 void SessionStateAnimator::StartAnimation(int container_mask,
469 AnimationType type, 485 AnimationType type,
470 AnimationSpeed speed) { 486 AnimationSpeed speed) {
471 aura::Window::Windows containers; 487 aura::Window::Windows containers;
472 GetContainers(container_mask, &containers); 488 GetContainers(container_mask, &containers);
473 for (aura::Window::Windows::const_iterator it = containers.begin(); 489 for (aura::Window::Windows::const_iterator it = containers.begin();
474 it != containers.end(); ++it) { 490 it != containers.end(); ++it) {
475 RunAnimationForWindow(*it, type, speed, NULL); 491 RunAnimationForWindow(*it, type, speed, NULL);
476 } 492 }
477 } 493 }
478 494
479 // Apply animation |type| to all containers described by |container_mask|. 495 // Apply animation |type| to all containers described by |container_mask|.
480 void SessionStateAnimator::StartAnimationWithCallback( 496 void SessionStateAnimator::StartAnimationWithCallback(
481 int container_mask, 497 int container_mask,
482 AnimationType type, 498 AnimationType type,
483 AnimationSpeed speed, 499 AnimationSpeed speed,
484 base::Callback<void(void)>& callback) { 500 base::Callback<void(void)>& callback) {
485 aura::Window::Windows containers; 501 aura::Window::Windows containers;
486 GetContainers(container_mask, &containers); 502 GetContainers(container_mask, &containers);
487 for (aura::Window::Windows::const_iterator it = containers.begin(); 503 for (aura::Window::Windows::const_iterator it = containers.begin();
488 it != containers.end(); ++it) { 504 it != containers.end(); ++it) {
489 ui::LayerAnimationObserver* observer = 505 ui::LayerAnimationObserver* observer =
490 new CallbackAnimationObserver(callback); 506 new CallbackAnimationObserver(callback);
491 RunAnimationForWindow(*it, type, speed, observer); 507 RunAnimationForWindow(*it, type, speed, observer);
492 } 508 }
493 } 509 }
494 510
511 void SessionStateAnimator::StartAnimationWithObserver(
512 int container_mask,
513 AnimationType type,
514 AnimationSpeed speed,
515 ui::LayerAnimationObserver* observer) {
516 aura::Window::Windows containers;
517 GetContainers(container_mask, &containers);
518 for (aura::Window::Windows::const_iterator it = containers.begin();
519 it != containers.end(); ++it) {
520 RunAnimationForWindow(*it, type, speed, observer);
521 }
522 }
523
495 void SessionStateAnimator::StartGlobalAnimation(AnimationType type, 524 void SessionStateAnimator::StartGlobalAnimation(AnimationType type,
496 AnimationSpeed speed) { 525 AnimationSpeed speed) {
497 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); 526 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow();
498 RunAnimationForWindow(root_window, type, speed, NULL); 527 RunAnimationForWindow(root_window, type, speed, NULL);
499 } 528 }
500 529
501 void SessionStateAnimator::RunAnimationForWindow( 530 void SessionStateAnimator::RunAnimationForWindow(
502 aura::Window* window, 531 aura::Window* window,
503 AnimationType type, 532 AnimationType type,
504 AnimationSpeed speed, 533 AnimationSpeed speed,
505 ui::LayerAnimationObserver* observer) { 534 ui::LayerAnimationObserver* observer) {
506 base::TimeDelta duration = GetDuration(speed); 535 base::TimeDelta duration = GetDuration(speed);
507 536
508 switch (type) { 537 switch (type) {
509 case ANIMATION_PARTIAL_CLOSE: 538 case ANIMATION_PARTIAL_CLOSE:
510 StartSlowCloseAnimationForWindow(window, duration, observer); 539 StartSlowCloseAnimationForWindow(window, duration, observer);
511 break; 540 break;
512 case ANIMATION_UNDO_PARTIAL_CLOSE: 541 case ANIMATION_UNDO_PARTIAL_CLOSE:
513 StartUndoSlowCloseAnimationForWindow(window, duration, observer); 542 StartUndoSlowCloseAnimationForWindow(window, duration, observer);
514 break; 543 break;
515 case ANIMATION_FULL_CLOSE: 544 case ANIMATION_FULL_CLOSE:
516 StartFastCloseAnimationForWindow(window, duration, observer); 545 StartFastCloseAnimationForWindow(window, duration, observer);
517 break; 546 break;
518 case ANIMATION_FADE_IN: 547 case ANIMATION_FADE_IN:
519 FadeInWindow(window, duration, observer); 548 StartOpacityAnimationForWindow(window, 1.0, duration, observer);
549 break;
550 case ANIMATION_FADE_OUT:
551 StartOpacityAnimationForWindow(window, 0.0, duration, observer);
520 break; 552 break;
521 case ANIMATION_HIDE_IMMEDIATELY: 553 case ANIMATION_HIDE_IMMEDIATELY:
522 DCHECK_EQ(speed, ANIMATION_SPEED_IMMEDIATE); 554 DCHECK_EQ(speed, ANIMATION_SPEED_IMMEDIATE);
523 HideWindowImmediately(window, observer); 555 HideWindowImmediately(window, observer);
524 break; 556 break;
525 case ANIMATION_RESTORE: 557 case ANIMATION_RESTORE:
526 DCHECK_EQ(speed, ANIMATION_SPEED_IMMEDIATE); 558 DCHECK_EQ(speed, ANIMATION_SPEED_IMMEDIATE);
527 RestoreWindow(window, observer); 559 RestoreWindow(window, observer);
528 break; 560 break;
529 case ANIMATION_LIFT: 561 case ANIMATION_LIFT:
530 HideWindow(window, duration, true, observer); 562 HideWindow(window, duration, true, observer);
531 break; 563 break;
532 case ANIMATION_DROP: 564 case ANIMATION_DROP:
533 ShowWindow(window, duration, true, observer); 565 ShowWindow(window, duration, true, observer);
534 break; 566 break;
567 case ANIMATION_UNDO_LIFT:
568 TransformWindowToBaseState(window, duration, observer);
569 break;
535 case ANIMATION_RAISE_TO_SCREEN: 570 case ANIMATION_RAISE_TO_SCREEN:
536 ShowWindow(window, duration, false, observer); 571 ShowWindow(window, duration, false, observer);
537 break; 572 break;
538 case ANIMATION_LOWER_BELOW_SCREEN: 573 case ANIMATION_LOWER_BELOW_SCREEN:
539 HideWindow(window, duration, false, observer); 574 HideWindow(window, duration, false, observer);
540 break; 575 break;
541 case ANIMATION_PARTIAL_FADE_IN: 576 case ANIMATION_PARTIAL_FADE_IN:
542 StartPartialFadeAnimation( 577 StartPartialFadeAnimation(
543 window, kPartialFadeRatio, duration, observer); 578 window, kPartialFadeRatio, duration, observer);
544 break; 579 break;
(...skipping 26 matching lines...) Expand all
571 foreground_->SetColor(SK_ColorWHITE); 606 foreground_->SetColor(SK_ColorWHITE);
572 foreground_->GetWidget()->Show(); 607 foreground_->GetWidget()->Show();
573 } 608 }
574 609
575 void SessionStateAnimator::DropForeground() { 610 void SessionStateAnimator::DropForeground() {
576 foreground_.reset(); 611 foreground_.reset();
577 } 612 }
578 613
579 } // namespace internal 614 } // namespace internal
580 } // namespace ash 615 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698