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 {
class ImageSkia;
}
namespace ui {
class LayerAnimator;
}
namespace wm {
class FocusRules;
}
......@@ -64,6 +68,10 @@ class ATHENA_EXPORT ScreenManager {
// Sets the background image.
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.
// TODO(oshima): Make this virtual function.
static wm::FocusRules* CreateFocusRules();
......
......@@ -18,6 +18,7 @@
#include "ui/aura/window_property.h"
#include "ui/aura/window_targeter.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/capture_controller.h"
......@@ -199,6 +200,7 @@ class ScreenManagerImpl : public ScreenManager {
virtual aura::Window* CreateContainer(const ContainerParams& params) OVERRIDE;
virtual aura::Window* GetContext() OVERRIDE { return root_window_; }
virtual void SetBackgroundImage(const gfx::ImageSkia& image) OVERRIDE;
virtual ui::LayerAnimator* GetScreenAnimator() OVERRIDE;
aura::Window* root_window_;
aura::Window* background_window_;
......@@ -322,6 +324,10 @@ void ScreenManagerImpl::SetBackgroundImage(const gfx::ImageSkia& image) {
background_controller_->SetImage(image);
}
ui::LayerAnimator* ScreenManagerImpl::GetScreenAnimator() {
return root_window_->layer()->GetAnimator();
}
} // namespace
ScreenManager::ContainerParams::ContainerParams(const std::string& n,
......
include_rules = [
"+athena/screen/public",
"+athena/system/public",
"+chromeos/dbus",
"+ui",
]
......@@ -4,13 +4,25 @@
#include "athena/system/power_button_controller.h"
#include "athena/screen/public/screen_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 {
// Duration of the shutdown animation.
const int kShutdownDurationMs = 1000;
// Duration of the cancel shutdown animation.
const int kCancelShutdownDurationMs = 500;
} // namespace
PowerButtonController::PowerButtonController()
: brightness_is_zero_(false),
shutdown_requested_(false) {
state_(STATE_OTHER) {
chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(
this);
}
......@@ -20,6 +32,23 @@ PowerButtonController::~PowerButtonController() {
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) {
if (brightness_is_zero_)
zero_brightness_end_time_ = base::TimeTicks::Now();
......@@ -28,7 +57,7 @@ void PowerButtonController::BrightnessChanged(int level, bool user_initiated) {
void PowerButtonController::PowerButtonEventReceived(
bool down,
const base::TimeTicks& details) {
const base::TimeTicks& timestamp) {
// Avoid requesting a shutdown if the power button is pressed while the screen
// is off (http://crbug.com/128451)
base::TimeDelta time_since_zero_brightness = brightness_is_zero_ ?
......@@ -37,8 +66,24 @@ void PowerButtonController::PowerButtonEventReceived(
if (time_since_zero_brightness.InMilliseconds() <= kShortTimeMs)
return;
if (down && !shutdown_requested_) {
shutdown_requested_ = true;
if (state_ == STATE_SHUTDOWN_REQUESTED)
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()
->GetPowerManagerClient()
->RequestShutdown();
......
......@@ -5,31 +5,52 @@
#ifndef 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 "ui/compositor/layer_animation_observer.h"
#include "ui/gfx/animation/tween.h"
namespace athena {
// 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:
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:
virtual void BrightnessChanged(int level, bool user_initiated) OVERRIDE;
virtual void PowerButtonEventReceived(
bool down,
const base::TimeTicks& timestamp) OVERRIDE;
private:
// ui::ImplicitAnimationObserver:
virtual void OnImplicitAnimationsCompleted() OVERRIDE;
// Whether the screen brightness was reduced to 0%.
bool brightness_is_zero_;
// The last time at which the screen brightness was 0%.
base::TimeTicks zero_brightness_end_time_;
// Whether shutdown was requested.
bool shutdown_requested_;
State state_;
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