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

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: Added ASH_EXPORT to SessionStateAnimator 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_)
436 OnAnimationCompleted();
437 }
438
439 virtual void OnLayerAnimationAborted(
440 ui::LayerAnimationSequence* sequence) OVERRIDE {
441 sequences_completed_++;
442 if (sequences_completed_ == sequences_attached_)
443 OnAnimationAborted();
444 }
445
446 virtual void OnLayerAnimationScheduled(
447 ui::LayerAnimationSequence* sequence) OVERRIDE {}
448
449 virtual void OnAttachedToSequence(
450 ui::LayerAnimationSequence* sequence) OVERRIDE {
451 LayerAnimationObserver::OnAttachedToSequence(sequence);
452 sequences_attached_++;
453 }
454
455 SessionStateAnimatorImpl* animator_; // not owned
456
457 // Number of sequences this observer was attached to.
458 int sequences_attached_;
459
460 // Number of sequences either ended or aborted.
461 int sequences_completed_;
462
463 DISALLOW_COPY_AND_ASSIGN(AnimationSequence);
464 };
465
466 bool SessionStateAnimatorImpl::TestApi::ContainersAreAnimated(
389 int container_mask, AnimationType type) const { 467 int container_mask, AnimationType type) const {
390 aura::Window::Windows containers; 468 aura::Window::Windows containers;
391 animator_->GetContainers(container_mask, &containers); 469 animator_->GetContainers(container_mask, &containers);
392 for (aura::Window::Windows::const_iterator it = containers.begin(); 470 for (aura::Window::Windows::const_iterator it = containers.begin();
393 it != containers.end(); ++it) { 471 it != containers.end(); ++it) {
394 aura::Window* window = *it; 472 aura::Window* window = *it;
395 ui::Layer* layer = window->layer(); 473 ui::Layer* layer = window->layer();
396 if (!IsLayerAnimated(layer, type)) 474 if (!IsLayerAnimated(layer, type))
397 return false; 475 return false;
398 } 476 }
399 return true; 477 return true;
400 } 478 }
401 479
402 bool SessionStateAnimator::TestApi::RootWindowIsAnimated(AnimationType type) 480 bool SessionStateAnimatorImpl::TestApi::RootWindowIsAnimated(AnimationType type)
403 const { 481 const {
404 aura::Window* root_window = Shell::GetPrimaryRootWindow(); 482 aura::Window* root_window = Shell::GetPrimaryRootWindow();
405 ui::Layer* layer = root_window->layer(); 483 ui::Layer* layer = root_window->layer();
406 return IsLayerAnimated(layer, type); 484 return IsLayerAnimated(layer, type);
407 } 485 }
408 486
409 const int SessionStateAnimator::kAllLockScreenContainersMask = 487 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 } 488 }
422 489
423 SessionStateAnimator::~SessionStateAnimator() { 490 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 } 491 }
452 492
453 // Fills |containers| with the containers described by |container_mask|. 493 // Fills |containers| with the containers described by |container_mask|.
454 void SessionStateAnimator::GetContainers(int container_mask, 494 void SessionStateAnimatorImpl::GetContainers(int container_mask,
455 aura::Window::Windows* containers) { 495 aura::Window::Windows* containers) {
456 aura::Window* root_window = Shell::GetPrimaryRootWindow(); 496 aura::Window* root_window = Shell::GetPrimaryRootWindow();
457 containers->clear(); 497 containers->clear();
458 498
499 if (container_mask & ROOT_CONTAINER) {
500 containers->push_back(Shell::GetPrimaryRootWindow());
501 }
502
459 if (container_mask & DESKTOP_BACKGROUND) { 503 if (container_mask & DESKTOP_BACKGROUND) {
460 containers->push_back(Shell::GetContainer( 504 containers->push_back(Shell::GetContainer(
461 root_window, kShellWindowId_DesktopBackgroundContainer)); 505 root_window, kShellWindowId_DesktopBackgroundContainer));
462 } 506 }
463 if (container_mask & LAUNCHER) { 507 if (container_mask & LAUNCHER) {
464 containers->push_back( 508 containers->push_back(
465 Shell::GetContainer(root_window, kShellWindowId_ShelfContainer)); 509 Shell::GetContainer(root_window, kShellWindowId_ShelfContainer));
466 } 510 }
467 if (container_mask & NON_LOCK_SCREEN_CONTAINERS) { 511 if (container_mask & NON_LOCK_SCREEN_CONTAINERS) {
468 // TODO(antrim): Figure out a way to eliminate a need to exclude launcher 512 // 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) { 530 if (container_mask & LOCK_SCREEN_CONTAINERS) {
487 containers->push_back(Shell::GetContainer( 531 containers->push_back(Shell::GetContainer(
488 root_window, kShellWindowId_LockScreenContainersContainer)); 532 root_window, kShellWindowId_LockScreenContainersContainer));
489 } 533 }
490 if (container_mask & LOCK_SCREEN_RELATED_CONTAINERS) { 534 if (container_mask & LOCK_SCREEN_RELATED_CONTAINERS) {
491 containers->push_back(Shell::GetContainer( 535 containers->push_back(Shell::GetContainer(
492 root_window, kShellWindowId_LockScreenRelatedContainersContainer)); 536 root_window, kShellWindowId_LockScreenRelatedContainersContainer));
493 } 537 }
494 } 538 }
495 539
496 void SessionStateAnimator::StartAnimation(int container_mask, 540 void SessionStateAnimatorImpl::StartAnimation(int container_mask,
497 AnimationType type, 541 AnimationType type,
498 AnimationSpeed speed) { 542 AnimationSpeed speed) {
499 aura::Window::Windows containers; 543 aura::Window::Windows containers;
500 GetContainers(container_mask, &containers); 544 GetContainers(container_mask, &containers);
501 for (aura::Window::Windows::const_iterator it = containers.begin(); 545 for (aura::Window::Windows::const_iterator it = containers.begin();
502 it != containers.end(); ++it) { 546 it != containers.end(); ++it) {
503 RunAnimationForWindow(*it, type, speed, NULL); 547 RunAnimationForWindow(*it, type, speed, NULL);
504 } 548 }
505 } 549 }
506 550
507 void SessionStateAnimator::StartAnimationWithCallback( 551 void SessionStateAnimatorImpl::StartAnimationWithCallback(
508 int container_mask, 552 int container_mask,
509 AnimationType type, 553 AnimationType type,
510 AnimationSpeed speed, 554 AnimationSpeed speed,
511 base::Callback<void(void)>& callback) { 555 base::Closure callback) {
512 aura::Window::Windows containers; 556 aura::Window::Windows containers;
513 GetContainers(container_mask, &containers); 557 GetContainers(container_mask, &containers);
514 for (aura::Window::Windows::const_iterator it = containers.begin(); 558 for (aura::Window::Windows::const_iterator it = containers.begin();
515 it != containers.end(); ++it) { 559 it != containers.end(); ++it) {
516 ui::LayerAnimationObserver* observer = 560 ui::LayerAnimationObserver* observer =
517 new CallbackAnimationObserver(callback); 561 new CallbackAnimationObserver(callback);
518 RunAnimationForWindow(*it, type, speed, observer); 562 RunAnimationForWindow(*it, type, speed, observer);
519 } 563 }
520 } 564 }
521 565
522 void SessionStateAnimator::StartAnimationWithObserver( 566 SessionStateAnimator::AnimationSequence*
567 SessionStateAnimatorImpl::BeginAnimationSequence(base::Closure callback) {
568 return new AnimationSequence(this, callback);
569 }
570
571 bool SessionStateAnimatorImpl::IsBackgroundHidden() const {
572 return !GetBackground()->IsVisible();
573 }
574
575 void SessionStateAnimatorImpl::ShowBackground() {
576 ui::ScopedLayerAnimationSettings settings(
577 GetBackground()->layer()->GetAnimator());
578 settings.SetTransitionDuration(base::TimeDelta());
579 GetBackground()->Show();
580 }
581
582 void SessionStateAnimatorImpl::HideBackground() {
583 ui::ScopedLayerAnimationSettings settings(
584 GetBackground()->layer()->GetAnimator());
585 settings.SetTransitionDuration(base::TimeDelta());
586 GetBackground()->Hide();
587 }
588
589 void SessionStateAnimatorImpl::StartAnimationInSequence(
523 int container_mask, 590 int container_mask,
524 AnimationType type, 591 AnimationType type,
525 AnimationSpeed speed, 592 AnimationSpeed speed,
526 ui::LayerAnimationObserver* observer) { 593 AnimationSequence* observer) {
527 aura::Window::Windows containers; 594 aura::Window::Windows containers;
528 GetContainers(container_mask, &containers); 595 GetContainers(container_mask, &containers);
529 for (aura::Window::Windows::const_iterator it = containers.begin(); 596 for (aura::Window::Windows::const_iterator it = containers.begin();
530 it != containers.end(); ++it) { 597 it != containers.end(); ++it) {
531 RunAnimationForWindow(*it, type, speed, observer); 598 RunAnimationForWindow(*it, type, speed, observer);
532 } 599 }
533 } 600 }
534 601
535 void SessionStateAnimator::StartGlobalAnimation(AnimationType type, 602 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, 603 aura::Window* window,
543 AnimationType type, 604 AnimationType type,
544 AnimationSpeed speed, 605 AnimationSpeed speed,
545 ui::LayerAnimationObserver* observer) { 606 ui::LayerAnimationObserver* observer) {
546 base::TimeDelta duration = GetDuration(speed); 607 base::TimeDelta duration = GetDuration(speed);
547 608
548 switch (type) { 609 switch (type) {
549 case ANIMATION_PARTIAL_CLOSE: 610 case ANIMATION_PARTIAL_CLOSE:
550 StartSlowCloseAnimationForWindow(window, duration, observer); 611 StartSlowCloseAnimationForWindow(window, duration, observer);
551 break; 612 break;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 window, 1.0, duration, gfx::Tween::EASE_IN, observer); 660 window, 1.0, duration, gfx::Tween::EASE_IN, observer);
600 break; 661 break;
601 case ANIMATION_UNDO_GRAYSCALE_BRIGHTNESS: 662 case ANIMATION_UNDO_GRAYSCALE_BRIGHTNESS:
602 StartGrayscaleBrightnessAnimationForWindow( 663 StartGrayscaleBrightnessAnimationForWindow(
603 window, 0.0, duration, gfx::Tween::EASE_IN_OUT, observer); 664 window, 0.0, duration, gfx::Tween::EASE_IN_OUT, observer);
604 break; 665 break;
605 } 666 }
606 } 667 }
607 668
608 } // namespace ash 669 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/session_state_animator_impl.h ('k') | chrome/browser/chromeos/power/power_button_observer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698