Commit 40fe028f authored by pkotwicz@chromium.org's avatar pkotwicz@chromium.org

Add fade to white animation when power button is pressed on Athena

BUG=398935
TEST=Manual, see bug
R=oshima
TBR=sky (For addition of DEPS to athena/system)

Review URL: https://codereview.chromium.org/451753002

Cr-Commit-Position: refs/heads/master@{#288482}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288482 0039d316-1c4b-4281-b951-d872f2087c98
parent 661ced98
...@@ -17,6 +17,10 @@ namespace gfx { ...@@ -17,6 +17,10 @@ namespace gfx {
class ImageSkia; class ImageSkia;
} }
namespace ui {
class LayerAnimator;
}
namespace wm { namespace wm {
class FocusRules; class FocusRules;
} }
...@@ -64,6 +68,10 @@ class ATHENA_EXPORT ScreenManager { ...@@ -64,6 +68,10 @@ class ATHENA_EXPORT ScreenManager {
// Sets the background image. // Sets the background image.
virtual void SetBackgroundImage(const gfx::ImageSkia& image) = 0; virtual void SetBackgroundImage(const gfx::ImageSkia& image) = 0;
// Returns the LayerAnimator to use to animate the entire screen (e.g. fade
// screen to white).
virtual ui::LayerAnimator* GetScreenAnimator() = 0;
// Create a focus rules. // Create a focus rules.
// TODO(oshima): Make this virtual function. // TODO(oshima): Make this virtual function.
static wm::FocusRules* CreateFocusRules(); static wm::FocusRules* CreateFocusRules();
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "ui/aura/window_property.h" #include "ui/aura/window_property.h"
#include "ui/aura/window_targeter.h" #include "ui/aura/window_targeter.h"
#include "ui/aura/window_tree_host.h" #include "ui/aura/window_tree_host.h"
#include "ui/compositor/layer.h"
#include "ui/wm/core/base_focus_rules.h" #include "ui/wm/core/base_focus_rules.h"
#include "ui/wm/core/capture_controller.h" #include "ui/wm/core/capture_controller.h"
...@@ -199,6 +200,7 @@ class ScreenManagerImpl : public ScreenManager { ...@@ -199,6 +200,7 @@ class ScreenManagerImpl : public ScreenManager {
virtual aura::Window* CreateContainer(const ContainerParams& params) OVERRIDE; virtual aura::Window* CreateContainer(const ContainerParams& params) OVERRIDE;
virtual aura::Window* GetContext() OVERRIDE { return root_window_; } virtual aura::Window* GetContext() OVERRIDE { return root_window_; }
virtual void SetBackgroundImage(const gfx::ImageSkia& image) OVERRIDE; virtual void SetBackgroundImage(const gfx::ImageSkia& image) OVERRIDE;
virtual ui::LayerAnimator* GetScreenAnimator() OVERRIDE;
aura::Window* root_window_; aura::Window* root_window_;
aura::Window* background_window_; aura::Window* background_window_;
...@@ -322,6 +324,10 @@ void ScreenManagerImpl::SetBackgroundImage(const gfx::ImageSkia& image) { ...@@ -322,6 +324,10 @@ void ScreenManagerImpl::SetBackgroundImage(const gfx::ImageSkia& image) {
background_controller_->SetImage(image); background_controller_->SetImage(image);
} }
ui::LayerAnimator* ScreenManagerImpl::GetScreenAnimator() {
return root_window_->layer()->GetAnimator();
}
} // namespace } // namespace
ScreenManager::ContainerParams::ContainerParams(const std::string& n, ScreenManager::ContainerParams::ContainerParams(const std::string& n,
......
include_rules = [ include_rules = [
"+athena/screen/public",
"+athena/system/public", "+athena/system/public",
"+chromeos/dbus", "+chromeos/dbus",
"+ui",
] ]
...@@ -4,13 +4,25 @@ ...@@ -4,13 +4,25 @@
#include "athena/system/power_button_controller.h" #include "athena/system/power_button_controller.h"
#include "athena/screen/public/screen_manager.h"
#include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/dbus_thread_manager.h"
#include "ui/compositor/layer_animator.h"
#include "ui/compositor/scoped_layer_animation_settings.h"
namespace athena { namespace athena {
namespace {
// Duration of the shutdown animation.
const int kShutdownDurationMs = 1000;
// Duration of the cancel shutdown animation.
const int kCancelShutdownDurationMs = 500;
} // namespace
PowerButtonController::PowerButtonController() PowerButtonController::PowerButtonController()
: brightness_is_zero_(false), : brightness_is_zero_(false),
shutdown_requested_(false) { state_(STATE_OTHER) {
chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver( chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(
this); this);
} }
...@@ -20,6 +32,23 @@ PowerButtonController::~PowerButtonController() { ...@@ -20,6 +32,23 @@ PowerButtonController::~PowerButtonController() {
this); this);
} }
void PowerButtonController::StartGrayscaleAndBrightnessAnimation(
float target,
int duration_ms,
gfx::Tween::Type tween_type) {
ui::LayerAnimator* animator = ScreenManager::Get()->GetScreenAnimator();
ui::ScopedLayerAnimationSettings settings(animator);
settings.SetTransitionDuration(
base::TimeDelta::FromMilliseconds(duration_ms));
settings.SetTweenType(tween_type);
settings.SetPreemptionStrategy(
ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
settings.AddObserver(this);
animator->SetBrightness(target);
animator->SetGrayscale(target);
}
void PowerButtonController::BrightnessChanged(int level, bool user_initiated) { void PowerButtonController::BrightnessChanged(int level, bool user_initiated) {
if (brightness_is_zero_) if (brightness_is_zero_)
zero_brightness_end_time_ = base::TimeTicks::Now(); zero_brightness_end_time_ = base::TimeTicks::Now();
...@@ -28,7 +57,7 @@ void PowerButtonController::BrightnessChanged(int level, bool user_initiated) { ...@@ -28,7 +57,7 @@ void PowerButtonController::BrightnessChanged(int level, bool user_initiated) {
void PowerButtonController::PowerButtonEventReceived( void PowerButtonController::PowerButtonEventReceived(
bool down, bool down,
const base::TimeTicks& details) { const base::TimeTicks& timestamp) {
// Avoid requesting a shutdown if the power button is pressed while the screen // Avoid requesting a shutdown if the power button is pressed while the screen
// is off (http://crbug.com/128451) // is off (http://crbug.com/128451)
base::TimeDelta time_since_zero_brightness = brightness_is_zero_ ? base::TimeDelta time_since_zero_brightness = brightness_is_zero_ ?
...@@ -37,8 +66,24 @@ void PowerButtonController::PowerButtonEventReceived( ...@@ -37,8 +66,24 @@ void PowerButtonController::PowerButtonEventReceived(
if (time_since_zero_brightness.InMilliseconds() <= kShortTimeMs) if (time_since_zero_brightness.InMilliseconds() <= kShortTimeMs)
return; return;
if (down && !shutdown_requested_) { if (state_ == STATE_SHUTDOWN_REQUESTED)
shutdown_requested_ = true; return;
StopObservingImplicitAnimations();
if (down) {
state_ = STATE_PRE_SHUTDOWN_ANIMATION;
StartGrayscaleAndBrightnessAnimation(
1.0f, kShutdownDurationMs, gfx::Tween::EASE_IN);
} else {
state_ = STATE_OTHER;
StartGrayscaleAndBrightnessAnimation(
0.0f, kCancelShutdownDurationMs, gfx::Tween::EASE_IN_OUT);
}
}
void PowerButtonController::OnImplicitAnimationsCompleted() {
if (state_ == STATE_PRE_SHUTDOWN_ANIMATION) {
state_ = STATE_SHUTDOWN_REQUESTED;
chromeos::DBusThreadManager::Get() chromeos::DBusThreadManager::Get()
->GetPowerManagerClient() ->GetPowerManagerClient()
->RequestShutdown(); ->RequestShutdown();
......
...@@ -5,31 +5,52 @@ ...@@ -5,31 +5,52 @@
#ifndef ATHENA_SYSTEM_POWER_BUTTON_CONTROLLER_H_ #ifndef ATHENA_SYSTEM_POWER_BUTTON_CONTROLLER_H_
#define ATHENA_SYSTEM_POWER_BUTTON_CONTROLLER_H_ #define ATHENA_SYSTEM_POWER_BUTTON_CONTROLLER_H_
#include "base/time/time.h"
#include "chromeos/dbus/power_manager_client.h" #include "chromeos/dbus/power_manager_client.h"
#include "ui/compositor/layer_animation_observer.h"
#include "ui/gfx/animation/tween.h"
namespace athena { namespace athena {
// Shuts down in response to the power button being pressed. // Shuts down in response to the power button being pressed.
class PowerButtonController : public chromeos::PowerManagerClient::Observer { class PowerButtonController : public chromeos::PowerManagerClient::Observer,
public ui::ImplicitAnimationObserver {
public: public:
PowerButtonController(); PowerButtonController();
virtual ~PowerButtonController(); virtual ~PowerButtonController();
private:
enum State {
// The screen is animating prior to shutdown. Shutdown can be canceled.
STATE_PRE_SHUTDOWN_ANIMATION,
// A D-Bus shutdown request has been sent. Shutdown cannot be canceled.
STATE_SHUTDOWN_REQUESTED,
STATE_OTHER
};
// Animates the screen's grayscale and brightness to |target|.
void StartGrayscaleAndBrightnessAnimation(float target,
int duration_ms,
gfx::Tween::Type tween_type);
// chromeos::PowerManagerClient::Observer: // chromeos::PowerManagerClient::Observer:
virtual void BrightnessChanged(int level, bool user_initiated) OVERRIDE; virtual void BrightnessChanged(int level, bool user_initiated) OVERRIDE;
virtual void PowerButtonEventReceived( virtual void PowerButtonEventReceived(
bool down, bool down,
const base::TimeTicks& timestamp) OVERRIDE; const base::TimeTicks& timestamp) OVERRIDE;
private: // ui::ImplicitAnimationObserver:
virtual void OnImplicitAnimationsCompleted() OVERRIDE;
// Whether the screen brightness was reduced to 0%. // Whether the screen brightness was reduced to 0%.
bool brightness_is_zero_; bool brightness_is_zero_;
// The last time at which the screen brightness was 0%. // The last time at which the screen brightness was 0%.
base::TimeTicks zero_brightness_end_time_; base::TimeTicks zero_brightness_end_time_;
// Whether shutdown was requested. State state_;
bool shutdown_requested_;
DISALLOW_COPY_AND_ASSIGN(PowerButtonController); DISALLOW_COPY_AND_ASSIGN(PowerButtonController);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment