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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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), | 103 lid_open_past_180_(false), |
| 104 touchview_usage_interval_start_time_(base::Time::Now()), | 104 touchview_usage_interval_start_time_(base::Time::Now()), |
| 105 tick_clock_(new base::DefaultTickClock()), | 105 tick_clock_(new base::DefaultTickClock()), |
| 106 #if defined(OS_CHROMEOS) | |
| 107 tablet_mode_switch_was_on_(false), | |
| 108 #endif | |
| 106 lid_is_closed_(false) { | 109 lid_is_closed_(false) { |
| 107 Shell* shell = Shell::GetInstance(); | 110 Shell* shell = Shell::GetInstance(); |
| 108 shell->AddShellObserver(this); | 111 shell->AddShellObserver(this); |
| 109 shell->metrics()->RecordUserMetricsAction( | 112 shell->metrics()->RecordUserMetricsAction( |
| 110 ash::UMA_MAXIMIZE_MODE_INITIALLY_DISABLED); | 113 ash::UMA_MAXIMIZE_MODE_INITIALLY_DISABLED); |
| 111 | 114 |
| 112 #if defined(OS_CHROMEOS) | 115 #if defined(OS_CHROMEOS) |
| 113 // TODO(jonross): Do not create MaximizeModeController if the flag is | 116 // TODO(jonross): Do not create MaximizeModeController if the flag is |
| 114 // unavailable. This will require refactoring | 117 // unavailable. This will require refactoring |
| 115 // 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... | |
| 217 } | 220 } |
| 218 | 221 |
| 219 void MaximizeModeController::LidEventReceived(bool open, | 222 void MaximizeModeController::LidEventReceived(bool open, |
| 220 const base::TimeTicks& time) { | 223 const base::TimeTicks& time) { |
| 221 if (open) | 224 if (open) |
| 222 last_lid_open_time_ = time; | 225 last_lid_open_time_ = time; |
| 223 lid_is_closed_ = !open; | 226 lid_is_closed_ = !open; |
| 224 LeaveMaximizeMode(); | 227 LeaveMaximizeMode(); |
| 225 } | 228 } |
| 226 | 229 |
| 230 void MaximizeModeController::TabletModeEventReceived( | |
| 231 bool on, | |
| 232 const base::TimeTicks& time) { | |
| 233 if (on) { | |
| 234 chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this); | |
| 235 EnterMaximizeMode(); | |
| 236 } else { | |
| 237 tablet_mode_switch_was_on_ = true; | |
| 238 chromeos::AccelerometerReader::GetInstance()->AddObserver(this); | |
|
Daniel Erat
2016/06/06 15:24:55
this approach seems problematic. if powerd sends m
jcliang
2016/06/06 16:48:36
I didn't realize that {Add|Remove}Observer() are n
| |
| 239 } | |
| 240 } | |
| 241 | |
| 227 void MaximizeModeController::SuspendImminent() { | 242 void MaximizeModeController::SuspendImminent() { |
| 228 // The system is about to suspend, so record TouchView usage interval metrics | 243 // The system is about to suspend, so record TouchView usage interval metrics |
| 229 // based on whether TouchView mode is currently active. | 244 // based on whether TouchView mode is currently active. |
| 230 RecordTouchViewUsageInterval(CurrentTouchViewIntervalType()); | 245 RecordTouchViewUsageInterval(CurrentTouchViewIntervalType()); |
| 231 } | 246 } |
| 232 | 247 |
| 233 void MaximizeModeController::SuspendDone( | 248 void MaximizeModeController::SuspendDone( |
| 234 const base::TimeDelta& sleep_duration) { | 249 const base::TimeDelta& sleep_duration) { |
| 235 // We do not want TouchView usage metrics to include time spent in suspend. | 250 // We do not want TouchView usage metrics to include time spent in suspend. |
| 236 touchview_usage_interval_start_time_ = base::Time::Now(); | 251 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. | 263 // approach the same values making any angle calculations highly inaccurate. |
| 249 // Smooth out instantaneous acceleration when nearly vertical to increase | 264 // Smooth out instantaneous acceleration when nearly vertical to increase |
| 250 // accuracy. | 265 // accuracy. |
| 251 float largest_hinge_acceleration = | 266 float largest_hinge_acceleration = |
| 252 std::max(std::abs(base_reading.x()), std::abs(lid_reading.x())); | 267 std::max(std::abs(base_reading.x()), std::abs(lid_reading.x())); |
| 253 float smoothing_ratio = | 268 float smoothing_ratio = |
| 254 std::max(0.0f, std::min(1.0f, (largest_hinge_acceleration - | 269 std::max(0.0f, std::min(1.0f, (largest_hinge_acceleration - |
| 255 kHingeVerticalSmoothingStart) / | 270 kHingeVerticalSmoothingStart) / |
| 256 (kHingeVerticalSmoothingMaximum - | 271 (kHingeVerticalSmoothingMaximum - |
| 257 kHingeVerticalSmoothingStart))); | 272 kHingeVerticalSmoothingStart))); |
| 273 bool is_base_vertical = | |
| 274 std::abs(base_reading.x()) > kHingeVerticalSmoothingMaximum; | |
| 258 | 275 |
| 259 base_smoothed_.Scale(smoothing_ratio); | 276 base_smoothed_.Scale(smoothing_ratio); |
| 260 base_reading.Scale(1.0f - smoothing_ratio); | 277 base_reading.Scale(1.0f - smoothing_ratio); |
| 261 base_smoothed_.Add(base_reading); | 278 base_smoothed_.Add(base_reading); |
| 262 | 279 |
| 263 lid_smoothed_.Scale(smoothing_ratio); | 280 lid_smoothed_.Scale(smoothing_ratio); |
| 264 lid_reading.Scale(1.0f - smoothing_ratio); | 281 lid_reading.Scale(1.0f - smoothing_ratio); |
| 265 lid_smoothed_.Add(lid_reading); | 282 lid_smoothed_.Add(lid_reading); |
| 266 | 283 |
| 267 // Ignore the component of acceleration parallel to the hinge for the purposes | 284 // Ignore the component of acceleration parallel to the hinge for the purposes |
| 268 // of hinge angle calculation. | 285 // of hinge angle calculation. |
| 269 gfx::Vector3dF base_flattened(base_smoothed_); | 286 gfx::Vector3dF base_flattened(base_smoothed_); |
| 270 gfx::Vector3dF lid_flattened(lid_smoothed_); | 287 gfx::Vector3dF lid_flattened(lid_smoothed_); |
| 271 base_flattened.set_x(0.0f); | 288 base_flattened.set_x(0.0f); |
| 272 lid_flattened.set_x(0.0f); | 289 lid_flattened.set_x(0.0f); |
| 273 | 290 |
| 274 // Compute the angle between the base and the lid. | 291 // Compute the angle between the base and the lid. |
| 275 float lid_angle = 180.0f - gfx::ClockwiseAngleBetweenVectorsInDegrees( | 292 float lid_angle = 180.0f - gfx::ClockwiseAngleBetweenVectorsInDegrees( |
| 276 base_flattened, lid_flattened, hinge_vector); | 293 base_flattened, lid_flattened, hinge_vector); |
| 277 if (lid_angle < 0.0f) | 294 if (lid_angle < 0.0f) |
| 278 lid_angle += 360.0f; | 295 lid_angle += 360.0f; |
| 279 | 296 |
| 280 bool is_angle_stable = lid_angle >= kMinStableAngle && | 297 bool is_angle_stable = !is_base_vertical && lid_angle >= kMinStableAngle && |
| 281 lid_angle <= kMaxStableAngle; | 298 lid_angle <= kMaxStableAngle; |
| 282 | 299 |
| 283 // Clear the last_lid_open_time_ for a stable reading so that there is less | 300 // 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 | 301 // chance of a delay if the lid is moved from the close state to the fully |
| 285 // open state very quickly. | 302 // open state very quickly. |
| 286 if (is_angle_stable) | 303 if (is_angle_stable) |
| 287 last_lid_open_time_ = base::TimeTicks(); | 304 last_lid_open_time_ = base::TimeTicks(); |
| 288 | 305 |
| 289 // Toggle maximize mode on or off when corresponding thresholds are passed. | 306 // Toggle maximize mode on or off when corresponding thresholds are passed. |
| 290 if (lid_open_past_180_ && is_angle_stable && | 307 if ((lid_open_past_180_ || tablet_mode_switch_was_on_) && is_angle_stable && |
| 291 lid_angle <= kExitMaximizeModeAngle) { | 308 lid_angle <= kExitMaximizeModeAngle) { |
| 292 lid_open_past_180_ = false; | 309 lid_open_past_180_ = false; |
| 310 tablet_mode_switch_was_on_ = false; | |
| 293 LeaveMaximizeMode(); | 311 LeaveMaximizeMode(); |
| 294 } else if (!lid_open_past_180_ && !lid_is_closed_ && | 312 } else if (!lid_open_past_180_ && !lid_is_closed_ && |
| 295 lid_angle >= kEnterMaximizeModeAngle && | 313 lid_angle >= kEnterMaximizeModeAngle && |
| 296 (is_angle_stable || !WasLidOpenedRecently())) { | 314 (is_angle_stable || !WasLidOpenedRecently())) { |
| 297 lid_open_past_180_ = true; | 315 lid_open_past_180_ = true; |
| 298 EnterMaximizeMode(); | 316 EnterMaximizeMode(); |
| 299 } | 317 } |
| 300 } | 318 } |
| 301 #endif // OS_CHROMEOS | 319 #endif // OS_CHROMEOS |
| 302 | 320 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 415 return elapsed_time.InSeconds() <= kLidRecentlyOpenedDurationSeconds; | 433 return elapsed_time.InSeconds() <= kLidRecentlyOpenedDurationSeconds; |
| 416 } | 434 } |
| 417 | 435 |
| 418 void MaximizeModeController::SetTickClockForTest( | 436 void MaximizeModeController::SetTickClockForTest( |
| 419 std::unique_ptr<base::TickClock> tick_clock) { | 437 std::unique_ptr<base::TickClock> tick_clock) { |
| 420 DCHECK(tick_clock_); | 438 DCHECK(tick_clock_); |
| 421 tick_clock_ = std::move(tick_clock); | 439 tick_clock_ = std::move(tick_clock); |
| 422 } | 440 } |
| 423 | 441 |
| 424 } // namespace ash | 442 } // namespace ash |
| OLD | NEW |