| 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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 user_rotation_(display::Display::ROTATE_0), | 161 user_rotation_(display::Display::ROTATE_0), |
| 162 current_rotation_(display::Display::ROTATE_0) { | 162 current_rotation_(display::Display::ROTATE_0) { |
| 163 Shell::GetInstance()->AddShellObserver(this); | 163 Shell::GetInstance()->AddShellObserver(this); |
| 164 } | 164 } |
| 165 | 165 |
| 166 ScreenOrientationController::~ScreenOrientationController() { | 166 ScreenOrientationController::~ScreenOrientationController() { |
| 167 Shell::GetInstance()->RemoveShellObserver(this); | 167 Shell::GetInstance()->RemoveShellObserver(this); |
| 168 chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this); | 168 chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this); |
| 169 WmShell::Get()->RemoveDisplayObserver(this); | 169 WmShell::Get()->RemoveDisplayObserver(this); |
| 170 Shell::GetInstance()->activation_client()->RemoveObserver(this); | 170 Shell::GetInstance()->activation_client()->RemoveObserver(this); |
| 171 for (auto& windows : locking_windows_) | 171 for (auto& windows : lock_info_map_) |
| 172 windows.first->aura_window()->RemoveObserver(this); | 172 windows.first->aura_window()->RemoveObserver(this); |
| 173 } | 173 } |
| 174 | 174 |
| 175 void ScreenOrientationController::AddObserver(Observer* observer) { | 175 void ScreenOrientationController::AddObserver(Observer* observer) { |
| 176 observers_.AddObserver(observer); | 176 observers_.AddObserver(observer); |
| 177 } | 177 } |
| 178 | 178 |
| 179 void ScreenOrientationController::RemoveObserver(Observer* observer) { | 179 void ScreenOrientationController::RemoveObserver(Observer* observer) { |
| 180 observers_.RemoveObserver(observer); | 180 observers_.RemoveObserver(observer); |
| 181 } | 181 } |
| 182 | 182 |
| 183 void ScreenOrientationController::LockOrientationForWindow( | 183 void ScreenOrientationController::LockOrientationForWindow( |
| 184 WmWindow* requesting_window, | 184 WmWindow* requesting_window, |
| 185 blink::WebScreenOrientationLockType lock_orientation) { | 185 blink::WebScreenOrientationLockType lock_orientation, |
| 186 if (locking_windows_.empty()) | 186 LockCompletionBehavior lock_completion_behavior) { |
| 187 if (lock_info_map_.empty()) |
| 187 Shell::GetInstance()->activation_client()->AddObserver(this); | 188 Shell::GetInstance()->activation_client()->AddObserver(this); |
| 188 | 189 |
| 189 if (!requesting_window->aura_window()->HasObserver(this)) | 190 if (!requesting_window->aura_window()->HasObserver(this)) |
| 190 requesting_window->aura_window()->AddObserver(this); | 191 requesting_window->aura_window()->AddObserver(this); |
| 191 locking_windows_[requesting_window] = lock_orientation; | 192 lock_info_map_[requesting_window] = |
| 193 LockInfo(lock_orientation, lock_completion_behavior); |
| 192 | 194 |
| 193 ApplyLockForActiveWindow(); | 195 ApplyLockForActiveWindow(); |
| 194 } | 196 } |
| 195 | 197 |
| 196 void ScreenOrientationController::UnlockOrientationForWindow(WmWindow* window) { | 198 void ScreenOrientationController::UnlockOrientationForWindow(WmWindow* window) { |
| 197 locking_windows_.erase(window); | 199 lock_info_map_.erase(window); |
| 198 if (locking_windows_.empty()) | 200 if (lock_info_map_.empty()) |
| 199 Shell::GetInstance()->activation_client()->RemoveObserver(this); | 201 Shell::GetInstance()->activation_client()->RemoveObserver(this); |
| 200 window->aura_window()->RemoveObserver(this); | 202 window->aura_window()->RemoveObserver(this); |
| 201 ApplyLockForActiveWindow(); | 203 ApplyLockForActiveWindow(); |
| 202 } | 204 } |
| 203 | 205 |
| 204 void ScreenOrientationController::UnlockAll() { | 206 void ScreenOrientationController::UnlockAll() { |
| 205 for (auto pair : locking_windows_) | 207 for (auto pair : lock_info_map_) |
| 206 pair.first->aura_window()->RemoveObserver(this); | 208 pair.first->aura_window()->RemoveObserver(this); |
| 207 locking_windows_.clear(); | 209 lock_info_map_.clear(); |
| 208 Shell::GetInstance()->activation_client()->RemoveObserver(this); | 210 Shell::GetInstance()->activation_client()->RemoveObserver(this); |
| 209 SetRotationLockedInternal(false); | 211 SetRotationLockedInternal(false); |
| 210 if (user_rotation_ != current_rotation_) | 212 if (user_rotation_ != current_rotation_) |
| 211 SetDisplayRotation(user_rotation_, display::Display::ROTATION_SOURCE_USER); | 213 SetDisplayRotation(user_rotation_, display::Display::ROTATION_SOURCE_USER); |
| 212 } | 214 } |
| 213 | 215 |
| 214 bool ScreenOrientationController::ScreenOrientationProviderSupported() const { | 216 bool ScreenOrientationController::ScreenOrientationProviderSupported() const { |
| 215 return Shell::Get() | 217 return Shell::Get() |
| 216 ->maximize_mode_controller() | 218 ->maximize_mode_controller() |
| 217 ->IsMaximizeModeWindowManagerEnabled() && | 219 ->IsMaximizeModeWindowManagerEnabled() && |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 // Currently contents::WebContents will only be able to lock rotation while | 257 // Currently contents::WebContents will only be able to lock rotation while |
| 256 // fullscreen. In this state a user cannot click on the tab strip to change. If | 258 // fullscreen. In this state a user cannot click on the tab strip to change. If |
| 257 // this becomes supported for non-fullscreen tabs then the following interferes | 259 // this becomes supported for non-fullscreen tabs then the following interferes |
| 258 // with TabDragController. OnWindowVisibilityChanged is called between a mouse | 260 // with TabDragController. OnWindowVisibilityChanged is called between a mouse |
| 259 // down and mouse up. The rotation this triggers leads to a coordinate space | 261 // down and mouse up. The rotation this triggers leads to a coordinate space |
| 260 // change in the middle of an event. Causes the tab to separate from the tab | 262 // change in the middle of an event. Causes the tab to separate from the tab |
| 261 // strip. | 263 // strip. |
| 262 void ScreenOrientationController::OnWindowVisibilityChanged( | 264 void ScreenOrientationController::OnWindowVisibilityChanged( |
| 263 aura::Window* window, | 265 aura::Window* window, |
| 264 bool visible) { | 266 bool visible) { |
| 265 if (locking_windows_.find(WmWindow::Get(window)) == locking_windows_.end()) | 267 if (lock_info_map_.find(WmWindow::Get(window)) == lock_info_map_.end()) |
| 266 return; | 268 return; |
| 267 ApplyLockForActiveWindow(); | 269 ApplyLockForActiveWindow(); |
| 268 } | 270 } |
| 269 | 271 |
| 270 void ScreenOrientationController::OnAccelerometerUpdated( | 272 void ScreenOrientationController::OnAccelerometerUpdated( |
| 271 scoped_refptr<const chromeos::AccelerometerUpdate> update) { | 273 scoped_refptr<const chromeos::AccelerometerUpdate> update) { |
| 272 if (rotation_locked_ && !CanRotateInLockedState()) | 274 if (rotation_locked_ && !CanRotateInLockedState()) |
| 273 return; | 275 return; |
| 274 if (!update->has(chromeos::ACCELEROMETER_SOURCE_SCREEN)) | 276 if (!update->has(chromeos::ACCELEROMETER_SOURCE_SCREEN)) |
| 275 return; | 277 return; |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 display_manager->registered_internal_display_rotation()); | 523 display_manager->registered_internal_display_rotation()); |
| 522 } | 524 } |
| 523 | 525 |
| 524 void ScreenOrientationController::ApplyLockForActiveWindow() { | 526 void ScreenOrientationController::ApplyLockForActiveWindow() { |
| 525 MruWindowTracker::WindowList mru_windows( | 527 MruWindowTracker::WindowList mru_windows( |
| 526 Shell::GetInstance()->mru_window_tracker()->BuildMruWindowList()); | 528 Shell::GetInstance()->mru_window_tracker()->BuildMruWindowList()); |
| 527 | 529 |
| 528 for (WmWindow* window : mru_windows) { | 530 for (WmWindow* window : mru_windows) { |
| 529 if (!window->GetTargetVisibility()) | 531 if (!window->GetTargetVisibility()) |
| 530 continue; | 532 continue; |
| 531 for (auto const& pair : locking_windows_) { | 533 for (auto& pair : lock_info_map_) { |
| 532 if (pair.first->GetTargetVisibility() && window->Contains(pair.first)) { | 534 if (pair.first->GetTargetVisibility() && window->Contains(pair.first)) { |
| 533 LockRotationToOrientation( | 535 LockRotationToOrientation(ResolveOrientationLock( |
| 534 ResolveOrientationLock(pair.second, user_locked_orientation_)); | 536 pair.second.orientation, user_locked_orientation_)); |
| 537 if (pair.second.lock_completion_behavior == |
| 538 LockCompletionBehavior::DisableSensor) { |
| 539 pair.second.orientation = RotationToOrientation(current_rotation_); |
| 540 pair.second.lock_completion_behavior = LockCompletionBehavior::None; |
| 541 LockRotationToOrientation(pair.second.orientation); |
| 542 } |
| 535 return; | 543 return; |
| 536 } | 544 } |
| 537 } | 545 } |
| 538 // The default orientation for all chrome browser/apps windows is | 546 // The default orientation for all chrome browser/apps windows is |
| 539 // ANY, so use the user_locked_orientation_; | 547 // ANY, so use the user_locked_orientation_; |
| 540 if (window->GetTargetVisibility() && | 548 if (window->GetTargetVisibility() && |
| 541 static_cast<AppType>(window->GetAppType()) != AppType::OTHERS) { | 549 static_cast<AppType>(window->GetAppType()) != AppType::OTHERS) { |
| 542 LockRotationToOrientation(user_locked_orientation_); | 550 LockRotationToOrientation(user_locked_orientation_); |
| 543 return; | 551 return; |
| 544 } | 552 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 557 if (natural_orientation_ == rotation_locked_orientation_) { | 565 if (natural_orientation_ == rotation_locked_orientation_) { |
| 558 return rotation == display::Display::ROTATE_0 || | 566 return rotation == display::Display::ROTATE_0 || |
| 559 rotation == display::Display::ROTATE_180; | 567 rotation == display::Display::ROTATE_180; |
| 560 } else { | 568 } else { |
| 561 return rotation == display::Display::ROTATE_90 || | 569 return rotation == display::Display::ROTATE_90 || |
| 562 rotation == display::Display::ROTATE_270; | 570 rotation == display::Display::ROTATE_270; |
| 563 } | 571 } |
| 564 return false; | 572 return false; |
| 565 } | 573 } |
| 566 | 574 |
| 575 blink::WebScreenOrientationLockType |
| 576 ScreenOrientationController::GetCurrentOrientationForTest() const { |
| 577 return RotationToOrientation(current_rotation_); |
| 578 } |
| 579 |
| 567 bool ScreenOrientationController::CanRotateInLockedState() { | 580 bool ScreenOrientationController::CanRotateInLockedState() { |
| 568 return rotation_locked_orientation_ == | 581 return rotation_locked_orientation_ == |
| 569 blink::WebScreenOrientationLockLandscape || | 582 blink::WebScreenOrientationLockLandscape || |
| 570 rotation_locked_orientation_ == | 583 rotation_locked_orientation_ == |
| 571 blink::WebScreenOrientationLockPortrait; | 584 blink::WebScreenOrientationLockPortrait; |
| 572 } | 585 } |
| 573 | 586 |
| 574 } // namespace ash | 587 } // namespace ash |
| OLD | NEW |