Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1805)

Unified Diff: athena/system/power_button_controller.cc

Issue 585623003: [Athena] Make a quick power button tap suspend the device (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: athena/system/power_button_controller.cc
diff --git a/athena/system/power_button_controller.cc b/athena/system/power_button_controller.cc
index b4195a3061a080c7ea01b60c68061beec61dfa74..8c125957d83fb8367ff936a14baed6ba0b77ff4e 100644
--- a/athena/system/power_button_controller.cc
+++ b/athena/system/power_button_controller.cc
@@ -5,23 +5,31 @@
#include "athena/system/power_button_controller.h"
#include "athena/screen/public/screen_manager.h"
+#include "base/strings/utf_string_conversions.h"
#include "chromeos/dbus/dbus_thread_manager.h"
-#include "ui/compositor/layer_animator.h"
-#include "ui/compositor/scoped_layer_animation_settings.h"
+#include "ui/gfx/font_list.h"
+#include "ui/views/background.h"
+#include "ui/views/border.h"
+#include "ui/views/controls/label.h"
+#include "ui/views/layout/box_layout.h"
+#include "ui/views/widget/widget.h"
namespace athena {
namespace {
-// Duration of the shutdown animation.
-const int kShutdownDurationMs = 1000;
+// The amount of time that the power button must be held to show the shutdown
+// warning dialog.
+const int kShowShutdownWarningTimeoutMs = 1000;
-// Duration of the cancel shutdown animation.
-const int kCancelShutdownDurationMs = 500;
+// The amount of time that the power button must be held to shut down the
+// device.
+const int kShutdownTimeoutMs = 5000;
} // namespace
-PowerButtonController::PowerButtonController()
- : brightness_is_zero_(false),
+PowerButtonController::PowerButtonController(aura::Window* dialog_container)
+ : warning_message_container_(dialog_container),
+ brightness_is_zero_(false),
state_(STATE_OTHER) {
chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(
this);
@@ -32,21 +40,47 @@ 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::ShowShutdownWarningDialog() {
+ state_ = STATE_SHUTDOWN_WARNING_VISIBLE;
+
+ shutdown_warning_message_.reset(new views::Widget);
+
+ views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
+ params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
+ params.parent = warning_message_container_;
+ shutdown_warning_message_->Init(params);
+
+ views::Label* label = new views::Label(
+ base::UTF8ToUTF16("Keep holding power button to shutdown."));
oshima 2014/09/22 17:20:19 TODO to use IDS
+ label->SetBackgroundColor(SK_ColorWHITE);
+ label->SetFontList(gfx::FontList().DeriveWithStyle(gfx::Font::BOLD));
+
+ views::View* container = new views::View;
+ container->AddChildView(label);
+
+ const int kBorderSpacing = 50;
+ container->SetLayoutManager(new views::BoxLayout(
+ views::BoxLayout::kHorizontal, kBorderSpacing, kBorderSpacing, 0));
+ container->set_background(
+ views::Background::CreateSolidBackground(SK_ColorWHITE));
+ container->SetBorder(views::Border::CreateSolidBorder(1, SK_ColorBLACK));
+
+ shutdown_warning_message_->SetContentsView(container);
+ shutdown_warning_message_->CenterWindow(container->GetPreferredSize());
+ shutdown_warning_message_->Show();
+
+ timer_.Start(FROM_HERE,
+ base::TimeDelta::FromMilliseconds(kShutdownTimeoutMs -
+ kShowShutdownWarningTimeoutMs),
+ this,
+ &PowerButtonController::Shutdown);
+}
+
+void PowerButtonController::Shutdown() {
+ state_ = STATE_SHUTDOWN_REQUESTED;
+ chromeos::DBusThreadManager::Get()
+ ->GetPowerManagerClient()
+ ->RequestShutdown();
}
void PowerButtonController::BrightnessChanged(int level, bool user_initiated) {
@@ -58,8 +92,8 @@ void PowerButtonController::BrightnessChanged(int level, bool user_initiated) {
void PowerButtonController::PowerButtonEventReceived(
bool down,
const base::TimeTicks& timestamp) {
- // Avoid requesting a shutdown if the power button is pressed while the screen
- // is off (http://crbug.com/128451)
+ // Avoid requesting suspend or 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_ ?
base::TimeDelta() : (base::TimeTicks::Now() - zero_brightness_end_time_);
const int kShortTimeMs = 10;
@@ -69,24 +103,22 @@ void PowerButtonController::PowerButtonEventReceived(
if (state_ == STATE_SHUTDOWN_REQUESTED)
return;
oshima 2014/09/22 17:20:18 can you move this to the top of the method?
- StopObservingImplicitAnimations();
if (down) {
- state_ = STATE_PRE_SHUTDOWN_ANIMATION;
- StartGrayscaleAndBrightnessAnimation(
- 1.0f, kShutdownDurationMs, gfx::Tween::EASE_IN);
+ state_ = STATE_SUSPEND_ON_RELEASE;
+ timer_.Start(
+ FROM_HERE,
+ base::TimeDelta::FromMilliseconds(kShowShutdownWarningTimeoutMs),
+ this,
+ &PowerButtonController::ShowShutdownWarningDialog);
} else {
+ if (state_ == STATE_SUSPEND_ON_RELEASE) {
+ chromeos::DBusThreadManager::Get()
+ ->GetPowerManagerClient()
+ ->RequestSuspend();
+ }
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();
+ timer_.Stop();
+ shutdown_warning_message_.reset();
}
}

Powered by Google App Engine
This is Rietveld 408576698