| 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 #ifndef ASH_DISPLAY_SCREEN_ORIENTATION_CONTROLLER_CHROMEOS_H_ | 5 #ifndef ASH_DISPLAY_SCREEN_ORIENTATION_CONTROLLER_CHROMEOS_H_ |
| 6 #define ASH_DISPLAY_SCREEN_ORIENTATION_CONTROLLER_CHROMEOS_H_ | 6 #define ASH_DISPLAY_SCREEN_ORIENTATION_CONTROLLER_CHROMEOS_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <unordered_map> |
| 9 | 9 |
| 10 #include "ash/ash_export.h" | 10 #include "ash/ash_export.h" |
| 11 #include "ash/common/shell_observer.h" | 11 #include "ash/common/shell_observer.h" |
| 12 #include "ash/common/wm_display_observer.h" | 12 #include "ash/common/wm_display_observer.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/observer_list.h" | 14 #include "base/observer_list.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 "third_party/WebKit/public/platform/modules/screen_orientation/WebScree
nOrientationLockType.h" | 17 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree
nOrientationLockType.h" |
| 18 #include "ui/aura/window_observer.h" | 18 #include "ui/aura/window_observer.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 36 // rotation lock. | 36 // rotation lock. |
| 37 class Observer { | 37 class Observer { |
| 38 public: | 38 public: |
| 39 // Invoked when rotation is locked or unlocked by a user. | 39 // Invoked when rotation is locked or unlocked by a user. |
| 40 virtual void OnUserRotationLockChanged() {} | 40 virtual void OnUserRotationLockChanged() {} |
| 41 | 41 |
| 42 protected: | 42 protected: |
| 43 virtual ~Observer() {} | 43 virtual ~Observer() {} |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 // Controls the behavior after lock is applied to the window (when |
| 47 // the window becomes active window). |DisableSensor| disables |
| 48 // the sensor based rotation and locks to the specific orientation. |
| 49 // For example, PORTRAIT may rotate to PORTRAIT_PRIMARY or |
| 50 // PORTRAIT_SECONDARY, and will allow rotate between these two. |
| 51 // |DisableSensor| will lock the orientation to the one of them |
| 52 // after locked to disalow the sensor basd rotation. |
| 53 enum class LockCompletionBehavior { |
| 54 None, |
| 55 DisableSensor, |
| 56 }; |
| 57 |
| 46 ScreenOrientationController(); | 58 ScreenOrientationController(); |
| 47 ~ScreenOrientationController() override; | 59 ~ScreenOrientationController() override; |
| 48 | 60 |
| 49 // Add/Remove observers. | 61 // Add/Remove observers. |
| 50 void AddObserver(Observer* observer); | 62 void AddObserver(Observer* observer); |
| 51 void RemoveObserver(Observer* observer); | 63 void RemoveObserver(Observer* observer); |
| 52 | 64 |
| 53 // Allows/unallows a window to lock the screen orientation. | 65 // Allows/unallows a window to lock the screen orientation. |
| 54 void LockOrientationForWindow( | 66 void LockOrientationForWindow( |
| 55 WmWindow* requesting_window, | 67 WmWindow* requesting_window, |
| 56 blink::WebScreenOrientationLockType lock_orientation); | 68 blink::WebScreenOrientationLockType lock_orientation, |
| 69 LockCompletionBehavior lock_completion_behavior); |
| 57 void UnlockOrientationForWindow(WmWindow* window); | 70 void UnlockOrientationForWindow(WmWindow* window); |
| 58 | 71 |
| 59 // Unlock all and set the rotation back to the user specified rotation. | 72 // Unlock all and set the rotation back to the user specified rotation. |
| 60 void UnlockAll(); | 73 void UnlockAll(); |
| 61 | 74 |
| 62 bool ScreenOrientationProviderSupported() const; | 75 bool ScreenOrientationProviderSupported() const; |
| 63 | 76 |
| 64 bool ignore_display_configuration_updates() const { | 77 bool ignore_display_configuration_updates() const { |
| 65 return ignore_display_configuration_updates_; | 78 return ignore_display_configuration_updates_; |
| 66 } | 79 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 // WmDisplayObserver: | 111 // WmDisplayObserver: |
| 99 void OnDisplayConfigurationChanged() override; | 112 void OnDisplayConfigurationChanged() override; |
| 100 | 113 |
| 101 // ShellObserver: | 114 // ShellObserver: |
| 102 void OnMaximizeModeStarted() override; | 115 void OnMaximizeModeStarted() override; |
| 103 void OnMaximizeModeEnded() override; | 116 void OnMaximizeModeEnded() override; |
| 104 | 117 |
| 105 private: | 118 private: |
| 106 friend class test::ScreenOrientationControllerTestApi; | 119 friend class test::ScreenOrientationControllerTestApi; |
| 107 | 120 |
| 121 struct LockInfo { |
| 122 LockInfo() {} |
| 123 LockInfo(blink::WebScreenOrientationLockType orientation, |
| 124 LockCompletionBehavior lock_completion_behavior) |
| 125 : orientation(orientation), |
| 126 lock_completion_behavior(lock_completion_behavior) {} |
| 127 |
| 128 blink::WebScreenOrientationLockType orientation = |
| 129 blink::WebScreenOrientationLockAny; |
| 130 LockCompletionBehavior lock_completion_behavior = |
| 131 LockCompletionBehavior::None; |
| 132 }; |
| 133 |
| 108 // Sets the display rotation for the given |source|. The new |rotation| will | 134 // Sets the display rotation for the given |source|. The new |rotation| will |
| 109 // also become active. Display changed notifications are surpressed for this | 135 // also become active. Display changed notifications are surpressed for this |
| 110 // change. | 136 // change. |
| 111 void SetDisplayRotation(display::Display::Rotation rotation, | 137 void SetDisplayRotation(display::Display::Rotation rotation, |
| 112 display::Display::RotationSource source); | 138 display::Display::RotationSource source); |
| 113 | 139 |
| 114 void SetRotationLockedInternal(bool rotation_locked); | 140 void SetRotationLockedInternal(bool rotation_locked); |
| 115 | 141 |
| 116 // A helper method that set locked to the given |orientation| and save it. | 142 // A helper method that set locked to the given |orientation| and save it. |
| 117 void SetLockToOrientation(blink::WebScreenOrientationLockType orientation); | 143 void SetLockToOrientation(blink::WebScreenOrientationLockType orientation); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 // window, and applies it. If there is none, rotation lock will be removed. | 182 // window, and applies it. If there is none, rotation lock will be removed. |
| 157 void ApplyLockForActiveWindow(); | 183 void ApplyLockForActiveWindow(); |
| 158 | 184 |
| 159 // Both |blink::WebScreenOrientationLockLandscape| and | 185 // Both |blink::WebScreenOrientationLockLandscape| and |
| 160 // |blink::WebScreenOrientationLockPortrait| allow for rotation between the | 186 // |blink::WebScreenOrientationLockPortrait| allow for rotation between the |
| 161 // two angles of the same screen orientation | 187 // two angles of the same screen orientation |
| 162 // (http://www.w3.org/TR/screen-orientation/). Returns true if |rotation| is | 188 // (http://www.w3.org/TR/screen-orientation/). Returns true if |rotation| is |
| 163 // supported for the current |rotation_locked_orientation_|. | 189 // supported for the current |rotation_locked_orientation_|. |
| 164 bool IsRotationAllowedInLockedState(display::Display::Rotation rotation); | 190 bool IsRotationAllowedInLockedState(display::Display::Rotation rotation); |
| 165 | 191 |
| 192 blink::WebScreenOrientationLockType GetCurrentOrientationForTest() const; |
| 193 |
| 166 // Certain orientation locks allow for rotation between the two angles of the | 194 // Certain orientation locks allow for rotation between the two angles of the |
| 167 // same screen orientation. Returns true if |rotation_locked_orientation_| | 195 // same screen orientation. Returns true if |rotation_locked_orientation_| |
| 168 // allows rotation. | 196 // allows rotation. |
| 169 bool CanRotateInLockedState(); | 197 bool CanRotateInLockedState(); |
| 170 | 198 |
| 171 // The orientation of the display when at a rotation of 0. | 199 // The orientation of the display when at a rotation of 0. |
| 172 blink::WebScreenOrientationLockType natural_orientation_; | 200 blink::WebScreenOrientationLockType natural_orientation_; |
| 173 | 201 |
| 174 // True when changes being applied cause OnDisplayConfigurationChanged() to be | 202 // True when changes being applied cause OnDisplayConfigurationChanged() to be |
| 175 // called, and for which these changes should be ignored. | 203 // called, and for which these changes should be ignored. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 191 | 219 |
| 192 // The current rotation set by ScreenOrientationController for the internal | 220 // The current rotation set by ScreenOrientationController for the internal |
| 193 // display. | 221 // display. |
| 194 display::Display::Rotation current_rotation_; | 222 display::Display::Rotation current_rotation_; |
| 195 | 223 |
| 196 // Rotation Lock observers. | 224 // Rotation Lock observers. |
| 197 base::ObserverList<Observer> observers_; | 225 base::ObserverList<Observer> observers_; |
| 198 | 226 |
| 199 // Tracks all windows that have requested a lock, as well as the requested | 227 // Tracks all windows that have requested a lock, as well as the requested |
| 200 // orientation. | 228 // orientation. |
| 201 std::map<WmWindow*, blink::WebScreenOrientationLockType> locking_windows_; | 229 std::unordered_map<WmWindow*, LockInfo> lock_info_map_; |
| 202 | 230 |
| 203 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationController); | 231 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationController); |
| 204 }; | 232 }; |
| 205 | 233 |
| 206 } // namespace ash | 234 } // namespace ash |
| 207 | 235 |
| 208 #endif // ASH_DISPLAY_SCREEN_ORIENTATION_CONTROLLER_CHROMEOS_H_ | 236 #endif // ASH_DISPLAY_SCREEN_ORIENTATION_CONTROLLER_CHROMEOS_H_ |
| OLD | NEW |