| 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 28 matching lines...) Expand all Loading... |
| 145 // maximize mode. | 147 // maximize mode. |
| 146 // TODO(mgiuca): This can result in false positives, as it returns true for | 148 // TODO(mgiuca): This can result in false positives, as it returns true for |
| 147 // any device with an accelerometer. Have TouchView-enabled devices explicitly | 149 // any device with an accelerometer. Have TouchView-enabled devices explicitly |
| 148 // set a flag, and change this implementation to simply return true iff the | 150 // set a flag, and change this implementation to simply return true iff the |
| 149 // flag is present (http://crbug.com/457445). | 151 // flag is present (http://crbug.com/457445). |
| 150 return have_seen_accelerometer_data_ || | 152 return have_seen_accelerometer_data_ || |
| 151 base::CommandLine::ForCurrentProcess()->HasSwitch( | 153 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 152 switches::kAshEnableTouchViewTesting); | 154 switches::kAshEnableTouchViewTesting); |
| 153 } | 155 } |
| 154 | 156 |
| 157 // TODO(jcliang): Hide or remove EnableMaximizeModeWindowManager |
| 158 // (http://crbug.com/620241). |
| 155 void MaximizeModeController::EnableMaximizeModeWindowManager( | 159 void MaximizeModeController::EnableMaximizeModeWindowManager( |
| 156 bool should_enable) { | 160 bool should_enable) { |
| 157 bool is_enabled = !!maximize_mode_window_manager_.get(); | 161 bool is_enabled = !!maximize_mode_window_manager_.get(); |
| 158 if (should_enable == is_enabled) | 162 if (should_enable == is_enabled) |
| 159 return; | 163 return; |
| 160 | 164 |
| 161 Shell* shell = Shell::GetInstance(); | 165 Shell* shell = Shell::GetInstance(); |
| 162 | 166 |
| 163 if (should_enable) { | 167 if (should_enable) { |
| 164 maximize_mode_window_manager_.reset(new MaximizeModeWindowManager()); | 168 maximize_mode_window_manager_.reset(new MaximizeModeWindowManager()); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 } | 222 } |
| 219 | 223 |
| 220 void MaximizeModeController::LidEventReceived(bool open, | 224 void MaximizeModeController::LidEventReceived(bool open, |
| 221 const base::TimeTicks& time) { | 225 const base::TimeTicks& time) { |
| 222 if (open) | 226 if (open) |
| 223 last_lid_open_time_ = time; | 227 last_lid_open_time_ = time; |
| 224 lid_is_closed_ = !open; | 228 lid_is_closed_ = !open; |
| 225 LeaveMaximizeMode(); | 229 LeaveMaximizeMode(); |
| 226 } | 230 } |
| 227 | 231 |
| 232 void MaximizeModeController::TabletModeEventReceived( |
| 233 bool on, |
| 234 const base::TimeTicks& time) { |
| 235 tablet_mode_switch_is_on_ = on; |
| 236 if (on && !IsMaximizeModeWindowManagerEnabled()) |
| 237 EnterMaximizeMode(); |
| 238 } |
| 239 |
| 228 void MaximizeModeController::SuspendImminent() { | 240 void MaximizeModeController::SuspendImminent() { |
| 229 // The system is about to suspend, so record TouchView usage interval metrics | 241 // The system is about to suspend, so record TouchView usage interval metrics |
| 230 // based on whether TouchView mode is currently active. | 242 // based on whether TouchView mode is currently active. |
| 231 RecordTouchViewUsageInterval(CurrentTouchViewIntervalType()); | 243 RecordTouchViewUsageInterval(CurrentTouchViewIntervalType()); |
| 232 } | 244 } |
| 233 | 245 |
| 234 void MaximizeModeController::SuspendDone( | 246 void MaximizeModeController::SuspendDone( |
| 235 const base::TimeDelta& sleep_duration) { | 247 const base::TimeDelta& sleep_duration) { |
| 236 // We do not want TouchView usage metrics to include time spent in suspend. | 248 // We do not want TouchView usage metrics to include time spent in suspend. |
| 237 touchview_usage_interval_start_time_ = base::Time::Now(); | 249 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 | 262 // Smooth out instantaneous acceleration when nearly vertical to increase |
| 251 // accuracy. | 263 // accuracy. |
| 252 float largest_hinge_acceleration = | 264 float largest_hinge_acceleration = |
| 253 std::max(std::abs(base_reading.x()), std::abs(lid_reading.x())); | 265 std::max(std::abs(base_reading.x()), std::abs(lid_reading.x())); |
| 254 float smoothing_ratio = | 266 float smoothing_ratio = |
| 255 std::max(0.0f, std::min(1.0f, (largest_hinge_acceleration - | 267 std::max(0.0f, std::min(1.0f, (largest_hinge_acceleration - |
| 256 kHingeVerticalSmoothingStart) / | 268 kHingeVerticalSmoothingStart) / |
| 257 (kHingeVerticalSmoothingMaximum - | 269 (kHingeVerticalSmoothingMaximum - |
| 258 kHingeVerticalSmoothingStart))); | 270 kHingeVerticalSmoothingStart))); |
| 259 | 271 |
| 272 // We cannot trust the computed lid angle when the device is held vertically. |
| 273 bool is_angle_reliable = |
| 274 largest_hinge_acceleration <= kHingeVerticalSmoothingMaximum; |
| 275 |
| 260 base_smoothed_.Scale(smoothing_ratio); | 276 base_smoothed_.Scale(smoothing_ratio); |
| 261 base_reading.Scale(1.0f - smoothing_ratio); | 277 base_reading.Scale(1.0f - smoothing_ratio); |
| 262 base_smoothed_.Add(base_reading); | 278 base_smoothed_.Add(base_reading); |
| 263 | 279 |
| 264 lid_smoothed_.Scale(smoothing_ratio); | 280 lid_smoothed_.Scale(smoothing_ratio); |
| 265 lid_reading.Scale(1.0f - smoothing_ratio); | 281 lid_reading.Scale(1.0f - smoothing_ratio); |
| 266 lid_smoothed_.Add(lid_reading); | 282 lid_smoothed_.Add(lid_reading); |
| 267 | 283 |
| 284 if (tablet_mode_switch_is_on_) |
| 285 return; |
| 286 |
| 268 // Ignore the component of acceleration parallel to the hinge for the purposes | 287 // Ignore the component of acceleration parallel to the hinge for the purposes |
| 269 // of hinge angle calculation. | 288 // of hinge angle calculation. |
| 270 gfx::Vector3dF base_flattened(base_smoothed_); | 289 gfx::Vector3dF base_flattened(base_smoothed_); |
| 271 gfx::Vector3dF lid_flattened(lid_smoothed_); | 290 gfx::Vector3dF lid_flattened(lid_smoothed_); |
| 272 base_flattened.set_x(0.0f); | 291 base_flattened.set_x(0.0f); |
| 273 lid_flattened.set_x(0.0f); | 292 lid_flattened.set_x(0.0f); |
| 274 | 293 |
| 275 // Compute the angle between the base and the lid. | 294 // Compute the angle between the base and the lid. |
| 276 float lid_angle = 180.0f - gfx::ClockwiseAngleBetweenVectorsInDegrees( | 295 float lid_angle = 180.0f - gfx::ClockwiseAngleBetweenVectorsInDegrees( |
| 277 base_flattened, lid_flattened, hinge_vector); | 296 base_flattened, lid_flattened, hinge_vector); |
| 278 if (lid_angle < 0.0f) | 297 if (lid_angle < 0.0f) |
| 279 lid_angle += 360.0f; | 298 lid_angle += 360.0f; |
| 280 | 299 |
| 281 bool is_angle_stable = lid_angle >= kMinStableAngle && | 300 bool is_angle_stable = is_angle_reliable && lid_angle >= kMinStableAngle && |
| 282 lid_angle <= kMaxStableAngle; | 301 lid_angle <= kMaxStableAngle; |
| 283 | 302 |
| 284 // Clear the last_lid_open_time_ for a stable reading so that there is less | 303 // 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 | 304 // chance of a delay if the lid is moved from the close state to the fully |
| 286 // open state very quickly. | 305 // open state very quickly. |
| 287 if (is_angle_stable) | 306 if (is_angle_stable) |
| 288 last_lid_open_time_ = base::TimeTicks(); | 307 last_lid_open_time_ = base::TimeTicks(); |
| 289 | 308 |
| 290 // Toggle maximize mode on or off when corresponding thresholds are passed. | 309 // Toggle maximize mode on or off when corresponding thresholds are passed. |
| 291 if (lid_open_past_180_ && is_angle_stable && | 310 if (IsMaximizeModeWindowManagerEnabled() && is_angle_stable && |
| 292 lid_angle <= kExitMaximizeModeAngle) { | 311 lid_angle <= kExitMaximizeModeAngle) { |
| 293 lid_open_past_180_ = false; | |
| 294 LeaveMaximizeMode(); | 312 LeaveMaximizeMode(); |
| 295 } else if (!lid_open_past_180_ && !lid_is_closed_ && | 313 } else if (!IsMaximizeModeWindowManagerEnabled() && !lid_is_closed_ && |
| 296 lid_angle >= kEnterMaximizeModeAngle && | 314 lid_angle >= kEnterMaximizeModeAngle && |
| 297 (is_angle_stable || !WasLidOpenedRecently())) { | 315 (is_angle_stable || !WasLidOpenedRecently())) { |
| 298 lid_open_past_180_ = true; | |
| 299 EnterMaximizeMode(); | 316 EnterMaximizeMode(); |
| 300 } | 317 } |
| 301 } | 318 } |
| 302 #endif // OS_CHROMEOS | 319 #endif // OS_CHROMEOS |
| 303 | 320 |
| 304 void MaximizeModeController::EnterMaximizeMode() { | 321 void MaximizeModeController::EnterMaximizeMode() { |
| 305 // Always reset first to avoid creation before destruction of a previous | 322 // Always reset first to avoid creation before destruction of a previous |
| 306 // object. | 323 // object. |
| 307 event_blocker_.reset(); | 324 event_blocker_.reset(); |
| 308 #if defined(USE_X11) | 325 #if defined(USE_X11) |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 return elapsed_time.InSeconds() <= kLidRecentlyOpenedDurationSeconds; | 433 return elapsed_time.InSeconds() <= kLidRecentlyOpenedDurationSeconds; |
| 417 } | 434 } |
| 418 | 435 |
| 419 void MaximizeModeController::SetTickClockForTest( | 436 void MaximizeModeController::SetTickClockForTest( |
| 420 std::unique_ptr<base::TickClock> tick_clock) { | 437 std::unique_ptr<base::TickClock> tick_clock) { |
| 421 DCHECK(tick_clock_); | 438 DCHECK(tick_clock_); |
| 422 tick_clock_ = std::move(tick_clock); | 439 tick_clock_ = std::move(tick_clock); |
| 423 } | 440 } |
| 424 | 441 |
| 425 } // namespace ash | 442 } // namespace ash |
| OLD | NEW |