Index: athena/screen/screen_animator_impl.cc |
diff --git a/athena/screen/screen_animator_impl.cc b/athena/screen/screen_animator_impl.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1e9666550628fd4baa6fa870451ad4c44e7b8edd |
--- /dev/null |
+++ b/athena/screen/screen_animator_impl.cc |
@@ -0,0 +1,74 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "athena/screen/screen_animator_impl.h" |
+ |
+#include "ui/aura/window.h" |
+#include "ui/compositor/layer.h" |
+#include "ui/compositor/layer_animation_observer.h" |
+#include "ui/compositor/scoped_layer_animation_settings.h" |
+#include "ui/gfx/animation/tween.h" |
+ |
+namespace athena { |
+namespace { |
+ |
+// Duration of the shutdown animation. |
+const int kShutdownDurationMs = 1000; |
+ |
+// Duration of the cancel shutdown animation. |
+const int kCancelShutdownDurationMs = 500; |
+ |
+// Animates |window|'s grayscale and brightness to |target|. If non-NULL, |
+// |observer| will be notified when the animation completes. |
+void StartGrayscaleAndBrightnessAnimation( |
+ aura::Window* window, |
+ float target, |
+ int duration_ms, |
+ gfx::Tween::Type tween_type, |
+ ui::ImplicitAnimationObserver* observer) { |
+ ui::Layer* layer = window->layer(); |
+ ui::ScopedLayerAnimationSettings settings(layer->GetAnimator()); |
+ settings.SetTransitionDuration( |
+ base::TimeDelta::FromMilliseconds(duration_ms)); |
+ settings.SetTweenType(tween_type); |
+ settings.SetPreemptionStrategy( |
+ ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
+ if (observer) |
+ settings.AddObserver(observer); |
+ |
+ layer->SetLayerBrightness(target); |
+ layer->SetLayerGrayscale(target); |
+} |
+ |
+} // namespace |
+ |
+ScreenAnimatorImpl::ScreenAnimatorImpl(aura::Window* root_window) |
+ : root_window_(root_window) { |
+} |
+ |
+ScreenAnimatorImpl::~ScreenAnimatorImpl() { |
+} |
+ |
+void ScreenAnimatorImpl::StartAnimation( |
+ AnimationType type, |
+ ui::ImplicitAnimationObserver* observer) { |
+ switch (type) { |
+ case ANIMATION_SHUTDOWN: |
+ StartGrayscaleAndBrightnessAnimation(root_window_, |
+ 1.0f, |
+ kShutdownDurationMs, |
+ gfx::Tween::EASE_IN, |
+ observer); |
+ break; |
+ case ANIMATION_CANCEL_SHUTDOWN: |
+ StartGrayscaleAndBrightnessAnimation(root_window_, |
+ 0.0f, |
+ kCancelShutdownDurationMs, |
+ gfx::Tween::EASE_IN_OUT, |
+ observer); |
+ break; |
+ } |
+} |
+ |
+} // namespace athena |