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

Side by Side 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 unified diff | Download patch
OLDNEW
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/wm/maximize_mode/maximize_mode_controller.h" 10 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h"
10 #include "ash/common/wm_shell.h" 11 #include "ash/common/wm_shell.h"
11 #include "ash/shell.h" 12 #include "ash/shell.h"
12 #include "ash/wm/lock_state_controller.h" 13 #include "ash/wm/lock_state_controller.h"
13 #include "base/time/default_tick_clock.h" 14 #include "base/time/default_tick_clock.h"
14 #include "chromeos/dbus/dbus_thread_manager.h" 15 #include "chromeos/dbus/dbus_thread_manager.h"
15 #include "ui/events/devices/input_device_manager.h" 16 #include "ui/events/devices/input_device_manager.h"
16 #include "ui/events/devices/stylus_state.h" 17 #include "ui/events/devices/stylus_state.h"
17 #include "ui/events/event.h" 18 #include "ui/events/event.h"
18 19
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 TabletPowerButtonController::TabletPowerButtonController( 67 TabletPowerButtonController::TabletPowerButtonController(
67 LockStateController* controller) 68 LockStateController* controller)
68 : tick_clock_(new base::DefaultTickClock()), 69 : tick_clock_(new base::DefaultTickClock()),
69 last_resume_time_(base::TimeTicks()), 70 last_resume_time_(base::TimeTicks()),
70 controller_(controller), 71 controller_(controller),
71 weak_ptr_factory_(this) { 72 weak_ptr_factory_(this) {
72 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver( 73 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(
73 this); 74 this);
74 ui::InputDeviceManager::GetInstance()->AddObserver(this); 75 ui::InputDeviceManager::GetInstance()->AddObserver(this);
75 Shell::GetInstance()->PrependPreTargetHandler(this); 76 Shell::GetInstance()->PrependPreTargetHandler(this);
77 WmShell::Get()->AddShellObserver(this);
76 78
77 GetInitialBacklightsForcedOff(); 79 GetInitialBacklightsForcedOff();
78 } 80 }
79 81
80 TabletPowerButtonController::~TabletPowerButtonController() { 82 TabletPowerButtonController::~TabletPowerButtonController() {
83 WmShell::Get()->RemoveShellObserver(this);
81 Shell::GetInstance()->RemovePreTargetHandler(this); 84 Shell::GetInstance()->RemovePreTargetHandler(this);
82 ui::InputDeviceManager::GetInstance()->RemoveObserver(this); 85 ui::InputDeviceManager::GetInstance()->RemoveObserver(this);
83 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver( 86 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(
84 this); 87 this);
85 } 88 }
86 89
87 bool TabletPowerButtonController::ShouldHandlePowerButtonEvents() const { 90 bool TabletPowerButtonController::ShouldHandlePowerButtonEvents() const {
88 return IsTabletModeSupported(); 91 return IsTabletModeSupported();
89 } 92 }
90 93
91 void TabletPowerButtonController::OnPowerButtonEvent( 94 void TabletPowerButtonController::OnPowerButtonEvent(
92 bool down, 95 bool down,
93 const base::TimeTicks& timestamp) { 96 const base::TimeTicks& timestamp) {
94 // When the system resumes in response to the power button being pressed, 97 // When the system resumes in response to the power button being pressed,
95 // Chrome receives powerd's SuspendDone signal and notification that the 98 // Chrome receives powerd's SuspendDone signal and notification that the
96 // backlight has been turned back on before seeing the power button events 99 // backlight has been turned back on before seeing the power button events
97 // that woke the system. Ignore events just after resuming to ensure that we 100 // that woke the system. Ignore events just after resuming to ensure that we
98 // don't turn the screen off in response to the events. 101 // don't turn the screen off in response to the events.
99 if (timestamp - last_resume_time_ <= 102 if (timestamp - last_resume_time_ <=
100 base::TimeDelta::FromMilliseconds(kIgnorePowerButtonAfterResumeMs)) { 103 base::TimeDelta::FromMilliseconds(kIgnorePowerButtonAfterResumeMs)) {
101 return; 104 return;
102 } 105 }
103 106
104 if (down) { 107 if (down) {
105 screen_off_when_power_button_down_ = brightness_level_is_zero_; 108 screen_off_when_power_button_down_ = brightness_level_is_zero_;
106 SetBacklightsForcedOff(false); 109 SetDisplayForcedOff(false);
107 StartShutdownTimer(); 110 StartShutdownTimer();
108 } else { 111 } else {
109 if (shutdown_timer_.IsRunning()) { 112 if (shutdown_timer_.IsRunning()) {
110 shutdown_timer_.Stop(); 113 shutdown_timer_.Stop();
111 if (!screen_off_when_power_button_down_) { 114 if (!screen_off_when_power_button_down_) {
112 SetBacklightsForcedOff(true); 115 SetDisplayForcedOff(true);
113 LockScreenIfRequired(); 116 LockScreenIfRequired();
114 } 117 }
115 } 118 }
116 screen_off_when_power_button_down_ = false; 119 screen_off_when_power_button_down_ = false;
117 120
118 // When power button is released, cancel shutdown animation whenever it is 121 // When power button is released, cancel shutdown animation whenever it is
119 // still cancellable. 122 // still cancellable.
120 if (controller_->CanCancelShutdownAnimation()) 123 if (controller_->CanCancelShutdownAnimation())
121 controller_->CancelShutdownAnimation(); 124 controller_->CancelShutdownAnimation();
122 } 125 }
123 } 126 }
124 127
125 void TabletPowerButtonController::PowerManagerRestarted() { 128 void TabletPowerButtonController::PowerManagerRestarted() {
126 chromeos::DBusThreadManager::Get() 129 chromeos::DBusThreadManager::Get()
127 ->GetPowerManagerClient() 130 ->GetPowerManagerClient()
128 ->SetBacklightsForcedOff(backlights_forced_off_); 131 ->SetBacklightsForcedOff(backlights_forced_off_);
129 } 132 }
130 133
131 void TabletPowerButtonController::BrightnessChanged(int level, 134 void TabletPowerButtonController::BrightnessChanged(int level,
132 bool user_initiated) { 135 bool user_initiated) {
133 brightness_level_is_zero_ = level == 0; 136 brightness_level_is_zero_ = level == 0;
134 } 137 }
135 138
136 void TabletPowerButtonController::SuspendDone( 139 void TabletPowerButtonController::SuspendDone(
137 const base::TimeDelta& sleep_duration) { 140 const base::TimeDelta& sleep_duration) {
138 last_resume_time_ = tick_clock_->NowTicks(); 141 last_resume_time_ = tick_clock_->NowTicks();
139 } 142 }
140 143
144 void TabletPowerButtonController::OnLoginStateChanged(LoginStatus status) {
145 bool touch_screen_enabled = !backlights_forced_off_;
146 // Sync the touch screen enabled state when there is a login status change as
147 // they might differ with the current display state.
148 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.
149 }
150
141 void TabletPowerButtonController::OnKeyEvent(ui::KeyEvent* event) { 151 void TabletPowerButtonController::OnKeyEvent(ui::KeyEvent* event) {
142 // Ignore key events generated by the power button since power button activity 152 // Ignore key events generated by the power button since power button activity
143 // is already handled by OnPowerButtonEvent(). 153 // is already handled by OnPowerButtonEvent().
144 if (event->key_code() == ui::VKEY_POWER) 154 if (event->key_code() == ui::VKEY_POWER)
145 return; 155 return;
146 156
147 if (!IsTabletModeActive() && backlights_forced_off_) 157 if (!IsTabletModeActive() && backlights_forced_off_)
148 SetBacklightsForcedOff(false); 158 SetDisplayForcedOff(false);
149 } 159 }
150 160
151 void TabletPowerButtonController::OnMouseEvent(ui::MouseEvent* event) { 161 void TabletPowerButtonController::OnMouseEvent(ui::MouseEvent* event) {
152 ui::EventPointerType pointer_type = event->pointer_details().pointer_type; 162 ui::EventPointerType pointer_type = event->pointer_details().pointer_type;
153 163
154 if (pointer_type != ui::EventPointerType::POINTER_TYPE_MOUSE || 164 if (pointer_type != ui::EventPointerType::POINTER_TYPE_MOUSE ||
155 (event->flags() & ui::EF_IS_SYNTHESIZED)) { 165 (event->flags() & ui::EF_IS_SYNTHESIZED)) {
156 return; 166 return;
157 } 167 }
158 168
159 if (!IsTabletModeActive() && backlights_forced_off_) 169 if (!IsTabletModeActive() && backlights_forced_off_)
160 SetBacklightsForcedOff(false); 170 SetDisplayForcedOff(false);
161 } 171 }
162 172
163 void TabletPowerButtonController::OnStylusStateChanged(ui::StylusState state) { 173 void TabletPowerButtonController::OnStylusStateChanged(ui::StylusState state) {
164 if (IsTabletModeSupported() && state == ui::StylusState::REMOVED && 174 if (IsTabletModeSupported() && state == ui::StylusState::REMOVED &&
165 backlights_forced_off_) { 175 backlights_forced_off_) {
166 SetBacklightsForcedOff(false); 176 SetDisplayForcedOff(false);
167 } 177 }
168 } 178 }
169 179
170 void TabletPowerButtonController::SetTickClockForTesting( 180 void TabletPowerButtonController::SetTickClockForTesting(
171 std::unique_ptr<base::TickClock> tick_clock) { 181 std::unique_ptr<base::TickClock> tick_clock) {
172 DCHECK(tick_clock); 182 DCHECK(tick_clock);
173 tick_clock_ = std::move(tick_clock); 183 tick_clock_ = std::move(tick_clock);
174 } 184 }
175 185
176 void TabletPowerButtonController::SetBacklightsForcedOff(bool forced_off) { 186 void TabletPowerButtonController::SetDisplayForcedOff(bool forced_off) {
177 if (backlights_forced_off_ == forced_off) 187 if (backlights_forced_off_ == forced_off)
178 return; 188 return;
179 189
190 // Set the display and keyboard backlights (if present) to |forced_off|.
180 chromeos::DBusThreadManager::Get() 191 chromeos::DBusThreadManager::Get()
181 ->GetPowerManagerClient() 192 ->GetPowerManagerClient()
182 ->SetBacklightsForcedOff(forced_off); 193 ->SetBacklightsForcedOff(forced_off);
183 backlights_forced_off_ = forced_off; 194 backlights_forced_off_ = forced_off;
184 195
196 bool touch_screen_enabled = !forced_off;
197 // 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.
198 WmShell* wm_shell = WmShell::Get();
199 wm_shell->delegate()->SetTouchscreenEnabled(touch_screen_enabled);
200
185 // Send an a11y alert. 201 // Send an a11y alert.
186 WmShell::Get()->accessibility_delegate()->TriggerAccessibilityAlert( 202 wm_shell->accessibility_delegate()->TriggerAccessibilityAlert(
187 forced_off ? A11Y_ALERT_SCREEN_OFF : A11Y_ALERT_SCREEN_ON); 203 forced_off ? A11Y_ALERT_SCREEN_OFF : A11Y_ALERT_SCREEN_ON);
188 } 204 }
189 205
190 void TabletPowerButtonController::GetInitialBacklightsForcedOff() { 206 void TabletPowerButtonController::GetInitialBacklightsForcedOff() {
191 chromeos::DBusThreadManager::Get() 207 chromeos::DBusThreadManager::Get()
192 ->GetPowerManagerClient() 208 ->GetPowerManagerClient()
193 ->GetBacklightsForcedOff(base::Bind( 209 ->GetBacklightsForcedOff(base::Bind(
194 &TabletPowerButtonController::OnGotInitialBacklightsForcedOff, 210 &TabletPowerButtonController::OnGotInitialBacklightsForcedOff,
195 weak_ptr_factory_.GetWeakPtr())); 211 weak_ptr_factory_.GetWeakPtr()));
196 } 212 }
(...skipping 18 matching lines...) Expand all
215 WmShell::Get()->GetSessionStateDelegate(); 231 WmShell::Get()->GetSessionStateDelegate();
216 if (session_state_delegate->ShouldLockScreenAutomatically() && 232 if (session_state_delegate->ShouldLockScreenAutomatically() &&
217 session_state_delegate->CanLockScreen() && 233 session_state_delegate->CanLockScreen() &&
218 !session_state_delegate->IsUserSessionBlocked() && 234 !session_state_delegate->IsUserSessionBlocked() &&
219 !controller_->LockRequested()) { 235 !controller_->LockRequested()) {
220 session_state_delegate->LockScreen(); 236 session_state_delegate->LockScreen();
221 } 237 }
222 } 238 }
223 239
224 } // namespace ash 240 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698