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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
48 } | 48 } |
49 | 49 |
50 // Returns true if device is currently in tablet/maximize mode, otherwise false. | 50 // Returns true if device is currently in tablet/maximize mode, otherwise false. |
51 bool IsTabletModeActive() { | 51 bool IsTabletModeActive() { |
52 MaximizeModeController* maximize_mode_controller = | 52 MaximizeModeController* maximize_mode_controller = |
53 Shell::Get()->maximize_mode_controller(); | 53 Shell::Get()->maximize_mode_controller(); |
54 return maximize_mode_controller && | 54 return maximize_mode_controller && |
55 maximize_mode_controller->IsMaximizeModeWindowManagerEnabled(); | 55 maximize_mode_controller->IsMaximizeModeWindowManagerEnabled(); |
56 } | 56 } |
57 | 57 |
58 // Update Touchscreen status based on the provided |local_pref_enabled|, which | |
Daniel Erat
2017/05/03 00:48:46
nit: s/Touchscreen/touchscreen/
Qiang(Joe) Xu
2017/05/03 03:14:22
Done.
| |
59 // is a reverse state of |backlights_forced_off_|. | |
Daniel Erat
2017/05/03 00:48:46
instead of referring to backlights_forced_off_ (wh
Qiang(Joe) Xu
2017/05/03 03:14:22
done by moving this to private method. That is bet
| |
60 void UpdateTouchscreenStatus(bool local_pref_enabled) { | |
Daniel Erat
2017/05/03 00:48:46
local_pref_enabled is a bit confusing. can you ren
Qiang(Joe) Xu
2017/05/03 03:14:22
Done.
| |
61 ShellDelegate* delegate = Shell::Get()->shell_delegate(); | |
62 delegate->SetTouchscreenEnabledInPrefs(local_pref_enabled, | |
63 true /* use_local_state */); | |
64 delegate->UpdateTouchscreenStatusFromPrefs(); | |
65 } | |
66 | |
58 } // namespace | 67 } // namespace |
59 | 68 |
60 TabletPowerButtonController::TestApi::TestApi( | 69 TabletPowerButtonController::TestApi::TestApi( |
61 TabletPowerButtonController* controller) | 70 TabletPowerButtonController* controller) |
62 : controller_(controller) {} | 71 : controller_(controller) {} |
63 | 72 |
64 TabletPowerButtonController::TestApi::~TestApi() {} | 73 TabletPowerButtonController::TestApi::~TestApi() {} |
65 | 74 |
66 bool TabletPowerButtonController::TestApi::ShutdownTimerIsRunning() const { | 75 bool TabletPowerButtonController::TestApi::ShutdownTimerIsRunning() const { |
67 return controller_->shutdown_timer_.IsRunning(); | 76 return controller_->shutdown_timer_.IsRunning(); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 | 222 |
214 void TabletPowerButtonController::SetDisplayForcedOff(bool forced_off) { | 223 void TabletPowerButtonController::SetDisplayForcedOff(bool forced_off) { |
215 if (backlights_forced_off_ == forced_off) | 224 if (backlights_forced_off_ == forced_off) |
216 return; | 225 return; |
217 | 226 |
218 // Set the display and keyboard backlights (if present) to |forced_off|. | 227 // Set the display and keyboard backlights (if present) to |forced_off|. |
219 chromeos::DBusThreadManager::Get() | 228 chromeos::DBusThreadManager::Get() |
220 ->GetPowerManagerClient() | 229 ->GetPowerManagerClient() |
221 ->SetBacklightsForcedOff(forced_off); | 230 ->SetBacklightsForcedOff(forced_off); |
222 backlights_forced_off_ = forced_off; | 231 backlights_forced_off_ = forced_off; |
223 | 232 |
Daniel Erat
2017/05/03 00:48:46
nit: delete blank line?
Qiang(Joe) Xu
2017/05/03 03:14:22
Done.
| |
224 ShellDelegate* delegate = Shell::Get()->shell_delegate(); | 233 UpdateTouchscreenStatus(!backlights_forced_off_); |
225 delegate->SetTouchscreenEnabledInPrefs(!forced_off, | |
226 true /* use_local_state */); | |
227 delegate->UpdateTouchscreenStatusFromPrefs(); | |
228 | 234 |
229 // Send an a11y alert. | 235 // Send an a11y alert. |
230 Shell::Get()->accessibility_delegate()->TriggerAccessibilityAlert( | 236 Shell::Get()->accessibility_delegate()->TriggerAccessibilityAlert( |
231 forced_off ? A11Y_ALERT_SCREEN_OFF : A11Y_ALERT_SCREEN_ON); | 237 forced_off ? A11Y_ALERT_SCREEN_OFF : A11Y_ALERT_SCREEN_ON); |
232 } | 238 } |
233 | 239 |
234 void TabletPowerButtonController::GetInitialBacklightsForcedOff() { | 240 void TabletPowerButtonController::GetInitialBacklightsForcedOff() { |
235 chromeos::DBusThreadManager::Get() | 241 chromeos::DBusThreadManager::Get() |
236 ->GetPowerManagerClient() | 242 ->GetPowerManagerClient() |
237 ->GetBacklightsForcedOff(base::Bind( | 243 ->GetBacklightsForcedOff(base::Bind( |
238 &TabletPowerButtonController::OnGotInitialBacklightsForcedOff, | 244 &TabletPowerButtonController::OnGotInitialBacklightsForcedOff, |
239 weak_ptr_factory_.GetWeakPtr())); | 245 weak_ptr_factory_.GetWeakPtr())); |
240 } | 246 } |
241 | 247 |
242 void TabletPowerButtonController::OnGotInitialBacklightsForcedOff( | 248 void TabletPowerButtonController::OnGotInitialBacklightsForcedOff( |
243 bool is_forced_off) { | 249 bool is_forced_off) { |
244 backlights_forced_off_ = is_forced_off; | 250 backlights_forced_off_ = is_forced_off; |
251 UpdateTouchscreenStatus(!backlights_forced_off_); | |
245 } | 252 } |
246 | 253 |
247 void TabletPowerButtonController::StartShutdownTimer() { | 254 void TabletPowerButtonController::StartShutdownTimer() { |
248 base::TimeDelta timeout = base::TimeDelta::FromMilliseconds( | 255 base::TimeDelta timeout = base::TimeDelta::FromMilliseconds( |
249 screen_off_when_power_button_down_ ? kShutdownWhenScreenOffTimeoutMs | 256 screen_off_when_power_button_down_ ? kShutdownWhenScreenOffTimeoutMs |
250 : kShutdownWhenScreenOnTimeoutMs); | 257 : kShutdownWhenScreenOnTimeoutMs); |
251 shutdown_timer_.Start(FROM_HERE, timeout, this, | 258 shutdown_timer_.Start(FROM_HERE, timeout, this, |
252 &TabletPowerButtonController::OnShutdownTimeout); | 259 &TabletPowerButtonController::OnShutdownTimeout); |
253 } | 260 } |
254 | 261 |
255 void TabletPowerButtonController::OnShutdownTimeout() { | 262 void TabletPowerButtonController::OnShutdownTimeout() { |
256 controller_->StartShutdownAnimation(); | 263 controller_->StartShutdownAnimation(); |
257 } | 264 } |
258 | 265 |
259 void TabletPowerButtonController::LockScreenIfRequired() { | 266 void TabletPowerButtonController::LockScreenIfRequired() { |
260 SessionController* session_controller = Shell::Get()->session_controller(); | 267 SessionController* session_controller = Shell::Get()->session_controller(); |
261 if (session_controller->ShouldLockScreenAutomatically() && | 268 if (session_controller->ShouldLockScreenAutomatically() && |
262 session_controller->CanLockScreen() && | 269 session_controller->CanLockScreen() && |
263 !session_controller->IsUserSessionBlocked() && | 270 !session_controller->IsUserSessionBlocked() && |
264 !controller_->LockRequested()) { | 271 !controller_->LockRequested()) { |
265 session_controller->LockScreen(); | 272 session_controller->LockScreen(); |
266 } | 273 } |
267 } | 274 } |
268 | 275 |
269 } // namespace ash | 276 } // namespace ash |
OLD | NEW |