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 "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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 MaximizeModeController::MaximizeModeController() | 116 MaximizeModeController::MaximizeModeController() |
| 118 : rotation_locked_(false), | 117 : rotation_locked_(false), |
| 119 have_seen_accelerometer_data_(false), | 118 have_seen_accelerometer_data_(false), |
| 120 ignore_display_configuration_updates_(false), | 119 ignore_display_configuration_updates_(false), |
| 121 lid_open_past_180_(false), | 120 lid_open_past_180_(false), |
| 122 shutting_down_(false), | 121 shutting_down_(false), |
| 123 user_rotation_(gfx::Display::ROTATE_0), | 122 user_rotation_(gfx::Display::ROTATE_0), |
| 124 last_touchview_transition_time_(base::Time::Now()), | 123 last_touchview_transition_time_(base::Time::Now()), |
| 125 tick_clock_(new base::DefaultTickClock()), | 124 tick_clock_(new base::DefaultTickClock()), |
| 126 lid_is_closed_(false) { | 125 lid_is_closed_(false) { |
| 127 Shell::GetInstance()->accelerometer_controller()->AddObserver(this); | |
| 128 Shell::GetInstance()->AddShellObserver(this); | 126 Shell::GetInstance()->AddShellObserver(this); |
| 129 #if defined(OS_CHROMEOS) | 127 #if defined(OS_CHROMEOS) |
| 128 Shell::GetInstance()->accelerometer_reader()->AddObserver(this); | |
| 130 chromeos::DBusThreadManager::Get()-> | 129 chromeos::DBusThreadManager::Get()-> |
| 131 GetPowerManagerClient()->AddObserver(this); | 130 GetPowerManagerClient()->AddObserver(this); |
| 132 #endif // OS_CHROMEOS | 131 #endif // OS_CHROMEOS |
| 133 } | 132 } |
| 134 | 133 |
| 135 MaximizeModeController::~MaximizeModeController() { | 134 MaximizeModeController::~MaximizeModeController() { |
| 136 Shell::GetInstance()->RemoveShellObserver(this); | 135 Shell::GetInstance()->RemoveShellObserver(this); |
| 137 Shell::GetInstance()->accelerometer_controller()->RemoveObserver(this); | |
| 138 #if defined(OS_CHROMEOS) | 136 #if defined(OS_CHROMEOS) |
| 137 Shell::GetInstance()->accelerometer_reader()->RemoveObserver(this); | |
| 139 chromeos::DBusThreadManager::Get()-> | 138 chromeos::DBusThreadManager::Get()-> |
| 140 GetPowerManagerClient()->RemoveObserver(this); | 139 GetPowerManagerClient()->RemoveObserver(this); |
| 141 #endif // OS_CHROMEOS | 140 #endif // OS_CHROMEOS |
| 142 } | 141 } |
| 143 | 142 |
| 144 void MaximizeModeController::SetRotationLocked(bool rotation_locked) { | 143 void MaximizeModeController::SetRotationLocked(bool rotation_locked) { |
| 145 if (rotation_locked_ == rotation_locked) | 144 if (rotation_locked_ == rotation_locked) |
| 146 return; | 145 return; |
| 147 base::AutoReset<bool> auto_ignore_display_configuration_updates( | 146 base::AutoReset<bool> auto_ignore_display_configuration_updates( |
| 148 &ignore_display_configuration_updates_, true); | 147 &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) { | 194 void MaximizeModeController::AddWindow(aura::Window* window) { |
| 196 if (IsMaximizeModeWindowManagerEnabled()) | 195 if (IsMaximizeModeWindowManagerEnabled()) |
| 197 maximize_mode_window_manager_->AddWindow(window); | 196 maximize_mode_window_manager_->AddWindow(window); |
| 198 } | 197 } |
| 199 | 198 |
| 200 void MaximizeModeController::Shutdown() { | 199 void MaximizeModeController::Shutdown() { |
| 201 shutting_down_ = true; | 200 shutting_down_ = true; |
| 202 LeaveMaximizeMode(); | 201 LeaveMaximizeMode(); |
| 203 } | 202 } |
| 204 | 203 |
| 204 void MaximizeModeController::OnDisplayConfigurationChanged() { | |
|
jonross
2014/12/11 23:09:27
I actually moved OnAccelerometerUpdated down into
flackr
2014/12/12 16:47:10
Acknowledged.
| |
| 205 if (ignore_display_configuration_updates_) | |
| 206 return; | |
| 207 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
| 208 gfx::Display::Rotation user_rotation = | |
| 209 display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId()) | |
| 210 .rotation(); | |
| 211 if (user_rotation != current_rotation_) { | |
| 212 // A user may change other display configuration settings. When the user | |
| 213 // does change the rotation setting, then lock rotation to prevent the | |
| 214 // accelerometer from erasing their change. | |
| 215 SetRotationLocked(true); | |
| 216 user_rotation_ = user_rotation; | |
| 217 current_rotation_ = user_rotation; | |
| 218 } | |
| 219 } | |
| 220 | |
| 221 #if defined(OS_CHROMEOS) | |
| 205 void MaximizeModeController::OnAccelerometerUpdated( | 222 void MaximizeModeController::OnAccelerometerUpdated( |
| 206 const ui::AccelerometerUpdate& update) { | 223 const ui::AccelerometerUpdate& update) { |
| 207 bool first_accelerometer_update = !have_seen_accelerometer_data_; | 224 bool first_accelerometer_update = !have_seen_accelerometer_data_; |
| 208 have_seen_accelerometer_data_ = true; | 225 have_seen_accelerometer_data_ = true; |
| 209 | 226 |
| 210 // Ignore the reading if it appears unstable. The reading is considered | 227 // 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 | 228 // 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. | 229 // reading from the lid differs too much from the reading from the base. |
| 213 float lid_magnitude = update.has(ui::ACCELEROMETER_SOURCE_SCREEN) ? | 230 float lid_magnitude = update.has(ui::ACCELEROMETER_SOURCE_SCREEN) ? |
| 214 update.get(ui::ACCELEROMETER_SOURCE_SCREEN).Length() : 0.0f; | 231 update.get(ui::ACCELEROMETER_SOURCE_SCREEN).Length() : 0.0f; |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 241 | 258 |
| 242 if (first_accelerometer_update) { | 259 if (first_accelerometer_update) { |
| 243 // On the first accelerometer update we will know if we have entered | 260 // On the first accelerometer update we will know if we have entered |
| 244 // maximize mode or not. Update the preferences to reflect the current | 261 // maximize mode or not. Update the preferences to reflect the current |
| 245 // state. | 262 // state. |
| 246 Shell::GetInstance()->display_manager()-> | 263 Shell::GetInstance()->display_manager()-> |
| 247 RegisterDisplayRotationProperties(rotation_locked_, current_rotation_); | 264 RegisterDisplayRotationProperties(rotation_locked_, current_rotation_); |
| 248 } | 265 } |
| 249 } | 266 } |
| 250 | 267 |
| 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, | 268 void MaximizeModeController::LidEventReceived(bool open, |
| 269 const base::TimeTicks& time) { | 269 const base::TimeTicks& time) { |
| 270 if (open) | 270 if (open) |
| 271 last_lid_open_time_ = time; | 271 last_lid_open_time_ = time; |
| 272 lid_is_closed_ = !open; | 272 lid_is_closed_ = !open; |
| 273 LeaveMaximizeMode(); | 273 LeaveMaximizeMode(); |
| 274 } | 274 } |
| 275 | 275 |
| 276 void MaximizeModeController::SuspendImminent() { | 276 void MaximizeModeController::SuspendImminent() { |
| 277 RecordTouchViewStateTransition(); | 277 RecordTouchViewStateTransition(); |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 506 return elapsed_time <= kLidRecentlyOpenedDuration; | 506 return elapsed_time <= kLidRecentlyOpenedDuration; |
| 507 } | 507 } |
| 508 | 508 |
| 509 void MaximizeModeController::SetTickClockForTest( | 509 void MaximizeModeController::SetTickClockForTest( |
| 510 scoped_ptr<base::TickClock> tick_clock) { | 510 scoped_ptr<base::TickClock> tick_clock) { |
| 511 DCHECK(tick_clock_); | 511 DCHECK(tick_clock_); |
| 512 tick_clock_ = tick_clock.Pass(); | 512 tick_clock_ = tick_clock.Pass(); |
| 513 } | 513 } |
| 514 | 514 |
| 515 } // namespace ash | 515 } // namespace ash |
| OLD | NEW |