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/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 | 241 |
| 185 for (auto& observer : observers_) | 242 for (auto& observer : observers_) |
| 186 observer.OnUserRotationLockChanged(); | 243 observer.OnUserRotationLockChanged(); |
| 187 } | 244 } |
| 188 | 245 |
| 189 void ScreenOrientationController::OnWindowActivated(ActivationReason reason, | 246 void ScreenOrientationController::OnWindowActivated(ActivationReason reason, |
| 190 aura::Window* gained_active, | 247 aura::Window* gained_active, |
| 191 aura::Window* lost_active) { | 248 aura::Window* lost_active) { |
| 192 ApplyLockForActiveWindow(); | 249 ApplyLockForActiveWindow(); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 253 if (display::Display::HasInternalDisplay()) { | 310 if (display::Display::HasInternalDisplay()) { |
| 254 current_rotation_ = user_rotation_ = | 311 current_rotation_ = user_rotation_ = |
| 255 WmShell::Get() | 312 WmShell::Get() |
| 256 ->GetDisplayInfo(display::Display::InternalDisplayId()) | 313 ->GetDisplayInfo(display::Display::InternalDisplayId()) |
| 257 .GetActiveRotation(); | 314 .GetActiveRotation(); |
| 258 } | 315 } |
| 259 if (!rotation_locked_) | 316 if (!rotation_locked_) |
| 260 LoadDisplayRotationProperties(); | 317 LoadDisplayRotationProperties(); |
| 261 chromeos::AccelerometerReader::GetInstance()->AddObserver(this); | 318 chromeos::AccelerometerReader::GetInstance()->AddObserver(this); |
| 262 WmShell::Get()->AddDisplayObserver(this); | 319 WmShell::Get()->AddDisplayObserver(this); |
| 320 | |
| 321 ApplyLockForActiveWindow(); | |
| 322 for (auto& observer : observers_) | |
| 323 observer.OnUserRotationLockChanged(); | |
|
jonross
2017/03/24 15:21:04
Do we want to send this if there was no rotation l
oshima
2017/03/24 16:33:43
no lock is still one of states, so I consider this
jonross
2017/03/24 16:46:49
Okay that sgtm
| |
| 263 } | 324 } |
| 264 | 325 |
| 265 void ScreenOrientationController::OnMaximizeModeEnded() { | 326 void ScreenOrientationController::OnMaximizeModeEnded() { |
| 266 chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this); | 327 chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this); |
| 267 WmShell::Get()->RemoveDisplayObserver(this); | 328 WmShell::Get()->RemoveDisplayObserver(this); |
| 268 if (current_rotation_ != user_rotation_) | 329 if (current_rotation_ != user_rotation_) |
| 269 SetDisplayRotation(user_rotation_, display::Display::ROTATION_SOURCE_USER); | 330 SetDisplayRotation(user_rotation_, display::Display::ROTATION_SOURCE_USER); |
| 270 } | 331 } |
| 271 | 332 |
| 272 void ScreenOrientationController::SetDisplayRotation( | 333 void ScreenOrientationController::SetDisplayRotation( |
| 273 display::Display::Rotation rotation, | 334 display::Display::Rotation rotation, |
| 274 display::Display::RotationSource source) { | 335 display::Display::RotationSource source) { |
| 275 if (!display::Display::HasInternalDisplay()) | 336 if (!display::Display::HasInternalDisplay()) |
| 276 return; | 337 return; |
| 277 current_rotation_ = rotation; | 338 current_rotation_ = rotation; |
| 278 base::AutoReset<bool> auto_ignore_display_configuration_updates( | 339 base::AutoReset<bool> auto_ignore_display_configuration_updates( |
| 279 &ignore_display_configuration_updates_, true); | 340 &ignore_display_configuration_updates_, true); |
| 280 | 341 |
| 281 Shell::GetInstance()->display_configuration_controller()->SetDisplayRotation( | 342 Shell::GetInstance()->display_configuration_controller()->SetDisplayRotation( |
| 282 display::Display::InternalDisplayId(), rotation, source); | 343 display::Display::InternalDisplayId(), rotation, source); |
| 283 } | 344 } |
| 284 | 345 |
| 285 void ScreenOrientationController::SetRotationLockedInternal( | 346 void ScreenOrientationController::SetRotationLockedInternal( |
| 286 bool rotation_locked) { | 347 bool rotation_locked) { |
| 287 if (rotation_locked_ == rotation_locked) | 348 if (rotation_locked_ == rotation_locked) |
| 288 return; | 349 return; |
| 289 rotation_locked_ = rotation_locked; | 350 rotation_locked_ = rotation_locked; |
| 290 if (!rotation_locked_) | 351 if (!rotation_locked_) |
| 291 rotation_locked_orientation_ = blink::WebScreenOrientationLockAny; | 352 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 } | 353 } |
| 299 | 354 |
| 300 void ScreenOrientationController::LockRotation( | 355 void ScreenOrientationController::LockRotation( |
| 301 display::Display::Rotation rotation, | 356 display::Display::Rotation rotation, |
| 302 display::Display::RotationSource source) { | 357 display::Display::RotationSource source) { |
| 303 SetRotationLockedInternal(true); | 358 SetRotationLockedInternal(true); |
| 304 SetDisplayRotation(rotation, source); | 359 SetDisplayRotation(rotation, source); |
| 305 } | 360 } |
| 306 | 361 |
| 307 void ScreenOrientationController::LockRotationToOrientation( | 362 void ScreenOrientationController::LockRotationToOrientation( |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 437 SetDisplayRotation(new_rotation, | 492 SetDisplayRotation(new_rotation, |
| 438 display::Display::ROTATION_SOURCE_ACCELEROMETER); | 493 display::Display::ROTATION_SOURCE_ACCELEROMETER); |
| 439 } | 494 } |
| 440 } | 495 } |
| 441 | 496 |
| 442 void ScreenOrientationController::LoadDisplayRotationProperties() { | 497 void ScreenOrientationController::LoadDisplayRotationProperties() { |
| 443 display::DisplayManager* display_manager = | 498 display::DisplayManager* display_manager = |
| 444 Shell::GetInstance()->display_manager(); | 499 Shell::GetInstance()->display_manager(); |
| 445 if (!display_manager->registered_internal_display_rotation_lock()) | 500 if (!display_manager->registered_internal_display_rotation_lock()) |
| 446 return; | 501 return; |
| 447 SetDisplayRotation(display_manager->registered_internal_display_rotation(), | 502 user_locked_orientation_ = RotationToOrientation( |
| 448 display::Display::ROTATION_SOURCE_ACCELEROMETER); | 503 display_manager->registered_internal_display_rotation()); |
| 449 SetRotationLockedInternal(true); | |
| 450 } | 504 } |
| 451 | 505 |
| 452 void ScreenOrientationController::ApplyLockForActiveWindow() { | 506 void ScreenOrientationController::ApplyLockForActiveWindow() { |
| 453 MruWindowTracker::WindowList mru_windows( | 507 MruWindowTracker::WindowList mru_windows( |
| 454 Shell::GetInstance()->mru_window_tracker()->BuildMruWindowList()); | 508 Shell::GetInstance()->mru_window_tracker()->BuildMruWindowList()); |
| 455 | 509 |
| 456 for (WmWindow* window : mru_windows) { | 510 for (WmWindow* window : mru_windows) { |
| 457 if (!window->GetTargetVisibility()) | 511 if (!window->GetTargetVisibility()) |
| 458 continue; | 512 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_) { | 513 for (auto const& pair : locking_windows_) { |
| 463 if (pair.first->GetTargetVisibility() && window->Contains(pair.first)) { | 514 if (pair.first->GetTargetVisibility() && window->Contains(pair.first)) { |
| 464 LockRotationToOrientation(pair.second == | 515 LockRotationToOrientation( |
| 465 blink::WebScreenOrientationLockAny | 516 ResolveOrientationLock(pair.second, user_locked_orientation_)); |
| 466 ? user_locked_orientation_ | |
| 467 : pair.second); | |
| 468 return; | 517 return; |
| 469 } | 518 } |
| 470 } | 519 } |
| 471 // The default orientation for all chrome browser/apps windows is | 520 // The default orientation for all chrome browser/apps windows is |
| 472 // ANY, so use the user_locked_orientation_; | 521 // ANY, so use the user_locked_orientation_; |
| 473 if (window->GetTargetVisibility() && | 522 if (window->GetTargetVisibility() && |
| 474 static_cast<AppType>(window->GetAppType()) != AppType::OTHERS) { | 523 static_cast<AppType>(window->GetAppType()) != AppType::OTHERS) { |
| 475 LockRotationToOrientation(user_locked_orientation_); | 524 LockRotationToOrientation(user_locked_orientation_); |
| 476 return; | 525 return; |
| 477 } | 526 } |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 498 } | 547 } |
| 499 | 548 |
| 500 bool ScreenOrientationController::CanRotateInLockedState() { | 549 bool ScreenOrientationController::CanRotateInLockedState() { |
| 501 return rotation_locked_orientation_ == | 550 return rotation_locked_orientation_ == |
| 502 blink::WebScreenOrientationLockLandscape || | 551 blink::WebScreenOrientationLockLandscape || |
| 503 rotation_locked_orientation_ == | 552 rotation_locked_orientation_ == |
| 504 blink::WebScreenOrientationLockPortrait; | 553 blink::WebScreenOrientationLockPortrait; |
| 505 } | 554 } |
| 506 | 555 |
| 507 } // namespace ash | 556 } // namespace ash |
| OLD | NEW |