0

Fix black background when locking with fullscreen window:

Store background container visibility before lock animation, animate it's visibility on lock/unlock.
Change launcher to animate opacity-only (no size transformations).
Update tests so that handle new cases, and become more readable.
Also contains two lock animation fixes:
1) Shutdown animation now have correct cancel timing (it was tarting actual shutdown too early)
2) Flickering on starting and cancelling lock was removed, and tests were updated.

BUG=162646, 162645


Review URL: https://chromiumcodereview.appspot.com/11453012

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@173461 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
antrim@chromium.org
2012-12-17 15:02:33 +00:00
parent 0f2927b0b9
commit 72e8d4eb6e
5 changed files with 1274 additions and 439 deletions

@ -120,15 +120,16 @@ void StartPartialFadeAnimation(aura::Window* window,
sequence->AddObserver(observer);
}
// Fades |window| in to full opacity over |duration|.
void FadeInWindow(aura::Window* window,
base::TimeDelta duration,
ui::LayerAnimationObserver* observer) {
// Fades |window| to |opacity| over |duration|.
void StartOpacityAnimationForWindow(aura::Window* window,
float opacity,
base::TimeDelta duration,
ui::LayerAnimationObserver* observer) {
ui::LayerAnimator* animator = window->layer()->GetAnimator();
animator->set_preemption_strategy(
ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
ui::LayerAnimationSequence* sequence = new ui::LayerAnimationSequence(
ui::LayerAnimationElement::CreateOpacityElement(1.0, duration));
ui::LayerAnimationElement::CreateOpacityElement(opacity, duration));
animator->StartAnimation(sequence);
if (observer)
sequence->AddObserver(observer);
@ -158,6 +159,8 @@ void HideWindow(aura::Window* window,
ui::Layer* layer = window->layer();
ui::ScopedLayerAnimationSettings settings(layer->GetAnimator());
settings.SetPreemptionStrategy(
ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
settings.SetTransitionDuration(duration);
settings.SetTweenType(ui::Tween::EASE_OUT);
@ -188,19 +191,16 @@ void HideWindow(aura::Window* window,
}
}
void ShowWindow(aura::Window* window,
base::TimeDelta duration,
bool above,
ui::LayerAnimationObserver* observer) {
// Animates |window| to identity transform and full opacity over |duration|.
void TransformWindowToBaseState(aura::Window* window,
base::TimeDelta duration,
ui::LayerAnimationObserver* observer) {
ui::Layer* layer = window->layer();
ui::ScopedLayerAnimationSettings settings(layer->GetAnimator());
// Set initial state of animation
settings.SetTransitionDuration(base::TimeDelta());
SetTransformForScaleAnimation(layer,
above ? LAYER_SCALE_ANIMATION_ABOVE : LAYER_SCALE_ANIMATION_BELOW);
// Animate to target values.
settings.SetPreemptionStrategy(
ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
settings.SetTransitionDuration(duration);
settings.SetTweenType(ui::Tween::EASE_OUT);
@ -223,6 +223,23 @@ void ShowWindow(aura::Window* window,
}
}
void ShowWindow(aura::Window* window,
base::TimeDelta duration,
bool above,
ui::LayerAnimationObserver* observer) {
ui::Layer* layer = window->layer();
ui::ScopedLayerAnimationSettings settings(layer->GetAnimator());
// Set initial state of animation
settings.SetPreemptionStrategy(
ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
settings.SetTransitionDuration(base::TimeDelta());
SetTransformForScaleAnimation(layer,
above ? LAYER_SCALE_ANIMATION_ABOVE : LAYER_SCALE_ANIMATION_BELOW);
TransformWindowToBaseState(window, duration, observer);
}
// Starts grayscale/brightness animation for |window| over |duration|. Target
// value for both grayscale and brightness are specified by |target|.
void StartGrayscaleBrightnessAnimationForWindow(
@ -232,8 +249,26 @@ void StartGrayscaleBrightnessAnimationForWindow(
ui::LayerAnimationObserver* observer) {
ui::LayerAnimator* animator = window->layer()->GetAnimator();
std::vector<ui::LayerAnimationSequence*> animations =
CreateBrightnessGrayscaleAnimationSequence(target, duration);
scoped_ptr<ui::LayerAnimationSequence> brightness_sequence(
new ui::LayerAnimationSequence());
scoped_ptr<ui::LayerAnimationSequence> grayscale_sequence(
new ui::LayerAnimationSequence());
scoped_ptr<ui::LayerAnimationElement> brightness_element(
ui::LayerAnimationElement::CreateBrightnessElement(
target, duration));
brightness_element->set_tween_type(ui::Tween::EASE_IN);
brightness_sequence->AddElement(brightness_element.release());
scoped_ptr<ui::LayerAnimationElement> grayscale_element(
ui::LayerAnimationElement::CreateGrayscaleElement(
target, duration));
grayscale_element->set_tween_type(ui::Tween::EASE_IN);
grayscale_sequence->AddElement(grayscale_element.release());
std::vector<ui::LayerAnimationSequence*> animations;
animations.push_back(brightness_sequence.release());
animations.push_back(grayscale_sequence.release());
if (observer)
animations[0]->AddObserver(observer);
@ -299,6 +334,10 @@ bool IsLayerAnimated(ui::Layer* layer,
if (layer->GetTargetOpacity() < 0.9999)
return false;
break;
case SessionStateAnimator::ANIMATION_FADE_OUT:
if (layer->GetTargetOpacity() > 0.0001)
return false;
break;
case SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY:
if (layer->GetTargetOpacity() > 0.0001)
return false;
@ -318,6 +357,7 @@ bool IsLayerAnimated(ui::Layer* layer,
return false;
break;
case SessionStateAnimator::ANIMATION_DROP:
case SessionStateAnimator::ANIMATION_UNDO_LIFT:
//ToDo(antim) : check other effects
if (layer->GetTargetOpacity() < 0.9999)
return false;
@ -391,15 +431,15 @@ base::TimeDelta SessionStateAnimator::GetDuration(AnimationSpeed speed) {
case ANIMATION_SPEED_UNDOABLE:
return base::TimeDelta::FromMilliseconds(400);
case ANIMATION_SPEED_REVERT:
return base::TimeDelta::FromMilliseconds(100);
return base::TimeDelta::FromMilliseconds(150);
case ANIMATION_SPEED_FAST:
return base::TimeDelta::FromMilliseconds(150);
case ANIMATION_SPEED_SHOW_LOCK_SCREEN:
return base::TimeDelta::FromMilliseconds(200);
case ANIMATION_SPEED_MOVE_WINDOWS:
return base::TimeDelta::FromMilliseconds(400);
return base::TimeDelta::FromMilliseconds(350);
case ANIMATION_SPEED_UNDO_MOVE_WINDOWS:
return base::TimeDelta::FromMilliseconds(600);
return base::TimeDelta::FromMilliseconds(500);
case ANIMATION_SPEED_SHUTDOWN:
return base::TimeDelta::FromMilliseconds(1000);
case ANIMATION_SPEED_REVERT_SHUTDOWN:
@ -458,11 +498,6 @@ void SessionStateAnimator::GetContainers(int container_mask,
root_window,
internal::kShellWindowId_LockScreenRelatedContainersContainer));
}
if (container_mask & LOCK_SCREEN_SYSTEM_FOREGROUND) {
containers->push_back(Shell::GetContainer(
root_window,
internal::kShellWindowId_PowerButtonAnimationContainer));
}
}
void SessionStateAnimator::StartAnimation(int container_mask,
@ -476,7 +511,6 @@ void SessionStateAnimator::StartAnimation(int container_mask,
}
}
// Apply animation |type| to all containers described by |container_mask|.
void SessionStateAnimator::StartAnimationWithCallback(
int container_mask,
AnimationType type,
@ -492,6 +526,19 @@ void SessionStateAnimator::StartAnimationWithCallback(
}
}
void SessionStateAnimator::StartAnimationWithObserver(
int container_mask,
AnimationType type,
AnimationSpeed speed,
ui::LayerAnimationObserver* observer) {
aura::Window::Windows containers;
GetContainers(container_mask, &containers);
for (aura::Window::Windows::const_iterator it = containers.begin();
it != containers.end(); ++it) {
RunAnimationForWindow(*it, type, speed, observer);
}
}
void SessionStateAnimator::StartGlobalAnimation(AnimationType type,
AnimationSpeed speed) {
aura::RootWindow* root_window = Shell::GetPrimaryRootWindow();
@ -516,7 +563,10 @@ void SessionStateAnimator::RunAnimationForWindow(
StartFastCloseAnimationForWindow(window, duration, observer);
break;
case ANIMATION_FADE_IN:
FadeInWindow(window, duration, observer);
StartOpacityAnimationForWindow(window, 1.0, duration, observer);
break;
case ANIMATION_FADE_OUT:
StartOpacityAnimationForWindow(window, 0.0, duration, observer);
break;
case ANIMATION_HIDE_IMMEDIATELY:
DCHECK_EQ(speed, ANIMATION_SPEED_IMMEDIATE);
@ -532,6 +582,9 @@ void SessionStateAnimator::RunAnimationForWindow(
case ANIMATION_DROP:
ShowWindow(window, duration, true, observer);
break;
case ANIMATION_UNDO_LIFT:
TransformWindowToBaseState(window, duration, observer);
break;
case ANIMATION_RAISE_TO_SCREEN:
ShowWindow(window, duration, false, observer);
break;

@ -11,6 +11,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/timer.h"
#include "ui/aura/window.h"
#include "ui/compositor/layer_animation_observer.h"
namespace gfx {
class Rect;
@ -34,11 +35,13 @@ class ASH_EXPORT SessionStateAnimator {
ANIMATION_UNDO_PARTIAL_CLOSE,
ANIMATION_FULL_CLOSE,
ANIMATION_FADE_IN,
ANIMATION_FADE_OUT,
ANIMATION_HIDE_IMMEDIATELY,
ANIMATION_RESTORE,
// Animations that raise/lower windows to/from area "in front" of the
// screen.
ANIMATION_LIFT,
ANIMATION_UNDO_LIFT,
ANIMATION_DROP,
// Animations that raise/lower windows from/to area "behind" of the screen.
ANIMATION_RAISE_TO_SCREEN,
@ -97,8 +100,6 @@ class ASH_EXPORT SessionStateAnimator {
// Multiple system layers belong here like status, menu, tooltip
// and overlay layers.
LOCK_SCREEN_RELATED_CONTAINERS = 1 << 5,
LOCK_SCREEN_SYSTEM_FOREGROUND = 1 << 6,
};
// Helper class used by tests to access internal state.
@ -159,6 +160,13 @@ class ASH_EXPORT SessionStateAnimator {
AnimationSpeed speed,
base::Callback<void(void)>& callback);
// Apply animation |type| to all containers included in |container_mask| with
// specified |speed| and add |observer| to all animations.
void StartAnimationWithObserver(int container_mask,
AnimationType type,
AnimationSpeed speed,
ui::LayerAnimationObserver* observer);
// Applies animation |type| whith specified |speed| to the root container.
void StartGlobalAnimation(AnimationType type,
AnimationSpeed speed);

@ -11,7 +11,10 @@
#include "ash/wm/session_state_animator.h"
#include "base/bind_helpers.h"
#include "base/command_line.h"
#include "base/timer.h"
#include "ui/aura/root_window.h"
#include "ui/compositor/layer_animation_sequence.h"
#include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/views/corewm/compound_event_filter.h"
#if defined(OS_CHROMEOS)
@ -20,6 +23,115 @@
namespace ash {
namespace {
aura::Window* GetBackground() {
aura::RootWindow* root_window = Shell::GetPrimaryRootWindow();
return Shell::GetContainer(root_window,
internal::kShellWindowId_DesktopBackgroundContainer);
}
bool IsBackgroundHidden() {
return !GetBackground()->IsVisible();
}
void ShowBackground() {
ui::ScopedLayerAnimationSettings settings(
GetBackground()->layer()->GetAnimator());
settings.SetTransitionDuration(base::TimeDelta());
GetBackground()->Show();
}
void HideBackground() {
ui::ScopedLayerAnimationSettings settings(
GetBackground()->layer()->GetAnimator());
settings.SetTransitionDuration(base::TimeDelta());
GetBackground()->Hide();
}
// This observer is intended to use in cases when some action has to be taken
// once some animation successfully completes (i.e. it was not aborted).
// Observer will count a number of sequences it is attached to, and a number of
// finished sequences (either Ended or Aborted). Once these two numbers are
// equal, observer will delete itself, calling callback passed to constructor if
// there were no aborted animations.
// This way it can be either used to wait for some animation to be finished in
// multiple layers, to wait once a sequence of animations is finished in one
// layer or the mixture of both.
class AnimationFinishedObserver : public ui::LayerAnimationObserver {
public:
explicit AnimationFinishedObserver(base::Closure &callback)
: callback_(callback),
sequences_attached_(0),
sequences_completed_(0),
paused_(false) {
}
// Pauses observer: no checks will be made while paused. It can be used when
// a sequence has some immediate animations in the beginning.
void Pause() {
paused_ = true;
}
// Unpauses observer. It does a check and calls callback if conditions are
// met.
void Unpause() {
if (!paused_)
return;
paused_ = false;
if (sequences_completed_ == sequences_attached_) {
callback_.Run();
delete this;
}
}
private:
virtual ~AnimationFinishedObserver() {
}
// LayerAnimationObserver implementation
virtual void OnLayerAnimationEnded(
ui::LayerAnimationSequence* sequence) OVERRIDE {
sequences_completed_++;
if ((sequences_completed_ == sequences_attached_) && !paused_) {
callback_.Run();
delete this;
}
}
virtual void OnLayerAnimationAborted(
ui::LayerAnimationSequence* sequence) OVERRIDE {
sequences_completed_++;
if ((sequences_completed_ == sequences_attached_) && !paused_)
delete this;
}
virtual void OnLayerAnimationScheduled(
ui::LayerAnimationSequence* sequence) OVERRIDE {
}
virtual void OnAttachedToSequence(
ui::LayerAnimationSequence* sequence) OVERRIDE {
LayerAnimationObserver::OnAttachedToSequence(sequence);
sequences_attached_++;
}
// Callback to be called.
base::Closure callback_;
// Number of sequences this observer was attached to.
int sequences_attached_;
// Number of sequences either ended or aborted.
int sequences_completed_;
bool paused_;
DISALLOW_COPY_AND_ASSIGN(AnimationFinishedObserver);
};
} // namespace
SessionStateControllerImpl2::TestApi::TestApi(
SessionStateControllerImpl2* controller)
: controller_(controller) {
@ -32,7 +144,9 @@ SessionStateControllerImpl2::SessionStateControllerImpl2()
: login_status_(user::LOGGED_IN_NONE),
system_is_locked_(false),
shutting_down_(false),
shutdown_after_lock_(false) {
shutdown_after_lock_(false),
animating_lock_(false),
can_cancel_lock_animation_(false) {
Shell::GetPrimaryRootWindow()->AddRootWindowObserver(this);
}
@ -50,6 +164,7 @@ void SessionStateControllerImpl2::OnLoginStateChanged(
void SessionStateControllerImpl2::OnAppTerminating() {
// If we hear that Chrome is exiting but didn't request it ourselves, all we
// can really hope for is that we'll have time to clear the screen.
// This is also the case when the user signs off.
if (!shutting_down_) {
shutting_down_ = true;
Shell* shell = ash::Shell::GetInstance();
@ -69,22 +184,10 @@ void SessionStateControllerImpl2::OnLockStateChanged(bool locked) {
system_is_locked_ = locked;
if (locked) {
base::Callback<void(void)> callback =
base::Bind(&SessionStateControllerImpl2::OnLockScreenAnimationFinished,
base::Unretained(this));
animator_->StartAnimationWithCallback(
internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
internal::SessionStateAnimator::ANIMATION_RAISE_TO_SCREEN,
internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS,
callback);
lock_timer_.Stop();
StartPostLockAnimation();
lock_fail_timer_.Stop();
} else {
animator_->StartAnimation(
internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS |
internal::SessionStateAnimator::LAUNCHER,
internal::SessionStateAnimator::ANIMATION_DROP,
internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
StartUnlockAnimationAfterUIDestroyed();
}
}
@ -93,68 +196,27 @@ void SessionStateControllerImpl2::SetLockScreenDisplayedCallback(
lock_screen_displayed_callback_ = callback;
}
void SessionStateControllerImpl2::OnLockScreenAnimationFinished() {
FOR_EACH_OBSERVER(SessionStateObserver, observers_,
OnSessionStateEvent(
SessionStateObserver::EVENT_LOCK_ANIMATION_FINISHED));
if (!lock_screen_displayed_callback_.is_null()) {
lock_screen_displayed_callback_.Run();
lock_screen_displayed_callback_.Reset();
}
if (shutdown_after_lock_) {
shutdown_after_lock_ = false;
StartLockToShutdownTimer();
}
}
void SessionStateControllerImpl2::OnStartingLock() {
if (shutting_down_ || system_is_locked_)
return;
animator_->StartAnimation(
internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS |
internal::SessionStateAnimator::LAUNCHER,
internal::SessionStateAnimator::ANIMATION_LIFT,
internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
FOR_EACH_OBSERVER(SessionStateObserver, observers_,
OnSessionStateEvent(SessionStateObserver::EVENT_LOCK_ANIMATION_STARTED));
// Hide the screen locker containers so we can raise them later.
animator_->StartAnimation(
internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY,
internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE);
if (animating_lock_)
return;
StartImmediatePreLockAnimation();
}
void SessionStateControllerImpl2::StartLockAnimationAndLockImmediately() {
animator_->StartAnimation(
internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS |
internal::SessionStateAnimator::LAUNCHER,
internal::SessionStateAnimator::ANIMATION_LIFT,
internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
FOR_EACH_OBSERVER(SessionStateObserver, observers_,
OnSessionStateEvent(SessionStateObserver::EVENT_LOCK_ANIMATION_STARTED));
OnLockTimeout();
if (animating_lock_)
return;
StartImmediatePreLockAnimation();
}
void SessionStateControllerImpl2::StartLockAnimation(bool shutdown_after_lock) {
if (animating_lock_)
return;
shutdown_after_lock_ = shutdown_after_lock;
can_cancel_lock_animation_ = true;
animator_->StartAnimation(
internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS |
internal::SessionStateAnimator::LAUNCHER,
internal::SessionStateAnimator::ANIMATION_LIFT,
internal::SessionStateAnimator::ANIMATION_SPEED_UNDOABLE);
FOR_EACH_OBSERVER(SessionStateObserver, observers_,
OnSessionStateEvent(
SessionStateObserver::EVENT_PRELOCK_ANIMATION_STARTED));
StartLockTimer();
}
void SessionStateControllerImpl2::StartShutdownAnimation() {
animator_->StartGlobalAnimation(
internal::SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS,
internal::SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
StartPreShutdownAnimationTimer();
StartCancellablePreLockAnimation();
}
bool SessionStateControllerImpl2::LockRequested() {
@ -166,19 +228,15 @@ bool SessionStateControllerImpl2::ShutdownRequested() {
}
bool SessionStateControllerImpl2::CanCancelLockAnimation() {
return lock_timer_.IsRunning();
return can_cancel_lock_animation_;
}
void SessionStateControllerImpl2::CancelLockAnimation() {
if (!CanCancelLockAnimation())
return;
shutdown_after_lock_ = false;
animator_->StartAnimation(
internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS |
internal::SessionStateAnimator::LAUNCHER,
internal::SessionStateAnimator::ANIMATION_DROP,
internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
lock_timer_.Stop();
animating_lock_ = false;
CancelPreLockAnimation();
}
bool SessionStateControllerImpl2::CanCancelShutdownAnimation() {
@ -187,6 +245,10 @@ bool SessionStateControllerImpl2::CanCancelShutdownAnimation() {
lock_to_shutdown_timer_.IsRunning();
}
void SessionStateControllerImpl2::StartShutdownAnimation() {
StartCancellableShutdownAnimation();
}
void SessionStateControllerImpl2::CancelShutdownAnimation() {
if (!CanCancelShutdownAnimation())
return;
@ -217,10 +279,7 @@ void SessionStateControllerImpl2::RequestShutdownImpl() {
shell->env_filter()->set_cursor_hidden_by_filter(false);
shell->cursor_manager()->ShowCursor(false);
animator_->StartGlobalAnimation(
internal::SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS,
internal::SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
StartRealShutdownTimer();
StartShutdownAnimationImpl();
}
void SessionStateControllerImpl2::OnRootWindowHostCloseRequested(
@ -228,31 +287,10 @@ void SessionStateControllerImpl2::OnRootWindowHostCloseRequested(
Shell::GetInstance()->delegate()->Exit();
}
void SessionStateControllerImpl2::StartLockTimer() {
lock_timer_.Stop();
lock_timer_.Start(
FROM_HERE,
animator_->GetDuration(
internal::SessionStateAnimator::ANIMATION_SPEED_UNDOABLE),
this, &SessionStateControllerImpl2::OnLockTimeout);
}
void SessionStateControllerImpl2::OnLockTimeout() {
delegate_->RequestLockScreen();
lock_fail_timer_.Start(
FROM_HERE,
base::TimeDelta::FromMilliseconds(kLockFailTimeoutMs),
this, &SessionStateControllerImpl2::OnLockFailTimeout);
}
void SessionStateControllerImpl2::OnLockFailTimeout() {
DCHECK(!system_is_locked_);
// Undo lock animation.
animator_->StartAnimation(
internal::SessionStateAnimator::LAUNCHER |
internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
internal::SessionStateAnimator::ANIMATION_DROP,
internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
StartUnlockAnimationAfterUIDestroyed();
}
void SessionStateControllerImpl2::StartLockToShutdownTimer() {
@ -264,34 +302,58 @@ void SessionStateControllerImpl2::StartLockToShutdownTimer() {
this, &SessionStateControllerImpl2::OnLockToShutdownTimeout);
}
void SessionStateControllerImpl2::OnLockToShutdownTimeout() {
DCHECK(system_is_locked_);
StartShutdownAnimation();
StartCancellableShutdownAnimation();
}
void SessionStateControllerImpl2::StartCancellableShutdownAnimation() {
animator_->StartGlobalAnimation(
internal::SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS,
internal::SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
StartPreShutdownAnimationTimer();
}
void SessionStateControllerImpl2::StartShutdownAnimationImpl() {
animator_->StartGlobalAnimation(
internal::SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS,
internal::SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
StartRealShutdownTimer(true);
}
void SessionStateControllerImpl2::StartPreShutdownAnimationTimer() {
pre_shutdown_timer_.Stop();
pre_shutdown_timer_.Start(
FROM_HERE,
base::TimeDelta::FromMilliseconds(kShutdownTimeoutMs),
this, &SessionStateControllerImpl2::OnPreShutdownAnimationTimeout);
animator_->
GetDuration(internal::SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN),
this,
&SessionStateControllerImpl2::OnPreShutdownAnimationTimeout);
}
void SessionStateControllerImpl2::OnPreShutdownAnimationTimeout() {
if (!shutting_down_)
RequestShutdownImpl();
shutting_down_ = true;
Shell* shell = ash::Shell::GetInstance();
shell->env_filter()->set_cursor_hidden_by_filter(false);
shell->cursor_manager()->ShowCursor(false);
StartRealShutdownTimer(false);
}
void SessionStateControllerImpl2::StartRealShutdownTimer() {
void SessionStateControllerImpl2::StartRealShutdownTimer(
bool with_animation_time) {
base::TimeDelta duration =
base::TimeDelta::FromMilliseconds(kShutdownRequestDelayMs);
duration += animator_->GetDuration(
internal::SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
if (with_animation_time) {
duration += animator_->GetDuration(
internal::SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
}
real_shutdown_timer_.Start(
FROM_HERE,
duration,
this, &SessionStateControllerImpl2::OnRealShutdownTimeout);
this,
&SessionStateControllerImpl2::OnRealShutdownTimeout);
}
void SessionStateControllerImpl2::OnRealShutdownTimeout() {
@ -310,6 +372,158 @@ void SessionStateControllerImpl2::OnRealShutdownTimeout() {
void SessionStateControllerImpl2::OnLockScreenHide(
base::Callback<void(void)>& callback) {
StartUnlockAnimationBeforeUIDestroyed(callback);
}
void SessionStateControllerImpl2::LockAnimationCancelled() {
can_cancel_lock_animation_ = false;
RestoreUnlockedProperties();
}
void SessionStateControllerImpl2::PreLockAnimationFinished() {
can_cancel_lock_animation_ = false;
delegate_->RequestLockScreen();
lock_fail_timer_.Start(
FROM_HERE,
base::TimeDelta::FromMilliseconds(kLockFailTimeoutMs),
this,
&SessionStateControllerImpl2::OnLockFailTimeout);
}
void SessionStateControllerImpl2::PostLockAnimationFinished() {
animating_lock_ = false;
FOR_EACH_OBSERVER(SessionStateObserver, observers_,
OnSessionStateEvent(
SessionStateObserver::EVENT_LOCK_ANIMATION_FINISHED));
if (!lock_screen_displayed_callback_.is_null()) {
lock_screen_displayed_callback_.Run();
lock_screen_displayed_callback_.Reset();
}
if (shutdown_after_lock_) {
shutdown_after_lock_ = false;
StartLockToShutdownTimer();
}
}
void SessionStateControllerImpl2::UnlockAnimationAfterUIDestroyedFinished() {
RestoreUnlockedProperties();
}
void SessionStateControllerImpl2::StartImmediatePreLockAnimation() {
animating_lock_ = true;
StoreUnlockedProperties();
base::Closure next_animation_starter =
base::Bind(&SessionStateControllerImpl2::PreLockAnimationFinished,
base::Unretained(this));
ui::LayerAnimationObserver* observer =
new AnimationFinishedObserver(next_animation_starter);
animator_->StartAnimationWithObserver(
internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
internal::SessionStateAnimator::ANIMATION_LIFT,
internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS,
observer);
animator_->StartAnimationWithObserver(
internal::SessionStateAnimator::LAUNCHER,
internal::SessionStateAnimator::ANIMATION_FADE_OUT,
internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS,
observer);
// Hide the screen locker containers so we can raise them later.
animator_->StartAnimation(
internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY,
internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE);
AnimateBackgroundAppearanceIfNecessary(
internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS,
observer);
FOR_EACH_OBSERVER(SessionStateObserver, observers_,
OnSessionStateEvent(SessionStateObserver::EVENT_LOCK_ANIMATION_STARTED));
}
void SessionStateControllerImpl2::StartCancellablePreLockAnimation() {
animating_lock_ = true;
StoreUnlockedProperties();
base::Closure next_animation_starter =
base::Bind(&SessionStateControllerImpl2::PreLockAnimationFinished,
base::Unretained(this));
AnimationFinishedObserver* observer =
new AnimationFinishedObserver(next_animation_starter);
observer->Pause();
animator_->StartAnimationWithObserver(
internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
internal::SessionStateAnimator::ANIMATION_LIFT,
internal::SessionStateAnimator::ANIMATION_SPEED_UNDOABLE,
observer);
animator_->StartAnimationWithObserver(
internal::SessionStateAnimator::LAUNCHER,
internal::SessionStateAnimator::ANIMATION_FADE_OUT,
internal::SessionStateAnimator::ANIMATION_SPEED_UNDOABLE,
observer);
// Hide the screen locker containers so we can raise them later.
animator_->StartAnimation(
internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY,
internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE);
AnimateBackgroundAppearanceIfNecessary(
internal::SessionStateAnimator::ANIMATION_SPEED_UNDOABLE,
observer);
FOR_EACH_OBSERVER(SessionStateObserver, observers_,
OnSessionStateEvent(
SessionStateObserver::EVENT_PRELOCK_ANIMATION_STARTED));
observer->Unpause();
}
void SessionStateControllerImpl2::CancelPreLockAnimation() {
base::Closure next_animation_starter =
base::Bind(&SessionStateControllerImpl2::LockAnimationCancelled,
base::Unretained(this));
AnimationFinishedObserver* observer =
new AnimationFinishedObserver(next_animation_starter);
observer->Pause();
animator_->StartAnimationWithObserver(
internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
internal::SessionStateAnimator::ANIMATION_UNDO_LIFT,
internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS,
observer);
animator_->StartAnimationWithObserver(
internal::SessionStateAnimator::LAUNCHER,
internal::SessionStateAnimator::ANIMATION_FADE_IN,
internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS,
observer);
AnimateBackgroundHidingIfNecessary(
internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS,
observer);
observer->Unpause();
}
void SessionStateControllerImpl2::StartPostLockAnimation() {
base::Closure next_animation_starter =
base::Bind(&SessionStateControllerImpl2::PostLockAnimationFinished,
base::Unretained(this));
ui::LayerAnimationObserver* observer =
new AnimationFinishedObserver(next_animation_starter);
animator_->StartAnimationWithObserver(
internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
internal::SessionStateAnimator::ANIMATION_RAISE_TO_SCREEN,
internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS,
observer);
}
void SessionStateControllerImpl2::StartUnlockAnimationBeforeUIDestroyed(
base::Closure& callback) {
animator_->StartAnimationWithCallback(
internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
internal::SessionStateAnimator::ANIMATION_LIFT,
@ -317,4 +531,83 @@ void SessionStateControllerImpl2::OnLockScreenHide(
callback);
}
void SessionStateControllerImpl2::StartUnlockAnimationAfterUIDestroyed() {
base::Closure next_animation_starter =
base::Bind(
&SessionStateControllerImpl2::UnlockAnimationAfterUIDestroyedFinished,
base::Unretained(this));
ui::LayerAnimationObserver* observer =
new AnimationFinishedObserver(next_animation_starter);
animator_->StartAnimationWithObserver(
internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
internal::SessionStateAnimator::ANIMATION_DROP,
internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS,
observer);
animator_->StartAnimationWithObserver(
internal::SessionStateAnimator::LAUNCHER,
internal::SessionStateAnimator::ANIMATION_FADE_IN,
internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS,
observer);
AnimateBackgroundHidingIfNecessary(
internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS,
observer);
}
void SessionStateControllerImpl2::StoreUnlockedProperties() {
if (!unlocked_properties_.get()) {
unlocked_properties_.reset(new UnlockedStateProperties());
unlocked_properties_->background_is_hidden = IsBackgroundHidden();
}
if (unlocked_properties_->background_is_hidden) {
// Hide background so that it can be animated later.
animator_->StartAnimation(
internal::SessionStateAnimator::DESKTOP_BACKGROUND,
internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY,
internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE);
ShowBackground();
}
}
void SessionStateControllerImpl2::RestoreUnlockedProperties() {
if (!unlocked_properties_.get())
return;
if (unlocked_properties_->background_is_hidden) {
HideBackground();
// Restore background visibility.
animator_->StartAnimation(
internal::SessionStateAnimator::DESKTOP_BACKGROUND,
internal::SessionStateAnimator::ANIMATION_FADE_IN,
internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE);
}
unlocked_properties_.reset();
}
void SessionStateControllerImpl2::AnimateBackgroundAppearanceIfNecessary(
internal::SessionStateAnimator::AnimationSpeed speed,
ui::LayerAnimationObserver* observer) {
if (unlocked_properties_.get() &&
unlocked_properties_->background_is_hidden) {
animator_->StartAnimationWithObserver(
internal::SessionStateAnimator::DESKTOP_BACKGROUND,
internal::SessionStateAnimator::ANIMATION_FADE_IN,
speed,
observer);
}
}
void SessionStateControllerImpl2::AnimateBackgroundHidingIfNecessary(
internal::SessionStateAnimator::AnimationSpeed speed,
ui::LayerAnimationObserver* observer) {
if (unlocked_properties_.get() &&
unlocked_properties_->background_is_hidden) {
animator_->StartAnimationWithObserver(
internal::SessionStateAnimator::DESKTOP_BACKGROUND,
internal::SessionStateAnimator::ANIMATION_FADE_OUT,
speed,
observer);
}
}
} // namespace ash

@ -32,6 +32,28 @@ class SessionStateControllerImpl2Test;
// Displays onscreen animations and locks or suspends the system in response to
// the power button being pressed or released.
// Lock workflow:
// Entry points:
// * StartLockAnimation (bool shutdown after lock) - starts lock that can be
// cancelled.
// * StartLockAnimationAndLockImmediately - starts uninterruptible lock
// animation.
// This leads to call of either StartImmediatePreLockAnimation or
// StartCancellablePreLockAnimation. Once they complete
// PreLockAnimationFinished is called, and system lock is requested.
// Once system locks and lock UI is created, OnLockStateChanged is called, and
// StartPostLockAnimation is called. In PostLockAnimationFinished two
// things happen : EVENT_LOCK_ANIMATION_FINISHED notification is sent (it
// triggers third part of animation within lock UI), and check for continuing to
// shutdown is made.
//
// Unlock workflow:
// WebUI does first part of animation, and calls OnLockScreenHide(callback) that
// triggers StartUnlockAnimationBeforeUIDestroyed(callback). Once callback is
// called at the end of the animation, lock UI is deleted, system unlocks, and
// OnLockStateChanged is called. It leads to
// StartUnlockAnimationAfterUIDestroyed.
class ASH_EXPORT SessionStateControllerImpl2 : public SessionStateController {
public:
@ -42,9 +64,6 @@ class ASH_EXPORT SessionStateControllerImpl2 : public SessionStateController {
virtual ~TestApi();
bool lock_timer_is_running() const {
return controller_->lock_timer_.IsRunning();
}
bool lock_fail_timer_is_running() const {
return controller_->lock_fail_timer_.IsRunning();
}
@ -57,11 +76,13 @@ class ASH_EXPORT SessionStateControllerImpl2 : public SessionStateController {
bool real_shutdown_timer_is_running() const {
return controller_->real_shutdown_timer_.IsRunning();
}
void trigger_lock_timeout() {
controller_->OnLockTimeout();
controller_->lock_timer_.Stop();
bool is_animating_lock() const {
return controller_->animating_lock_;
}
bool is_lock_cancellable() const {
return controller_->CanCancelLockAnimation();
}
void trigger_lock_fail_timeout() {
controller_->OnLockFailTimeout();
controller_->lock_fail_timer_.Stop();
@ -121,14 +142,12 @@ class ASH_EXPORT SessionStateControllerImpl2 : public SessionStateController {
friend class test::SessionStateControllerImpl2Test;
private:
struct UnlockedStateProperties {
bool background_is_hidden;
};
void RequestShutdownImpl();
// Starts lock timer.
void StartLockTimer();
// Requests that the screen be locked and starts |lock_fail_timer_|.
void OnLockTimeout();
// Reverts the pre-lock animation, reports the error.
void OnLockFailTimeout();
@ -145,14 +164,52 @@ class ASH_EXPORT SessionStateControllerImpl2 : public SessionStateController {
void OnPreShutdownAnimationTimeout();
// Starts timer for final shutdown animation.
void StartRealShutdownTimer();
// If |with_animation_time| is true, it will also include time of "fade to
// white" shutdown animation.
void StartRealShutdownTimer(bool with_animation_time);
// Requests that the machine be shut down.
void OnRealShutdownTimeout();
// Starts shutdown animation that can be cancelled and starts pre-shutdown
// timer.
void StartCancellableShutdownAnimation();
// Starts non-cancellable animation and starts real shutdown timer that
// includes animation time.
void StartShutdownAnimationImpl();
// Triggers late animations on the lock screen.
void OnLockScreenAnimationFinished();
void StartImmediatePreLockAnimation();
void StartCancellablePreLockAnimation();
void CancelPreLockAnimation();
void StartPostLockAnimation();
// This method calls |callback| when animation completes.
void StartUnlockAnimationBeforeUIDestroyed(base::Closure &callback);
void StartUnlockAnimationAfterUIDestroyed();
// These methods are called when corresponding animation completes.
void LockAnimationCancelled();
void PreLockAnimationFinished();
void PostLockAnimationFinished();
void UnlockAnimationAfterUIDestroyedFinished();
// Stores properties of UI that have to be temporarily modified while locking.
void StoreUnlockedProperties();
void RestoreUnlockedProperties();
// Fades in background layer with |speed| if it was hidden in unlocked state.
void AnimateBackgroundAppearanceIfNecessary(
ash::internal::SessionStateAnimator::AnimationSpeed speed,
ui::LayerAnimationObserver* observer);
// Fades out background layer with |speed| if it was hidden in unlocked state.
void AnimateBackgroundHidingIfNecessary(
ash::internal::SessionStateAnimator::AnimationSpeed speed,
ui::LayerAnimationObserver* observer);
// The current login status, or original login status from before we locked.
user::LoginStatus login_status_;
@ -166,10 +223,13 @@ class ASH_EXPORT SessionStateControllerImpl2 : public SessionStateController {
// locking.
bool shutdown_after_lock_;
// Started when the user first presses the power button while in a
// logged-in-as-a-non-guest-user, unlocked state. When it fires, we lock the
// screen.
base::OneShotTimer<SessionStateControllerImpl2> lock_timer_;
// Indicates that controller displays lock animation.
bool animating_lock_;
// Indicates that lock animation can be undone.
bool can_cancel_lock_animation_;
scoped_ptr<UnlockedStateProperties> unlocked_properties_;
// Started when we request that the screen be locked. When it fires, we
// assume that our request got dropped.

File diff suppressed because it is too large Load Diff