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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 Loading... | |
| 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 if (on) { | |
|
Daniel Erat
2016/06/06 18:57:14
nit: you can simplify this to:
tablet_mode_swit
jcliang
2016/06/07 07:27:30
Done.
| |
| 235 tablet_mode_switch_is_on_ = true; | |
| 236 if (!IsMaximizeModeWindowManagerEnabled()) | |
| 237 EnterMaximizeMode(); | |
| 238 } else { | |
| 239 tablet_mode_switch_is_on_ = false; | |
| 240 } | |
| 241 } | |
| 242 | |
| 227 void MaximizeModeController::SuspendImminent() { | 243 void MaximizeModeController::SuspendImminent() { |
| 228 // The system is about to suspend, so record TouchView usage interval metrics | 244 // The system is about to suspend, so record TouchView usage interval metrics |
| 229 // based on whether TouchView mode is currently active. | 245 // based on whether TouchView mode is currently active. |
| 230 RecordTouchViewUsageInterval(CurrentTouchViewIntervalType()); | 246 RecordTouchViewUsageInterval(CurrentTouchViewIntervalType()); |
| 231 } | 247 } |
| 232 | 248 |
| 233 void MaximizeModeController::SuspendDone( | 249 void MaximizeModeController::SuspendDone( |
| 234 const base::TimeDelta& sleep_duration) { | 250 const base::TimeDelta& sleep_duration) { |
| 235 // We do not want TouchView usage metrics to include time spent in suspend. | 251 // We do not want TouchView usage metrics to include time spent in suspend. |
| 236 touchview_usage_interval_start_time_ = base::Time::Now(); | 252 touchview_usage_interval_start_time_ = base::Time::Now(); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 248 // approach the same values making any angle calculations highly inaccurate. | 264 // approach the same values making any angle calculations highly inaccurate. |
| 249 // Smooth out instantaneous acceleration when nearly vertical to increase | 265 // Smooth out instantaneous acceleration when nearly vertical to increase |
| 250 // accuracy. | 266 // accuracy. |
| 251 float largest_hinge_acceleration = | 267 float largest_hinge_acceleration = |
| 252 std::max(std::abs(base_reading.x()), std::abs(lid_reading.x())); | 268 std::max(std::abs(base_reading.x()), std::abs(lid_reading.x())); |
| 253 float smoothing_ratio = | 269 float smoothing_ratio = |
| 254 std::max(0.0f, std::min(1.0f, (largest_hinge_acceleration - | 270 std::max(0.0f, std::min(1.0f, (largest_hinge_acceleration - |
| 255 kHingeVerticalSmoothingStart) / | 271 kHingeVerticalSmoothingStart) / |
| 256 (kHingeVerticalSmoothingMaximum - | 272 (kHingeVerticalSmoothingMaximum - |
| 257 kHingeVerticalSmoothingStart))); | 273 kHingeVerticalSmoothingStart))); |
| 274 bool is_base_vertical = | |
| 275 std::abs(base_reading.x()) > kHingeVerticalSmoothingMaximum; | |
|
Daniel Erat
2016/06/06 18:57:14
could you add a comment here? i don't understand e
jcliang
2016/06/07 07:27:30
Done.
| |
| 258 | 276 |
| 259 base_smoothed_.Scale(smoothing_ratio); | 277 base_smoothed_.Scale(smoothing_ratio); |
| 260 base_reading.Scale(1.0f - smoothing_ratio); | 278 base_reading.Scale(1.0f - smoothing_ratio); |
| 261 base_smoothed_.Add(base_reading); | 279 base_smoothed_.Add(base_reading); |
| 262 | 280 |
| 263 lid_smoothed_.Scale(smoothing_ratio); | 281 lid_smoothed_.Scale(smoothing_ratio); |
| 264 lid_reading.Scale(1.0f - smoothing_ratio); | 282 lid_reading.Scale(1.0f - smoothing_ratio); |
| 265 lid_smoothed_.Add(lid_reading); | 283 lid_smoothed_.Add(lid_reading); |
| 266 | 284 |
| 267 // 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 |
| 268 // of hinge angle calculation. | 286 // of hinge angle calculation. |
| 269 gfx::Vector3dF base_flattened(base_smoothed_); | 287 gfx::Vector3dF base_flattened(base_smoothed_); |
| 270 gfx::Vector3dF lid_flattened(lid_smoothed_); | 288 gfx::Vector3dF lid_flattened(lid_smoothed_); |
| 271 base_flattened.set_x(0.0f); | 289 base_flattened.set_x(0.0f); |
| 272 lid_flattened.set_x(0.0f); | 290 lid_flattened.set_x(0.0f); |
| 273 | 291 |
| 274 // Compute the angle between the base and the lid. | 292 // Compute the angle between the base and the lid. |
| 275 float lid_angle = 180.0f - gfx::ClockwiseAngleBetweenVectorsInDegrees( | 293 float lid_angle = 180.0f - gfx::ClockwiseAngleBetweenVectorsInDegrees( |
| 276 base_flattened, lid_flattened, hinge_vector); | 294 base_flattened, lid_flattened, hinge_vector); |
| 277 if (lid_angle < 0.0f) | 295 if (lid_angle < 0.0f) |
| 278 lid_angle += 360.0f; | 296 lid_angle += 360.0f; |
| 279 | 297 |
| 280 bool is_angle_stable = lid_angle >= kMinStableAngle && | 298 bool is_angle_stable = !is_base_vertical && lid_angle >= kMinStableAngle && |
| 281 lid_angle <= kMaxStableAngle; | 299 lid_angle <= kMaxStableAngle; |
| 282 | 300 |
| 283 // 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 |
| 284 // 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 |
| 285 // open state very quickly. | 303 // open state very quickly. |
| 286 if (is_angle_stable) | 304 if (is_angle_stable) |
| 287 last_lid_open_time_ = base::TimeTicks(); | 305 last_lid_open_time_ = base::TimeTicks(); |
| 288 | 306 |
| 289 // Toggle maximize mode on or off when corresponding thresholds are passed. | 307 // Toggle maximize mode on or off when corresponding thresholds are passed. |
| 290 if (lid_open_past_180_ && is_angle_stable && | 308 if (IsMaximizeModeWindowManagerEnabled() && is_angle_stable && |
| 291 lid_angle <= kExitMaximizeModeAngle) { | 309 lid_angle <= kExitMaximizeModeAngle) { |
| 292 lid_open_past_180_ = false; | |
| 293 LeaveMaximizeMode(); | 310 LeaveMaximizeMode(); |
| 294 } else if (!lid_open_past_180_ && !lid_is_closed_ && | 311 } else if (!IsMaximizeModeWindowManagerEnabled() && !lid_is_closed_ && |
| 295 lid_angle >= kEnterMaximizeModeAngle && | 312 lid_angle >= kEnterMaximizeModeAngle && |
| 296 (is_angle_stable || !WasLidOpenedRecently())) { | 313 (is_angle_stable || !WasLidOpenedRecently())) { |
| 297 lid_open_past_180_ = true; | |
| 298 EnterMaximizeMode(); | 314 EnterMaximizeMode(); |
| 299 } | 315 } |
| 300 } | 316 } |
| 301 #endif // OS_CHROMEOS | 317 #endif // OS_CHROMEOS |
| 302 | 318 |
| 303 void MaximizeModeController::EnterMaximizeMode() { | 319 void MaximizeModeController::EnterMaximizeMode() { |
| 304 // Always reset first to avoid creation before destruction of a previous | 320 // Always reset first to avoid creation before destruction of a previous |
| 305 // object. | 321 // object. |
| 306 event_blocker_.reset(); | 322 event_blocker_.reset(); |
| 307 #if defined(USE_X11) | 323 #if defined(USE_X11) |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 415 return elapsed_time.InSeconds() <= kLidRecentlyOpenedDurationSeconds; | 431 return elapsed_time.InSeconds() <= kLidRecentlyOpenedDurationSeconds; |
| 416 } | 432 } |
| 417 | 433 |
| 418 void MaximizeModeController::SetTickClockForTest( | 434 void MaximizeModeController::SetTickClockForTest( |
| 419 std::unique_ptr<base::TickClock> tick_clock) { | 435 std::unique_ptr<base::TickClock> tick_clock) { |
| 420 DCHECK(tick_clock_); | 436 DCHECK(tick_clock_); |
| 421 tick_clock_ = std::move(tick_clock); | 437 tick_clock_ = std::move(tick_clock); |
| 422 } | 438 } |
| 423 | 439 |
| 424 } // namespace ash | 440 } // namespace ash |
| OLD | NEW |