Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 ui::ConvertAccelerometerReadingToVector3dF( | 94 ui::ConvertAccelerometerReadingToVector3dF( |
| 95 update.get(chromeos::ACCELEROMETER_SOURCE_SCREEN)).Length()) <= | 95 update.get(chromeos::ACCELEROMETER_SOURCE_SCREEN)).Length()) <= |
| 96 kNoisyMagnitudeDeviation; | 96 kNoisyMagnitudeDeviation; |
| 97 } | 97 } |
| 98 #endif // OS_CHROMEOS | 98 #endif // OS_CHROMEOS |
| 99 | 99 |
| 100 } // namespace | 100 } // namespace |
| 101 | 101 |
| 102 MaximizeModeController::MaximizeModeController() | 102 MaximizeModeController::MaximizeModeController() |
| 103 : have_seen_accelerometer_data_(false), | 103 : have_seen_accelerometer_data_(false), |
| 104 lid_open_past_180_(false), | |
| 105 touchview_usage_interval_start_time_(base::Time::Now()), | 104 touchview_usage_interval_start_time_(base::Time::Now()), |
| 106 tick_clock_(new base::DefaultTickClock()), | 105 tick_clock_(new base::DefaultTickClock()), |
| 106 #if defined(OS_CHROMEOS) | |
| 107 tablet_mode_switch_is_on_(false), | |
| 108 #endif | |
| 107 lid_is_closed_(false) { | 109 lid_is_closed_(false) { |
| 108 WmShell::Get()->AddShellObserver(this); | 110 WmShell::Get()->AddShellObserver(this); |
| 109 Shell* shell = Shell::GetInstance(); | 111 Shell* shell = Shell::GetInstance(); |
| 110 shell->metrics()->RecordUserMetricsAction( | 112 shell->metrics()->RecordUserMetricsAction( |
| 111 ash::UMA_MAXIMIZE_MODE_INITIALLY_DISABLED); | 113 ash::UMA_MAXIMIZE_MODE_INITIALLY_DISABLED); |
| 112 | 114 |
| 113 #if defined(OS_CHROMEOS) | 115 #if defined(OS_CHROMEOS) |
| 114 // TODO(jonross): Do not create MaximizeModeController if the flag is | 116 // TODO(jonross): Do not create MaximizeModeController if the flag is |
| 115 // unavailable. This will require refactoring | 117 // unavailable. This will require refactoring |
| 116 // IsMaximizeModeWindowManagerEnabled to check for the existance of the | 118 // IsMaximizeModeWindowManagerEnabled to check for the existance of the |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 } | 220 } |
| 219 | 221 |
| 220 void MaximizeModeController::LidEventReceived(bool open, | 222 void MaximizeModeController::LidEventReceived(bool open, |
| 221 const base::TimeTicks& time) { | 223 const base::TimeTicks& time) { |
| 222 if (open) | 224 if (open) |
| 223 last_lid_open_time_ = time; | 225 last_lid_open_time_ = time; |
| 224 lid_is_closed_ = !open; | 226 lid_is_closed_ = !open; |
| 225 LeaveMaximizeMode(); | 227 LeaveMaximizeMode(); |
| 226 } | 228 } |
| 227 | 229 |
| 230 void MaximizeModeController::TabletModeEventReceived( | |
| 231 bool on, | |
| 232 const base::TimeTicks& time) { | |
| 233 tablet_mode_switch_is_on_ = on; | |
| 234 if (on && !IsMaximizeModeWindowManagerEnabled()) | |
| 235 EnterMaximizeMode(); | |
| 236 } | |
| 237 | |
| 228 void MaximizeModeController::SuspendImminent() { | 238 void MaximizeModeController::SuspendImminent() { |
| 229 // The system is about to suspend, so record TouchView usage interval metrics | 239 // The system is about to suspend, so record TouchView usage interval metrics |
| 230 // based on whether TouchView mode is currently active. | 240 // based on whether TouchView mode is currently active. |
| 231 RecordTouchViewUsageInterval(CurrentTouchViewIntervalType()); | 241 RecordTouchViewUsageInterval(CurrentTouchViewIntervalType()); |
| 232 } | 242 } |
| 233 | 243 |
| 234 void MaximizeModeController::SuspendDone( | 244 void MaximizeModeController::SuspendDone( |
| 235 const base::TimeDelta& sleep_duration) { | 245 const base::TimeDelta& sleep_duration) { |
| 236 // We do not want TouchView usage metrics to include time spent in suspend. | 246 // We do not want TouchView usage metrics to include time spent in suspend. |
| 237 touchview_usage_interval_start_time_ = base::Time::Now(); | 247 touchview_usage_interval_start_time_ = base::Time::Now(); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 250 // Smooth out instantaneous acceleration when nearly vertical to increase | 260 // Smooth out instantaneous acceleration when nearly vertical to increase |
| 251 // accuracy. | 261 // accuracy. |
| 252 float largest_hinge_acceleration = | 262 float largest_hinge_acceleration = |
| 253 std::max(std::abs(base_reading.x()), std::abs(lid_reading.x())); | 263 std::max(std::abs(base_reading.x()), std::abs(lid_reading.x())); |
| 254 float smoothing_ratio = | 264 float smoothing_ratio = |
| 255 std::max(0.0f, std::min(1.0f, (largest_hinge_acceleration - | 265 std::max(0.0f, std::min(1.0f, (largest_hinge_acceleration - |
| 256 kHingeVerticalSmoothingStart) / | 266 kHingeVerticalSmoothingStart) / |
| 257 (kHingeVerticalSmoothingMaximum - | 267 (kHingeVerticalSmoothingMaximum - |
| 258 kHingeVerticalSmoothingStart))); | 268 kHingeVerticalSmoothingStart))); |
| 259 | 269 |
| 270 // We cannot trust the computed lid angle when the device is held vertically. | |
| 271 bool is_angle_reliable = | |
| 272 std::abs(base_reading.x()) <= kHingeVerticalSmoothingMaximum; | |
|
flackr
2016/06/15 07:53:24
This should check largest_hinge_acceleration inste
jcliang
2016/06/15 08:14:10
Done.
| |
| 273 | |
| 260 base_smoothed_.Scale(smoothing_ratio); | 274 base_smoothed_.Scale(smoothing_ratio); |
| 261 base_reading.Scale(1.0f - smoothing_ratio); | 275 base_reading.Scale(1.0f - smoothing_ratio); |
| 262 base_smoothed_.Add(base_reading); | 276 base_smoothed_.Add(base_reading); |
| 263 | 277 |
| 264 lid_smoothed_.Scale(smoothing_ratio); | 278 lid_smoothed_.Scale(smoothing_ratio); |
| 265 lid_reading.Scale(1.0f - smoothing_ratio); | 279 lid_reading.Scale(1.0f - smoothing_ratio); |
| 266 lid_smoothed_.Add(lid_reading); | 280 lid_smoothed_.Add(lid_reading); |
| 267 | 281 |
| 282 if (tablet_mode_switch_is_on_) | |
| 283 return; | |
| 284 | |
| 268 // Ignore the component of acceleration parallel to the hinge for the purposes | 285 // Ignore the component of acceleration parallel to the hinge for the purposes |
| 269 // of hinge angle calculation. | 286 // of hinge angle calculation. |
| 270 gfx::Vector3dF base_flattened(base_smoothed_); | 287 gfx::Vector3dF base_flattened(base_smoothed_); |
| 271 gfx::Vector3dF lid_flattened(lid_smoothed_); | 288 gfx::Vector3dF lid_flattened(lid_smoothed_); |
| 272 base_flattened.set_x(0.0f); | 289 base_flattened.set_x(0.0f); |
| 273 lid_flattened.set_x(0.0f); | 290 lid_flattened.set_x(0.0f); |
| 274 | 291 |
| 275 // Compute the angle between the base and the lid. | 292 // Compute the angle between the base and the lid. |
| 276 float lid_angle = 180.0f - gfx::ClockwiseAngleBetweenVectorsInDegrees( | 293 float lid_angle = 180.0f - gfx::ClockwiseAngleBetweenVectorsInDegrees( |
| 277 base_flattened, lid_flattened, hinge_vector); | 294 base_flattened, lid_flattened, hinge_vector); |
| 278 if (lid_angle < 0.0f) | 295 if (lid_angle < 0.0f) |
| 279 lid_angle += 360.0f; | 296 lid_angle += 360.0f; |
| 280 | 297 |
| 281 bool is_angle_stable = lid_angle >= kMinStableAngle && | 298 bool is_angle_stable = is_angle_reliable && lid_angle >= kMinStableAngle && |
| 282 lid_angle <= kMaxStableAngle; | 299 lid_angle <= kMaxStableAngle; |
| 283 | 300 |
| 284 // Clear the last_lid_open_time_ for a stable reading so that there is less | 301 // Clear the last_lid_open_time_ for a stable reading so that there is less |
| 285 // chance of a delay if the lid is moved from the close state to the fully | 302 // chance of a delay if the lid is moved from the close state to the fully |
| 286 // open state very quickly. | 303 // open state very quickly. |
| 287 if (is_angle_stable) | 304 if (is_angle_stable) |
| 288 last_lid_open_time_ = base::TimeTicks(); | 305 last_lid_open_time_ = base::TimeTicks(); |
| 289 | 306 |
| 290 // Toggle maximize mode on or off when corresponding thresholds are passed. | 307 // Toggle maximize mode on or off when corresponding thresholds are passed. |
| 291 if (lid_open_past_180_ && is_angle_stable && | 308 if (IsMaximizeModeWindowManagerEnabled() && is_angle_stable && |
|
flackr
2016/06/15 07:53:24
Unfortunately IsMaximizeModeWindowManagerEnabled i
jcliang
2016/06/15 08:14:10
So this change will only impact touchview testing
| |
| 292 lid_angle <= kExitMaximizeModeAngle) { | 309 lid_angle <= kExitMaximizeModeAngle) { |
| 293 lid_open_past_180_ = false; | |
| 294 LeaveMaximizeMode(); | 310 LeaveMaximizeMode(); |
| 295 } else if (!lid_open_past_180_ && !lid_is_closed_ && | 311 } else if (!IsMaximizeModeWindowManagerEnabled() && !lid_is_closed_ && |
| 296 lid_angle >= kEnterMaximizeModeAngle && | 312 lid_angle >= kEnterMaximizeModeAngle && |
| 297 (is_angle_stable || !WasLidOpenedRecently())) { | 313 (is_angle_stable || !WasLidOpenedRecently())) { |
| 298 lid_open_past_180_ = true; | |
| 299 EnterMaximizeMode(); | 314 EnterMaximizeMode(); |
| 300 } | 315 } |
| 301 } | 316 } |
| 302 #endif // OS_CHROMEOS | 317 #endif // OS_CHROMEOS |
| 303 | 318 |
| 304 void MaximizeModeController::EnterMaximizeMode() { | 319 void MaximizeModeController::EnterMaximizeMode() { |
| 305 // Always reset first to avoid creation before destruction of a previous | 320 // Always reset first to avoid creation before destruction of a previous |
| 306 // object. | 321 // object. |
| 307 event_blocker_.reset(); | 322 event_blocker_.reset(); |
| 308 #if defined(USE_X11) | 323 #if defined(USE_X11) |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 416 return elapsed_time.InSeconds() <= kLidRecentlyOpenedDurationSeconds; | 431 return elapsed_time.InSeconds() <= kLidRecentlyOpenedDurationSeconds; |
| 417 } | 432 } |
| 418 | 433 |
| 419 void MaximizeModeController::SetTickClockForTest( | 434 void MaximizeModeController::SetTickClockForTest( |
| 420 std::unique_ptr<base::TickClock> tick_clock) { | 435 std::unique_ptr<base::TickClock> tick_clock) { |
| 421 DCHECK(tick_clock_); | 436 DCHECK(tick_clock_); |
| 422 tick_clock_ = std::move(tick_clock); | 437 tick_clock_ = std::move(tick_clock); |
| 423 } | 438 } |
| 424 | 439 |
| 425 } // namespace ash | 440 } // namespace ash |
| OLD | NEW |