Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9376)

Unified Diff: ash/system/chromeos/power/tablet_power_button_controller.cc

Issue 2533373002: Enabled/disable touch screen in TabletPowerButtonController (Closed)
Patch Set: add SetTouchscreenEnabled and OnLoginStateChanged Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ash/system/chromeos/power/tablet_power_button_controller.cc
diff --git a/ash/system/chromeos/power/tablet_power_button_controller.cc b/ash/system/chromeos/power/tablet_power_button_controller.cc
index 06d9efae2292990d999ea471bae6c94bf3424912..041072cab7d992c01e07c41dbdb8bbc127c1e594 100644
--- a/ash/system/chromeos/power/tablet_power_button_controller.cc
+++ b/ash/system/chromeos/power/tablet_power_button_controller.cc
@@ -6,6 +6,7 @@
#include "ash/common/accessibility_delegate.h"
#include "ash/common/session/session_state_delegate.h"
+#include "ash/common/shell_delegate.h"
#include "ash/common/wm/maximize_mode/maximize_mode_controller.h"
#include "ash/common/wm_shell.h"
#include "ash/shell.h"
@@ -73,11 +74,13 @@ TabletPowerButtonController::TabletPowerButtonController(
this);
ui::InputDeviceManager::GetInstance()->AddObserver(this);
Shell::GetInstance()->PrependPreTargetHandler(this);
+ WmShell::Get()->AddShellObserver(this);
GetInitialBacklightsForcedOff();
}
TabletPowerButtonController::~TabletPowerButtonController() {
+ WmShell::Get()->RemoveShellObserver(this);
Shell::GetInstance()->RemovePreTargetHandler(this);
ui::InputDeviceManager::GetInstance()->RemoveObserver(this);
chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(
@@ -103,13 +106,13 @@ void TabletPowerButtonController::OnPowerButtonEvent(
if (down) {
screen_off_when_power_button_down_ = brightness_level_is_zero_;
- SetBacklightsForcedOff(false);
+ SetDisplayForcedOff(false);
StartShutdownTimer();
} else {
if (shutdown_timer_.IsRunning()) {
shutdown_timer_.Stop();
if (!screen_off_when_power_button_down_) {
- SetBacklightsForcedOff(true);
+ SetDisplayForcedOff(true);
LockScreenIfRequired();
}
}
@@ -138,6 +141,13 @@ void TabletPowerButtonController::SuspendDone(
last_resume_time_ = tick_clock_->NowTicks();
}
+void TabletPowerButtonController::OnLoginStateChanged(LoginStatus status) {
+ bool touch_screen_enabled = !backlights_forced_off_;
+ // Sync the touch screen enabled state when there is a login status change as
+ // they might differ with the current display state.
+ WmShell::Get()->delegate()->SetTouchscreenEnabled(touch_screen_enabled);
Daniel Erat 2016/11/30 22:58:07 is there a possibility of a race here? is it guara
Qiang(Joe) Xu 2016/12/02 17:42:52 done by removing this.
+}
+
void TabletPowerButtonController::OnKeyEvent(ui::KeyEvent* event) {
// Ignore key events generated by the power button since power button activity
// is already handled by OnPowerButtonEvent().
@@ -145,7 +155,7 @@ void TabletPowerButtonController::OnKeyEvent(ui::KeyEvent* event) {
return;
if (!IsTabletModeActive() && backlights_forced_off_)
- SetBacklightsForcedOff(false);
+ SetDisplayForcedOff(false);
}
void TabletPowerButtonController::OnMouseEvent(ui::MouseEvent* event) {
@@ -157,13 +167,13 @@ void TabletPowerButtonController::OnMouseEvent(ui::MouseEvent* event) {
}
if (!IsTabletModeActive() && backlights_forced_off_)
- SetBacklightsForcedOff(false);
+ SetDisplayForcedOff(false);
}
void TabletPowerButtonController::OnStylusStateChanged(ui::StylusState state) {
if (IsTabletModeSupported() && state == ui::StylusState::REMOVED &&
backlights_forced_off_) {
- SetBacklightsForcedOff(false);
+ SetDisplayForcedOff(false);
}
}
@@ -173,17 +183,23 @@ void TabletPowerButtonController::SetTickClockForTesting(
tick_clock_ = std::move(tick_clock);
}
-void TabletPowerButtonController::SetBacklightsForcedOff(bool forced_off) {
+void TabletPowerButtonController::SetDisplayForcedOff(bool forced_off) {
if (backlights_forced_off_ == forced_off)
return;
+ // Set the display and keyboard backlights (if present) to |forced_off|.
chromeos::DBusThreadManager::Get()
->GetPowerManagerClient()
->SetBacklightsForcedOff(forced_off);
backlights_forced_off_ = forced_off;
+ bool touch_screen_enabled = !forced_off;
+ // Set the enabled state of touchscreen to |touch_screen_enabled|.
Daniel Erat 2016/11/30 22:58:07 remove this comment; it's obvious from the code
Qiang(Joe) Xu 2016/12/02 17:42:51 Done.
+ WmShell* wm_shell = WmShell::Get();
+ wm_shell->delegate()->SetTouchscreenEnabled(touch_screen_enabled);
+
// Send an a11y alert.
- WmShell::Get()->accessibility_delegate()->TriggerAccessibilityAlert(
+ wm_shell->accessibility_delegate()->TriggerAccessibilityAlert(
forced_off ? A11Y_ALERT_SCREEN_OFF : A11Y_ALERT_SCREEN_ON);
}

Powered by Google App Engine
This is Rietveld 408576698