Chromium Code Reviews| 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..e1c3f550816853b9a8b9092bf2eea58472251cb8 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 pressed 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 pressed 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,45 @@ 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() { |
|
flackr
2014/09/19 14:45:29
I think when this shows we should no longer suspen
|
| + 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 pressing power button to shutdown.")); |
|
flackr
2014/09/19 14:45:29
nit s/pressing/holding
|
| + 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 +90,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 +101,22 @@ void PowerButtonController::PowerButtonEventReceived( |
| if (state_ == STATE_SHUTDOWN_REQUESTED) |
| return; |
| - 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(); |
| } |
| } |