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 #include "athena/system/power_button_controller.h" | 5 #include "athena/system/power_button_controller.h" |
6 | 6 |
7 #include "athena/screen/public/screen_manager.h" | |
7 #include "chromeos/dbus/dbus_thread_manager.h" | 8 #include "chromeos/dbus/dbus_thread_manager.h" |
9 #include "ui/compositor/layer_animator.h" | |
10 #include "ui/compositor/scoped_layer_animation_settings.h" | |
8 | 11 |
9 namespace athena { | 12 namespace athena { |
13 namespace { | |
14 | |
15 // Duration of the shutdown animation. | |
16 const int kShutdownDurationMs = 1000; | |
17 | |
18 // Duration of the cancel shutdown animation. | |
19 const int kCancelShutdownDurationMs = 500; | |
20 | |
21 } // namespace | |
10 | 22 |
11 PowerButtonController::PowerButtonController() | 23 PowerButtonController::PowerButtonController() |
12 : brightness_is_zero_(false), | 24 : brightness_is_zero_(false), |
13 shutdown_requested_(false) { | 25 state_(STATE_OTHER) { |
14 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver( | 26 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver( |
15 this); | 27 this); |
16 } | 28 } |
17 | 29 |
18 PowerButtonController::~PowerButtonController() { | 30 PowerButtonController::~PowerButtonController() { |
19 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver( | 31 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver( |
20 this); | 32 this); |
21 } | 33 } |
22 | 34 |
35 void PowerButtonController::StartGrayscaleAndBrightnessAnimation( | |
36 float target, | |
37 int duration_ms, | |
38 gfx::Tween::Type tween_type) { | |
39 ui::LayerAnimator* animator = ScreenManager::Get()->GetScreenAnimator(); | |
40 ui::ScopedLayerAnimationSettings settings(animator); | |
41 settings.SetTransitionDuration( | |
42 base::TimeDelta::FromMilliseconds(duration_ms)); | |
43 settings.SetTweenType(tween_type); | |
44 settings.SetPreemptionStrategy( | |
45 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
46 settings.AddObserver(this); | |
47 | |
48 animator->SetBrightness(target); | |
49 animator->SetGrayscale(target); | |
oshima
2014/08/08 20:36:52
FYI: I'll probably move this out to somewhere, but
| |
50 } | |
51 | |
23 void PowerButtonController::BrightnessChanged(int level, bool user_initiated) { | 52 void PowerButtonController::BrightnessChanged(int level, bool user_initiated) { |
24 if (brightness_is_zero_) | 53 if (brightness_is_zero_) |
25 zero_brightness_end_time_ = base::TimeTicks::Now(); | 54 zero_brightness_end_time_ = base::TimeTicks::Now(); |
26 brightness_is_zero_ = (level == 0); | 55 brightness_is_zero_ = (level == 0); |
27 } | 56 } |
28 | 57 |
29 void PowerButtonController::PowerButtonEventReceived( | 58 void PowerButtonController::PowerButtonEventReceived( |
30 bool down, | 59 bool down, |
31 const base::TimeTicks& details) { | 60 const base::TimeTicks& timestamp) { |
32 // Avoid requesting a shutdown if the power button is pressed while the screen | 61 // Avoid requesting a shutdown if the power button is pressed while the screen |
33 // is off (http://crbug.com/128451) | 62 // is off (http://crbug.com/128451) |
34 base::TimeDelta time_since_zero_brightness = brightness_is_zero_ ? | 63 base::TimeDelta time_since_zero_brightness = brightness_is_zero_ ? |
35 base::TimeDelta() : (base::TimeTicks::Now() - zero_brightness_end_time_); | 64 base::TimeDelta() : (base::TimeTicks::Now() - zero_brightness_end_time_); |
36 const int kShortTimeMs = 10; | 65 const int kShortTimeMs = 10; |
37 if (time_since_zero_brightness.InMilliseconds() <= kShortTimeMs) | 66 if (time_since_zero_brightness.InMilliseconds() <= kShortTimeMs) |
38 return; | 67 return; |
39 | 68 |
40 if (down && !shutdown_requested_) { | 69 if (state_ == STATE_SHUTDOWN_REQUESTED) |
41 shutdown_requested_ = true; | 70 return; |
71 | |
72 StopObservingImplicitAnimations(); | |
73 if (down) { | |
74 state_ = STATE_PRE_SHUTDOWN_ANIMATION; | |
75 StartGrayscaleAndBrightnessAnimation( | |
76 1.0f, kShutdownDurationMs, gfx::Tween::EASE_IN); | |
77 } else { | |
78 state_ = STATE_OTHER; | |
79 StartGrayscaleAndBrightnessAnimation( | |
80 0.0f, kCancelShutdownDurationMs, gfx::Tween::EASE_IN_OUT); | |
81 } | |
82 } | |
83 | |
84 void PowerButtonController::OnImplicitAnimationsCompleted() { | |
85 if (state_ == STATE_PRE_SHUTDOWN_ANIMATION) { | |
86 state_ = STATE_SHUTDOWN_REQUESTED; | |
42 chromeos::DBusThreadManager::Get() | 87 chromeos::DBusThreadManager::Get() |
43 ->GetPowerManagerClient() | 88 ->GetPowerManagerClient() |
44 ->RequestShutdown(); | 89 ->RequestShutdown(); |
45 } | 90 } |
46 } | 91 } |
47 | 92 |
48 } // namespace athena | 93 } // namespace athena |
OLD | NEW |