Index: athena/system/power_button_controller.cc |
diff --git a/athena/system/power_button_controller.cc b/athena/system/power_button_controller.cc |
index c54ca46419af9bc7481d2a02ec9f42e08ee8942d..bd455ab3843087614e830c0518d771b4e6320bb5 100644 |
--- a/athena/system/power_button_controller.cc |
+++ b/athena/system/power_button_controller.cc |
@@ -4,13 +4,36 @@ |
#include "athena/system/power_button_controller.h" |
+#include "athena/screen/public/screen_manager.h" |
+#include "base/bind.h" |
+#include "base/message_loop/message_loop.h" |
#include "chromeos/dbus/dbus_thread_manager.h" |
+#include "ui/aura/window.h" |
+#include "ui/compositor/layer.h" |
+#include "ui/compositor/scoped_layer_animation_settings.h" |
+#include "ui/gfx/animation/tween.h" |
namespace athena { |
+namespace { |
+ |
+// Duration of the animation prior to shutdown. |
+const int kPreShutdownDurationMs = 1000; |
+ |
+// Duration of the animation when shutdown is canceled. |
+const int kCancelShutdownDurationMs = 500; |
+ |
+// Additional time (beyond kPreShutdownDurationMs) to wait after starting |
+// the pre-shutdown animation before actually shutting down to give time for the |
+// last frame of the animation to get painted. |
+const int kShutdownRequestDelayMs = 50; |
+ |
+} // namespace |
+ |
PowerButtonController::PowerButtonController() |
: brightness_is_zero_(false), |
- shutdown_requested_(false) { |
+ shutdown_requested_(false), |
+ can_cancel_shutdown_(true) { |
chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver( |
this); |
} |
@@ -20,6 +43,29 @@ PowerButtonController::~PowerButtonController() { |
this); |
} |
+void PowerButtonController::StartGrayscaleAndBrightnessAnimation( |
+ float target, |
+ int duration_ms, |
+ gfx::Tween::Type tween_type) { |
+ ui::Layer* layer = |
+ ScreenManager::Get()->GetContext()->GetRootWindow()->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); |
+ settings.AddObserver(this); |
+ layer->SetLayerBrightness(target); |
+ layer->SetLayerGrayscale(target); |
flackr
2014/08/07 18:23:31
Defer to oshima, but I suspect we'll want these an
oshima
2014/08/07 19:53:38
I'm actually fine to implement the animation itsel
|
+} |
+ |
+void PowerButtonController::Shutdown() { |
+ chromeos::DBusThreadManager::Get() |
+ ->GetPowerManagerClient() |
+ ->RequestShutdown(); |
+} |
+ |
void PowerButtonController::BrightnessChanged(int level, bool user_initiated) { |
if (brightness_is_zero_) |
zero_brightness_end_time_ = base::TimeTicks::Now(); |
@@ -28,7 +74,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,11 +83,27 @@ void PowerButtonController::PowerButtonEventReceived( |
if (time_since_zero_brightness.InMilliseconds() <= kShortTimeMs) |
return; |
- if (down && !shutdown_requested_) { |
- shutdown_requested_ = true; |
- chromeos::DBusThreadManager::Get() |
- ->GetPowerManagerClient() |
- ->RequestShutdown(); |
+ if (!can_cancel_shutdown_) |
flackr
2014/08/07 18:23:31
Seems a bit arbitrary to no longer allow canceling
oshima
2014/08/07 19:53:38
can we use state enum rather than multiple boolean
|
+ return; |
+ |
+ StopObservingImplicitAnimations(); |
+ shutdown_requested_ = down; |
+ if (shutdown_requested_) { |
+ StartGrayscaleAndBrightnessAnimation( |
+ 1.0f, kPreShutdownDurationMs, gfx::Tween::EASE_IN); |
+ } else { |
+ StartGrayscaleAndBrightnessAnimation( |
+ 0.0f, kCancelShutdownDurationMs, gfx::Tween::EASE_IN_OUT); |
+ } |
+} |
+ |
+void PowerButtonController::OnImplicitAnimationsCompleted() { |
+ if (shutdown_requested_) { |
+ can_cancel_shutdown_ = false; |
+ base::MessageLoopForUI::current()->PostDelayedTask( |
+ FROM_HERE, |
+ base::Bind(&PowerButtonController::Shutdown, base::Unretained(this)), |
+ base::TimeDelta::FromMilliseconds(kShutdownRequestDelayMs)); |
} |
} |