OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef ATHENA_SYSTEM_POWER_BUTTON_CONTROLLER_H_ | 5 #ifndef ATHENA_SYSTEM_POWER_BUTTON_CONTROLLER_H_ |
6 #define ATHENA_SYSTEM_POWER_BUTTON_CONTROLLER_H_ | 6 #define ATHENA_SYSTEM_POWER_BUTTON_CONTROLLER_H_ |
7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" |
8 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "base/timer/timer.h" |
9 #include "chromeos/dbus/power_manager_client.h" | 11 #include "chromeos/dbus/power_manager_client.h" |
10 #include "ui/compositor/layer_animation_observer.h" | 12 |
11 #include "ui/gfx/animation/tween.h" | 13 namespace aura { |
| 14 class Window; |
| 15 } |
| 16 |
| 17 namespace views { |
| 18 class Widget; |
| 19 } |
12 | 20 |
13 namespace athena { | 21 namespace athena { |
14 | 22 |
15 // Shuts down in response to the power button being pressed. | 23 // Shuts down in response to the power button being pressed. |
16 class PowerButtonController : public chromeos::PowerManagerClient::Observer, | 24 class PowerButtonController : public chromeos::PowerManagerClient::Observer { |
17 public ui::ImplicitAnimationObserver { | |
18 public: | 25 public: |
19 PowerButtonController(); | 26 explicit PowerButtonController(aura::Window* dialog_container); |
20 virtual ~PowerButtonController(); | 27 virtual ~PowerButtonController(); |
21 | 28 |
22 private: | 29 private: |
23 enum State { | 30 enum State { |
24 // The screen is animating prior to shutdown. Shutdown can be canceled. | 31 // A suspend request will be sent when the power button is released. |
25 STATE_PRE_SHUTDOWN_ANIMATION, | 32 STATE_SUSPEND_ON_RELEASE, |
26 | 33 |
27 // A D-Bus shutdown request has been sent. Shutdown cannot be canceled. | 34 // A D-Bus shutdown request has been sent. Shutdown cannot be canceled. |
28 STATE_SHUTDOWN_REQUESTED, | 35 STATE_SHUTDOWN_REQUESTED, |
29 | 36 |
30 STATE_OTHER | 37 STATE_OTHER |
31 }; | 38 }; |
32 | 39 |
33 // Animates the screen's grayscale and brightness to |target|. | 40 // Shows the shutdown warning dialog. |
34 void StartGrayscaleAndBrightnessAnimation(float target, | 41 void ShowShutdownWarningDialog(); |
35 int duration_ms, | 42 |
36 gfx::Tween::Type tween_type); | 43 // Requests shutdown. |
| 44 void Shutdown(); |
37 | 45 |
38 // chromeos::PowerManagerClient::Observer: | 46 // chromeos::PowerManagerClient::Observer: |
39 virtual void BrightnessChanged(int level, bool user_initiated) OVERRIDE; | 47 virtual void BrightnessChanged(int level, bool user_initiated) OVERRIDE; |
40 virtual void PowerButtonEventReceived( | 48 virtual void PowerButtonEventReceived( |
41 bool down, | 49 bool down, |
42 const base::TimeTicks& timestamp) OVERRIDE; | 50 const base::TimeTicks& timestamp) OVERRIDE; |
43 | 51 |
44 // ui::ImplicitAnimationObserver: | 52 // Parent container that |shutdown_warning_message_| should use. |
45 virtual void OnImplicitAnimationsCompleted() OVERRIDE; | 53 aura::Window* warning_message_container_; |
| 54 |
| 55 // Shows a warning that the device is about to be shut down. |
| 56 scoped_ptr<views::Widget> shutdown_warning_message_; |
46 | 57 |
47 // Whether the screen brightness was reduced to 0%. | 58 // Whether the screen brightness was reduced to 0%. |
48 bool brightness_is_zero_; | 59 bool brightness_is_zero_; |
49 | 60 |
50 // The last time at which the screen brightness was 0%. | 61 // The last time at which the screen brightness was 0%. |
51 base::TimeTicks zero_brightness_end_time_; | 62 base::TimeTicks zero_brightness_end_time_; |
52 | 63 |
53 State state_; | 64 State state_; |
54 | 65 |
| 66 base::OneShotTimer<PowerButtonController> timer_; |
| 67 |
55 DISALLOW_COPY_AND_ASSIGN(PowerButtonController); | 68 DISALLOW_COPY_AND_ASSIGN(PowerButtonController); |
56 }; | 69 }; |
57 | 70 |
58 } // namespace athena | 71 } // namespace athena |
59 | 72 |
60 #endif // ATHENA_SYSTEM_POWER_BUTTON_CONTROLLER_H_ | 73 #endif // ATHENA_SYSTEM_POWER_BUTTON_CONTROLLER_H_ |
OLD | NEW |