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

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

Issue 326813004: Added quick lock mechanism while in Touchview (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Enabled LockStateControllerTests for Background hiding & addressed other comments. Created 6 years, 3 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_impl.h"
6
7 #include <vector>
6 8
7 #include "ash/shell.h" 9 #include "ash/shell.h"
8 #include "ash/shell_window_ids.h" 10 #include "ash/shell_window_ids.h"
9 #include "ash/wm/window_animations.h" 11 #include "ash/wm/window_animations.h"
10 #include "ui/aura/client/aura_constants.h" 12 #include "ui/aura/client/aura_constants.h"
11 #include "ui/aura/window_event_dispatcher.h" 13 #include "ui/aura/window_event_dispatcher.h"
12 #include "ui/compositor/layer_animation_observer.h" 14 #include "ui/compositor/layer_animation_observer.h"
13 #include "ui/compositor/layer_animation_sequence.h" 15 #include "ui/compositor/layer_animation_sequence.h"
14 #include "ui/compositor/scoped_layer_animation_settings.h" 16 #include "ui/compositor/scoped_layer_animation_settings.h"
15 #include "ui/views/widget/widget.h" 17 #include "ui/views/widget/widget.h"
16 18
17 namespace ash { 19 namespace ash {
18 namespace { 20 namespace {
19 21
20 // 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
21 // pre-shutdown states. 23 // pre-shutdown states.
22 const float kSlowCloseSizeRatio = 0.95f; 24 const float kSlowCloseSizeRatio = 0.95f;
23 25
24 // Maximum opacity of white layer when animating pre-shutdown state. 26 // Maximum opacity of white layer when animating pre-shutdown state.
25 const float kPartialFadeRatio = 0.3f; 27 const float kPartialFadeRatio = 0.3f;
26 28
27 // Minimum size. Not zero as it causes numeric issues. 29 // Minimum size. Not zero as it causes numeric issues.
28 const float kMinimumScale = 1e-4f; 30 const float kMinimumScale = 1e-4f;
29 31
32 // Returns the primary root window's container.
33 aura::Window* GetBackground() {
34 aura::Window* root_window = Shell::GetPrimaryRootWindow();
35 return Shell::GetContainer(root_window,
36 kShellWindowId_DesktopBackgroundContainer);
37 }
38
30 // Returns the transform that should be applied to containers for the slow-close 39 // Returns the transform that should be applied to containers for the slow-close
31 // animation. 40 // animation.
32 gfx::Transform GetSlowCloseTransform() { 41 gfx::Transform GetSlowCloseTransform() {
33 gfx::Size root_size = Shell::GetPrimaryRootWindow()->bounds().size(); 42 gfx::Size root_size = Shell::GetPrimaryRootWindow()->bounds().size();
34 gfx::Transform transform; 43 gfx::Transform transform;
35 transform.Translate( 44 transform.Translate(
36 floor(0.5 * (1.0 - kSlowCloseSizeRatio) * root_size.width() + 0.5), 45 floor(0.5 * (1.0 - kSlowCloseSizeRatio) * root_size.width() + 0.5),
37 floor(0.5 * (1.0 - kSlowCloseSizeRatio) * root_size.height() + 0.5)); 46 floor(0.5 * (1.0 - kSlowCloseSizeRatio) * root_size.height() + 0.5));
38 transform.Scale(kSlowCloseSizeRatio, kSlowCloseSizeRatio); 47 transform.Scale(kSlowCloseSizeRatio, kSlowCloseSizeRatio);
39 return transform; 48 return transform;
40 } 49 }
41 50
42 // Returns the transform that should be applied to containers for the fast-close 51 // Returns the transform that should be applied to containers for the fast-close
43 // animation. 52 // animation.
44 gfx::Transform GetFastCloseTransform() { 53 gfx::Transform GetFastCloseTransform() {
45 gfx::Size root_size = Shell::GetPrimaryRootWindow()->bounds().size(); 54 gfx::Size root_size = Shell::GetPrimaryRootWindow()->bounds().size();
46 gfx::Transform transform; 55 gfx::Transform transform;
56
47 transform.Translate(floor(0.5 * root_size.width() + 0.5), 57 transform.Translate(floor(0.5 * root_size.width() + 0.5),
48 floor(0.5 * root_size.height() + 0.5)); 58 floor(0.5 * root_size.height() + 0.5));
49 transform.Scale(kMinimumScale, kMinimumScale); 59 transform.Scale(kMinimumScale, kMinimumScale);
50 return transform; 60 return transform;
51 } 61 }
52 62
53 // Slowly shrinks |window| to a slightly-smaller size. 63 // Slowly shrinks |window| to a slightly-smaller size.
54 void StartSlowCloseAnimationForWindow(aura::Window* window, 64 void StartSlowCloseAnimationForWindow(aura::Window* window,
55 base::TimeDelta duration, 65 base::TimeDelta duration,
56 ui::LayerAnimationObserver* observer) { 66 ui::LayerAnimationObserver* observer) {
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 animator->set_preemption_strategy( 285 animator->set_preemption_strategy(
276 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 286 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
277 287
278 animator->StartTogether(animations); 288 animator->StartTogether(animations);
279 } 289 }
280 290
281 // Animation observer that will drop animated foreground once animation is 291 // Animation observer that will drop animated foreground once animation is
282 // finished. It is used in when undoing shutdown animation. 292 // finished. It is used in when undoing shutdown animation.
283 class CallbackAnimationObserver : public ui::LayerAnimationObserver { 293 class CallbackAnimationObserver : public ui::LayerAnimationObserver {
284 public: 294 public:
285 explicit CallbackAnimationObserver(base::Callback<void(void)> &callback) 295 explicit CallbackAnimationObserver(base::Closure callback)
286 : callback_(callback) { 296 : callback_(callback) {
287 } 297 }
288 virtual ~CallbackAnimationObserver() { 298 virtual ~CallbackAnimationObserver() {
289 } 299 }
290 300
291 private: 301 private:
292 // Overridden from ui::LayerAnimationObserver: 302 // Overridden from ui::LayerAnimationObserver:
293 virtual void OnLayerAnimationEnded(ui::LayerAnimationSequence* seq) 303 virtual void OnLayerAnimationEnded(ui::LayerAnimationSequence* seq)
294 OVERRIDE { 304 OVERRIDE {
295 // Drop foreground once animation is over. 305 // Drop foreground once animation is over.
296 callback_.Run(); 306 callback_.Run();
297 delete this; 307 delete this;
298 } 308 }
299 309
300 virtual void OnLayerAnimationAborted(ui::LayerAnimationSequence* seq) 310 virtual void OnLayerAnimationAborted(ui::LayerAnimationSequence* seq)
301 OVERRIDE { 311 OVERRIDE {
302 // Drop foreground once animation is over. 312 // Drop foreground once animation is over.
303 callback_.Run(); 313 callback_.Run();
304 delete this; 314 delete this;
305 } 315 }
306 316
307 virtual void OnLayerAnimationScheduled(ui::LayerAnimationSequence* seq) 317 virtual void OnLayerAnimationScheduled(ui::LayerAnimationSequence* seq)
308 OVERRIDE {} 318 OVERRIDE {}
309 319
310 base::Callback<void(void)> callback_; 320 base::Closure callback_;
311 321
312 DISALLOW_COPY_AND_ASSIGN(CallbackAnimationObserver); 322 DISALLOW_COPY_AND_ASSIGN(CallbackAnimationObserver);
313 }; 323 };
314 324
315 325
316 bool IsLayerAnimated(ui::Layer* layer, 326 bool IsLayerAnimated(ui::Layer* layer,
317 SessionStateAnimator::AnimationType type) { 327 SessionStateAnimator::AnimationType type) {
318 switch (type) { 328 switch (type) {
319 case SessionStateAnimator::ANIMATION_PARTIAL_CLOSE: 329 case SessionStateAnimator::ANIMATION_PARTIAL_CLOSE:
320 if (layer->GetTargetTransform() != GetSlowCloseTransform()) 330 if (layer->GetTargetTransform() != GetSlowCloseTransform())
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 break; 388 break;
379 default: 389 default:
380 NOTREACHED() << "Unhandled animation type " << type; 390 NOTREACHED() << "Unhandled animation type " << type;
381 return false; 391 return false;
382 } 392 }
383 return true; 393 return true;
384 } 394 }
385 395
386 } // namespace 396 } // namespace
387 397
388 bool SessionStateAnimator::TestApi::ContainersAreAnimated( 398 // This observer is intended to use in cases when some action has to be taken
399 // once some animation successfully completes (i.e. it was not aborted).
400 // Observer will count a number of sequences it is attached to, and a number of
401 // finished sequences (either Ended or Aborted). Once these two numbers are
402 // equal, observer will delete itself, calling callback passed to constructor if
403 // there were no aborted animations.
404 // This way it can be either used to wait for some animation to be finished in
405 // multiple layers, to wait once a sequence of animations is finished in one
406 // layer or the mixture of both.
407 class SessionStateAnimatorImpl::AnimationSequence
408 : public SessionStateAnimator::AnimationSequence,
409 public ui::LayerAnimationObserver {
410 public:
411 explicit AnimationSequence(
412 SessionStateAnimatorImpl* animator,
413 base::Closure callback)
414 : SessionStateAnimator::AnimationSequence(callback),
415 animator_(animator),
416 sequences_attached_(0),
417 sequences_completed_(0) {
418 }
419
420 // SessionStateAnimator::AnimationSequence:
421 virtual void StartAnimation(
422 int container_mask,
423 SessionStateAnimator::AnimationType type,
424 SessionStateAnimator::AnimationSpeed speed) OVERRIDE {
425 animator_->StartAnimationInSequence(container_mask, type, speed, this);
426 }
427
428 private:
429 virtual ~AnimationSequence() {}
430
431 // ui::LayerAnimationObserver:
432 virtual void OnLayerAnimationEnded(
433 ui::LayerAnimationSequence* sequence) OVERRIDE {
434 sequences_completed_++;
435 if (sequences_completed_ == sequences_attached_) {
Daniel Erat 2014/09/09 17:42:09 nit: omit curly brackets here since the statement
bruthig 2014/09/09 17:55:22 Done.
436 OnAnimationCompleted();
437 }
438 }
439
440 virtual void OnLayerAnimationAborted(
441 ui::LayerAnimationSequence* sequence) OVERRIDE {
442 sequences_completed_++;
443 if (sequences_completed_ == sequences_attached_)
444 OnAnimationAborted();
445 }
446
447 virtual void OnLayerAnimationScheduled(
448 ui::LayerAnimationSequence* sequence) OVERRIDE {}
449
450 virtual void OnAttachedToSequence(
451 ui::LayerAnimationSequence* sequence) OVERRIDE {
452 LayerAnimationObserver::OnAttachedToSequence(sequence);
453 sequences_attached_++;
454 }
455
456 SessionStateAnimatorImpl* animator_; // not owned
457
458 // Number of sequences this observer was attached to.
459 int sequences_attached_;
460
461 // Number of sequences either ended or aborted.
462 int sequences_completed_;
463
464 DISALLOW_COPY_AND_ASSIGN(AnimationSequence);
465 };
466
467 bool SessionStateAnimatorImpl::TestApi::ContainersAreAnimated(
389 int container_mask, AnimationType type) const { 468 int container_mask, AnimationType type) const {
390 aura::Window::Windows containers; 469 aura::Window::Windows containers;
391 animator_->GetContainers(container_mask, &containers); 470 animator_->GetContainers(container_mask, &containers);
392 for (aura::Window::Windows::const_iterator it = containers.begin(); 471 for (aura::Window::Windows::const_iterator it = containers.begin();
393 it != containers.end(); ++it) { 472 it != containers.end(); ++it) {
394 aura::Window* window = *it; 473 aura::Window* window = *it;
395 ui::Layer* layer = window->layer(); 474 ui::Layer* layer = window->layer();
396 if (!IsLayerAnimated(layer, type)) 475 if (!IsLayerAnimated(layer, type))
397 return false; 476 return false;
398 } 477 }
399 return true; 478 return true;
400 } 479 }
401 480
402 bool SessionStateAnimator::TestApi::RootWindowIsAnimated(AnimationType type) 481 bool SessionStateAnimatorImpl::TestApi::RootWindowIsAnimated(AnimationType type)
403 const { 482 const {
404 aura::Window* root_window = Shell::GetPrimaryRootWindow(); 483 aura::Window* root_window = Shell::GetPrimaryRootWindow();
405 ui::Layer* layer = root_window->layer(); 484 ui::Layer* layer = root_window->layer();
406 return IsLayerAnimated(layer, type); 485 return IsLayerAnimated(layer, type);
407 } 486 }
408 487
409 const int SessionStateAnimator::kAllLockScreenContainersMask = 488 SessionStateAnimatorImpl::SessionStateAnimatorImpl() {
410 SessionStateAnimator::LOCK_SCREEN_BACKGROUND |
411 SessionStateAnimator::LOCK_SCREEN_CONTAINERS |
412 SessionStateAnimator::LOCK_SCREEN_RELATED_CONTAINERS;
413
414 const int SessionStateAnimator::kAllContainersMask =
415 SessionStateAnimator::kAllLockScreenContainersMask |
416 SessionStateAnimator::DESKTOP_BACKGROUND |
417 SessionStateAnimator::LAUNCHER |
418 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS;
419
420 SessionStateAnimator::SessionStateAnimator() {
421 } 489 }
422 490
423 SessionStateAnimator::~SessionStateAnimator() { 491 SessionStateAnimatorImpl::~SessionStateAnimatorImpl() {
424 }
425
426 base::TimeDelta SessionStateAnimator::GetDuration(AnimationSpeed speed) {
427 switch (speed) {
428 case ANIMATION_SPEED_IMMEDIATE:
429 return base::TimeDelta();
430 case ANIMATION_SPEED_UNDOABLE:
431 return base::TimeDelta::FromMilliseconds(400);
432 case ANIMATION_SPEED_REVERT:
433 return base::TimeDelta::FromMilliseconds(150);
434 case ANIMATION_SPEED_FAST:
435 return base::TimeDelta::FromMilliseconds(150);
436 case ANIMATION_SPEED_SHOW_LOCK_SCREEN:
437 return base::TimeDelta::FromMilliseconds(200);
438 case ANIMATION_SPEED_MOVE_WINDOWS:
439 return base::TimeDelta::FromMilliseconds(350);
440 case ANIMATION_SPEED_UNDO_MOVE_WINDOWS:
441 return base::TimeDelta::FromMilliseconds(350);
442 case ANIMATION_SPEED_SHUTDOWN:
443 return base::TimeDelta::FromMilliseconds(1000);
444 case ANIMATION_SPEED_REVERT_SHUTDOWN:
445 return base::TimeDelta::FromMilliseconds(500);
446 }
447 // Satisfy compilers that do not understand that we will return from switch
448 // above anyway.
449 DCHECK(false) << "Unhandled animation speed " << speed;
450 return base::TimeDelta();
451 } 492 }
452 493
453 // Fills |containers| with the containers described by |container_mask|. 494 // Fills |containers| with the containers described by |container_mask|.
454 void SessionStateAnimator::GetContainers(int container_mask, 495 void SessionStateAnimatorImpl::GetContainers(int container_mask,
455 aura::Window::Windows* containers) { 496 aura::Window::Windows* containers) {
456 aura::Window* root_window = Shell::GetPrimaryRootWindow(); 497 aura::Window* root_window = Shell::GetPrimaryRootWindow();
457 containers->clear(); 498 containers->clear();
458 499
500 if (container_mask & ROOT_CONTAINER) {
501 containers->push_back(Shell::GetPrimaryRootWindow());
502 }
503
459 if (container_mask & DESKTOP_BACKGROUND) { 504 if (container_mask & DESKTOP_BACKGROUND) {
460 containers->push_back(Shell::GetContainer( 505 containers->push_back(Shell::GetContainer(
461 root_window, kShellWindowId_DesktopBackgroundContainer)); 506 root_window, kShellWindowId_DesktopBackgroundContainer));
462 } 507 }
463 if (container_mask & LAUNCHER) { 508 if (container_mask & LAUNCHER) {
464 containers->push_back( 509 containers->push_back(
465 Shell::GetContainer(root_window, kShellWindowId_ShelfContainer)); 510 Shell::GetContainer(root_window, kShellWindowId_ShelfContainer));
466 } 511 }
467 if (container_mask & NON_LOCK_SCREEN_CONTAINERS) { 512 if (container_mask & NON_LOCK_SCREEN_CONTAINERS) {
468 // TODO(antrim): Figure out a way to eliminate a need to exclude launcher 513 // TODO(antrim): Figure out a way to eliminate a need to exclude launcher
(...skipping 17 matching lines...) Expand all
486 if (container_mask & LOCK_SCREEN_CONTAINERS) { 531 if (container_mask & LOCK_SCREEN_CONTAINERS) {
487 containers->push_back(Shell::GetContainer( 532 containers->push_back(Shell::GetContainer(
488 root_window, kShellWindowId_LockScreenContainersContainer)); 533 root_window, kShellWindowId_LockScreenContainersContainer));
489 } 534 }
490 if (container_mask & LOCK_SCREEN_RELATED_CONTAINERS) { 535 if (container_mask & LOCK_SCREEN_RELATED_CONTAINERS) {
491 containers->push_back(Shell::GetContainer( 536 containers->push_back(Shell::GetContainer(
492 root_window, kShellWindowId_LockScreenRelatedContainersContainer)); 537 root_window, kShellWindowId_LockScreenRelatedContainersContainer));
493 } 538 }
494 } 539 }
495 540
496 void SessionStateAnimator::StartAnimation(int container_mask, 541 void SessionStateAnimatorImpl::StartAnimation(int container_mask,
497 AnimationType type, 542 AnimationType type,
498 AnimationSpeed speed) { 543 AnimationSpeed speed) {
499 aura::Window::Windows containers; 544 aura::Window::Windows containers;
500 GetContainers(container_mask, &containers); 545 GetContainers(container_mask, &containers);
501 for (aura::Window::Windows::const_iterator it = containers.begin(); 546 for (aura::Window::Windows::const_iterator it = containers.begin();
502 it != containers.end(); ++it) { 547 it != containers.end(); ++it) {
503 RunAnimationForWindow(*it, type, speed, NULL); 548 RunAnimationForWindow(*it, type, speed, NULL);
504 } 549 }
505 } 550 }
506 551
507 void SessionStateAnimator::StartAnimationWithCallback( 552 void SessionStateAnimatorImpl::StartAnimationWithCallback(
508 int container_mask, 553 int container_mask,
509 AnimationType type, 554 AnimationType type,
510 AnimationSpeed speed, 555 AnimationSpeed speed,
511 base::Callback<void(void)>& callback) { 556 base::Closure callback) {
512 aura::Window::Windows containers; 557 aura::Window::Windows containers;
513 GetContainers(container_mask, &containers); 558 GetContainers(container_mask, &containers);
514 for (aura::Window::Windows::const_iterator it = containers.begin(); 559 for (aura::Window::Windows::const_iterator it = containers.begin();
515 it != containers.end(); ++it) { 560 it != containers.end(); ++it) {
516 ui::LayerAnimationObserver* observer = 561 ui::LayerAnimationObserver* observer =
517 new CallbackAnimationObserver(callback); 562 new CallbackAnimationObserver(callback);
518 RunAnimationForWindow(*it, type, speed, observer); 563 RunAnimationForWindow(*it, type, speed, observer);
519 } 564 }
520 } 565 }
521 566
522 void SessionStateAnimator::StartAnimationWithObserver( 567 SessionStateAnimator::AnimationSequence*
568 SessionStateAnimatorImpl::BeginAnimationSequence(base::Closure callback) {
569 return new AnimationSequence(this, callback);
570 }
571
572 bool SessionStateAnimatorImpl::IsBackgroundHidden() const {
573 return !GetBackground()->IsVisible();
574 }
575
576 void SessionStateAnimatorImpl::ShowBackground() {
577 ui::ScopedLayerAnimationSettings settings(
578 GetBackground()->layer()->GetAnimator());
579 settings.SetTransitionDuration(base::TimeDelta());
580 GetBackground()->Show();
581 }
582
583 void SessionStateAnimatorImpl::HideBackground() {
584 ui::ScopedLayerAnimationSettings settings(
585 GetBackground()->layer()->GetAnimator());
586 settings.SetTransitionDuration(base::TimeDelta());
587 GetBackground()->Hide();
588 }
589
590 void SessionStateAnimatorImpl::StartAnimationInSequence(
523 int container_mask, 591 int container_mask,
524 AnimationType type, 592 AnimationType type,
525 AnimationSpeed speed, 593 AnimationSpeed speed,
526 ui::LayerAnimationObserver* observer) { 594 AnimationSequence* observer) {
527 aura::Window::Windows containers; 595 aura::Window::Windows containers;
528 GetContainers(container_mask, &containers); 596 GetContainers(container_mask, &containers);
529 for (aura::Window::Windows::const_iterator it = containers.begin(); 597 for (aura::Window::Windows::const_iterator it = containers.begin();
530 it != containers.end(); ++it) { 598 it != containers.end(); ++it) {
531 RunAnimationForWindow(*it, type, speed, observer); 599 RunAnimationForWindow(*it, type, speed, observer);
532 } 600 }
533 } 601 }
534 602
535 void SessionStateAnimator::StartGlobalAnimation(AnimationType type, 603 void SessionStateAnimatorImpl::RunAnimationForWindow(
536 AnimationSpeed speed) {
537 aura::Window* root_window = Shell::GetPrimaryRootWindow();
538 RunAnimationForWindow(root_window, type, speed, NULL);
539 }
540
541 void SessionStateAnimator::RunAnimationForWindow(
542 aura::Window* window, 604 aura::Window* window,
543 AnimationType type, 605 AnimationType type,
544 AnimationSpeed speed, 606 AnimationSpeed speed,
545 ui::LayerAnimationObserver* observer) { 607 ui::LayerAnimationObserver* observer) {
546 base::TimeDelta duration = GetDuration(speed); 608 base::TimeDelta duration = GetDuration(speed);
547 609
548 switch (type) { 610 switch (type) {
549 case ANIMATION_PARTIAL_CLOSE: 611 case ANIMATION_PARTIAL_CLOSE:
550 StartSlowCloseAnimationForWindow(window, duration, observer); 612 StartSlowCloseAnimationForWindow(window, duration, observer);
551 break; 613 break;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 window, 1.0, duration, gfx::Tween::EASE_IN, observer); 661 window, 1.0, duration, gfx::Tween::EASE_IN, observer);
600 break; 662 break;
601 case ANIMATION_UNDO_GRAYSCALE_BRIGHTNESS: 663 case ANIMATION_UNDO_GRAYSCALE_BRIGHTNESS:
602 StartGrayscaleBrightnessAnimationForWindow( 664 StartGrayscaleBrightnessAnimationForWindow(
603 window, 0.0, duration, gfx::Tween::EASE_IN_OUT, observer); 665 window, 0.0, duration, gfx::Tween::EASE_IN_OUT, observer);
604 break; 666 break;
605 } 667 }
606 } 668 }
607 669
608 } // namespace ash 670 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698