| 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_shell.h" | 9 #include "ash/common/wm_shell.h" |
| 10 #include "ash/common/wm_window.h" | 10 #include "ash/common/wm_window.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 current_rotation_(display::Display::ROTATE_0) { | 69 current_rotation_(display::Display::ROTATE_0) { |
| 70 WmShell::Get()->AddShellObserver(this); | 70 WmShell::Get()->AddShellObserver(this); |
| 71 } | 71 } |
| 72 | 72 |
| 73 ScreenOrientationController::~ScreenOrientationController() { | 73 ScreenOrientationController::~ScreenOrientationController() { |
| 74 WmShell::Get()->RemoveShellObserver(this); | 74 WmShell::Get()->RemoveShellObserver(this); |
| 75 chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this); | 75 chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this); |
| 76 WmShell::Get()->RemoveDisplayObserver(this); | 76 WmShell::Get()->RemoveDisplayObserver(this); |
| 77 WmShell::Get()->RemoveActivationObserver(this); | 77 WmShell::Get()->RemoveActivationObserver(this); |
| 78 for (auto& windows : locking_windows_) | 78 for (auto& windows : locking_windows_) |
| 79 windows.first->RemoveObserver(this); | 79 windows.first->aura_window()->RemoveObserver(this); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void ScreenOrientationController::AddObserver(Observer* observer) { | 82 void ScreenOrientationController::AddObserver(Observer* observer) { |
| 83 observers_.AddObserver(observer); | 83 observers_.AddObserver(observer); |
| 84 } | 84 } |
| 85 | 85 |
| 86 void ScreenOrientationController::RemoveObserver(Observer* observer) { | 86 void ScreenOrientationController::RemoveObserver(Observer* observer) { |
| 87 observers_.RemoveObserver(observer); | 87 observers_.RemoveObserver(observer); |
| 88 } | 88 } |
| 89 | 89 |
| 90 void ScreenOrientationController::LockOrientationForWindow( | 90 void ScreenOrientationController::LockOrientationForWindow( |
| 91 WmWindow* requesting_window, | 91 WmWindow* requesting_window, |
| 92 blink::WebScreenOrientationLockType lock_orientation) { | 92 blink::WebScreenOrientationLockType lock_orientation) { |
| 93 if (locking_windows_.empty()) | 93 if (locking_windows_.empty()) |
| 94 WmShell::Get()->AddActivationObserver(this); | 94 WmShell::Get()->AddActivationObserver(this); |
| 95 | 95 |
| 96 if (!requesting_window->HasObserver(this)) | 96 if (!requesting_window->aura_window()->HasObserver(this)) |
| 97 requesting_window->AddObserver(this); | 97 requesting_window->aura_window()->AddObserver(this); |
| 98 locking_windows_[requesting_window] = lock_orientation; | 98 locking_windows_[requesting_window] = lock_orientation; |
| 99 | 99 |
| 100 ApplyLockForActiveWindow(); | 100 ApplyLockForActiveWindow(); |
| 101 } | 101 } |
| 102 | 102 |
| 103 void ScreenOrientationController::UnlockOrientationForWindow(WmWindow* window) { | 103 void ScreenOrientationController::UnlockOrientationForWindow(WmWindow* window) { |
| 104 locking_windows_.erase(window); | 104 locking_windows_.erase(window); |
| 105 if (locking_windows_.empty()) | 105 if (locking_windows_.empty()) |
| 106 WmShell::Get()->RemoveActivationObserver(this); | 106 WmShell::Get()->RemoveActivationObserver(this); |
| 107 window->RemoveObserver(this); | 107 window->aura_window()->RemoveObserver(this); |
| 108 ApplyLockForActiveWindow(); | 108 ApplyLockForActiveWindow(); |
| 109 } | 109 } |
| 110 | 110 |
| 111 void ScreenOrientationController::UnlockAll() { | 111 void ScreenOrientationController::UnlockAll() { |
| 112 for (auto pair : locking_windows_) | 112 for (auto pair : locking_windows_) |
| 113 pair.first->RemoveObserver(this); | 113 pair.first->aura_window()->RemoveObserver(this); |
| 114 locking_windows_.clear(); | 114 locking_windows_.clear(); |
| 115 WmShell::Get()->RemoveActivationObserver(this); | 115 WmShell::Get()->RemoveActivationObserver(this); |
| 116 SetRotationLocked(false); | 116 SetRotationLocked(false); |
| 117 if (user_rotation_ != current_rotation_) | 117 if (user_rotation_ != current_rotation_) |
| 118 SetDisplayRotation(user_rotation_, display::Display::ROTATION_SOURCE_USER); | 118 SetDisplayRotation(user_rotation_, display::Display::ROTATION_SOURCE_USER); |
| 119 } | 119 } |
| 120 | 120 |
| 121 bool ScreenOrientationController::ScreenOrientationProviderSupported() const { | 121 bool ScreenOrientationController::ScreenOrientationProviderSupported() const { |
| 122 return WmShell::Get() | 122 return WmShell::Get() |
| 123 ->maximize_mode_controller() | 123 ->maximize_mode_controller() |
| (...skipping 30 matching lines...) Expand all Loading... |
| 154 Shell::GetInstance()->display_configuration_controller()->SetDisplayRotation( | 154 Shell::GetInstance()->display_configuration_controller()->SetDisplayRotation( |
| 155 display::Display::InternalDisplayId(), rotation, source, | 155 display::Display::InternalDisplayId(), rotation, source, |
| 156 true /* user_action */); | 156 true /* user_action */); |
| 157 } | 157 } |
| 158 | 158 |
| 159 void ScreenOrientationController::OnWindowActivated(WmWindow* gained_active, | 159 void ScreenOrientationController::OnWindowActivated(WmWindow* gained_active, |
| 160 WmWindow* lost_active) { | 160 WmWindow* lost_active) { |
| 161 ApplyLockForActiveWindow(); | 161 ApplyLockForActiveWindow(); |
| 162 } | 162 } |
| 163 | 163 |
| 164 void ScreenOrientationController::OnWindowDestroying(WmWindow* window) { | 164 void ScreenOrientationController::OnWindowDestroying(aura::Window* window) { |
| 165 UnlockOrientationForWindow(window); | 165 UnlockOrientationForWindow(WmWindow::Get(window)); |
| 166 } | 166 } |
| 167 | 167 |
| 168 // Currently contents::WebContents will only be able to lock rotation while | 168 // Currently contents::WebContents will only be able to lock rotation while |
| 169 // fullscreen. In this state a user cannot click on the tab strip to change. If | 169 // fullscreen. In this state a user cannot click on the tab strip to change. If |
| 170 // this becomes supported for non-fullscreen tabs then the following interferes | 170 // this becomes supported for non-fullscreen tabs then the following interferes |
| 171 // with TabDragController. OnWindowVisibilityChanged is called between a mouse | 171 // with TabDragController. OnWindowVisibilityChanged is called between a mouse |
| 172 // down and mouse up. The rotation this triggers leads to a coordinate space | 172 // down and mouse up. The rotation this triggers leads to a coordinate space |
| 173 // change in the middle of an event. Causes the tab to separate from the tab | 173 // change in the middle of an event. Causes the tab to separate from the tab |
| 174 // strip. | 174 // strip. |
| 175 void ScreenOrientationController::OnWindowVisibilityChanged(WmWindow* window, | 175 void ScreenOrientationController::OnWindowVisibilityChanged( |
| 176 bool visible) { | 176 aura::Window* window, |
| 177 if (locking_windows_.find(window) == locking_windows_.end()) | 177 bool visible) { |
| 178 if (locking_windows_.find(WmWindow::Get(window)) == locking_windows_.end()) |
| 178 return; | 179 return; |
| 179 ApplyLockForActiveWindow(); | 180 ApplyLockForActiveWindow(); |
| 180 } | 181 } |
| 181 | 182 |
| 182 void ScreenOrientationController::OnAccelerometerUpdated( | 183 void ScreenOrientationController::OnAccelerometerUpdated( |
| 183 scoped_refptr<const chromeos::AccelerometerUpdate> update) { | 184 scoped_refptr<const chromeos::AccelerometerUpdate> update) { |
| 184 if (rotation_locked_ && !CanRotateInLockedState()) | 185 if (rotation_locked_ && !CanRotateInLockedState()) |
| 185 return; | 186 return; |
| 186 if (!update->has(chromeos::ACCELEROMETER_SOURCE_SCREEN)) | 187 if (!update->has(chromeos::ACCELEROMETER_SOURCE_SCREEN)) |
| 187 return; | 188 return; |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 } | 420 } |
| 420 | 421 |
| 421 bool ScreenOrientationController::CanRotateInLockedState() { | 422 bool ScreenOrientationController::CanRotateInLockedState() { |
| 422 return rotation_locked_orientation_ == | 423 return rotation_locked_orientation_ == |
| 423 blink::WebScreenOrientationLockLandscape || | 424 blink::WebScreenOrientationLockLandscape || |
| 424 rotation_locked_orientation_ == | 425 rotation_locked_orientation_ == |
| 425 blink::WebScreenOrientationLockPortrait; | 426 blink::WebScreenOrientationLockPortrait; |
| 426 } | 427 } |
| 427 | 428 |
| 428 } // namespace ash | 429 } // namespace ash |
| OLD | NEW |