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

Side by Side Diff: ash/wm/tablet_mode/tablet_mode_controller.cc

Issue 2906803002: Rename MaximizeMode to TabletMode (Closed)
Patch Set: updated filter Created 3 years, 7 months 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/wm/maximize_mode/maximize_mode_controller.h" 5 #include "ash/wm/tablet_mode/tablet_mode_controller.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "ash/ash_switches.h" 9 #include "ash/ash_switches.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
11 #include "ash/shell_port.h" 11 #include "ash/shell_port.h"
12 #include "ash/wm/maximize_mode/maximize_mode_window_manager.h" 12 #include "ash/wm/tablet_mode/scoped_disable_internal_mouse_and_keyboard.h"
13 #include "ash/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard.h" 13 #include "ash/wm/tablet_mode/tablet_mode_window_manager.h"
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/command_line.h" 15 #include "base/command_line.h"
16 #include "base/metrics/histogram_macros.h" 16 #include "base/metrics/histogram_macros.h"
17 #include "base/time/default_tick_clock.h" 17 #include "base/time/default_tick_clock.h"
18 #include "base/time/tick_clock.h" 18 #include "base/time/tick_clock.h"
19 #include "chromeos/dbus/dbus_thread_manager.h" 19 #include "chromeos/dbus/dbus_thread_manager.h"
20 #include "ui/base/accelerators/accelerator.h" 20 #include "ui/base/accelerators/accelerator.h"
21 #include "ui/chromeos/accelerometer/accelerometer_util.h" 21 #include "ui/chromeos/accelerometer/accelerometer_util.h"
22 #include "ui/display/display.h" 22 #include "ui/display/display.h"
23 #include "ui/events/event.h" 23 #include "ui/events/event.h"
24 #include "ui/events/keycodes/keyboard_codes.h" 24 #include "ui/events/keycodes/keyboard_codes.h"
25 #include "ui/gfx/geometry/vector3d_f.h" 25 #include "ui/gfx/geometry/vector3d_f.h"
26 26
27 namespace ash { 27 namespace ash {
28 28
29 namespace { 29 namespace {
30 30
31 // The hinge angle at which to enter maximize mode. 31 // The hinge angle at which to enter tablet mode.
32 const float kEnterMaximizeModeAngle = 200.0f; 32 const float kEnterTabletModeAngle = 200.0f;
33 33
34 // The angle at which to exit maximize mode, this is specifically less than the 34 // The angle at which to exit tablet mode, this is specifically less than the
35 // angle to enter maximize mode to prevent rapid toggling when near the angle. 35 // angle to enter tablet mode to prevent rapid toggling when near the angle.
36 const float kExitMaximizeModeAngle = 160.0f; 36 const float kExitTabletModeAngle = 160.0f;
37 37
38 // Defines a range for which accelerometer readings are considered accurate. 38 // Defines a range for which accelerometer readings are considered accurate.
39 // When the lid is near open (or near closed) the accelerometer readings may be 39 // When the lid is near open (or near closed) the accelerometer readings may be
40 // inaccurate and a lid that is fully open may appear to be near closed (and 40 // inaccurate and a lid that is fully open may appear to be near closed (and
41 // vice versa). 41 // vice versa).
42 const float kMinStableAngle = 20.0f; 42 const float kMinStableAngle = 20.0f;
43 const float kMaxStableAngle = 340.0f; 43 const float kMaxStableAngle = 340.0f;
44 44
45 // The time duration to consider the lid to be recently opened. 45 // The time duration to consider the lid to be recently opened.
46 // This is used to prevent entering maximize mode if an erroneous accelerometer 46 // This is used to prevent entering tablet mode if an erroneous accelerometer
47 // reading makes the lid appear to be fully open when the user is opening the 47 // reading makes the lid appear to be fully open when the user is opening the
48 // lid from a closed position. 48 // lid from a closed position.
49 const int kLidRecentlyOpenedDurationSeconds = 2; 49 const int kLidRecentlyOpenedDurationSeconds = 2;
50 50
51 // When the device approaches vertical orientation (i.e. portrait orientation) 51 // When the device approaches vertical orientation (i.e. portrait orientation)
52 // the accelerometers for the base and lid approach the same values (i.e. 52 // the accelerometers for the base and lid approach the same values (i.e.
53 // gravity pointing in the direction of the hinge). When this happens abrupt 53 // gravity pointing in the direction of the hinge). When this happens abrupt
54 // small acceleration perpendicular to the hinge can lead to incorrect hinge 54 // small acceleration perpendicular to the hinge can lead to incorrect hinge
55 // angle calculations. To prevent this the accelerometer updates will be 55 // angle calculations. To prevent this the accelerometer updates will be
56 // smoothed over time in order to reduce this noise. 56 // smoothed over time in order to reduce this noise.
(...skipping 21 matching lines...) Expand all
78 ui::ConvertAccelerometerReadingToVector3dF( 78 ui::ConvertAccelerometerReadingToVector3dF(
79 update.get(chromeos::ACCELEROMETER_SOURCE_SCREEN)) 79 update.get(chromeos::ACCELEROMETER_SOURCE_SCREEN))
80 .Length()) <= kNoisyMagnitudeDeviation; 80 .Length()) <= kNoisyMagnitudeDeviation;
81 } 81 }
82 82
83 bool IsEnabled() { 83 bool IsEnabled() {
84 return base::CommandLine::ForCurrentProcess()->HasSwitch( 84 return base::CommandLine::ForCurrentProcess()->HasSwitch(
85 switches::kAshEnableTouchView); 85 switches::kAshEnableTouchView);
86 } 86 }
87 87
88 // Checks the command line to see which force maximize mode is turned on, if 88 // Checks the command line to see which force tablet mode is turned on, if
89 // any. 89 // any.
90 MaximizeModeController::ForceTabletMode GetMaximizeMode() { 90 TabletModeController::ForceTabletMode GetTabletMode() {
91 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 91 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
92 if (command_line->HasSwitch(switches::kAshForceTabletMode)) { 92 if (command_line->HasSwitch(switches::kAshForceTabletMode)) {
93 std::string switch_value = 93 std::string switch_value =
94 command_line->GetSwitchValueASCII(switches::kAshForceTabletMode); 94 command_line->GetSwitchValueASCII(switches::kAshForceTabletMode);
95 if (switch_value == switches::kAshForceTabletModeClamshell) 95 if (switch_value == switches::kAshForceTabletModeClamshell)
96 return MaximizeModeController::ForceTabletMode::CLAMSHELL; 96 return TabletModeController::ForceTabletMode::CLAMSHELL;
97 97
98 if (switch_value == switches::kAshForceTabletModeTouchView) 98 if (switch_value == switches::kAshForceTabletModeTouchView)
99 return MaximizeModeController::ForceTabletMode::TOUCHVIEW; 99 return TabletModeController::ForceTabletMode::TOUCHVIEW;
100 } 100 }
101 return MaximizeModeController::ForceTabletMode::NONE; 101 return TabletModeController::ForceTabletMode::NONE;
102 } 102 }
103 103
104 } // namespace 104 } // namespace
105 105
106 MaximizeModeController::MaximizeModeController() 106 TabletModeController::TabletModeController()
107 : have_seen_accelerometer_data_(false), 107 : have_seen_accelerometer_data_(false),
108 can_detect_lid_angle_(false), 108 can_detect_lid_angle_(false),
109 touchview_usage_interval_start_time_(base::Time::Now()), 109 touchview_usage_interval_start_time_(base::Time::Now()),
110 tick_clock_(new base::DefaultTickClock()), 110 tick_clock_(new base::DefaultTickClock()),
111 tablet_mode_switch_is_on_(false), 111 tablet_mode_switch_is_on_(false),
112 lid_is_closed_(false), 112 lid_is_closed_(false),
113 scoped_session_observer_(this), 113 scoped_session_observer_(this),
114 weak_factory_(this) { 114 weak_factory_(this) {
115 Shell::Get()->AddShellObserver(this); 115 Shell::Get()->AddShellObserver(this);
116 ShellPort::Get()->RecordUserMetricsAction( 116 ShellPort::Get()->RecordUserMetricsAction(
117 UMA_MAXIMIZE_MODE_INITIALLY_DISABLED); 117 UMA_MAXIMIZE_MODE_INITIALLY_DISABLED);
118 118
119 // TODO(jonross): Do not create MaximizeModeController if the flag is 119 // TODO(jonross): Do not create TabletModeController if the flag is
120 // unavailable. This will require refactoring 120 // unavailable. This will require refactoring
121 // IsMaximizeModeWindowManagerEnabled to check for the existance of the 121 // IsTabletModeWindowManagerEnabled to check for the existance of the
122 // controller. 122 // controller.
123 if (IsEnabled()) { 123 if (IsEnabled()) {
124 ShellPort::Get()->AddDisplayObserver(this); 124 ShellPort::Get()->AddDisplayObserver(this);
125 chromeos::AccelerometerReader::GetInstance()->AddObserver(this); 125 chromeos::AccelerometerReader::GetInstance()->AddObserver(this);
126 } 126 }
127 chromeos::PowerManagerClient* power_manager_client = 127 chromeos::PowerManagerClient* power_manager_client =
128 chromeos::DBusThreadManager::Get()->GetPowerManagerClient(); 128 chromeos::DBusThreadManager::Get()->GetPowerManagerClient();
129 power_manager_client->AddObserver(this); 129 power_manager_client->AddObserver(this);
130 power_manager_client->GetSwitchStates(base::Bind( 130 power_manager_client->GetSwitchStates(base::Bind(
131 &MaximizeModeController::OnGetSwitchStates, weak_factory_.GetWeakPtr())); 131 &TabletModeController::OnGetSwitchStates, weak_factory_.GetWeakPtr()));
132 } 132 }
133 133
134 MaximizeModeController::~MaximizeModeController() { 134 TabletModeController::~TabletModeController() {
135 Shell::Get()->RemoveShellObserver(this); 135 Shell::Get()->RemoveShellObserver(this);
136 136
137 if (IsEnabled()) { 137 if (IsEnabled()) {
138 ShellPort::Get()->RemoveDisplayObserver(this); 138 ShellPort::Get()->RemoveDisplayObserver(this);
139 chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this); 139 chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this);
140 } 140 }
141 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver( 141 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(
142 this); 142 this);
143 } 143 }
144 144
145 bool MaximizeModeController::CanEnterMaximizeMode() { 145 bool TabletModeController::CanEnterTabletMode() {
146 // If we have ever seen accelerometer data, then HandleHingeRotation may 146 // If we have ever seen accelerometer data, then HandleHingeRotation may
147 // trigger maximize mode at some point in the future. 147 // trigger tablet mode at some point in the future.
148 // All TouchView-enabled devices can enter maximized mode. 148 // All TouchView-enabled devices can enter tablet mode.
149 return have_seen_accelerometer_data_ || IsEnabled(); 149 return have_seen_accelerometer_data_ || IsEnabled();
150 } 150 }
151 151
152 // TODO(jcliang): Hide or remove EnableMaximizeModeWindowManager 152 // TODO(jcliang): Hide or remove EnableTabletModeWindowManager
153 // (http://crbug.com/620241). 153 // (http://crbug.com/620241).
154 void MaximizeModeController::EnableMaximizeModeWindowManager( 154 void TabletModeController::EnableTabletModeWindowManager(bool should_enable) {
155 bool should_enable) { 155 bool is_enabled = !!tablet_mode_window_manager_.get();
156 bool is_enabled = !!maximize_mode_window_manager_.get();
157 if (should_enable == is_enabled) 156 if (should_enable == is_enabled)
158 return; 157 return;
159 158
160 if (should_enable) { 159 if (should_enable) {
161 maximize_mode_window_manager_.reset(new MaximizeModeWindowManager()); 160 tablet_mode_window_manager_.reset(new TabletModeWindowManager());
162 // TODO(jonross): Move the maximize mode notifications from ShellObserver 161 // TODO(jonross): Move the tablet mode notifications from ShellObserver
163 // to MaximizeModeController::Observer 162 // to TabletModeController::Observer
164 ShellPort::Get()->RecordUserMetricsAction(UMA_MAXIMIZE_MODE_ENABLED); 163 ShellPort::Get()->RecordUserMetricsAction(UMA_MAXIMIZE_MODE_ENABLED);
165 Shell::Get()->NotifyMaximizeModeStarted(); 164 Shell::Get()->NotifyTabletModeStarted();
166 165
167 observers_.ForAllPtrs([](mojom::TouchViewObserver* observer) { 166 observers_.ForAllPtrs([](mojom::TouchViewObserver* observer) {
168 observer->OnTouchViewToggled(true); 167 observer->OnTouchViewToggled(true);
169 }); 168 });
170 169
171 } else { 170 } else {
172 maximize_mode_window_manager_->SetIgnoreWmEventsForExit(); 171 tablet_mode_window_manager_->SetIgnoreWmEventsForExit();
173 Shell::Get()->NotifyMaximizeModeEnding(); 172 Shell::Get()->NotifyTabletModeEnding();
174 maximize_mode_window_manager_.reset(); 173 tablet_mode_window_manager_.reset();
175 ShellPort::Get()->RecordUserMetricsAction(UMA_MAXIMIZE_MODE_DISABLED); 174 ShellPort::Get()->RecordUserMetricsAction(UMA_MAXIMIZE_MODE_DISABLED);
176 Shell::Get()->NotifyMaximizeModeEnded(); 175 Shell::Get()->NotifyTabletModeEnded();
177 176
178 observers_.ForAllPtrs([](mojom::TouchViewObserver* observer) { 177 observers_.ForAllPtrs([](mojom::TouchViewObserver* observer) {
179 observer->OnTouchViewToggled(false); 178 observer->OnTouchViewToggled(false);
180 }); 179 });
181 } 180 }
182 } 181 }
183 182
184 bool MaximizeModeController::IsMaximizeModeWindowManagerEnabled() const { 183 bool TabletModeController::IsTabletModeWindowManagerEnabled() const {
185 return maximize_mode_window_manager_.get() != NULL; 184 return tablet_mode_window_manager_.get() != NULL;
186 } 185 }
187 186
188 void MaximizeModeController::AddWindow(aura::Window* window) { 187 void TabletModeController::AddWindow(aura::Window* window) {
189 if (IsMaximizeModeWindowManagerEnabled()) 188 if (IsTabletModeWindowManagerEnabled())
190 maximize_mode_window_manager_->AddWindow(window); 189 tablet_mode_window_manager_->AddWindow(window);
191 } 190 }
192 191
193 void MaximizeModeController::BindRequest( 192 void TabletModeController::BindRequest(mojom::TouchViewManagerRequest request) {
194 mojom::TouchViewManagerRequest request) {
195 bindings_.AddBinding(this, std::move(request)); 193 bindings_.AddBinding(this, std::move(request));
196 } 194 }
197 195
198 void MaximizeModeController::OnAccelerometerUpdated( 196 void TabletModeController::OnAccelerometerUpdated(
199 scoped_refptr<const chromeos::AccelerometerUpdate> update) { 197 scoped_refptr<const chromeos::AccelerometerUpdate> update) {
200 if (!AllowEnterExitMaximizeMode()) 198 if (!AllowEnterExitTabletMode())
201 return; 199 return;
202 200
203 have_seen_accelerometer_data_ = true; 201 have_seen_accelerometer_data_ = true;
204 can_detect_lid_angle_ = 202 can_detect_lid_angle_ =
205 update->has(chromeos::ACCELEROMETER_SOURCE_SCREEN) && 203 update->has(chromeos::ACCELEROMETER_SOURCE_SCREEN) &&
206 update->has(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD); 204 update->has(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD);
207 205
208 if (!can_detect_lid_angle_) 206 if (!can_detect_lid_angle_)
209 return; 207 return;
210 208
211 if (!display::Display::HasInternalDisplay()) 209 if (!display::Display::HasInternalDisplay())
212 return; 210 return;
213 211
214 if (!ShellPort::Get()->IsActiveDisplayId( 212 if (!ShellPort::Get()->IsActiveDisplayId(
215 display::Display::InternalDisplayId())) { 213 display::Display::InternalDisplayId())) {
216 return; 214 return;
217 } 215 }
218 216
219 // Whether or not we enter maximize mode affects whether we handle screen 217 // Whether or not we enter tablet mode affects whether we handle screen
220 // rotation, so determine whether to enter maximize mode first. 218 // rotation, so determine whether to enter tablet mode first.
221 if (ui::IsAccelerometerReadingStable(*update, 219 if (ui::IsAccelerometerReadingStable(*update,
222 chromeos::ACCELEROMETER_SOURCE_SCREEN) && 220 chromeos::ACCELEROMETER_SOURCE_SCREEN) &&
223 ui::IsAccelerometerReadingStable( 221 ui::IsAccelerometerReadingStable(
224 *update, chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD) && 222 *update, chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD) &&
225 IsAngleBetweenAccelerometerReadingsStable(*update)) { 223 IsAngleBetweenAccelerometerReadingsStable(*update)) {
226 // update.has(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD) 224 // update.has(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD)
227 // Ignore the reading if it appears unstable. The reading is considered 225 // Ignore the reading if it appears unstable. The reading is considered
228 // unstable if it deviates too much from gravity and/or the magnitude of the 226 // unstable if it deviates too much from gravity and/or the magnitude of the
229 // reading from the lid differs too much from the reading from the base. 227 // reading from the lid differs too much from the reading from the base.
230 HandleHingeRotation(update); 228 HandleHingeRotation(update);
231 } 229 }
232 } 230 }
233 231
234 void MaximizeModeController::LidEventReceived( 232 void TabletModeController::LidEventReceived(
235 chromeos::PowerManagerClient::LidState state, 233 chromeos::PowerManagerClient::LidState state,
236 const base::TimeTicks& time) { 234 const base::TimeTicks& time) {
237 if (!AllowEnterExitMaximizeMode()) 235 if (!AllowEnterExitTabletMode())
238 return; 236 return;
239 237
240 const bool open = state == chromeos::PowerManagerClient::LidState::OPEN; 238 const bool open = state == chromeos::PowerManagerClient::LidState::OPEN;
241 if (open) 239 if (open)
242 last_lid_open_time_ = time; 240 last_lid_open_time_ = time;
243 lid_is_closed_ = !open; 241 lid_is_closed_ = !open;
244 LeaveMaximizeMode(); 242 LeaveTabletMode();
245 } 243 }
246 244
247 void MaximizeModeController::TabletModeEventReceived( 245 void TabletModeController::TabletModeEventReceived(
248 chromeos::PowerManagerClient::TabletMode mode, 246 chromeos::PowerManagerClient::TabletMode mode,
249 const base::TimeTicks& time) { 247 const base::TimeTicks& time) {
250 if (!AllowEnterExitMaximizeMode()) 248 if (!AllowEnterExitTabletMode())
251 return; 249 return;
252 250
253 const bool on = mode == chromeos::PowerManagerClient::TabletMode::ON; 251 const bool on = mode == chromeos::PowerManagerClient::TabletMode::ON;
254 tablet_mode_switch_is_on_ = on; 252 tablet_mode_switch_is_on_ = on;
255 // Do not change if docked. 253 // Do not change if docked.
256 if (!display::Display::HasInternalDisplay() || 254 if (!display::Display::HasInternalDisplay() ||
257 !ShellPort::Get()->IsActiveDisplayId( 255 !ShellPort::Get()->IsActiveDisplayId(
258 display::Display::InternalDisplayId())) { 256 display::Display::InternalDisplayId())) {
259 return; 257 return;
260 } 258 }
261 // The tablet mode switch activates at 300 degrees, so it is always reliable 259 // The tablet mode switch activates at 300 degrees, so it is always reliable
262 // when |on|. However we wish to exit maximize mode at a smaller angle, so 260 // when |on|. However we wish to exit tablet mode at a smaller angle, so
263 // when |on| is false we ignore if it is possible to calculate the lid angle. 261 // when |on| is false we ignore if it is possible to calculate the lid angle.
264 if (on && !IsMaximizeModeWindowManagerEnabled()) { 262 if (on && !IsTabletModeWindowManagerEnabled()) {
265 EnterMaximizeMode(); 263 EnterTabletMode();
266 } else if (!on && IsMaximizeModeWindowManagerEnabled() && 264 } else if (!on && IsTabletModeWindowManagerEnabled() &&
267 !can_detect_lid_angle_) { 265 !can_detect_lid_angle_) {
268 LeaveMaximizeMode(); 266 LeaveTabletMode();
269 } 267 }
270 } 268 }
271 269
272 void MaximizeModeController::SuspendImminent() { 270 void TabletModeController::SuspendImminent() {
273 // The system is about to suspend, so record TouchView usage interval metrics 271 // The system is about to suspend, so record TouchView usage interval metrics
274 // based on whether TouchView mode is currently active. 272 // based on whether TouchView mode is currently active.
275 RecordTouchViewUsageInterval(CurrentTouchViewIntervalType()); 273 RecordTouchViewUsageInterval(CurrentTouchViewIntervalType());
276 } 274 }
277 275
278 void MaximizeModeController::SuspendDone( 276 void TabletModeController::SuspendDone(const base::TimeDelta& sleep_duration) {
279 const base::TimeDelta& sleep_duration) {
280 // We do not want TouchView usage metrics to include time spent in suspend. 277 // We do not want TouchView usage metrics to include time spent in suspend.
281 touchview_usage_interval_start_time_ = base::Time::Now(); 278 touchview_usage_interval_start_time_ = base::Time::Now();
282 } 279 }
283 280
284 void MaximizeModeController::HandleHingeRotation( 281 void TabletModeController::HandleHingeRotation(
285 scoped_refptr<const chromeos::AccelerometerUpdate> update) { 282 scoped_refptr<const chromeos::AccelerometerUpdate> update) {
286 static const gfx::Vector3dF hinge_vector(1.0f, 0.0f, 0.0f); 283 static const gfx::Vector3dF hinge_vector(1.0f, 0.0f, 0.0f);
287 gfx::Vector3dF base_reading(ui::ConvertAccelerometerReadingToVector3dF( 284 gfx::Vector3dF base_reading(ui::ConvertAccelerometerReadingToVector3dF(
288 update->get(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD))); 285 update->get(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD)));
289 gfx::Vector3dF lid_reading(ui::ConvertAccelerometerReadingToVector3dF( 286 gfx::Vector3dF lid_reading(ui::ConvertAccelerometerReadingToVector3dF(
290 update->get(chromeos::ACCELEROMETER_SOURCE_SCREEN))); 287 update->get(chromeos::ACCELEROMETER_SOURCE_SCREEN)));
291 288
292 // As the hinge approaches a vertical angle, the base and lid accelerometers 289 // As the hinge approaches a vertical angle, the base and lid accelerometers
293 // approach the same values making any angle calculations highly inaccurate. 290 // approach the same values making any angle calculations highly inaccurate.
294 // Smooth out instantaneous acceleration when nearly vertical to increase 291 // Smooth out instantaneous acceleration when nearly vertical to increase
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 328
332 bool is_angle_stable = is_angle_reliable && lid_angle >= kMinStableAngle && 329 bool is_angle_stable = is_angle_reliable && lid_angle >= kMinStableAngle &&
333 lid_angle <= kMaxStableAngle; 330 lid_angle <= kMaxStableAngle;
334 331
335 // Clear the last_lid_open_time_ for a stable reading so that there is less 332 // Clear the last_lid_open_time_ for a stable reading so that there is less
336 // chance of a delay if the lid is moved from the close state to the fully 333 // chance of a delay if the lid is moved from the close state to the fully
337 // open state very quickly. 334 // open state very quickly.
338 if (is_angle_stable) 335 if (is_angle_stable)
339 last_lid_open_time_ = base::TimeTicks(); 336 last_lid_open_time_ = base::TimeTicks();
340 337
341 // Toggle maximize mode on or off when corresponding thresholds are passed. 338 // Toggle tablet mode on or off when corresponding thresholds are passed.
342 if (IsMaximizeModeWindowManagerEnabled() && is_angle_stable && 339 if (IsTabletModeWindowManagerEnabled() && is_angle_stable &&
343 lid_angle <= kExitMaximizeModeAngle) { 340 lid_angle <= kExitTabletModeAngle) {
344 LeaveMaximizeMode(); 341 LeaveTabletMode();
345 } else if (!IsMaximizeModeWindowManagerEnabled() && !lid_is_closed_ && 342 } else if (!IsTabletModeWindowManagerEnabled() && !lid_is_closed_ &&
346 lid_angle >= kEnterMaximizeModeAngle && 343 lid_angle >= kEnterTabletModeAngle &&
347 (is_angle_stable || !WasLidOpenedRecently())) { 344 (is_angle_stable || !WasLidOpenedRecently())) {
348 EnterMaximizeMode(); 345 EnterTabletMode();
349 } 346 }
350 } 347 }
351 348
352 void MaximizeModeController::EnterMaximizeMode() { 349 void TabletModeController::EnterTabletMode() {
353 // Always reset first to avoid creation before destruction of a previous 350 // Always reset first to avoid creation before destruction of a previous
354 // object. 351 // object.
355 event_blocker_ = 352 event_blocker_ =
356 ShellPort::Get()->CreateScopedDisableInternalMouseAndKeyboard(); 353 ShellPort::Get()->CreateScopedDisableInternalMouseAndKeyboard();
357 354
358 if (IsMaximizeModeWindowManagerEnabled()) 355 if (IsTabletModeWindowManagerEnabled())
359 return; 356 return;
360 EnableMaximizeModeWindowManager(true); 357 EnableTabletModeWindowManager(true);
361 } 358 }
362 359
363 void MaximizeModeController::LeaveMaximizeMode() { 360 void TabletModeController::LeaveTabletMode() {
364 event_blocker_.reset(); 361 event_blocker_.reset();
365 362
366 if (!IsMaximizeModeWindowManagerEnabled()) 363 if (!IsTabletModeWindowManagerEnabled())
367 return; 364 return;
368 EnableMaximizeModeWindowManager(false); 365 EnableTabletModeWindowManager(false);
369 } 366 }
370 367
371 // Called after maximize mode has started, windows might still animate though. 368 // Called after tablet mode has started, windows might still animate though.
372 void MaximizeModeController::OnMaximizeModeStarted() { 369 void TabletModeController::OnTabletModeStarted() {
373 RecordTouchViewUsageInterval(TOUCH_VIEW_INTERVAL_INACTIVE); 370 RecordTouchViewUsageInterval(TOUCH_VIEW_INTERVAL_INACTIVE);
374 } 371 }
375 372
376 // Called after maximize mode has ended, windows might still be returning to 373 // Called after tablet mode has ended, windows might still be returning to
377 // their original position. 374 // their original position.
378 void MaximizeModeController::OnMaximizeModeEnded() { 375 void TabletModeController::OnTabletModeEnded() {
379 RecordTouchViewUsageInterval(TOUCH_VIEW_INTERVAL_ACTIVE); 376 RecordTouchViewUsageInterval(TOUCH_VIEW_INTERVAL_ACTIVE);
380 } 377 }
381 378
382 void MaximizeModeController::OnShellInitialized() { 379 void TabletModeController::OnShellInitialized() {
383 force_tablet_mode_ = GetMaximizeMode(); 380 force_tablet_mode_ = GetTabletMode();
384 if (force_tablet_mode_ == ForceTabletMode::TOUCHVIEW) 381 if (force_tablet_mode_ == ForceTabletMode::TOUCHVIEW)
385 EnterMaximizeMode(); 382 EnterTabletMode();
386 } 383 }
387 384
388 void MaximizeModeController::OnDisplayConfigurationChanged() { 385 void TabletModeController::OnDisplayConfigurationChanged() {
389 if (!display::Display::HasInternalDisplay() || 386 if (!display::Display::HasInternalDisplay() ||
390 !ShellPort::Get()->IsActiveDisplayId( 387 !ShellPort::Get()->IsActiveDisplayId(
391 display::Display::InternalDisplayId())) { 388 display::Display::InternalDisplayId())) {
392 LeaveMaximizeMode(); 389 LeaveTabletMode();
393 } else if (tablet_mode_switch_is_on_ && 390 } else if (tablet_mode_switch_is_on_ && !IsTabletModeWindowManagerEnabled()) {
394 !IsMaximizeModeWindowManagerEnabled()) {
395 // The internal display has returned, as we are exiting docked mode. 391 // The internal display has returned, as we are exiting docked mode.
396 // The device is still in tablet mode, so trigger maximize mode, as this 392 // The device is still in tablet mode, so trigger tablet mode, as this
397 // switch leads to the ignoring of accelerometer events. When the switch is 393 // switch leads to the ignoring of accelerometer events. When the switch is
398 // not set the next stable accelerometer readings will trigger maximize 394 // not set the next stable accelerometer readings will trigger maximize
399 // mode. 395 // mode.
400 EnterMaximizeMode(); 396 EnterTabletMode();
401 } 397 }
402 } 398 }
403 399
404 void MaximizeModeController::RecordTouchViewUsageInterval( 400 void TabletModeController::RecordTouchViewUsageInterval(
405 TouchViewIntervalType type) { 401 TouchViewIntervalType type) {
406 if (!CanEnterMaximizeMode()) 402 if (!CanEnterTabletMode())
407 return; 403 return;
408 404
409 base::Time current_time = base::Time::Now(); 405 base::Time current_time = base::Time::Now();
410 base::TimeDelta delta = current_time - touchview_usage_interval_start_time_; 406 base::TimeDelta delta = current_time - touchview_usage_interval_start_time_;
411 switch (type) { 407 switch (type) {
412 case TOUCH_VIEW_INTERVAL_INACTIVE: 408 case TOUCH_VIEW_INTERVAL_INACTIVE:
413 UMA_HISTOGRAM_LONG_TIMES("Ash.TouchView.TouchViewInactive", delta); 409 UMA_HISTOGRAM_LONG_TIMES("Ash.TouchView.TouchViewInactive", delta);
414 total_non_touchview_time_ += delta; 410 total_non_touchview_time_ += delta;
415 break; 411 break;
416 case TOUCH_VIEW_INTERVAL_ACTIVE: 412 case TOUCH_VIEW_INTERVAL_ACTIVE:
417 UMA_HISTOGRAM_LONG_TIMES("Ash.TouchView.TouchViewActive", delta); 413 UMA_HISTOGRAM_LONG_TIMES("Ash.TouchView.TouchViewActive", delta);
418 total_touchview_time_ += delta; 414 total_touchview_time_ += delta;
419 break; 415 break;
420 } 416 }
421 417
422 touchview_usage_interval_start_time_ = current_time; 418 touchview_usage_interval_start_time_ = current_time;
423 } 419 }
424 420
425 MaximizeModeController::TouchViewIntervalType 421 TabletModeController::TouchViewIntervalType
426 MaximizeModeController::CurrentTouchViewIntervalType() { 422 TabletModeController::CurrentTouchViewIntervalType() {
427 if (IsMaximizeModeWindowManagerEnabled()) 423 if (IsTabletModeWindowManagerEnabled())
428 return TOUCH_VIEW_INTERVAL_ACTIVE; 424 return TOUCH_VIEW_INTERVAL_ACTIVE;
429 return TOUCH_VIEW_INTERVAL_INACTIVE; 425 return TOUCH_VIEW_INTERVAL_INACTIVE;
430 } 426 }
431 427
432 void MaximizeModeController::AddObserver(mojom::TouchViewObserverPtr observer) { 428 void TabletModeController::AddObserver(mojom::TouchViewObserverPtr observer) {
433 observer->OnTouchViewToggled(IsMaximizeModeWindowManagerEnabled()); 429 observer->OnTouchViewToggled(IsTabletModeWindowManagerEnabled());
434 observers_.AddPtr(std::move(observer)); 430 observers_.AddPtr(std::move(observer));
435 } 431 }
436 432
437 bool MaximizeModeController::AllowEnterExitMaximizeMode() const { 433 bool TabletModeController::AllowEnterExitTabletMode() const {
438 return force_tablet_mode_ == ForceTabletMode::NONE; 434 return force_tablet_mode_ == ForceTabletMode::NONE;
439 } 435 }
440 436
441 void MaximizeModeController::OnChromeTerminating() { 437 void TabletModeController::OnChromeTerminating() {
442 // The system is about to shut down, so record TouchView usage interval 438 // The system is about to shut down, so record TouchView usage interval
443 // metrics based on whether TouchView mode is currently active. 439 // metrics based on whether TouchView mode is currently active.
444 RecordTouchViewUsageInterval(CurrentTouchViewIntervalType()); 440 RecordTouchViewUsageInterval(CurrentTouchViewIntervalType());
445 441
446 if (CanEnterMaximizeMode()) { 442 if (CanEnterTabletMode()) {
447 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.TouchView.TouchViewActiveTotal", 443 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.TouchView.TouchViewActiveTotal",
448 total_touchview_time_.InMinutes(), 1, 444 total_touchview_time_.InMinutes(), 1,
449 base::TimeDelta::FromDays(7).InMinutes(), 50); 445 base::TimeDelta::FromDays(7).InMinutes(), 50);
450 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.TouchView.TouchViewInactiveTotal", 446 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.TouchView.TouchViewInactiveTotal",
451 total_non_touchview_time_.InMinutes(), 1, 447 total_non_touchview_time_.InMinutes(), 1,
452 base::TimeDelta::FromDays(7).InMinutes(), 50); 448 base::TimeDelta::FromDays(7).InMinutes(), 50);
453 base::TimeDelta total_runtime = 449 base::TimeDelta total_runtime =
454 total_touchview_time_ + total_non_touchview_time_; 450 total_touchview_time_ + total_non_touchview_time_;
455 if (total_runtime.InSeconds() > 0) { 451 if (total_runtime.InSeconds() > 0) {
456 UMA_HISTOGRAM_PERCENTAGE( 452 UMA_HISTOGRAM_PERCENTAGE(
457 "Ash.TouchView.TouchViewActivePercentage", 453 "Ash.TouchView.TouchViewActivePercentage",
458 100 * total_touchview_time_.InSeconds() / total_runtime.InSeconds()); 454 100 * total_touchview_time_.InSeconds() / total_runtime.InSeconds());
459 } 455 }
460 } 456 }
461 } 457 }
462 458
463 void MaximizeModeController::OnGetSwitchStates( 459 void TabletModeController::OnGetSwitchStates(
464 chromeos::PowerManagerClient::LidState lid_state, 460 chromeos::PowerManagerClient::LidState lid_state,
465 chromeos::PowerManagerClient::TabletMode tablet_mode) { 461 chromeos::PowerManagerClient::TabletMode tablet_mode) {
466 LidEventReceived(lid_state, base::TimeTicks::Now()); 462 LidEventReceived(lid_state, base::TimeTicks::Now());
467 TabletModeEventReceived(tablet_mode, base::TimeTicks::Now()); 463 TabletModeEventReceived(tablet_mode, base::TimeTicks::Now());
468 } 464 }
469 465
470 bool MaximizeModeController::WasLidOpenedRecently() const { 466 bool TabletModeController::WasLidOpenedRecently() const {
471 if (last_lid_open_time_.is_null()) 467 if (last_lid_open_time_.is_null())
472 return false; 468 return false;
473 469
474 base::TimeTicks now = tick_clock_->NowTicks(); 470 base::TimeTicks now = tick_clock_->NowTicks();
475 DCHECK(now >= last_lid_open_time_); 471 DCHECK(now >= last_lid_open_time_);
476 base::TimeDelta elapsed_time = now - last_lid_open_time_; 472 base::TimeDelta elapsed_time = now - last_lid_open_time_;
477 return elapsed_time.InSeconds() <= kLidRecentlyOpenedDurationSeconds; 473 return elapsed_time.InSeconds() <= kLidRecentlyOpenedDurationSeconds;
478 } 474 }
479 475
480 void MaximizeModeController::SetTickClockForTest( 476 void TabletModeController::SetTickClockForTest(
481 std::unique_ptr<base::TickClock> tick_clock) { 477 std::unique_ptr<base::TickClock> tick_clock) {
482 DCHECK(tick_clock_); 478 DCHECK(tick_clock_);
483 tick_clock_ = std::move(tick_clock); 479 tick_clock_ = std::move(tick_clock);
484 } 480 }
485 481
486 } // namespace ash 482 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698