| 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" |
| 11 #include "ash/display/display_configuration_controller.h" | 11 #include "ash/display/display_configuration_controller.h" |
| 12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 13 #include "base/auto_reset.h" | 13 #include "base/auto_reset.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "chromeos/accelerometer/accelerometer_reader.h" | 15 #include "chromeos/accelerometer/accelerometer_reader.h" |
| 16 #include "chromeos/accelerometer/accelerometer_types.h" | 16 #include "chromeos/accelerometer/accelerometer_types.h" |
| 17 #include "ui/chromeos/accelerometer/accelerometer_util.h" | 17 #include "ui/chromeos/accelerometer/accelerometer_util.h" |
| 18 #include "ui/display/display.h" | 18 #include "ui/display/display.h" |
| 19 #include "ui/display/manager/display_manager.h" | 19 #include "ui/display/manager/display_manager.h" |
| 20 #include "ui/display/manager/managed_display_info.h" | 20 #include "ui/display/manager/managed_display_info.h" |
| 21 #include "ui/gfx/geometry/size.h" | 21 #include "ui/gfx/geometry/size.h" |
| 22 #include "ui/wm/public/activation_client.h" |
| 22 | 23 |
| 23 namespace ash { | 24 namespace ash { |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 // The angle which the screen has to be rotated past before the display will | 28 // The angle which the screen has to be rotated past before the display will |
| 28 // rotate to match it (i.e. 45.0f is no stickiness). | 29 // rotate to match it (i.e. 45.0f is no stickiness). |
| 29 const float kDisplayRotationStickyAngleDegrees = 60.0f; | 30 const float kDisplayRotationStickyAngleDegrees = 60.0f; |
| 30 | 31 |
| 31 // The minimum acceleration in m/s^2 in a direction required to trigger screen | 32 // The minimum acceleration in m/s^2 in a direction required to trigger screen |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 rotation_locked_orientation_(blink::WebScreenOrientationLockAny), | 68 rotation_locked_orientation_(blink::WebScreenOrientationLockAny), |
| 68 user_rotation_(display::Display::ROTATE_0), | 69 user_rotation_(display::Display::ROTATE_0), |
| 69 current_rotation_(display::Display::ROTATE_0) { | 70 current_rotation_(display::Display::ROTATE_0) { |
| 70 WmShell::Get()->AddShellObserver(this); | 71 WmShell::Get()->AddShellObserver(this); |
| 71 } | 72 } |
| 72 | 73 |
| 73 ScreenOrientationController::~ScreenOrientationController() { | 74 ScreenOrientationController::~ScreenOrientationController() { |
| 74 WmShell::Get()->RemoveShellObserver(this); | 75 WmShell::Get()->RemoveShellObserver(this); |
| 75 chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this); | 76 chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this); |
| 76 WmShell::Get()->RemoveDisplayObserver(this); | 77 WmShell::Get()->RemoveDisplayObserver(this); |
| 77 WmShell::Get()->RemoveActivationObserver(this); | 78 Shell::GetInstance()->activation_client()->RemoveObserver(this); |
| 78 for (auto& windows : locking_windows_) | 79 for (auto& windows : locking_windows_) |
| 79 windows.first->aura_window()->RemoveObserver(this); | 80 windows.first->aura_window()->RemoveObserver(this); |
| 80 } | 81 } |
| 81 | 82 |
| 82 void ScreenOrientationController::AddObserver(Observer* observer) { | 83 void ScreenOrientationController::AddObserver(Observer* observer) { |
| 83 observers_.AddObserver(observer); | 84 observers_.AddObserver(observer); |
| 84 } | 85 } |
| 85 | 86 |
| 86 void ScreenOrientationController::RemoveObserver(Observer* observer) { | 87 void ScreenOrientationController::RemoveObserver(Observer* observer) { |
| 87 observers_.RemoveObserver(observer); | 88 observers_.RemoveObserver(observer); |
| 88 } | 89 } |
| 89 | 90 |
| 90 void ScreenOrientationController::LockOrientationForWindow( | 91 void ScreenOrientationController::LockOrientationForWindow( |
| 91 WmWindow* requesting_window, | 92 WmWindow* requesting_window, |
| 92 blink::WebScreenOrientationLockType lock_orientation) { | 93 blink::WebScreenOrientationLockType lock_orientation) { |
| 93 if (locking_windows_.empty()) | 94 if (locking_windows_.empty()) |
| 94 WmShell::Get()->AddActivationObserver(this); | 95 Shell::GetInstance()->activation_client()->AddObserver(this); |
| 95 | 96 |
| 96 if (!requesting_window->aura_window()->HasObserver(this)) | 97 if (!requesting_window->aura_window()->HasObserver(this)) |
| 97 requesting_window->aura_window()->AddObserver(this); | 98 requesting_window->aura_window()->AddObserver(this); |
| 98 locking_windows_[requesting_window] = lock_orientation; | 99 locking_windows_[requesting_window] = lock_orientation; |
| 99 | 100 |
| 100 ApplyLockForActiveWindow(); | 101 ApplyLockForActiveWindow(); |
| 101 } | 102 } |
| 102 | 103 |
| 103 void ScreenOrientationController::UnlockOrientationForWindow(WmWindow* window) { | 104 void ScreenOrientationController::UnlockOrientationForWindow(WmWindow* window) { |
| 104 locking_windows_.erase(window); | 105 locking_windows_.erase(window); |
| 105 if (locking_windows_.empty()) | 106 if (locking_windows_.empty()) |
| 106 WmShell::Get()->RemoveActivationObserver(this); | 107 Shell::GetInstance()->activation_client()->RemoveObserver(this); |
| 107 window->aura_window()->RemoveObserver(this); | 108 window->aura_window()->RemoveObserver(this); |
| 108 ApplyLockForActiveWindow(); | 109 ApplyLockForActiveWindow(); |
| 109 } | 110 } |
| 110 | 111 |
| 111 void ScreenOrientationController::UnlockAll() { | 112 void ScreenOrientationController::UnlockAll() { |
| 112 for (auto pair : locking_windows_) | 113 for (auto pair : locking_windows_) |
| 113 pair.first->aura_window()->RemoveObserver(this); | 114 pair.first->aura_window()->RemoveObserver(this); |
| 114 locking_windows_.clear(); | 115 locking_windows_.clear(); |
| 115 WmShell::Get()->RemoveActivationObserver(this); | 116 Shell::GetInstance()->activation_client()->RemoveObserver(this); |
| 116 SetRotationLocked(false); | 117 SetRotationLocked(false); |
| 117 if (user_rotation_ != current_rotation_) | 118 if (user_rotation_ != current_rotation_) |
| 118 SetDisplayRotation(user_rotation_, display::Display::ROTATION_SOURCE_USER); | 119 SetDisplayRotation(user_rotation_, display::Display::ROTATION_SOURCE_USER); |
| 119 } | 120 } |
| 120 | 121 |
| 121 bool ScreenOrientationController::ScreenOrientationProviderSupported() const { | 122 bool ScreenOrientationController::ScreenOrientationProviderSupported() const { |
| 122 return WmShell::Get() | 123 return WmShell::Get() |
| 123 ->maximize_mode_controller() | 124 ->maximize_mode_controller() |
| 124 ->IsMaximizeModeWindowManagerEnabled() && | 125 ->IsMaximizeModeWindowManagerEnabled() && |
| 125 !base::CommandLine::ForCurrentProcess()->HasSwitch( | 126 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 148 if (!display::Display::HasInternalDisplay()) | 149 if (!display::Display::HasInternalDisplay()) |
| 149 return; | 150 return; |
| 150 current_rotation_ = rotation; | 151 current_rotation_ = rotation; |
| 151 base::AutoReset<bool> auto_ignore_display_configuration_updates( | 152 base::AutoReset<bool> auto_ignore_display_configuration_updates( |
| 152 &ignore_display_configuration_updates_, true); | 153 &ignore_display_configuration_updates_, true); |
| 153 | 154 |
| 154 Shell::GetInstance()->display_configuration_controller()->SetDisplayRotation( | 155 Shell::GetInstance()->display_configuration_controller()->SetDisplayRotation( |
| 155 display::Display::InternalDisplayId(), rotation, source); | 156 display::Display::InternalDisplayId(), rotation, source); |
| 156 } | 157 } |
| 157 | 158 |
| 158 void ScreenOrientationController::OnWindowActivated(WmWindow* gained_active, | 159 void ScreenOrientationController::OnWindowActivated(ActivationReason reason, |
| 159 WmWindow* lost_active) { | 160 aura::Window* gained_active, |
| 161 aura::Window* lost_active) { |
| 160 ApplyLockForActiveWindow(); | 162 ApplyLockForActiveWindow(); |
| 161 } | 163 } |
| 162 | 164 |
| 163 void ScreenOrientationController::OnWindowDestroying(aura::Window* window) { | 165 void ScreenOrientationController::OnWindowDestroying(aura::Window* window) { |
| 164 UnlockOrientationForWindow(WmWindow::Get(window)); | 166 UnlockOrientationForWindow(WmWindow::Get(window)); |
| 165 } | 167 } |
| 166 | 168 |
| 167 // Currently contents::WebContents will only be able to lock rotation while | 169 // Currently contents::WebContents will only be able to lock rotation while |
| 168 // fullscreen. In this state a user cannot click on the tab strip to change. If | 170 // fullscreen. In this state a user cannot click on the tab strip to change. If |
| 169 // this becomes supported for non-fullscreen tabs then the following interferes | 171 // this becomes supported for non-fullscreen tabs then the following interferes |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 } | 421 } |
| 420 | 422 |
| 421 bool ScreenOrientationController::CanRotateInLockedState() { | 423 bool ScreenOrientationController::CanRotateInLockedState() { |
| 422 return rotation_locked_orientation_ == | 424 return rotation_locked_orientation_ == |
| 423 blink::WebScreenOrientationLockLandscape || | 425 blink::WebScreenOrientationLockLandscape || |
| 424 rotation_locked_orientation_ == | 426 rotation_locked_orientation_ == |
| 425 blink::WebScreenOrientationLockPortrait; | 427 blink::WebScreenOrientationLockPortrait; |
| 426 } | 428 } |
| 427 | 429 |
| 428 } // namespace ash | 430 } // namespace ash |
| OLD | NEW |