OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ash/system/chromeos/power/tablet_power_button_controller.h" | 5 #include "ash/system/chromeos/power/tablet_power_button_controller.h" |
6 | 6 |
7 #include "ash/common/accessibility_delegate.h" | 7 #include "ash/common/accessibility_delegate.h" |
8 #include "ash/common/session/session_state_delegate.h" | 8 #include "ash/common/session/session_state_delegate.h" |
9 #include "ash/common/shell_delegate.h" | 9 #include "ash/common/shell_delegate.h" |
10 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" | 10 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
11 #include "ash/common/wm_shell.h" | 11 #include "ash/common/wm_shell.h" |
12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
13 #include "ash/wm/lock_state_controller.h" | 13 #include "ash/wm/lock_state_controller.h" |
14 #include "base/time/default_tick_clock.h" | 14 #include "base/time/default_tick_clock.h" |
15 #include "chromeos/dbus/dbus_thread_manager.h" | 15 #include "chromeos/dbus/dbus_thread_manager.h" |
16 #include "ui/events/devices/input_device_manager.h" | 16 #include "ui/events/devices/input_device_manager.h" |
17 #include "ui/events/devices/stylus_state.h" | 17 #include "ui/events/devices/stylus_state.h" |
18 #include "ui/events/event.h" | 18 #include "ui/events/event.h" |
19 | 19 |
20 namespace ash { | 20 namespace ash { |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 // Amount of time the power button must be held to start the pre-shutdown | 24 // Amount of time the power button must be held to start the pre-shutdown |
25 // animation when in tablet mode. | 25 // animation when in tablet mode. |
26 constexpr int kShutdownTimeoutMs = 500; | 26 constexpr int kShutdownTimeoutMs = 500; |
27 | 27 |
| 28 // Amount of time to delay locking screen after display is forced off. |
| 29 constexpr int kLockScreenTimeoutMs = 1000; |
| 30 |
28 // Amount of time since last SuspendDone() that power button event needs to be | 31 // Amount of time since last SuspendDone() that power button event needs to be |
29 // ignored. | 32 // ignored. |
30 constexpr int kIgnorePowerButtonAfterResumeMs = 2000; | 33 constexpr int kIgnorePowerButtonAfterResumeMs = 2000; |
31 | 34 |
32 // Returns true if device is a convertible/tablet device or has | 35 // Returns true if device is a convertible/tablet device or has |
33 // kAshEnableTouchViewTesting in test, otherwise false. | 36 // kAshEnableTouchViewTesting in test, otherwise false. |
34 bool IsTabletModeSupported() { | 37 bool IsTabletModeSupported() { |
35 MaximizeModeController* maximize_mode_controller = | 38 MaximizeModeController* maximize_mode_controller = |
36 WmShell::Get()->maximize_mode_controller(); | 39 WmShell::Get()->maximize_mode_controller(); |
37 return maximize_mode_controller && | 40 return maximize_mode_controller && |
(...skipping 19 matching lines...) Expand all Loading... |
57 bool TabletPowerButtonController::TestApi::ShutdownTimerIsRunning() const { | 60 bool TabletPowerButtonController::TestApi::ShutdownTimerIsRunning() const { |
58 return controller_->shutdown_timer_.IsRunning(); | 61 return controller_->shutdown_timer_.IsRunning(); |
59 } | 62 } |
60 | 63 |
61 void TabletPowerButtonController::TestApi::TriggerShutdownTimeout() { | 64 void TabletPowerButtonController::TestApi::TriggerShutdownTimeout() { |
62 DCHECK(ShutdownTimerIsRunning()); | 65 DCHECK(ShutdownTimerIsRunning()); |
63 controller_->OnShutdownTimeout(); | 66 controller_->OnShutdownTimeout(); |
64 controller_->shutdown_timer_.Stop(); | 67 controller_->shutdown_timer_.Stop(); |
65 } | 68 } |
66 | 69 |
| 70 bool TabletPowerButtonController::TestApi::LockScreenTimerIsRunning() const { |
| 71 return controller_->lock_screen_timer_.IsRunning(); |
| 72 } |
| 73 |
| 74 void TabletPowerButtonController::TestApi::TriggerLockScreenTimeout() { |
| 75 DCHECK(LockScreenTimerIsRunning()); |
| 76 controller_->OnLockScreenTimeout(); |
| 77 controller_->lock_screen_timer_.Stop(); |
| 78 } |
| 79 |
67 TabletPowerButtonController::TabletPowerButtonController( | 80 TabletPowerButtonController::TabletPowerButtonController( |
68 LockStateController* controller) | 81 LockStateController* controller) |
69 : tick_clock_(new base::DefaultTickClock()), | 82 : tick_clock_(new base::DefaultTickClock()), |
70 last_resume_time_(base::TimeTicks()), | 83 last_resume_time_(base::TimeTicks()), |
71 force_off_on_button_up_(true), | 84 force_off_on_button_up_(true), |
72 controller_(controller), | 85 controller_(controller), |
73 weak_ptr_factory_(this) { | 86 weak_ptr_factory_(this) { |
74 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver( | 87 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver( |
75 this); | 88 this); |
76 WmShell::Get()->AddShellObserver(this); | 89 WmShell::Get()->AddShellObserver(this); |
(...skipping 24 matching lines...) Expand all Loading... |
101 // Chrome receives powerd's SuspendDone signal and notification that the | 114 // Chrome receives powerd's SuspendDone signal and notification that the |
102 // backlight has been turned back on before seeing the power button events | 115 // backlight has been turned back on before seeing the power button events |
103 // that woke the system. Avoid forcing off display just after resuming to | 116 // that woke the system. Avoid forcing off display just after resuming to |
104 // ensure that we don't turn the display off in response to the events. | 117 // ensure that we don't turn the display off in response to the events. |
105 if (timestamp - last_resume_time_ <= | 118 if (timestamp - last_resume_time_ <= |
106 base::TimeDelta::FromMilliseconds(kIgnorePowerButtonAfterResumeMs)) { | 119 base::TimeDelta::FromMilliseconds(kIgnorePowerButtonAfterResumeMs)) { |
107 force_off_on_button_up_ = false; | 120 force_off_on_button_up_ = false; |
108 } | 121 } |
109 screen_off_when_power_button_down_ = brightness_level_is_zero_; | 122 screen_off_when_power_button_down_ = brightness_level_is_zero_; |
110 SetDisplayForcedOff(false); | 123 SetDisplayForcedOff(false); |
| 124 lock_screen_timer_.Stop(); |
111 StartShutdownTimer(); | 125 StartShutdownTimer(); |
112 } else { | 126 } else { |
113 if (shutdown_timer_.IsRunning()) { | 127 if (shutdown_timer_.IsRunning()) { |
114 shutdown_timer_.Stop(); | 128 shutdown_timer_.Stop(); |
115 if (!screen_off_when_power_button_down_ && force_off_on_button_up_) { | 129 if (!screen_off_when_power_button_down_ && force_off_on_button_up_) { |
116 SetDisplayForcedOff(true); | 130 SetDisplayForcedOff(true); |
117 LockScreenIfRequired(); | 131 LockScreenIfRequired(); |
118 } | 132 } |
119 } | 133 } |
120 | 134 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 if (controller_->CanCancelShutdownAnimation()) | 166 if (controller_->CanCancelShutdownAnimation()) |
153 controller_->CancelShutdownAnimation(); | 167 controller_->CancelShutdownAnimation(); |
154 } | 168 } |
155 | 169 |
156 void TabletPowerButtonController::OnKeyEvent(ui::KeyEvent* event) { | 170 void TabletPowerButtonController::OnKeyEvent(ui::KeyEvent* event) { |
157 // Ignore key events generated by the power button since power button activity | 171 // Ignore key events generated by the power button since power button activity |
158 // is already handled by OnPowerButtonEvent(). | 172 // is already handled by OnPowerButtonEvent(). |
159 if (event->key_code() == ui::VKEY_POWER) | 173 if (event->key_code() == ui::VKEY_POWER) |
160 return; | 174 return; |
161 | 175 |
162 if (!IsTabletModeActive() && backlights_forced_off_) | 176 if (!IsTabletModeActive() && backlights_forced_off_) { |
163 SetDisplayForcedOff(false); | 177 SetDisplayForcedOff(false); |
| 178 lock_screen_timer_.Stop(); |
| 179 } |
164 } | 180 } |
165 | 181 |
166 void TabletPowerButtonController::OnMouseEvent(ui::MouseEvent* event) { | 182 void TabletPowerButtonController::OnMouseEvent(ui::MouseEvent* event) { |
167 if (event->flags() & ui::EF_IS_SYNTHESIZED) | 183 if (event->flags() & ui::EF_IS_SYNTHESIZED) |
168 return; | 184 return; |
169 | 185 |
170 if (!IsTabletModeActive() && backlights_forced_off_) | 186 if (!IsTabletModeActive() && backlights_forced_off_) { |
171 SetDisplayForcedOff(false); | 187 SetDisplayForcedOff(false); |
| 188 lock_screen_timer_.Stop(); |
| 189 } |
172 } | 190 } |
173 | 191 |
174 void TabletPowerButtonController::OnStylusStateChanged(ui::StylusState state) { | 192 void TabletPowerButtonController::OnStylusStateChanged(ui::StylusState state) { |
175 if (IsTabletModeSupported() && state == ui::StylusState::REMOVED && | 193 if (IsTabletModeSupported() && state == ui::StylusState::REMOVED && |
176 backlights_forced_off_) { | 194 backlights_forced_off_) { |
177 SetDisplayForcedOff(false); | 195 SetDisplayForcedOff(false); |
| 196 lock_screen_timer_.Stop(); |
178 } | 197 } |
179 } | 198 } |
180 | 199 |
181 void TabletPowerButtonController::SetTickClockForTesting( | 200 void TabletPowerButtonController::SetTickClockForTesting( |
182 std::unique_ptr<base::TickClock> tick_clock) { | 201 std::unique_ptr<base::TickClock> tick_clock) { |
183 DCHECK(tick_clock); | 202 DCHECK(tick_clock); |
184 tick_clock_ = std::move(tick_clock); | 203 tick_clock_ = std::move(tick_clock); |
185 } | 204 } |
186 | 205 |
187 void TabletPowerButtonController::SetDisplayForcedOff(bool forced_off) { | 206 void TabletPowerButtonController::SetDisplayForcedOff(bool forced_off) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 controller_->StartShutdownAnimation(); | 246 controller_->StartShutdownAnimation(); |
228 } | 247 } |
229 | 248 |
230 void TabletPowerButtonController::LockScreenIfRequired() { | 249 void TabletPowerButtonController::LockScreenIfRequired() { |
231 SessionStateDelegate* session_state_delegate = | 250 SessionStateDelegate* session_state_delegate = |
232 WmShell::Get()->GetSessionStateDelegate(); | 251 WmShell::Get()->GetSessionStateDelegate(); |
233 if (session_state_delegate->ShouldLockScreenAutomatically() && | 252 if (session_state_delegate->ShouldLockScreenAutomatically() && |
234 session_state_delegate->CanLockScreen() && | 253 session_state_delegate->CanLockScreen() && |
235 !session_state_delegate->IsUserSessionBlocked() && | 254 !session_state_delegate->IsUserSessionBlocked() && |
236 !controller_->LockRequested()) { | 255 !controller_->LockRequested()) { |
237 session_state_delegate->LockScreen(); | 256 lock_screen_timer_.Start( |
| 257 FROM_HERE, base::TimeDelta::FromMilliseconds(kLockScreenTimeoutMs), |
| 258 this, &TabletPowerButtonController::OnLockScreenTimeout); |
238 } | 259 } |
239 } | 260 } |
240 | 261 |
| 262 void TabletPowerButtonController::OnLockScreenTimeout() { |
| 263 WmShell::Get()->GetSessionStateDelegate()->LockScreen(); |
| 264 } |
| 265 |
241 } // namespace ash | 266 } // namespace ash |
OLD | NEW |