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

Side by Side Diff: ash/system/chromeos/power/tablet_power_button_controller.cc

Issue 2533373002: Enabled/disable touch screen in TabletPowerButtonController (Closed)
Patch Set: nits 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 } 90 }
90 91
91 void TabletPowerButtonController::OnPowerButtonEvent( 92 void TabletPowerButtonController::OnPowerButtonEvent(
92 bool down, 93 bool down,
93 const base::TimeTicks& timestamp) { 94 const base::TimeTicks& timestamp) {
94 // When the system resumes in response to the power button being pressed, 95 // When the system resumes in response to the power button being pressed,
95 // Chrome receives powerd's SuspendDone signal and notification that the 96 // Chrome receives powerd's SuspendDone signal and notification that the
96 // backlight has been turned back on before seeing the power button events 97 // 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 98 // 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. 99 // don't turn the screen off in response to the events.
100 //
101 // TODO(warx): pressing power button should also StartShutdownTimer() in this
102 // case. Reorganize the code to support that.
99 if (timestamp - last_resume_time_ <= 103 if (timestamp - last_resume_time_ <=
100 base::TimeDelta::FromMilliseconds(kIgnorePowerButtonAfterResumeMs)) { 104 base::TimeDelta::FromMilliseconds(kIgnorePowerButtonAfterResumeMs)) {
101 // If backlights are forced off, stop forcing off because resuming system 105 // If backlights are forced off, stop forcing off because resuming system
102 // doesn't handle this. 106 // doesn't handle this.
103 if (down && backlights_forced_off_) 107 if (down && backlights_forced_off_)
104 SetBacklightsForcedOff(false); 108 SetDisplayForcedOff(false);
105 return; 109 return;
106 } 110 }
107 111
108 if (down) { 112 if (down) {
109 screen_off_when_power_button_down_ = brightness_level_is_zero_; 113 screen_off_when_power_button_down_ = brightness_level_is_zero_;
110 SetBacklightsForcedOff(false); 114 SetDisplayForcedOff(false);
111 StartShutdownTimer(); 115 StartShutdownTimer();
112 } else { 116 } else {
113 if (shutdown_timer_.IsRunning()) { 117 if (shutdown_timer_.IsRunning()) {
114 shutdown_timer_.Stop(); 118 shutdown_timer_.Stop();
115 if (!screen_off_when_power_button_down_) { 119 if (!screen_off_when_power_button_down_) {
116 SetBacklightsForcedOff(true); 120 SetDisplayForcedOff(true);
117 LockScreenIfRequired(); 121 LockScreenIfRequired();
118 } 122 }
119 } 123 }
120 screen_off_when_power_button_down_ = false; 124 screen_off_when_power_button_down_ = false;
121 125
122 // When power button is released, cancel shutdown animation whenever it is 126 // When power button is released, cancel shutdown animation whenever it is
123 // still cancellable. 127 // still cancellable.
124 if (controller_->CanCancelShutdownAnimation()) 128 if (controller_->CanCancelShutdownAnimation())
125 controller_->CancelShutdownAnimation(); 129 controller_->CancelShutdownAnimation();
126 } 130 }
(...skipping 15 matching lines...) Expand all
142 last_resume_time_ = tick_clock_->NowTicks(); 146 last_resume_time_ = tick_clock_->NowTicks();
143 } 147 }
144 148
145 void TabletPowerButtonController::OnKeyEvent(ui::KeyEvent* event) { 149 void TabletPowerButtonController::OnKeyEvent(ui::KeyEvent* event) {
146 // Ignore key events generated by the power button since power button activity 150 // Ignore key events generated by the power button since power button activity
147 // is already handled by OnPowerButtonEvent(). 151 // is already handled by OnPowerButtonEvent().
148 if (event->key_code() == ui::VKEY_POWER) 152 if (event->key_code() == ui::VKEY_POWER)
149 return; 153 return;
150 154
151 if (!IsTabletModeActive() && backlights_forced_off_) 155 if (!IsTabletModeActive() && backlights_forced_off_)
152 SetBacklightsForcedOff(false); 156 SetDisplayForcedOff(false);
153 } 157 }
154 158
155 void TabletPowerButtonController::OnMouseEvent(ui::MouseEvent* event) { 159 void TabletPowerButtonController::OnMouseEvent(ui::MouseEvent* event) {
156 ui::EventPointerType pointer_type = event->pointer_details().pointer_type; 160 ui::EventPointerType pointer_type = event->pointer_details().pointer_type;
157 161
158 if (pointer_type != ui::EventPointerType::POINTER_TYPE_MOUSE || 162 if (pointer_type != ui::EventPointerType::POINTER_TYPE_MOUSE ||
159 (event->flags() & ui::EF_IS_SYNTHESIZED)) { 163 (event->flags() & ui::EF_IS_SYNTHESIZED)) {
160 return; 164 return;
161 } 165 }
162 166
163 if (!IsTabletModeActive() && backlights_forced_off_) 167 if (!IsTabletModeActive() && backlights_forced_off_)
164 SetBacklightsForcedOff(false); 168 SetDisplayForcedOff(false);
165 } 169 }
166 170
167 void TabletPowerButtonController::OnStylusStateChanged(ui::StylusState state) { 171 void TabletPowerButtonController::OnStylusStateChanged(ui::StylusState state) {
168 if (IsTabletModeSupported() && state == ui::StylusState::REMOVED && 172 if (IsTabletModeSupported() && state == ui::StylusState::REMOVED &&
169 backlights_forced_off_) { 173 backlights_forced_off_) {
170 SetBacklightsForcedOff(false); 174 SetDisplayForcedOff(false);
171 } 175 }
172 } 176 }
173 177
174 void TabletPowerButtonController::SetTickClockForTesting( 178 void TabletPowerButtonController::SetTickClockForTesting(
175 std::unique_ptr<base::TickClock> tick_clock) { 179 std::unique_ptr<base::TickClock> tick_clock) {
176 DCHECK(tick_clock); 180 DCHECK(tick_clock);
177 tick_clock_ = std::move(tick_clock); 181 tick_clock_ = std::move(tick_clock);
178 } 182 }
179 183
180 void TabletPowerButtonController::SetBacklightsForcedOff(bool forced_off) { 184 void TabletPowerButtonController::SetDisplayForcedOff(bool forced_off) {
181 if (backlights_forced_off_ == forced_off) 185 if (backlights_forced_off_ == forced_off)
182 return; 186 return;
183 187
188 // Set the display and keyboard backlights (if present) to |forced_off|.
184 chromeos::DBusThreadManager::Get() 189 chromeos::DBusThreadManager::Get()
185 ->GetPowerManagerClient() 190 ->GetPowerManagerClient()
186 ->SetBacklightsForcedOff(forced_off); 191 ->SetBacklightsForcedOff(forced_off);
187 backlights_forced_off_ = forced_off; 192 backlights_forced_off_ = forced_off;
188 193
194 ShellDelegate* delegate = WmShell::Get()->delegate();
195 delegate->SetTouchscreenEnabledInPrefs(!forced_off,
196 true /* use_local_state */);
197 delegate->UpdateTouchscreenStatusFromPrefs();
198
189 // Send an a11y alert. 199 // Send an a11y alert.
190 WmShell::Get()->accessibility_delegate()->TriggerAccessibilityAlert( 200 WmShell::Get()->accessibility_delegate()->TriggerAccessibilityAlert(
191 forced_off ? A11Y_ALERT_SCREEN_OFF : A11Y_ALERT_SCREEN_ON); 201 forced_off ? A11Y_ALERT_SCREEN_OFF : A11Y_ALERT_SCREEN_ON);
192 } 202 }
193 203
194 void TabletPowerButtonController::GetInitialBacklightsForcedOff() { 204 void TabletPowerButtonController::GetInitialBacklightsForcedOff() {
195 chromeos::DBusThreadManager::Get() 205 chromeos::DBusThreadManager::Get()
196 ->GetPowerManagerClient() 206 ->GetPowerManagerClient()
197 ->GetBacklightsForcedOff(base::Bind( 207 ->GetBacklightsForcedOff(base::Bind(
198 &TabletPowerButtonController::OnGotInitialBacklightsForcedOff, 208 &TabletPowerButtonController::OnGotInitialBacklightsForcedOff,
(...skipping 20 matching lines...) Expand all
219 WmShell::Get()->GetSessionStateDelegate(); 229 WmShell::Get()->GetSessionStateDelegate();
220 if (session_state_delegate->ShouldLockScreenAutomatically() && 230 if (session_state_delegate->ShouldLockScreenAutomatically() &&
221 session_state_delegate->CanLockScreen() && 231 session_state_delegate->CanLockScreen() &&
222 !session_state_delegate->IsUserSessionBlocked() && 232 !session_state_delegate->IsUserSessionBlocked() &&
223 !controller_->LockRequested()) { 233 !controller_->LockRequested()) {
224 session_state_delegate->LockScreen(); 234 session_state_delegate->LockScreen();
225 } 235 }
226 } 236 }
227 237
228 } // namespace ash 238 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698