| 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 "ash/accelerators/accelerator_controller.h" | 7 #include "ash/accelerators/accelerator_controller.h" |
| 8 #include "ash/accelerators/accelerator_table.h" | 8 #include "ash/accelerators/accelerator_table.h" |
| 9 #include "ash/accelerometer/accelerometer_controller.h" | |
| 10 #include "ash/ash_switches.h" | 9 #include "ash/ash_switches.h" |
| 11 #include "ash/display/display_manager.h" | 10 #include "ash/display/display_manager.h" |
| 12 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 13 #include "ash/wm/maximize_mode/maximize_mode_window_manager.h" | 12 #include "ash/wm/maximize_mode/maximize_mode_window_manager.h" |
| 14 #include "ash/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard.h" | 13 #include "ash/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard.h" |
| 15 #include "base/auto_reset.h" | 14 #include "base/auto_reset.h" |
| 16 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 17 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 18 #include "base/time/default_tick_clock.h" | 17 #include "base/time/default_tick_clock.h" |
| 19 #include "base/time/tick_clock.h" | 18 #include "base/time/tick_clock.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 48 const float kMinStableAngle = 20.0f; | 47 const float kMinStableAngle = 20.0f; |
| 49 const float kMaxStableAngle = 340.0f; | 48 const float kMaxStableAngle = 340.0f; |
| 50 | 49 |
| 51 // The time duration to consider the lid to be recently opened. | 50 // The time duration to consider the lid to be recently opened. |
| 52 // This is used to prevent entering maximize mode if an erroneous accelerometer | 51 // This is used to prevent entering maximize mode if an erroneous accelerometer |
| 53 // reading makes the lid appear to be fully open when the user is opening the | 52 // reading makes the lid appear to be fully open when the user is opening the |
| 54 // lid from a closed position. | 53 // lid from a closed position. |
| 55 const base::TimeDelta kLidRecentlyOpenedDuration = | 54 const base::TimeDelta kLidRecentlyOpenedDuration = |
| 56 base::TimeDelta::FromSeconds(2); | 55 base::TimeDelta::FromSeconds(2); |
| 57 | 56 |
| 58 // The mean acceleration due to gravity on Earth in m/s^2. | |
| 59 const float kMeanGravity = 9.80665f; | |
| 60 | |
| 61 // When the device approaches vertical orientation (i.e. portrait orientation) | 57 // When the device approaches vertical orientation (i.e. portrait orientation) |
| 62 // the accelerometers for the base and lid approach the same values (i.e. | 58 // the accelerometers for the base and lid approach the same values (i.e. |
| 63 // gravity pointing in the direction of the hinge). When this happens we cannot | 59 // gravity pointing in the direction of the hinge). When this happens we cannot |
| 64 // compute the hinge angle reliably and must turn ignore accelerometer readings. | 60 // compute the hinge angle reliably and must turn ignore accelerometer readings. |
| 65 // This is the minimum acceleration perpendicular to the hinge under which to | 61 // This is the minimum acceleration perpendicular to the hinge under which to |
| 66 // detect hinge angle in m/s^2. | 62 // detect hinge angle in m/s^2. |
| 67 const float kHingeAngleDetectionThreshold = 2.5f; | 63 const float kHingeAngleDetectionThreshold = 2.5f; |
| 68 | 64 |
| 65 #if defined(OS_CHROMEOS) |
| 66 // The mean acceleration due to gravity on Earth in m/s^2. |
| 67 const float kMeanGravity = 9.80665f; |
| 68 |
| 69 // The maximum deviation from the acceleration expected due to gravity under | 69 // The maximum deviation from the acceleration expected due to gravity under |
| 70 // which to detect hinge angle and screen rotation in m/s^2 | 70 // which to detect hinge angle and screen rotation in m/s^2 |
| 71 const float kDeviationFromGravityThreshold = 1.0f; | 71 const float kDeviationFromGravityThreshold = 1.0f; |
| 72 | 72 |
| 73 // The maximum deviation between the magnitude of the two accelerometers under | 73 // The maximum deviation between the magnitude of the two accelerometers under |
| 74 // which to detect hinge angle and screen rotation in m/s^2. These | 74 // which to detect hinge angle and screen rotation in m/s^2. These |
| 75 // accelerometers are attached to the same physical device and so should be | 75 // accelerometers are attached to the same physical device and so should be |
| 76 // under the same acceleration. | 76 // under the same acceleration. |
| 77 const float kNoisyMagnitudeDeviation = 1.0f; | 77 const float kNoisyMagnitudeDeviation = 1.0f; |
| 78 #endif |
| 78 | 79 |
| 79 // The angle which the screen has to be rotated past before the display will | 80 // The angle which the screen has to be rotated past before the display will |
| 80 // rotate to match it (i.e. 45.0f is no stickiness). | 81 // rotate to match it (i.e. 45.0f is no stickiness). |
| 81 const float kDisplayRotationStickyAngleDegrees = 60.0f; | 82 const float kDisplayRotationStickyAngleDegrees = 60.0f; |
| 82 | 83 |
| 83 // The minimum acceleration in m/s^2 in a direction required to trigger screen | 84 // The minimum acceleration in m/s^2 in a direction required to trigger screen |
| 84 // rotation. This prevents rapid toggling of rotation when the device is near | 85 // rotation. This prevents rapid toggling of rotation when the device is near |
| 85 // flat and there is very little screen aligned force on it. The value is | 86 // flat and there is very little screen aligned force on it. The value is |
| 86 // effectively the sine of the rise angle required times the acceleration due | 87 // effectively the sine of the rise angle required times the acceleration due |
| 87 // to gravity, with the current value requiring at least a 25 degree rise. | 88 // to gravity, with the current value requiring at least a 25 degree rise. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 117 MaximizeModeController::MaximizeModeController() | 118 MaximizeModeController::MaximizeModeController() |
| 118 : rotation_locked_(false), | 119 : rotation_locked_(false), |
| 119 have_seen_accelerometer_data_(false), | 120 have_seen_accelerometer_data_(false), |
| 120 ignore_display_configuration_updates_(false), | 121 ignore_display_configuration_updates_(false), |
| 121 lid_open_past_180_(false), | 122 lid_open_past_180_(false), |
| 122 shutting_down_(false), | 123 shutting_down_(false), |
| 123 user_rotation_(gfx::Display::ROTATE_0), | 124 user_rotation_(gfx::Display::ROTATE_0), |
| 124 last_touchview_transition_time_(base::Time::Now()), | 125 last_touchview_transition_time_(base::Time::Now()), |
| 125 tick_clock_(new base::DefaultTickClock()), | 126 tick_clock_(new base::DefaultTickClock()), |
| 126 lid_is_closed_(false) { | 127 lid_is_closed_(false) { |
| 127 Shell::GetInstance()->accelerometer_controller()->AddObserver(this); | |
| 128 Shell::GetInstance()->AddShellObserver(this); | 128 Shell::GetInstance()->AddShellObserver(this); |
| 129 #if defined(OS_CHROMEOS) | 129 #if defined(OS_CHROMEOS) |
| 130 Shell::GetInstance()->accelerometer_reader()->AddObserver(this); |
| 130 chromeos::DBusThreadManager::Get()-> | 131 chromeos::DBusThreadManager::Get()-> |
| 131 GetPowerManagerClient()->AddObserver(this); | 132 GetPowerManagerClient()->AddObserver(this); |
| 132 #endif // OS_CHROMEOS | 133 #endif // OS_CHROMEOS |
| 133 } | 134 } |
| 134 | 135 |
| 135 MaximizeModeController::~MaximizeModeController() { | 136 MaximizeModeController::~MaximizeModeController() { |
| 136 Shell::GetInstance()->RemoveShellObserver(this); | 137 Shell::GetInstance()->RemoveShellObserver(this); |
| 137 Shell::GetInstance()->accelerometer_controller()->RemoveObserver(this); | |
| 138 #if defined(OS_CHROMEOS) | 138 #if defined(OS_CHROMEOS) |
| 139 Shell::GetInstance()->accelerometer_reader()->RemoveObserver(this); |
| 139 chromeos::DBusThreadManager::Get()-> | 140 chromeos::DBusThreadManager::Get()-> |
| 140 GetPowerManagerClient()->RemoveObserver(this); | 141 GetPowerManagerClient()->RemoveObserver(this); |
| 141 #endif // OS_CHROMEOS | 142 #endif // OS_CHROMEOS |
| 142 } | 143 } |
| 143 | 144 |
| 144 void MaximizeModeController::SetRotationLocked(bool rotation_locked) { | 145 void MaximizeModeController::SetRotationLocked(bool rotation_locked) { |
| 145 if (rotation_locked_ == rotation_locked) | 146 if (rotation_locked_ == rotation_locked) |
| 146 return; | 147 return; |
| 147 base::AutoReset<bool> auto_ignore_display_configuration_updates( | 148 base::AutoReset<bool> auto_ignore_display_configuration_updates( |
| 148 &ignore_display_configuration_updates_, true); | 149 &ignore_display_configuration_updates_, true); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 void MaximizeModeController::AddWindow(aura::Window* window) { | 196 void MaximizeModeController::AddWindow(aura::Window* window) { |
| 196 if (IsMaximizeModeWindowManagerEnabled()) | 197 if (IsMaximizeModeWindowManagerEnabled()) |
| 197 maximize_mode_window_manager_->AddWindow(window); | 198 maximize_mode_window_manager_->AddWindow(window); |
| 198 } | 199 } |
| 199 | 200 |
| 200 void MaximizeModeController::Shutdown() { | 201 void MaximizeModeController::Shutdown() { |
| 201 shutting_down_ = true; | 202 shutting_down_ = true; |
| 202 LeaveMaximizeMode(); | 203 LeaveMaximizeMode(); |
| 203 } | 204 } |
| 204 | 205 |
| 206 void MaximizeModeController::OnDisplayConfigurationChanged() { |
| 207 if (ignore_display_configuration_updates_) |
| 208 return; |
| 209 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 210 gfx::Display::Rotation user_rotation = |
| 211 display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId()) |
| 212 .rotation(); |
| 213 if (user_rotation != current_rotation_) { |
| 214 // A user may change other display configuration settings. When the user |
| 215 // does change the rotation setting, then lock rotation to prevent the |
| 216 // accelerometer from erasing their change. |
| 217 SetRotationLocked(true); |
| 218 user_rotation_ = user_rotation; |
| 219 current_rotation_ = user_rotation; |
| 220 } |
| 221 } |
| 222 |
| 223 #if defined(OS_CHROMEOS) |
| 205 void MaximizeModeController::OnAccelerometerUpdated( | 224 void MaximizeModeController::OnAccelerometerUpdated( |
| 206 const ui::AccelerometerUpdate& update) { | 225 const ui::AccelerometerUpdate& update) { |
| 207 bool first_accelerometer_update = !have_seen_accelerometer_data_; | 226 bool first_accelerometer_update = !have_seen_accelerometer_data_; |
| 208 have_seen_accelerometer_data_ = true; | 227 have_seen_accelerometer_data_ = true; |
| 209 | 228 |
| 210 // Ignore the reading if it appears unstable. The reading is considered | 229 // Ignore the reading if it appears unstable. The reading is considered |
| 211 // unstable if it deviates too much from gravity and/or the magnitude of the | 230 // unstable if it deviates too much from gravity and/or the magnitude of the |
| 212 // reading from the lid differs too much from the reading from the base. | 231 // reading from the lid differs too much from the reading from the base. |
| 213 float lid_magnitude = update.has(ui::ACCELEROMETER_SOURCE_SCREEN) ? | 232 float lid_magnitude = update.has(ui::ACCELEROMETER_SOURCE_SCREEN) ? |
| 214 update.get(ui::ACCELEROMETER_SOURCE_SCREEN).Length() : 0.0f; | 233 update.get(ui::ACCELEROMETER_SOURCE_SCREEN).Length() : 0.0f; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 241 | 260 |
| 242 if (first_accelerometer_update) { | 261 if (first_accelerometer_update) { |
| 243 // On the first accelerometer update we will know if we have entered | 262 // On the first accelerometer update we will know if we have entered |
| 244 // maximize mode or not. Update the preferences to reflect the current | 263 // maximize mode or not. Update the preferences to reflect the current |
| 245 // state. | 264 // state. |
| 246 Shell::GetInstance()->display_manager()-> | 265 Shell::GetInstance()->display_manager()-> |
| 247 RegisterDisplayRotationProperties(rotation_locked_, current_rotation_); | 266 RegisterDisplayRotationProperties(rotation_locked_, current_rotation_); |
| 248 } | 267 } |
| 249 } | 268 } |
| 250 | 269 |
| 251 void MaximizeModeController::OnDisplayConfigurationChanged() { | |
| 252 if (ignore_display_configuration_updates_) | |
| 253 return; | |
| 254 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
| 255 gfx::Display::Rotation user_rotation = display_manager-> | |
| 256 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | |
| 257 if (user_rotation != current_rotation_) { | |
| 258 // A user may change other display configuration settings. When the user | |
| 259 // does change the rotation setting, then lock rotation to prevent the | |
| 260 // accelerometer from erasing their change. | |
| 261 SetRotationLocked(true); | |
| 262 user_rotation_ = user_rotation; | |
| 263 current_rotation_ = user_rotation; | |
| 264 } | |
| 265 } | |
| 266 | |
| 267 #if defined(OS_CHROMEOS) | |
| 268 void MaximizeModeController::LidEventReceived(bool open, | 270 void MaximizeModeController::LidEventReceived(bool open, |
| 269 const base::TimeTicks& time) { | 271 const base::TimeTicks& time) { |
| 270 if (open) | 272 if (open) |
| 271 last_lid_open_time_ = time; | 273 last_lid_open_time_ = time; |
| 272 lid_is_closed_ = !open; | 274 lid_is_closed_ = !open; |
| 273 LeaveMaximizeMode(); | 275 LeaveMaximizeMode(); |
| 274 } | 276 } |
| 275 | 277 |
| 276 void MaximizeModeController::SuspendImminent() { | 278 void MaximizeModeController::SuspendImminent() { |
| 277 RecordTouchViewStateTransition(); | 279 RecordTouchViewStateTransition(); |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 return elapsed_time <= kLidRecentlyOpenedDuration; | 508 return elapsed_time <= kLidRecentlyOpenedDuration; |
| 507 } | 509 } |
| 508 | 510 |
| 509 void MaximizeModeController::SetTickClockForTest( | 511 void MaximizeModeController::SetTickClockForTest( |
| 510 scoped_ptr<base::TickClock> tick_clock) { | 512 scoped_ptr<base::TickClock> tick_clock) { |
| 511 DCHECK(tick_clock_); | 513 DCHECK(tick_clock_); |
| 512 tick_clock_ = tick_clock.Pass(); | 514 tick_clock_ = tick_clock.Pass(); |
| 513 } | 515 } |
| 514 | 516 |
| 515 } // namespace ash | 517 } // namespace ash |
| OLD | NEW |