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