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