| 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" | 9 #include "ash/accelerometer/accelerometer_controller.h" |
| 10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 have_seen_accelerometer_data_(false), | 139 have_seen_accelerometer_data_(false), |
| 140 in_set_screen_rotation_(false), | 140 in_set_screen_rotation_(false), |
| 141 user_rotation_(gfx::Display::ROTATE_0) { | 141 user_rotation_(gfx::Display::ROTATE_0) { |
| 142 Shell::GetInstance()->accelerometer_controller()->AddObserver(this); | 142 Shell::GetInstance()->accelerometer_controller()->AddObserver(this); |
| 143 } | 143 } |
| 144 | 144 |
| 145 MaximizeModeController::~MaximizeModeController() { | 145 MaximizeModeController::~MaximizeModeController() { |
| 146 Shell::GetInstance()->accelerometer_controller()->RemoveObserver(this); | 146 Shell::GetInstance()->accelerometer_controller()->RemoveObserver(this); |
| 147 } | 147 } |
| 148 | 148 |
| 149 void MaximizeModeController::SetRotationLocked(bool rotation_locked) { |
| 150 if (rotation_locked_ == rotation_locked) |
| 151 return; |
| 152 rotation_locked_ = rotation_locked; |
| 153 FOR_EACH_OBSERVER(Observer, observers_, |
| 154 OnRotationLockChanged(rotation_locked_)); |
| 155 } |
| 156 |
| 157 void MaximizeModeController::AddObserver(Observer* observer) { |
| 158 observers_.AddObserver(observer); |
| 159 } |
| 160 |
| 161 void MaximizeModeController::RemoveObserver(Observer* observer) { |
| 162 observers_.RemoveObserver(observer); |
| 163 } |
| 164 |
| 149 bool MaximizeModeController::CanEnterMaximizeMode() { | 165 bool MaximizeModeController::CanEnterMaximizeMode() { |
| 150 // If we have ever seen accelerometer data, then HandleHingeRotation may | 166 // If we have ever seen accelerometer data, then HandleHingeRotation may |
| 151 // trigger maximize mode at some point in the future. | 167 // trigger maximize mode at some point in the future. |
| 152 // The --enable-touch-view-testing switch can also mean that we may enter | 168 // The --enable-touch-view-testing switch can also mean that we may enter |
| 153 // maximize mode. | 169 // maximize mode. |
| 154 return have_seen_accelerometer_data_ || | 170 return have_seen_accelerometer_data_ || |
| 155 CommandLine::ForCurrentProcess()->HasSwitch( | 171 CommandLine::ForCurrentProcess()->HasSwitch( |
| 156 switches::kAshEnableTouchViewTesting); | 172 switches::kAshEnableTouchViewTesting); |
| 157 } | 173 } |
| 158 | 174 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 std::abs(lid_magnitude - 1.0f) > kDeviationFromGravityThreshold) { | 208 std::abs(lid_magnitude - 1.0f) > kDeviationFromGravityThreshold) { |
| 193 return; | 209 return; |
| 194 } | 210 } |
| 195 | 211 |
| 196 // Responding to the hinge rotation can change the maximize mode state which | 212 // Responding to the hinge rotation can change the maximize mode state which |
| 197 // affects screen rotation, so we handle hinge rotation first. | 213 // affects screen rotation, so we handle hinge rotation first. |
| 198 HandleHingeRotation(base, lid); | 214 HandleHingeRotation(base, lid); |
| 199 HandleScreenRotation(lid); | 215 HandleScreenRotation(lid); |
| 200 } | 216 } |
| 201 | 217 |
| 218 void MaximizeModeController::OnDisplayConfigurationChanged() { |
| 219 if (in_set_screen_rotation_) |
| 220 return; |
| 221 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 222 gfx::Display::Rotation user_rotation = display_manager-> |
| 223 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); |
| 224 if (user_rotation != current_rotation_) { |
| 225 // A user may change other display configuration settings. When the user |
| 226 // does change the rotation setting, then lock rotation to prevent the |
| 227 // accelerometer from erasing their change. |
| 228 SetRotationLocked(true); |
| 229 user_rotation_ = user_rotation; |
| 230 current_rotation_ = user_rotation; |
| 231 } |
| 232 } |
| 233 |
| 202 void MaximizeModeController::HandleHingeRotation(const gfx::Vector3dF& base, | 234 void MaximizeModeController::HandleHingeRotation(const gfx::Vector3dF& base, |
| 203 const gfx::Vector3dF& lid) { | 235 const gfx::Vector3dF& lid) { |
| 204 static const gfx::Vector3dF hinge_vector(0.0f, 1.0f, 0.0f); | 236 static const gfx::Vector3dF hinge_vector(0.0f, 1.0f, 0.0f); |
| 205 bool maximize_mode_engaged = IsMaximizeModeWindowManagerEnabled(); | 237 bool maximize_mode_engaged = IsMaximizeModeWindowManagerEnabled(); |
| 206 // Ignore the component of acceleration parallel to the hinge for the purposes | 238 // Ignore the component of acceleration parallel to the hinge for the purposes |
| 207 // of hinge angle calculation. | 239 // of hinge angle calculation. |
| 208 gfx::Vector3dF base_flattened(base); | 240 gfx::Vector3dF base_flattened(base); |
| 209 gfx::Vector3dF lid_flattened(lid); | 241 gfx::Vector3dF lid_flattened(lid); |
| 210 base_flattened.set_y(0.0f); | 242 base_flattened.set_y(0.0f); |
| 211 lid_flattened.set_y(0.0f); | 243 lid_flattened.set_y(0.0f); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 232 LeaveMaximizeMode(); | 264 LeaveMaximizeMode(); |
| 233 } else if (!maximize_mode_engaged && | 265 } else if (!maximize_mode_engaged && |
| 234 angle > kEnterMaximizeModeAngle) { | 266 angle > kEnterMaximizeModeAngle) { |
| 235 EnterMaximizeMode(); | 267 EnterMaximizeMode(); |
| 236 } | 268 } |
| 237 } | 269 } |
| 238 | 270 |
| 239 void MaximizeModeController::HandleScreenRotation(const gfx::Vector3dF& lid) { | 271 void MaximizeModeController::HandleScreenRotation(const gfx::Vector3dF& lid) { |
| 240 bool maximize_mode_engaged = IsMaximizeModeWindowManagerEnabled(); | 272 bool maximize_mode_engaged = IsMaximizeModeWindowManagerEnabled(); |
| 241 | 273 |
| 274 // TODO(jonross): track the updated rotation angle even when locked. So that |
| 275 // when rotation lock is removed the accelerometer rotation can be applied |
| 276 // without waiting for the next update. |
| 242 if (!maximize_mode_engaged || rotation_locked_) | 277 if (!maximize_mode_engaged || rotation_locked_) |
| 243 return; | 278 return; |
| 244 | 279 |
| 245 DisplayManager* display_manager = | 280 DisplayManager* display_manager = |
| 246 Shell::GetInstance()->display_manager(); | 281 Shell::GetInstance()->display_manager(); |
| 247 gfx::Display::Rotation current_rotation = display_manager->GetDisplayInfo( | 282 gfx::Display::Rotation current_rotation = display_manager->GetDisplayInfo( |
| 248 gfx::Display::InternalDisplayId()).rotation(); | 283 gfx::Display::InternalDisplayId()).rotation(); |
| 249 | 284 |
| 250 // After determining maximize mode state, determine if the screen should | 285 // After determining maximize mode state, determine if the screen should |
| 251 // be rotated. | 286 // be rotated. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 | 329 |
| 295 if (new_rotation != current_rotation) | 330 if (new_rotation != current_rotation) |
| 296 SetDisplayRotation(display_manager, new_rotation); | 331 SetDisplayRotation(display_manager, new_rotation); |
| 297 } | 332 } |
| 298 | 333 |
| 299 void MaximizeModeController::SetDisplayRotation( | 334 void MaximizeModeController::SetDisplayRotation( |
| 300 DisplayManager* display_manager, | 335 DisplayManager* display_manager, |
| 301 gfx::Display::Rotation rotation) { | 336 gfx::Display::Rotation rotation) { |
| 302 base::AutoReset<bool> auto_in_set_screen_rotation( | 337 base::AutoReset<bool> auto_in_set_screen_rotation( |
| 303 &in_set_screen_rotation_, true); | 338 &in_set_screen_rotation_, true); |
| 339 current_rotation_ = rotation; |
| 304 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), | 340 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), |
| 305 rotation); | 341 rotation); |
| 306 } | 342 } |
| 307 | 343 |
| 308 void MaximizeModeController::EnterMaximizeMode() { | 344 void MaximizeModeController::EnterMaximizeMode() { |
| 309 // TODO(jonross): Listen for display configuration changes. If the user | |
| 310 // causes a rotation change a rotation lock should be applied. | |
| 311 // https://crbug.com/369505 | |
| 312 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 345 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 313 user_rotation_ = display_manager-> | 346 current_rotation_ = user_rotation_ = display_manager-> |
| 314 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | 347 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); |
| 315 EnableMaximizeModeWindowManager(true); | 348 EnableMaximizeModeWindowManager(true); |
| 316 event_blocker_.reset(new MaximizeModeEventBlocker); | 349 event_blocker_.reset(new MaximizeModeEventBlocker); |
| 317 #if defined(OS_CHROMEOS) | 350 #if defined(OS_CHROMEOS) |
| 318 event_handler_.reset(new ScreenshotActionHandler); | 351 event_handler_.reset(new ScreenshotActionHandler); |
| 319 #endif | 352 #endif |
| 353 Shell::GetInstance()->display_controller()->AddObserver(this); |
| 320 } | 354 } |
| 321 | 355 |
| 322 void MaximizeModeController::LeaveMaximizeMode() { | 356 void MaximizeModeController::LeaveMaximizeMode() { |
| 323 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 357 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 324 DisplayInfo info = display_manager-> | 358 gfx::Display::Rotation current_rotation = display_manager-> |
| 325 GetDisplayInfo(gfx::Display::InternalDisplayId()); | 359 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); |
| 326 gfx::Display::Rotation current_rotation = info.rotation(); | |
| 327 if (current_rotation != user_rotation_) | 360 if (current_rotation != user_rotation_) |
| 328 SetDisplayRotation(display_manager, user_rotation_); | 361 SetDisplayRotation(display_manager, user_rotation_); |
| 329 rotation_locked_ = false; | 362 rotation_locked_ = false; |
| 330 EnableMaximizeModeWindowManager(false); | 363 EnableMaximizeModeWindowManager(false); |
| 331 event_blocker_.reset(); | 364 event_blocker_.reset(); |
| 332 event_handler_.reset(); | 365 event_handler_.reset(); |
| 366 Shell::GetInstance()->display_controller()->RemoveObserver(this); |
| 333 } | 367 } |
| 334 | 368 |
| 335 } // namespace ash | 369 } // namespace ash |
| OLD | NEW |