Chromium Code Reviews| Index: ash/wm/session_state_animator.cc |
| diff --git a/ash/wm/session_state_animator.cc b/ash/wm/session_state_animator.cc |
| index 92006619860356903ec00612dc41cecdf17af4bd..b629451920d44462aa50117d0996288dadf163f1 100644 |
| --- a/ash/wm/session_state_animator.cc |
| +++ b/ash/wm/session_state_animator.cc |
| @@ -6,8 +6,12 @@ |
| #include "ash/shell.h" |
| #include "ash/shell_window_ids.h" |
| +#include "ash/wm/workspace/workspace_animations.h" |
| +#include "ui/aura/client/aura_constants.h" |
| #include "ui/aura/root_window.h" |
| +#include "ui/compositor/layer_animation_observer.h" |
| #include "ui/compositor/layer_animation_sequence.h" |
| +#include "ui/views/widget/widget.h" |
| namespace ash { |
| namespace internal { |
| @@ -36,6 +40,9 @@ const int kLockFadeInAnimMs = 200; |
| // pre-shutdown states. |
| const float kSlowCloseSizeRatio = 0.95f; |
| +// Maximum opacity of white layer when animating pre-shutdown state. |
| +const float kPartialFadeRatio = 0.3f; |
| + |
| // Returns the transform that should be applied to containers for the slow-close |
| // animation. |
| gfx::Transform GetSlowCloseTransform() { |
| @@ -100,6 +107,22 @@ void StartFastCloseAnimationForWindow(aura::Window* window) { |
| 0.0, base::TimeDelta::FromMilliseconds(kFastCloseAnimMs)))); |
| } |
| +// Fades |window| to a |target_opacity| for a |lengthMs| milliseconds. |
|
Daniel Erat
2012/10/23 16:02:11
nit: s/to a/to/, s/for a/over/, s/lengthMs/length_
|
| +void StartPartialFadeAnimation(aura::Window* window, |
| + float target_opacity, |
| + int length_ms, |
|
Daniel Erat
2012/10/23 16:02:11
use base::TimeDelta instead
Denis Kuznetsov (DE-MUC)
2012/10/23 16:07:30
What is the reason for that?
It will require base:
Daniel Erat
2012/10/23 16:13:03
It makes the units obvious to anyone who's reading
|
| + 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( |
| + target_opacity, base::TimeDelta::FromMilliseconds(length_ms))); |
| + animator->StartAnimation(sequence); |
| + if (observer) |
| + sequence->AddObserver(observer); |
| +} |
| + |
| // Fades |window| in to full opacity. |
| void FadeInWindow(aura::Window* window) { |
| ui::LayerAnimator* animator = window->layer()->GetAnimator(); |
| @@ -123,6 +146,60 @@ void RestoreWindow(aura::Window* window) { |
| window->layer()->SetOpacity(1.0); |
| } |
| +void RaiseWindow(aura::Window* window, int length_ms) { |
|
Daniel Erat
2012/10/23 16:02:11
base::TimeDelta
|
| + WorkspaceAnimationDetails details; |
| + details.direction = WORKSPACE_ANIMATE_UP; |
| + details.animate = true; |
| + details.animate_scale = true; |
| + details.animate_opacity = true; |
| + details.duration = base::TimeDelta::FromMilliseconds(length_ms); |
| + HideWorkspace(window, details); |
| +} |
| + |
| +void LowerWindow(aura::Window* window, int length_ms) { |
|
Daniel Erat
2012/10/23 16:02:11
base::TimeDelta
|
| + WorkspaceAnimationDetails details; |
| + details.direction = WORKSPACE_ANIMATE_DOWN; |
| + details.animate = true; |
| + details.animate_scale = true; |
| + details.animate_opacity = true; |
| + details.duration = base::TimeDelta::FromMilliseconds(length_ms); |
| + ShowWorkspace(window, details); |
| +} |
| + |
| +// Animation observer that would drop animated Foreground once animation is |
|
Daniel Erat
2012/10/23 16:02:11
nit: s/would/will/, s/Foreground/foreground/
|
| +// finished. It is used in when undoing shutdown animation. |
| +class ForegroundDropAnimationObserver : public ui::LayerAnimationObserver { |
| + public: |
| + explicit ForegroundDropAnimationObserver(SessionStateAnimator* animator) |
| + : animator_(animator) { |
| + } |
| + virtual ~ForegroundDropAnimationObserver() { |
| + } |
| + |
| + private: |
| + // Overridden from ui::LayerAnimationObserver: |
| + virtual void OnLayerAnimationEnded(ui::LayerAnimationSequence* seq) |
| + OVERRIDE { |
| + // Drop foreground once animation is over. |
| + animator_->DropForeground(); |
| + delete this; |
| + } |
| + |
| + virtual void OnLayerAnimationAborted(ui::LayerAnimationSequence* seq) |
| + OVERRIDE { |
| + // Drop foreground once animation is over. |
| + animator_->DropForeground(); |
| + delete this; |
| + } |
| + |
| + virtual void OnLayerAnimationScheduled(ui::LayerAnimationSequence* seq) |
| + OVERRIDE {} |
| + |
| + SessionStateAnimator* animator_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ForegroundDropAnimationObserver); |
| +}; |
| + |
| } // namespace |
| void SessionStateAnimator::TestApi::TriggerHideBlackLayerTimeout() { |
| @@ -249,6 +326,11 @@ 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)); |
| + } |
| } |
| // Apply animation |type| to all containers described by |container_mask|. |
| @@ -279,6 +361,23 @@ void SessionStateAnimator::StartAnimation(int container_mask, |
| case ANIMATION_RESTORE: |
| RestoreWindow(window); |
| break; |
| + case ANIMATION_RAISE: |
| + RaiseWindow(window, kSlowCloseAnimMs); |
| + break; |
| + case ANIMATION_LOWER: |
| + LowerWindow(window, kSlowCloseAnimMs); |
| + break; |
| + case ANIMATION_PARTIAL_FADE_IN: |
| + StartPartialFadeAnimation(window, kPartialFadeRatio, kSlowCloseAnimMs, |
| + NULL); |
| + break; |
| + case ANIMATION_UNDO_PARTIAL_FADE_IN: |
| + StartPartialFadeAnimation(window, 0.0, kUndoSlowCloseAnimMs, |
| + new ForegroundDropAnimationObserver(this)); |
| + break; |
| + case ANIMATION_FULL_FADE_IN: |
| + StartPartialFadeAnimation(window, 1.0, kFastCloseAnimMs, NULL); |
| + break; |
| default: |
| NOTREACHED() << "Unhandled animation type " << type; |
| } |
| @@ -319,5 +418,22 @@ void SessionStateAnimator::ScheduleDropBlackLayer() { |
| this, &SessionStateAnimator::DropBlackLayer); |
| } |
| +void SessionStateAnimator::CreateForeground() { |
| + if (foreground_.get()) |
| + return; |
| + aura::Window* window = Shell::GetContainer( |
| + Shell::GetPrimaryRootWindow(), |
| + internal::kShellWindowId_PowerButtonAnimationContainer); |
| + HideWindow(window); |
| + foreground_.reset( |
| + new ColoredWindowController(window, "SessionStateAnimatorForeground")); |
| + foreground_->SetColor(SK_ColorWHITE); |
| + foreground_->GetWidget()->Show(); |
| +} |
| + |
| +void SessionStateAnimator::DropForeground() { |
| + foreground_.reset(); |
| +} |
| + |
| } // namespace internal |
| } // namespace ash |