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/power/tablet_power_button_controller.h" | 5 #include "ash/system/power/tablet_power_button_controller.h" |
6 | 6 |
7 #include "ash/accessibility_delegate.h" | 7 #include "ash/accessibility_delegate.h" |
8 #include "ash/session/session_controller.h" | 8 #include "ash/session/session_controller.h" |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/shell_delegate.h" | 10 #include "ash/shell_delegate.h" |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 | 213 |
214 void TabletPowerButtonController::SetDisplayForcedOff(bool forced_off) { | 214 void TabletPowerButtonController::SetDisplayForcedOff(bool forced_off) { |
215 if (backlights_forced_off_ == forced_off) | 215 if (backlights_forced_off_ == forced_off) |
216 return; | 216 return; |
217 | 217 |
218 // Set the display and keyboard backlights (if present) to |forced_off|. | 218 // Set the display and keyboard backlights (if present) to |forced_off|. |
219 chromeos::DBusThreadManager::Get() | 219 chromeos::DBusThreadManager::Get() |
220 ->GetPowerManagerClient() | 220 ->GetPowerManagerClient() |
221 ->SetBacklightsForcedOff(forced_off); | 221 ->SetBacklightsForcedOff(forced_off); |
222 backlights_forced_off_ = forced_off; | 222 backlights_forced_off_ = forced_off; |
223 | 223 UpdateTouchscreenStatus(); |
224 ShellDelegate* delegate = Shell::Get()->shell_delegate(); | |
225 delegate->SetTouchscreenEnabledInPrefs(!forced_off, | |
226 true /* use_local_state */); | |
227 delegate->UpdateTouchscreenStatusFromPrefs(); | |
228 | 224 |
229 // Send an a11y alert. | 225 // Send an a11y alert. |
230 Shell::Get()->accessibility_delegate()->TriggerAccessibilityAlert( | 226 Shell::Get()->accessibility_delegate()->TriggerAccessibilityAlert( |
231 forced_off ? A11Y_ALERT_SCREEN_OFF : A11Y_ALERT_SCREEN_ON); | 227 forced_off ? A11Y_ALERT_SCREEN_OFF : A11Y_ALERT_SCREEN_ON); |
232 } | 228 } |
233 | 229 |
234 void TabletPowerButtonController::GetInitialBacklightsForcedOff() { | 230 void TabletPowerButtonController::GetInitialBacklightsForcedOff() { |
235 chromeos::DBusThreadManager::Get() | 231 chromeos::DBusThreadManager::Get() |
236 ->GetPowerManagerClient() | 232 ->GetPowerManagerClient() |
237 ->GetBacklightsForcedOff(base::Bind( | 233 ->GetBacklightsForcedOff(base::Bind( |
238 &TabletPowerButtonController::OnGotInitialBacklightsForcedOff, | 234 &TabletPowerButtonController::OnGotInitialBacklightsForcedOff, |
239 weak_ptr_factory_.GetWeakPtr())); | 235 weak_ptr_factory_.GetWeakPtr())); |
240 } | 236 } |
241 | 237 |
242 void TabletPowerButtonController::OnGotInitialBacklightsForcedOff( | 238 void TabletPowerButtonController::OnGotInitialBacklightsForcedOff( |
243 bool is_forced_off) { | 239 bool is_forced_off) { |
244 backlights_forced_off_ = is_forced_off; | 240 backlights_forced_off_ = is_forced_off; |
| 241 UpdateTouchscreenStatus(); |
| 242 } |
| 243 |
| 244 void TabletPowerButtonController::UpdateTouchscreenStatus() { |
| 245 ShellDelegate* delegate = Shell::Get()->shell_delegate(); |
| 246 delegate->SetTouchscreenEnabledInPrefs(!backlights_forced_off_, |
| 247 true /* use_local_state */); |
| 248 delegate->UpdateTouchscreenStatusFromPrefs(); |
245 } | 249 } |
246 | 250 |
247 void TabletPowerButtonController::StartShutdownTimer() { | 251 void TabletPowerButtonController::StartShutdownTimer() { |
248 base::TimeDelta timeout = base::TimeDelta::FromMilliseconds( | 252 base::TimeDelta timeout = base::TimeDelta::FromMilliseconds( |
249 screen_off_when_power_button_down_ ? kShutdownWhenScreenOffTimeoutMs | 253 screen_off_when_power_button_down_ ? kShutdownWhenScreenOffTimeoutMs |
250 : kShutdownWhenScreenOnTimeoutMs); | 254 : kShutdownWhenScreenOnTimeoutMs); |
251 shutdown_timer_.Start(FROM_HERE, timeout, this, | 255 shutdown_timer_.Start(FROM_HERE, timeout, this, |
252 &TabletPowerButtonController::OnShutdownTimeout); | 256 &TabletPowerButtonController::OnShutdownTimeout); |
253 } | 257 } |
254 | 258 |
255 void TabletPowerButtonController::OnShutdownTimeout() { | 259 void TabletPowerButtonController::OnShutdownTimeout() { |
256 controller_->StartShutdownAnimation(); | 260 controller_->StartShutdownAnimation(); |
257 } | 261 } |
258 | 262 |
259 void TabletPowerButtonController::LockScreenIfRequired() { | 263 void TabletPowerButtonController::LockScreenIfRequired() { |
260 SessionController* session_controller = Shell::Get()->session_controller(); | 264 SessionController* session_controller = Shell::Get()->session_controller(); |
261 if (session_controller->ShouldLockScreenAutomatically() && | 265 if (session_controller->ShouldLockScreenAutomatically() && |
262 session_controller->CanLockScreen() && | 266 session_controller->CanLockScreen() && |
263 !session_controller->IsUserSessionBlocked() && | 267 !session_controller->IsUserSessionBlocked() && |
264 !controller_->LockRequested()) { | 268 !controller_->LockRequested()) { |
265 session_controller->LockScreen(); | 269 session_controller->LockScreen(); |
266 } | 270 } |
267 } | 271 } |
268 | 272 |
269 } // namespace ash | 273 } // namespace ash |
OLD | NEW |