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

Side by Side Diff: ash/wm/maximize_mode/maximize_mode_controller.cc

Issue 2020553003: Hook up TABLET_MODE switch to maximize_mode_controller (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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/maximize_mode/maximize_mode_controller.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "ash/accelerators/accelerator_controller.h" 9 #include "ash/accelerators/accelerator_controller.h"
10 #include "ash/accelerators/accelerator_table.h" 10 #include "ash/accelerators/accelerator_table.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 ui::ConvertAccelerometerReadingToVector3dF( 93 ui::ConvertAccelerometerReadingToVector3dF(
94 update.get(chromeos::ACCELEROMETER_SOURCE_SCREEN)).Length()) <= 94 update.get(chromeos::ACCELEROMETER_SOURCE_SCREEN)).Length()) <=
95 kNoisyMagnitudeDeviation; 95 kNoisyMagnitudeDeviation;
96 } 96 }
97 #endif // OS_CHROMEOS 97 #endif // OS_CHROMEOS
98 98
99 } // namespace 99 } // namespace
100 100
101 MaximizeModeController::MaximizeModeController() 101 MaximizeModeController::MaximizeModeController()
102 : have_seen_accelerometer_data_(false), 102 : have_seen_accelerometer_data_(false),
103 lid_open_past_180_(false),
104 touchview_usage_interval_start_time_(base::Time::Now()), 103 touchview_usage_interval_start_time_(base::Time::Now()),
105 tick_clock_(new base::DefaultTickClock()), 104 tick_clock_(new base::DefaultTickClock()),
105 #if defined(OS_CHROMEOS)
106 tablet_mode_switch_is_on_(false),
107 #endif
106 lid_is_closed_(false) { 108 lid_is_closed_(false) {
107 Shell* shell = Shell::GetInstance(); 109 Shell* shell = Shell::GetInstance();
108 shell->AddShellObserver(this); 110 shell->AddShellObserver(this);
109 shell->metrics()->RecordUserMetricsAction( 111 shell->metrics()->RecordUserMetricsAction(
110 ash::UMA_MAXIMIZE_MODE_INITIALLY_DISABLED); 112 ash::UMA_MAXIMIZE_MODE_INITIALLY_DISABLED);
111 113
112 #if defined(OS_CHROMEOS) 114 #if defined(OS_CHROMEOS)
113 // TODO(jonross): Do not create MaximizeModeController if the flag is 115 // TODO(jonross): Do not create MaximizeModeController if the flag is
114 // unavailable. This will require refactoring 116 // unavailable. This will require refactoring
115 // IsMaximizeModeWindowManagerEnabled to check for the existance of the 117 // IsMaximizeModeWindowManagerEnabled to check for the existance of the
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 // Whether or not we enter maximize mode affects whether we handle screen 203 // Whether or not we enter maximize mode affects whether we handle screen
202 // rotation, so determine whether to enter maximize mode first. 204 // rotation, so determine whether to enter maximize mode first.
203 if (!update->has(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD)) { 205 if (!update->has(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD)) {
204 if (first_accelerometer_update) 206 if (first_accelerometer_update)
205 EnterMaximizeMode(); 207 EnterMaximizeMode();
206 } else if (ui::IsAccelerometerReadingStable( 208 } else if (ui::IsAccelerometerReadingStable(
207 *update, chromeos::ACCELEROMETER_SOURCE_SCREEN) && 209 *update, chromeos::ACCELEROMETER_SOURCE_SCREEN) &&
208 ui::IsAccelerometerReadingStable( 210 ui::IsAccelerometerReadingStable(
209 *update, chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD) && 211 *update, chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD) &&
210 IsAngleBetweenAccelerometerReadingsStable(*update)) { 212 IsAngleBetweenAccelerometerReadingsStable(*update)) {
213 if (tablet_mode_switch_is_on_)
214 return;
211 // update.has(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD) 215 // update.has(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD)
212 // Ignore the reading if it appears unstable. The reading is considered 216 // Ignore the reading if it appears unstable. The reading is considered
213 // unstable if it deviates too much from gravity and/or the magnitude of the 217 // unstable if it deviates too much from gravity and/or the magnitude of the
214 // reading from the lid differs too much from the reading from the base. 218 // reading from the lid differs too much from the reading from the base.
215 HandleHingeRotation(update); 219 HandleHingeRotation(update);
216 } 220 }
217 } 221 }
218 222
219 void MaximizeModeController::LidEventReceived(bool open, 223 void MaximizeModeController::LidEventReceived(bool open,
220 const base::TimeTicks& time) { 224 const base::TimeTicks& time) {
221 if (open) 225 if (open)
222 last_lid_open_time_ = time; 226 last_lid_open_time_ = time;
223 lid_is_closed_ = !open; 227 lid_is_closed_ = !open;
224 LeaveMaximizeMode(); 228 LeaveMaximizeMode();
225 } 229 }
226 230
231 void MaximizeModeController::TabletModeEventReceived(
232 bool on,
233 const base::TimeTicks& time) {
234 tablet_mode_switch_is_on_ = on;
235 if (on && !IsMaximizeModeWindowManagerEnabled())
236 EnterMaximizeMode();
237 }
238
227 void MaximizeModeController::SuspendImminent() { 239 void MaximizeModeController::SuspendImminent() {
228 // The system is about to suspend, so record TouchView usage interval metrics 240 // The system is about to suspend, so record TouchView usage interval metrics
229 // based on whether TouchView mode is currently active. 241 // based on whether TouchView mode is currently active.
230 RecordTouchViewUsageInterval(CurrentTouchViewIntervalType()); 242 RecordTouchViewUsageInterval(CurrentTouchViewIntervalType());
231 } 243 }
232 244
233 void MaximizeModeController::SuspendDone( 245 void MaximizeModeController::SuspendDone(
234 const base::TimeDelta& sleep_duration) { 246 const base::TimeDelta& sleep_duration) {
235 // We do not want TouchView usage metrics to include time spent in suspend. 247 // We do not want TouchView usage metrics to include time spent in suspend.
236 touchview_usage_interval_start_time_ = base::Time::Now(); 248 touchview_usage_interval_start_time_ = base::Time::Now();
(...skipping 12 matching lines...) Expand all
249 // Smooth out instantaneous acceleration when nearly vertical to increase 261 // Smooth out instantaneous acceleration when nearly vertical to increase
250 // accuracy. 262 // accuracy.
251 float largest_hinge_acceleration = 263 float largest_hinge_acceleration =
252 std::max(std::abs(base_reading.x()), std::abs(lid_reading.x())); 264 std::max(std::abs(base_reading.x()), std::abs(lid_reading.x()));
253 float smoothing_ratio = 265 float smoothing_ratio =
254 std::max(0.0f, std::min(1.0f, (largest_hinge_acceleration - 266 std::max(0.0f, std::min(1.0f, (largest_hinge_acceleration -
255 kHingeVerticalSmoothingStart) / 267 kHingeVerticalSmoothingStart) /
256 (kHingeVerticalSmoothingMaximum - 268 (kHingeVerticalSmoothingMaximum -
257 kHingeVerticalSmoothingStart))); 269 kHingeVerticalSmoothingStart)));
258 270
271 // We cannot trust the computed lid angle when the device is held vertically.
272 bool is_angle_reliable =
273 std::abs(base_reading.x()) > kHingeVerticalSmoothingMaximum;
274
259 base_smoothed_.Scale(smoothing_ratio); 275 base_smoothed_.Scale(smoothing_ratio);
260 base_reading.Scale(1.0f - smoothing_ratio); 276 base_reading.Scale(1.0f - smoothing_ratio);
261 base_smoothed_.Add(base_reading); 277 base_smoothed_.Add(base_reading);
262 278
263 lid_smoothed_.Scale(smoothing_ratio); 279 lid_smoothed_.Scale(smoothing_ratio);
264 lid_reading.Scale(1.0f - smoothing_ratio); 280 lid_reading.Scale(1.0f - smoothing_ratio);
265 lid_smoothed_.Add(lid_reading); 281 lid_smoothed_.Add(lid_reading);
266 282
267 // Ignore the component of acceleration parallel to the hinge for the purposes 283 // Ignore the component of acceleration parallel to the hinge for the purposes
268 // of hinge angle calculation. 284 // of hinge angle calculation.
269 gfx::Vector3dF base_flattened(base_smoothed_); 285 gfx::Vector3dF base_flattened(base_smoothed_);
270 gfx::Vector3dF lid_flattened(lid_smoothed_); 286 gfx::Vector3dF lid_flattened(lid_smoothed_);
271 base_flattened.set_x(0.0f); 287 base_flattened.set_x(0.0f);
272 lid_flattened.set_x(0.0f); 288 lid_flattened.set_x(0.0f);
273 289
274 // Compute the angle between the base and the lid. 290 // Compute the angle between the base and the lid.
275 float lid_angle = 180.0f - gfx::ClockwiseAngleBetweenVectorsInDegrees( 291 float lid_angle = 180.0f - gfx::ClockwiseAngleBetweenVectorsInDegrees(
276 base_flattened, lid_flattened, hinge_vector); 292 base_flattened, lid_flattened, hinge_vector);
277 if (lid_angle < 0.0f) 293 if (lid_angle < 0.0f)
278 lid_angle += 360.0f; 294 lid_angle += 360.0f;
279 295
280 bool is_angle_stable = lid_angle >= kMinStableAngle && 296 bool is_angle_stable = !is_angle_reliable && lid_angle >= kMinStableAngle &&
jonross 2016/06/07 15:27:15 On devices without a tablet mode switch, does this
jcliang 2016/06/07 16:57:23 Ah, there's a typo here. I forgot to invert the co
jonross 2016/06/07 22:04:42 That SGTM
281 lid_angle <= kMaxStableAngle; 297 lid_angle <= kMaxStableAngle;
282 298
283 // Clear the last_lid_open_time_ for a stable reading so that there is less 299 // Clear the last_lid_open_time_ for a stable reading so that there is less
284 // chance of a delay if the lid is moved from the close state to the fully 300 // chance of a delay if the lid is moved from the close state to the fully
285 // open state very quickly. 301 // open state very quickly.
286 if (is_angle_stable) 302 if (is_angle_stable)
287 last_lid_open_time_ = base::TimeTicks(); 303 last_lid_open_time_ = base::TimeTicks();
288 304
289 // Toggle maximize mode on or off when corresponding thresholds are passed. 305 // Toggle maximize mode on or off when corresponding thresholds are passed.
290 if (lid_open_past_180_ && is_angle_stable && 306 if (IsMaximizeModeWindowManagerEnabled() && is_angle_stable &&
291 lid_angle <= kExitMaximizeModeAngle) { 307 lid_angle <= kExitMaximizeModeAngle) {
292 lid_open_past_180_ = false;
293 LeaveMaximizeMode(); 308 LeaveMaximizeMode();
294 } else if (!lid_open_past_180_ && !lid_is_closed_ && 309 } else if (!IsMaximizeModeWindowManagerEnabled() && !lid_is_closed_ &&
295 lid_angle >= kEnterMaximizeModeAngle && 310 lid_angle >= kEnterMaximizeModeAngle &&
296 (is_angle_stable || !WasLidOpenedRecently())) { 311 (is_angle_stable || !WasLidOpenedRecently())) {
297 lid_open_past_180_ = true;
298 EnterMaximizeMode(); 312 EnterMaximizeMode();
299 } 313 }
300 } 314 }
301 #endif // OS_CHROMEOS 315 #endif // OS_CHROMEOS
302 316
303 void MaximizeModeController::EnterMaximizeMode() { 317 void MaximizeModeController::EnterMaximizeMode() {
304 // Always reset first to avoid creation before destruction of a previous 318 // Always reset first to avoid creation before destruction of a previous
305 // object. 319 // object.
306 event_blocker_.reset(); 320 event_blocker_.reset();
307 #if defined(USE_X11) 321 #if defined(USE_X11)
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 return elapsed_time.InSeconds() <= kLidRecentlyOpenedDurationSeconds; 429 return elapsed_time.InSeconds() <= kLidRecentlyOpenedDurationSeconds;
416 } 430 }
417 431
418 void MaximizeModeController::SetTickClockForTest( 432 void MaximizeModeController::SetTickClockForTest(
419 std::unique_ptr<base::TickClock> tick_clock) { 433 std::unique_ptr<base::TickClock> tick_clock) {
420 DCHECK(tick_clock_); 434 DCHECK(tick_clock_);
421 tick_clock_ = std::move(tick_clock); 435 tick_clock_ = std::move(tick_clock);
422 } 436 }
423 437
424 } // namespace ash 438 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/maximize_mode/maximize_mode_controller.h ('k') | ash/wm/maximize_mode/maximize_mode_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698