| 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/content/display/screen_orientation_controller_chromeos.h" | 5 #include "ash/content/display/screen_orientation_controller_chromeos.h" |
| 6 | 6 |
| 7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
| 8 #include "ash/display/display_info.h" | 8 #include "ash/display/display_info.h" |
| 9 #include "ash/display/display_manager.h" | 9 #include "ash/display/display_manager.h" |
| 10 #include "ash/rotator/screen_rotation_animator.h" | 10 #include "ash/rotator/screen_rotation_animator.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 const float kMinimumAccelerationScreenRotation = 4.2f; | 37 const float kMinimumAccelerationScreenRotation = 4.2f; |
| 38 | 38 |
| 39 blink::WebScreenOrientationLockType GetDisplayNaturalOrientation() { | 39 blink::WebScreenOrientationLockType GetDisplayNaturalOrientation() { |
| 40 if (!gfx::Display::HasInternalDisplay()) | 40 if (!gfx::Display::HasInternalDisplay()) |
| 41 return blink::WebScreenOrientationLockLandscape; | 41 return blink::WebScreenOrientationLockLandscape; |
| 42 | 42 |
| 43 ash::DisplayInfo info = | 43 ash::DisplayInfo info = |
| 44 ash::Shell::GetInstance()->display_manager()->GetDisplayInfo( | 44 ash::Shell::GetInstance()->display_manager()->GetDisplayInfo( |
| 45 gfx::Display::InternalDisplayId()); | 45 gfx::Display::InternalDisplayId()); |
| 46 gfx::Size size = info.size_in_pixel(); | 46 gfx::Size size = info.size_in_pixel(); |
| 47 switch (info.rotation()) { | 47 switch (info.GetActiveRotation()) { |
| 48 case gfx::Display::ROTATE_0: | 48 case gfx::Display::ROTATE_0: |
| 49 case gfx::Display::ROTATE_180: | 49 case gfx::Display::ROTATE_180: |
| 50 return size.height() >= size.width() | 50 return size.height() >= size.width() |
| 51 ? blink::WebScreenOrientationLockPortrait | 51 ? blink::WebScreenOrientationLockPortrait |
| 52 : blink::WebScreenOrientationLockLandscape; | 52 : blink::WebScreenOrientationLockLandscape; |
| 53 case gfx::Display::ROTATE_90: | 53 case gfx::Display::ROTATE_90: |
| 54 case gfx::Display::ROTATE_270: | 54 case gfx::Display::ROTATE_270: |
| 55 return size.height() < size.width() | 55 return size.height() < size.width() |
| 56 ? blink::WebScreenOrientationLockPortrait | 56 ? blink::WebScreenOrientationLockPortrait |
| 57 : blink::WebScreenOrientationLockLandscape; | 57 : blink::WebScreenOrientationLockLandscape; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 OnRotationLockChanged(rotation_locked_)); | 103 OnRotationLockChanged(rotation_locked_)); |
| 104 if (!gfx::Display::HasInternalDisplay()) | 104 if (!gfx::Display::HasInternalDisplay()) |
| 105 return; | 105 return; |
| 106 base::AutoReset<bool> auto_ignore_display_configuration_updates( | 106 base::AutoReset<bool> auto_ignore_display_configuration_updates( |
| 107 &ignore_display_configuration_updates_, true); | 107 &ignore_display_configuration_updates_, true); |
| 108 Shell::GetInstance()->display_manager()->RegisterDisplayRotationProperties( | 108 Shell::GetInstance()->display_manager()->RegisterDisplayRotationProperties( |
| 109 rotation_locked_, current_rotation_); | 109 rotation_locked_, current_rotation_); |
| 110 } | 110 } |
| 111 | 111 |
| 112 void ScreenOrientationController::SetDisplayRotation( | 112 void ScreenOrientationController::SetDisplayRotation( |
| 113 gfx::Display::Rotation rotation) { | 113 gfx::Display::Rotation rotation, |
| 114 gfx::Display::RotationSource source) { |
| 114 if (!gfx::Display::HasInternalDisplay()) | 115 if (!gfx::Display::HasInternalDisplay()) |
| 115 return; | 116 return; |
| 116 current_rotation_ = rotation; | 117 current_rotation_ = rotation; |
| 117 base::AutoReset<bool> auto_ignore_display_configuration_updates( | 118 base::AutoReset<bool> auto_ignore_display_configuration_updates( |
| 118 &ignore_display_configuration_updates_, true); | 119 &ignore_display_configuration_updates_, true); |
| 119 ash::ScreenRotationAnimator(gfx::Display::InternalDisplayId()) | 120 ash::ScreenRotationAnimator(gfx::Display::InternalDisplayId()) |
| 120 .Rotate(rotation); | 121 .Rotate(rotation, source); |
| 121 } | 122 } |
| 122 | 123 |
| 123 void ScreenOrientationController::OnWindowActivated(aura::Window* gained_active, | 124 void ScreenOrientationController::OnWindowActivated(aura::Window* gained_active, |
| 124 aura::Window* lost_active) { | 125 aura::Window* lost_active) { |
| 125 ApplyLockForActiveWindow(); | 126 ApplyLockForActiveWindow(); |
| 126 } | 127 } |
| 127 | 128 |
| 128 // Currently contents::WebContents will only be able to lock rotation while | 129 // Currently contents::WebContents will only be able to lock rotation while |
| 129 // fullscreen. In this state a user cannot click on the tab strip to change. If | 130 // fullscreen. In this state a user cannot click on the tab strip to change. If |
| 130 // this becomes supported for non-fullscreen tabs then the following interferes | 131 // this becomes supported for non-fullscreen tabs then the following interferes |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 } | 192 } |
| 192 | 193 |
| 193 void ScreenOrientationController::OnDisplayConfigurationChanged() { | 194 void ScreenOrientationController::OnDisplayConfigurationChanged() { |
| 194 if (ignore_display_configuration_updates_) | 195 if (ignore_display_configuration_updates_) |
| 195 return; | 196 return; |
| 196 if (!gfx::Display::HasInternalDisplay()) | 197 if (!gfx::Display::HasInternalDisplay()) |
| 197 return; | 198 return; |
| 198 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 199 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 199 gfx::Display::Rotation user_rotation = | 200 gfx::Display::Rotation user_rotation = |
| 200 display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId()) | 201 display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId()) |
| 201 .rotation(); | 202 .GetActiveRotation(); |
| 202 if (user_rotation != current_rotation_) { | 203 if (user_rotation != current_rotation_) { |
| 203 // A user may change other display configuration settings. When the user | 204 // A user may change other display configuration settings. When the user |
| 204 // does change the rotation setting, then lock rotation to prevent the | 205 // does change the rotation setting, then lock rotation to prevent the |
| 205 // accelerometer from erasing their change. | 206 // accelerometer from erasing their change. |
| 206 SetRotationLocked(true); | 207 SetRotationLocked(true); |
| 207 user_rotation_ = current_rotation_ = user_rotation; | 208 user_rotation_ = current_rotation_ = user_rotation; |
| 208 } | 209 } |
| 209 } | 210 } |
| 210 | 211 |
| 211 void ScreenOrientationController::OnMaximizeModeStarted() { | 212 void ScreenOrientationController::OnMaximizeModeStarted() { |
| 212 // Do not exit early, as the internal display can be determined after Maximize | 213 // Do not exit early, as the internal display can be determined after Maximize |
| 213 // Mode has started. (chrome-os-partner:38796) | 214 // Mode has started. (chrome-os-partner:38796) |
| 214 // Always start observing. | 215 // Always start observing. |
| 215 if (gfx::Display::HasInternalDisplay()) { | 216 if (gfx::Display::HasInternalDisplay()) { |
| 216 current_rotation_ = user_rotation_ = | 217 current_rotation_ = user_rotation_ = |
| 217 Shell::GetInstance() | 218 Shell::GetInstance() |
| 218 ->display_manager() | 219 ->display_manager() |
| 219 ->GetDisplayInfo(gfx::Display::InternalDisplayId()) | 220 ->GetDisplayInfo(gfx::Display::InternalDisplayId()) |
| 220 .rotation(); | 221 .GetActiveRotation(); |
| 221 } | 222 } |
| 222 if (!rotation_locked_) | 223 if (!rotation_locked_) |
| 223 LoadDisplayRotationProperties(); | 224 LoadDisplayRotationProperties(); |
| 224 chromeos::AccelerometerReader::GetInstance()->AddObserver(this); | 225 chromeos::AccelerometerReader::GetInstance()->AddObserver(this); |
| 225 Shell::GetInstance()->display_controller()->AddObserver(this); | 226 Shell::GetInstance()->display_controller()->AddObserver(this); |
| 226 } | 227 } |
| 227 | 228 |
| 228 void ScreenOrientationController::OnMaximizeModeEnded() { | 229 void ScreenOrientationController::OnMaximizeModeEnded() { |
| 229 chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this); | 230 chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this); |
| 230 Shell::GetInstance()->display_controller()->RemoveObserver(this); | 231 Shell::GetInstance()->display_controller()->RemoveObserver(this); |
| 231 if (current_rotation_ != user_rotation_) | 232 if (current_rotation_ != user_rotation_) |
| 232 SetDisplayRotation(user_rotation_); | 233 SetDisplayRotation(user_rotation_, gfx::Display::ROTATION_SOURCE_USER); |
| 233 } | 234 } |
| 234 | 235 |
| 235 void ScreenOrientationController::LockRotation( | 236 void ScreenOrientationController::LockRotation( |
| 236 gfx::Display::Rotation rotation) { | 237 gfx::Display::Rotation rotation, |
| 238 gfx::Display::RotationSource source) { |
| 237 SetRotationLocked(true); | 239 SetRotationLocked(true); |
| 238 SetDisplayRotation(rotation); | 240 SetDisplayRotation(rotation, source); |
| 239 } | 241 } |
| 240 | 242 |
| 241 void ScreenOrientationController::LockRotationToOrientation( | 243 void ScreenOrientationController::LockRotationToOrientation( |
| 242 blink::WebScreenOrientationLockType lock_orientation) { | 244 blink::WebScreenOrientationLockType lock_orientation) { |
| 243 rotation_locked_orientation_ = lock_orientation; | 245 rotation_locked_orientation_ = lock_orientation; |
| 244 switch (lock_orientation) { | 246 switch (lock_orientation) { |
| 245 case blink::WebScreenOrientationLockAny: | 247 case blink::WebScreenOrientationLockAny: |
| 246 SetRotationLocked(false); | 248 SetRotationLocked(false); |
| 247 break; | 249 break; |
| 248 case blink::WebScreenOrientationLockDefault: | 250 case blink::WebScreenOrientationLockDefault: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 261 break; | 263 break; |
| 262 case blink::WebScreenOrientationLockLandscapeSecondary: | 264 case blink::WebScreenOrientationLockLandscapeSecondary: |
| 263 LockRotationToSecondaryOrientation( | 265 LockRotationToSecondaryOrientation( |
| 264 blink::WebScreenOrientationLockLandscape); | 266 blink::WebScreenOrientationLockLandscape); |
| 265 break; | 267 break; |
| 266 case blink::WebScreenOrientationLockLandscapePrimary: | 268 case blink::WebScreenOrientationLockLandscapePrimary: |
| 267 LockRotationToPrimaryOrientation( | 269 LockRotationToPrimaryOrientation( |
| 268 blink::WebScreenOrientationLockLandscape); | 270 blink::WebScreenOrientationLockLandscape); |
| 269 break; | 271 break; |
| 270 case blink::WebScreenOrientationLockNatural: | 272 case blink::WebScreenOrientationLockNatural: |
| 271 LockRotation(gfx::Display::ROTATE_0); | 273 LockRotation(gfx::Display::ROTATE_0, |
| 274 gfx::Display::ROTATION_SOURCE_ACTIVE); |
| 272 break; | 275 break; |
| 273 default: | 276 default: |
| 274 NOTREACHED(); | 277 NOTREACHED(); |
| 275 break; | 278 break; |
| 276 } | 279 } |
| 277 } | 280 } |
| 278 | 281 |
| 279 void ScreenOrientationController::LockRotationToPrimaryOrientation( | 282 void ScreenOrientationController::LockRotationToPrimaryOrientation( |
| 280 blink::WebScreenOrientationLockType lock_orientation) { | 283 blink::WebScreenOrientationLockType lock_orientation) { |
| 281 LockRotation(natural_orientation_ == lock_orientation | 284 LockRotation(natural_orientation_ == lock_orientation |
| 282 ? gfx::Display::ROTATE_0 | 285 ? gfx::Display::ROTATE_0 |
| 283 : gfx::Display::ROTATE_90); | 286 : gfx::Display::ROTATE_90, |
| 287 gfx::Display::ROTATION_SOURCE_ACTIVE); |
| 284 } | 288 } |
| 285 | 289 |
| 286 void ScreenOrientationController::LockRotationToSecondaryOrientation( | 290 void ScreenOrientationController::LockRotationToSecondaryOrientation( |
| 287 blink::WebScreenOrientationLockType lock_orientation) { | 291 blink::WebScreenOrientationLockType lock_orientation) { |
| 288 LockRotation(natural_orientation_ == lock_orientation | 292 LockRotation(natural_orientation_ == lock_orientation |
| 289 ? gfx::Display::ROTATE_180 | 293 ? gfx::Display::ROTATE_180 |
| 290 : gfx::Display::ROTATE_270); | 294 : gfx::Display::ROTATE_270, |
| 295 gfx::Display::ROTATION_SOURCE_ACTIVE); |
| 291 } | 296 } |
| 292 | 297 |
| 293 void ScreenOrientationController::LockToRotationMatchingOrientation( | 298 void ScreenOrientationController::LockToRotationMatchingOrientation( |
| 294 blink::WebScreenOrientationLockType lock_orientation) { | 299 blink::WebScreenOrientationLockType lock_orientation) { |
| 295 if (!gfx::Display::HasInternalDisplay()) | 300 if (!gfx::Display::HasInternalDisplay()) |
| 296 return; | 301 return; |
| 297 | 302 |
| 298 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 303 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 299 gfx::Display::Rotation rotation = | 304 gfx::Display::Rotation rotation = |
| 300 display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId()) | 305 display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId()) |
| 301 .rotation(); | 306 .GetActiveRotation(); |
| 302 if (natural_orientation_ == lock_orientation) { | 307 if (natural_orientation_ == lock_orientation) { |
| 303 if (rotation == gfx::Display::ROTATE_0 || | 308 if (rotation == gfx::Display::ROTATE_0 || |
| 304 rotation == gfx::Display::ROTATE_180) { | 309 rotation == gfx::Display::ROTATE_180) { |
| 305 SetRotationLocked(true); | 310 SetRotationLocked(true); |
| 306 } else { | 311 } else { |
| 307 LockRotation(gfx::Display::ROTATE_0); | 312 LockRotation(gfx::Display::ROTATE_0, |
| 313 gfx::Display::ROTATION_SOURCE_ACTIVE); |
| 308 } | 314 } |
| 309 } else { | 315 } else { |
| 310 if (rotation == gfx::Display::ROTATE_90 || | 316 if (rotation == gfx::Display::ROTATE_90 || |
| 311 rotation == gfx::Display::ROTATE_270) { | 317 rotation == gfx::Display::ROTATE_270) { |
| 312 SetRotationLocked(true); | 318 SetRotationLocked(true); |
| 313 } else { | 319 } else { |
| 314 LockRotation(gfx::Display::ROTATE_90); | 320 LockRotation(gfx::Display::ROTATE_90, |
| 321 gfx::Display::ROTATION_SOURCE_ACTIVE); |
| 315 } | 322 } |
| 316 } | 323 } |
| 317 } | 324 } |
| 318 | 325 |
| 319 void ScreenOrientationController::HandleScreenRotation( | 326 void ScreenOrientationController::HandleScreenRotation( |
| 320 const chromeos::AccelerometerReading& lid) { | 327 const chromeos::AccelerometerReading& lid) { |
| 321 gfx::Vector3dF lid_flattened(lid.x, lid.y, 0.0f); | 328 gfx::Vector3dF lid_flattened(lid.x, lid.y, 0.0f); |
| 322 float lid_flattened_length = lid_flattened.Length(); | 329 float lid_flattened_length = lid_flattened.Length(); |
| 323 // When the lid is close to being flat, don't change rotation as it is too | 330 // When the lid is close to being flat, don't change rotation as it is too |
| 324 // sensitive to slight movements. | 331 // sensitive to slight movements. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 gfx::Display::Rotation new_rotation = gfx::Display::ROTATE_90; | 363 gfx::Display::Rotation new_rotation = gfx::Display::ROTATE_90; |
| 357 if (angle < 90.0f) | 364 if (angle < 90.0f) |
| 358 new_rotation = gfx::Display::ROTATE_0; | 365 new_rotation = gfx::Display::ROTATE_0; |
| 359 else if (angle < 180.0f) | 366 else if (angle < 180.0f) |
| 360 new_rotation = gfx::Display::ROTATE_270; | 367 new_rotation = gfx::Display::ROTATE_270; |
| 361 else if (angle < 270.0f) | 368 else if (angle < 270.0f) |
| 362 new_rotation = gfx::Display::ROTATE_180; | 369 new_rotation = gfx::Display::ROTATE_180; |
| 363 | 370 |
| 364 if (new_rotation != current_rotation_ && | 371 if (new_rotation != current_rotation_ && |
| 365 IsRotationAllowedInLockedState(new_rotation)) | 372 IsRotationAllowedInLockedState(new_rotation)) |
| 366 SetDisplayRotation(new_rotation); | 373 SetDisplayRotation(new_rotation, |
| 374 gfx::Display::ROTATION_SOURCE_ACCELEROMETER); |
| 367 } | 375 } |
| 368 | 376 |
| 369 void ScreenOrientationController::LoadDisplayRotationProperties() { | 377 void ScreenOrientationController::LoadDisplayRotationProperties() { |
| 370 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 378 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 371 if (!display_manager->registered_internal_display_rotation_lock()) | 379 if (!display_manager->registered_internal_display_rotation_lock()) |
| 372 return; | 380 return; |
| 373 SetDisplayRotation(display_manager->registered_internal_display_rotation()); | 381 SetDisplayRotation(display_manager->registered_internal_display_rotation(), |
| 382 gfx::Display::ROTATION_SOURCE_ACCELEROMETER); |
| 374 SetRotationLocked(true); | 383 SetRotationLocked(true); |
| 375 } | 384 } |
| 376 | 385 |
| 377 void ScreenOrientationController::ApplyLockForActiveWindow() { | 386 void ScreenOrientationController::ApplyLockForActiveWindow() { |
| 378 aura::Window* active_window = | 387 aura::Window* active_window = |
| 379 Shell::GetInstance()->activation_client()->GetActiveWindow(); | 388 Shell::GetInstance()->activation_client()->GetActiveWindow(); |
| 380 for (auto const& windows : locking_windows_) { | 389 for (auto const& windows : locking_windows_) { |
| 381 if (windows.first->TargetVisibility() && | 390 if (windows.first->TargetVisibility() && |
| 382 active_window->Contains(windows.first)) { | 391 active_window->Contains(windows.first)) { |
| 383 LockRotationToOrientation(windows.second); | 392 LockRotationToOrientation(windows.second); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 414 } | 423 } |
| 415 | 424 |
| 416 bool ScreenOrientationController::CanRotateInLockedState() { | 425 bool ScreenOrientationController::CanRotateInLockedState() { |
| 417 return rotation_locked_orientation_ == | 426 return rotation_locked_orientation_ == |
| 418 blink::WebScreenOrientationLockLandscape || | 427 blink::WebScreenOrientationLockLandscape || |
| 419 rotation_locked_orientation_ == | 428 rotation_locked_orientation_ == |
| 420 blink::WebScreenOrientationLockPortrait; | 429 blink::WebScreenOrientationLockPortrait; |
| 421 } | 430 } |
| 422 | 431 |
| 423 } // namespace ash | 432 } // namespace ash |
| OLD | NEW |