| 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/display/screen_orientation_controller_chromeos.h" | 5 #include "ash/display/screen_orientation_controller_chromeos.h" |
| 6 | 6 |
| 7 #include "ash/common/ash_switches.h" | 7 #include "ash/common/ash_switches.h" |
| 8 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" | 8 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
| 9 #include "ash/common/wm/mru_window_tracker.h" | 9 #include "ash/common/wm/mru_window_tracker.h" |
| 10 #include "ash/common/wm/window_state.h" | 10 #include "ash/common/wm/window_state.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 case display::Display::ROTATE_90: | 55 case display::Display::ROTATE_90: |
| 56 case display::Display::ROTATE_270: | 56 case display::Display::ROTATE_270: |
| 57 return size.height() < size.width() | 57 return size.height() < size.width() |
| 58 ? blink::WebScreenOrientationLockPortrait | 58 ? blink::WebScreenOrientationLockPortrait |
| 59 : blink::WebScreenOrientationLockLandscape; | 59 : blink::WebScreenOrientationLockLandscape; |
| 60 } | 60 } |
| 61 NOTREACHED(); | 61 NOTREACHED(); |
| 62 return blink::WebScreenOrientationLockLandscape; | 62 return blink::WebScreenOrientationLockLandscape; |
| 63 } | 63 } |
| 64 | 64 |
| 65 blink::WebScreenOrientationLockType RotationToOrientation( |
| 66 display::Display::Rotation rotation) { |
| 67 blink::WebScreenOrientationLockType natural = GetDisplayNaturalOrientation(); |
| 68 if (natural == blink::WebScreenOrientationLockLandscape) { |
| 69 switch (rotation) { |
| 70 case display::Display::ROTATE_0: |
| 71 return blink::WebScreenOrientationLockLandscapePrimary; |
| 72 case display::Display::ROTATE_90: |
| 73 return blink::WebScreenOrientationLockPortraitPrimary; |
| 74 case display::Display::ROTATE_180: |
| 75 return blink::WebScreenOrientationLockLandscapeSecondary; |
| 76 case display::Display::ROTATE_270: |
| 77 return blink::WebScreenOrientationLockPortraitSecondary; |
| 78 } |
| 79 } else { // Natural portrait |
| 80 switch (rotation) { |
| 81 case display::Display::ROTATE_0: |
| 82 return blink::WebScreenOrientationLockPortraitPrimary; |
| 83 case display::Display::ROTATE_90: |
| 84 return blink::WebScreenOrientationLockLandscapePrimary; |
| 85 case display::Display::ROTATE_180: |
| 86 return blink::WebScreenOrientationLockPortraitSecondary; |
| 87 case display::Display::ROTATE_270: |
| 88 return blink::WebScreenOrientationLockLandscapeSecondary; |
| 89 } |
| 90 } |
| 91 NOTREACHED(); |
| 92 return blink::WebScreenOrientationLockAny; |
| 93 } |
| 94 |
| 95 // Returns the rotation that matches the orientation type. |
| 96 // Returns ROTATE_0 if the given orientation is ANY, which is used |
| 97 // to indicate that user didn't lock orientation. |
| 98 display::Display::Rotation OrientationToRotation( |
| 99 blink::WebScreenOrientationLockType orientation) { |
| 100 blink::WebScreenOrientationLockType natural = GetDisplayNaturalOrientation(); |
| 101 if (orientation == blink::WebScreenOrientationLockAny) { |
| 102 return display::Display::ROTATE_0; |
| 103 } |
| 104 |
| 105 if (natural == blink::WebScreenOrientationLockLandscape) { |
| 106 switch (orientation) { |
| 107 case blink::WebScreenOrientationLockLandscapePrimary: |
| 108 return display::Display::ROTATE_0; |
| 109 case blink::WebScreenOrientationLockPortraitPrimary: |
| 110 return display::Display::ROTATE_90; |
| 111 case blink::WebScreenOrientationLockLandscapeSecondary: |
| 112 return display::Display::ROTATE_180; |
| 113 case blink::WebScreenOrientationLockPortraitSecondary: |
| 114 return display::Display::ROTATE_270; |
| 115 default: |
| 116 break; |
| 117 } |
| 118 } else { // Natural portrait |
| 119 switch (orientation) { |
| 120 case blink::WebScreenOrientationLockPortraitPrimary: |
| 121 return display::Display::ROTATE_0; |
| 122 case blink::WebScreenOrientationLockLandscapePrimary: |
| 123 return display::Display::ROTATE_90; |
| 124 case blink::WebScreenOrientationLockPortraitSecondary: |
| 125 return display::Display::ROTATE_180; |
| 126 case blink::WebScreenOrientationLockLandscapeSecondary: |
| 127 return display::Display::ROTATE_270; |
| 128 default: |
| 129 break; |
| 130 } |
| 131 } |
| 132 NOTREACHED() << orientation; |
| 133 return display::Display::ROTATE_0; |
| 134 } |
| 135 |
| 136 // Returns the locked orientation that matches the application |
| 137 // requested orientation, or the application orientation itself |
| 138 // if it didn't match. |
| 139 blink::WebScreenOrientationLockType ResolveOrientationLock( |
| 140 blink::WebScreenOrientationLockType app_requested, |
| 141 blink::WebScreenOrientationLockType lock) { |
| 142 if (app_requested == blink::WebScreenOrientationLockAny || |
| 143 (app_requested == blink::WebScreenOrientationLockLandscape && |
| 144 (lock == blink::WebScreenOrientationLockLandscapePrimary || |
| 145 lock == blink::WebScreenOrientationLockLandscapeSecondary)) || |
| 146 (app_requested == blink::WebScreenOrientationLockPortrait && |
| 147 (lock == blink::WebScreenOrientationLockPortraitPrimary || |
| 148 lock == blink::WebScreenOrientationLockPortraitSecondary))) { |
| 149 return lock; |
| 150 } |
| 151 return app_requested; |
| 152 } |
| 153 |
| 65 } // namespace | 154 } // namespace |
| 66 | 155 |
| 67 ScreenOrientationController::ScreenOrientationController() | 156 ScreenOrientationController::ScreenOrientationController() |
| 68 : natural_orientation_(GetDisplayNaturalOrientation()), | 157 : natural_orientation_(GetDisplayNaturalOrientation()), |
| 69 ignore_display_configuration_updates_(false), | 158 ignore_display_configuration_updates_(false), |
| 70 rotation_locked_(false), | 159 rotation_locked_(false), |
| 71 rotation_locked_orientation_(blink::WebScreenOrientationLockAny), | 160 rotation_locked_orientation_(blink::WebScreenOrientationLockAny), |
| 72 user_rotation_(display::Display::ROTATE_0), | 161 user_rotation_(display::Display::ROTATE_0), |
| 73 current_rotation_(display::Display::ROTATE_0) { | 162 current_rotation_(display::Display::ROTATE_0) { |
| 74 Shell::GetInstance()->AddShellObserver(this); | 163 Shell::GetInstance()->AddShellObserver(this); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 | 213 |
| 125 bool ScreenOrientationController::ScreenOrientationProviderSupported() const { | 214 bool ScreenOrientationController::ScreenOrientationProviderSupported() const { |
| 126 return Shell::Get() | 215 return Shell::Get() |
| 127 ->maximize_mode_controller() | 216 ->maximize_mode_controller() |
| 128 ->IsMaximizeModeWindowManagerEnabled() && | 217 ->IsMaximizeModeWindowManagerEnabled() && |
| 129 !base::CommandLine::ForCurrentProcess()->HasSwitch( | 218 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 130 switches::kAshDisableScreenOrientationLock); | 219 switches::kAshDisableScreenOrientationLock); |
| 131 } | 220 } |
| 132 | 221 |
| 133 void ScreenOrientationController::ToggleUserRotationLock() { | 222 void ScreenOrientationController::ToggleUserRotationLock() { |
| 223 if (!display::Display::HasInternalDisplay()) |
| 224 return; |
| 225 |
| 134 if (user_rotation_locked()) { | 226 if (user_rotation_locked()) { |
| 135 user_locked_orientation_ = blink::WebScreenOrientationLockAny; | 227 user_locked_orientation_ = blink::WebScreenOrientationLockAny; |
| 136 } else { | 228 } else { |
| 137 display::Display::Rotation current_rotation = | 229 display::Display::Rotation current_rotation = |
| 138 WmShell::Get() | 230 WmShell::Get() |
| 139 ->GetDisplayInfo(display::Display::InternalDisplayId()) | 231 ->GetDisplayInfo(display::Display::InternalDisplayId()) |
| 140 .GetActiveRotation(); | 232 .GetActiveRotation(); |
| 141 blink::WebScreenOrientationLockType natural = | 233 user_locked_orientation_ = RotationToOrientation(current_rotation); |
| 142 GetDisplayNaturalOrientation(); | |
| 143 if (natural == blink::WebScreenOrientationLockLandscape) { | |
| 144 switch (current_rotation) { | |
| 145 case display::Display::ROTATE_0: | |
| 146 user_locked_orientation_ = | |
| 147 blink::WebScreenOrientationLockLandscapePrimary; | |
| 148 break; | |
| 149 case display::Display::ROTATE_90: | |
| 150 user_locked_orientation_ = | |
| 151 blink::WebScreenOrientationLockPortraitPrimary; | |
| 152 break; | |
| 153 case display::Display::ROTATE_180: | |
| 154 user_locked_orientation_ = | |
| 155 blink::WebScreenOrientationLockLandscapeSecondary; | |
| 156 break; | |
| 157 case display::Display::ROTATE_270: | |
| 158 user_locked_orientation_ = | |
| 159 blink::WebScreenOrientationLockPortraitSecondary; | |
| 160 break; | |
| 161 } | |
| 162 } else { // Natural portrait | |
| 163 switch (current_rotation) { | |
| 164 case display::Display::ROTATE_0: | |
| 165 user_locked_orientation_ = | |
| 166 blink::WebScreenOrientationLockPortraitPrimary; | |
| 167 break; | |
| 168 case display::Display::ROTATE_90: | |
| 169 user_locked_orientation_ = | |
| 170 blink::WebScreenOrientationLockLandscapePrimary; | |
| 171 break; | |
| 172 case display::Display::ROTATE_180: | |
| 173 user_locked_orientation_ = | |
| 174 blink::WebScreenOrientationLockPortraitSecondary; | |
| 175 break; | |
| 176 case display::Display::ROTATE_270: | |
| 177 user_locked_orientation_ = | |
| 178 blink::WebScreenOrientationLockLandscapeSecondary; | |
| 179 break; | |
| 180 } | |
| 181 } | |
| 182 } | 234 } |
| 235 base::AutoReset<bool> auto_ignore_display_configuration_updates( |
| 236 &ignore_display_configuration_updates_, true); |
| 237 Shell::GetInstance()->display_manager()->RegisterDisplayRotationProperties( |
| 238 user_rotation_locked(), OrientationToRotation(user_locked_orientation_)); |
| 239 |
| 183 ApplyLockForActiveWindow(); | 240 ApplyLockForActiveWindow(); |
| 184 | |
| 185 for (auto& observer : observers_) | 241 for (auto& observer : observers_) |
| 186 observer.OnUserRotationLockChanged(); | 242 observer.OnUserRotationLockChanged(); |
| 187 } | 243 } |
| 188 | 244 |
| 189 void ScreenOrientationController::OnWindowActivated(ActivationReason reason, | 245 void ScreenOrientationController::OnWindowActivated(ActivationReason reason, |
| 190 aura::Window* gained_active, | 246 aura::Window* gained_active, |
| 191 aura::Window* lost_active) { | 247 aura::Window* lost_active) { |
| 192 ApplyLockForActiveWindow(); | 248 ApplyLockForActiveWindow(); |
| 193 } | 249 } |
| 194 | 250 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 if (display::Display::HasInternalDisplay()) { | 309 if (display::Display::HasInternalDisplay()) { |
| 254 current_rotation_ = user_rotation_ = | 310 current_rotation_ = user_rotation_ = |
| 255 WmShell::Get() | 311 WmShell::Get() |
| 256 ->GetDisplayInfo(display::Display::InternalDisplayId()) | 312 ->GetDisplayInfo(display::Display::InternalDisplayId()) |
| 257 .GetActiveRotation(); | 313 .GetActiveRotation(); |
| 258 } | 314 } |
| 259 if (!rotation_locked_) | 315 if (!rotation_locked_) |
| 260 LoadDisplayRotationProperties(); | 316 LoadDisplayRotationProperties(); |
| 261 chromeos::AccelerometerReader::GetInstance()->AddObserver(this); | 317 chromeos::AccelerometerReader::GetInstance()->AddObserver(this); |
| 262 WmShell::Get()->AddDisplayObserver(this); | 318 WmShell::Get()->AddDisplayObserver(this); |
| 319 |
| 320 if (!display::Display::HasInternalDisplay()) |
| 321 return; |
| 322 ApplyLockForActiveWindow(); |
| 323 for (auto& observer : observers_) |
| 324 observer.OnUserRotationLockChanged(); |
| 263 } | 325 } |
| 264 | 326 |
| 265 void ScreenOrientationController::OnMaximizeModeEnded() { | 327 void ScreenOrientationController::OnMaximizeModeEnded() { |
| 266 chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this); | 328 chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this); |
| 267 WmShell::Get()->RemoveDisplayObserver(this); | 329 WmShell::Get()->RemoveDisplayObserver(this); |
| 330 if (!display::Display::HasInternalDisplay()) |
| 331 return; |
| 268 if (current_rotation_ != user_rotation_) | 332 if (current_rotation_ != user_rotation_) |
| 269 SetDisplayRotation(user_rotation_, display::Display::ROTATION_SOURCE_USER); | 333 SetDisplayRotation(user_rotation_, display::Display::ROTATION_SOURCE_USER); |
| 334 for (auto& observer : observers_) |
| 335 observer.OnUserRotationLockChanged(); |
| 270 } | 336 } |
| 271 | 337 |
| 272 void ScreenOrientationController::SetDisplayRotation( | 338 void ScreenOrientationController::SetDisplayRotation( |
| 273 display::Display::Rotation rotation, | 339 display::Display::Rotation rotation, |
| 274 display::Display::RotationSource source) { | 340 display::Display::RotationSource source) { |
| 275 if (!display::Display::HasInternalDisplay()) | 341 if (!display::Display::HasInternalDisplay()) |
| 276 return; | 342 return; |
| 277 current_rotation_ = rotation; | 343 current_rotation_ = rotation; |
| 278 base::AutoReset<bool> auto_ignore_display_configuration_updates( | 344 base::AutoReset<bool> auto_ignore_display_configuration_updates( |
| 279 &ignore_display_configuration_updates_, true); | 345 &ignore_display_configuration_updates_, true); |
| 280 | 346 |
| 281 Shell::GetInstance()->display_configuration_controller()->SetDisplayRotation( | 347 Shell::GetInstance()->display_configuration_controller()->SetDisplayRotation( |
| 282 display::Display::InternalDisplayId(), rotation, source); | 348 display::Display::InternalDisplayId(), rotation, source); |
| 283 } | 349 } |
| 284 | 350 |
| 285 void ScreenOrientationController::SetRotationLockedInternal( | 351 void ScreenOrientationController::SetRotationLockedInternal( |
| 286 bool rotation_locked) { | 352 bool rotation_locked) { |
| 287 if (rotation_locked_ == rotation_locked) | 353 if (rotation_locked_ == rotation_locked) |
| 288 return; | 354 return; |
| 289 rotation_locked_ = rotation_locked; | 355 rotation_locked_ = rotation_locked; |
| 290 if (!rotation_locked_) | 356 if (!rotation_locked_) |
| 291 rotation_locked_orientation_ = blink::WebScreenOrientationLockAny; | 357 rotation_locked_orientation_ = blink::WebScreenOrientationLockAny; |
| 292 if (!display::Display::HasInternalDisplay()) | |
| 293 return; | |
| 294 base::AutoReset<bool> auto_ignore_display_configuration_updates( | |
| 295 &ignore_display_configuration_updates_, true); | |
| 296 Shell::GetInstance()->display_manager()->RegisterDisplayRotationProperties( | |
| 297 rotation_locked_, current_rotation_); | |
| 298 } | 358 } |
| 299 | 359 |
| 300 void ScreenOrientationController::LockRotation( | 360 void ScreenOrientationController::LockRotation( |
| 301 display::Display::Rotation rotation, | 361 display::Display::Rotation rotation, |
| 302 display::Display::RotationSource source) { | 362 display::Display::RotationSource source) { |
| 303 SetRotationLockedInternal(true); | 363 SetRotationLockedInternal(true); |
| 304 SetDisplayRotation(rotation, source); | 364 SetDisplayRotation(rotation, source); |
| 305 } | 365 } |
| 306 | 366 |
| 307 void ScreenOrientationController::LockRotationToOrientation( | 367 void ScreenOrientationController::LockRotationToOrientation( |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 SetDisplayRotation(new_rotation, | 497 SetDisplayRotation(new_rotation, |
| 438 display::Display::ROTATION_SOURCE_ACCELEROMETER); | 498 display::Display::ROTATION_SOURCE_ACCELEROMETER); |
| 439 } | 499 } |
| 440 } | 500 } |
| 441 | 501 |
| 442 void ScreenOrientationController::LoadDisplayRotationProperties() { | 502 void ScreenOrientationController::LoadDisplayRotationProperties() { |
| 443 display::DisplayManager* display_manager = | 503 display::DisplayManager* display_manager = |
| 444 Shell::GetInstance()->display_manager(); | 504 Shell::GetInstance()->display_manager(); |
| 445 if (!display_manager->registered_internal_display_rotation_lock()) | 505 if (!display_manager->registered_internal_display_rotation_lock()) |
| 446 return; | 506 return; |
| 447 SetDisplayRotation(display_manager->registered_internal_display_rotation(), | 507 user_locked_orientation_ = RotationToOrientation( |
| 448 display::Display::ROTATION_SOURCE_ACCELEROMETER); | 508 display_manager->registered_internal_display_rotation()); |
| 449 SetRotationLockedInternal(true); | |
| 450 } | 509 } |
| 451 | 510 |
| 452 void ScreenOrientationController::ApplyLockForActiveWindow() { | 511 void ScreenOrientationController::ApplyLockForActiveWindow() { |
| 453 MruWindowTracker::WindowList mru_windows( | 512 MruWindowTracker::WindowList mru_windows( |
| 454 Shell::GetInstance()->mru_window_tracker()->BuildMruWindowList()); | 513 Shell::GetInstance()->mru_window_tracker()->BuildMruWindowList()); |
| 455 | 514 |
| 456 for (WmWindow* window : mru_windows) { | 515 for (WmWindow* window : mru_windows) { |
| 457 if (!window->GetTargetVisibility()) | 516 if (!window->GetTargetVisibility()) |
| 458 continue; | 517 continue; |
| 459 // TODO(oshima): If the application's orientation is landscape | |
| 460 // and user_locked_orientation_ is landscape primary or secondary, | |
| 461 // it should lock to the specific orientation. (and same for portrait). | |
| 462 for (auto const& pair : locking_windows_) { | 518 for (auto const& pair : locking_windows_) { |
| 463 if (pair.first->GetTargetVisibility() && window->Contains(pair.first)) { | 519 if (pair.first->GetTargetVisibility() && window->Contains(pair.first)) { |
| 464 LockRotationToOrientation(pair.second == | 520 LockRotationToOrientation( |
| 465 blink::WebScreenOrientationLockAny | 521 ResolveOrientationLock(pair.second, user_locked_orientation_)); |
| 466 ? user_locked_orientation_ | |
| 467 : pair.second); | |
| 468 return; | 522 return; |
| 469 } | 523 } |
| 470 } | 524 } |
| 471 // The default orientation for all chrome browser/apps windows is | 525 // The default orientation for all chrome browser/apps windows is |
| 472 // ANY, so use the user_locked_orientation_; | 526 // ANY, so use the user_locked_orientation_; |
| 473 if (window->GetTargetVisibility() && | 527 if (window->GetTargetVisibility() && |
| 474 static_cast<AppType>(window->GetAppType()) != AppType::OTHERS) { | 528 static_cast<AppType>(window->GetAppType()) != AppType::OTHERS) { |
| 475 LockRotationToOrientation(user_locked_orientation_); | 529 LockRotationToOrientation(user_locked_orientation_); |
| 476 return; | 530 return; |
| 477 } | 531 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 498 } | 552 } |
| 499 | 553 |
| 500 bool ScreenOrientationController::CanRotateInLockedState() { | 554 bool ScreenOrientationController::CanRotateInLockedState() { |
| 501 return rotation_locked_orientation_ == | 555 return rotation_locked_orientation_ == |
| 502 blink::WebScreenOrientationLockLandscape || | 556 blink::WebScreenOrientationLockLandscape || |
| 503 rotation_locked_orientation_ == | 557 rotation_locked_orientation_ == |
| 504 blink::WebScreenOrientationLockPortrait; | 558 blink::WebScreenOrientationLockPortrait; |
| 505 } | 559 } |
| 506 | 560 |
| 507 } // namespace ash | 561 } // namespace ash |
| OLD | NEW |