Chromium Code Reviews| 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 <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" |
| 19 #include "ui/display/display.h" | 19 #include "ui/display/display.h" |
| 20 #include "ui/wm/public/activation_change_observer.h" | 20 #include "ui/wm/public/activation_change_observer.h" |
| 21 | 21 |
| 22 namespace ash { | 22 namespace ash { |
| 23 namespace test { | |
| 24 class ScreenOrientationControllerTestApi; | |
| 25 } | |
| 23 | 26 |
| 24 // Implements ChromeOS specific functionality for ScreenOrientationProvider. | 27 // Implements ChromeOS specific functionality for ScreenOrientationProvider. |
| 25 class ASH_EXPORT ScreenOrientationController | 28 class ASH_EXPORT ScreenOrientationController |
| 26 : public aura::client::ActivationChangeObserver, | 29 : public aura::client::ActivationChangeObserver, |
| 27 public aura::WindowObserver, | 30 public aura::WindowObserver, |
| 28 public chromeos::AccelerometerReader::Observer, | 31 public chromeos::AccelerometerReader::Observer, |
| 29 public WmDisplayObserver, | 32 public WmDisplayObserver, |
| 30 public ShellObserver { | 33 public ShellObserver { |
| 31 public: | 34 public: |
| 32 // Observer that reports changes to the state of ScreenOrientationProvider's | 35 // Observer that reports changes to the state of ScreenOrientationProvider's |
| 33 // rotation lock. | 36 // rotation lock. |
| 34 class Observer { | 37 class Observer { |
| 35 public: | 38 public: |
| 36 // Invoked when rotation is locked or unlocked. | 39 // Invoked when rotation is locked or unlocked by a user. |
| 37 virtual void OnRotationLockChanged(bool rotation_locked) {} | 40 virtual void OnUserRotationLockChanged() {} |
| 38 | 41 |
| 39 protected: | 42 protected: |
| 40 virtual ~Observer() {} | 43 virtual ~Observer() {} |
| 41 }; | 44 }; |
| 42 | 45 |
| 43 ScreenOrientationController(); | 46 ScreenOrientationController(); |
| 44 ~ScreenOrientationController() override; | 47 ~ScreenOrientationController() override; |
| 45 | 48 |
| 46 // Add/Remove observers. | 49 // Add/Remove observers. |
| 47 void AddObserver(Observer* observer); | 50 void AddObserver(Observer* observer); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 59 bool ScreenOrientationProviderSupported() const; | 62 bool ScreenOrientationProviderSupported() const; |
| 60 | 63 |
| 61 bool ignore_display_configuration_updates() const { | 64 bool ignore_display_configuration_updates() const { |
| 62 return ignore_display_configuration_updates_; | 65 return ignore_display_configuration_updates_; |
| 63 } | 66 } |
| 64 | 67 |
| 65 // True if |rotation_lock_| has been set and accelerometer updates should not | 68 // True if |rotation_lock_| has been set and accelerometer updates should not |
| 66 // rotate the display. | 69 // rotate the display. |
| 67 bool rotation_locked() const { return rotation_locked_; } | 70 bool rotation_locked() const { return rotation_locked_; } |
| 68 | 71 |
| 69 // If |rotation_locked| future accelerometer updates should not change the | 72 bool user_rotation_locked() const { |
| 70 // display rotation. | 73 return user_locked_orientation_ != blink::WebScreenOrientationLockAny; |
| 71 void SetRotationLocked(bool rotation_locked); | 74 } |
| 72 | 75 |
| 73 // Sets the display rotation for the given |source|. The new |rotation| will | 76 // Trun on/off the user rotation lock. When turned on, it will lock |
| 74 // also become active. Display changed notifications are surpressed for this | 77 // the orientation to the current orientation. |
| 75 // change. | 78 // |user_rotation_locked()| method returns the current state of the |
| 76 void SetDisplayRotation(display::Display::Rotation rotation, | 79 // user rotation lock. |
| 77 display::Display::RotationSource source); | 80 void ToggleUserRotationLock(); |
|
oshima
2017/03/21 07:11:53
I'm using toggle instead of SetUserRotationLock to
jonross
2017/03/21 14:56:43
Using Toggle does make the unit testing harder to
oshima
2017/03/21 15:10:57
No it will never happen as UI is toggle. Passing b
jonross
2017/03/22 23:51:56
Well true->true might also end up being a confusin
| |
| 78 | 81 |
| 79 // aura::client::ActivationChangeObserver: | 82 // aura::client::ActivationChangeObserver: |
| 80 void OnWindowActivated(ActivationReason reason, | 83 void OnWindowActivated(ActivationReason reason, |
| 81 aura::Window* gained_active, | 84 aura::Window* gained_active, |
| 82 aura::Window* lost_active) override; | 85 aura::Window* lost_active) override; |
| 83 | 86 |
| 84 // aura::WindowObserver: | 87 // aura::WindowObserver: |
| 85 void OnWindowDestroying(aura::Window* window) override; | 88 void OnWindowDestroying(aura::Window* window) override; |
| 86 void OnWindowVisibilityChanged(aura::Window* window, bool visible) override; | 89 void OnWindowVisibilityChanged(aura::Window* window, bool visible) override; |
| 87 | 90 |
| 88 // chromeos::AccelerometerReader::Observer: | 91 // chromeos::AccelerometerReader::Observer: |
| 89 void OnAccelerometerUpdated( | 92 void OnAccelerometerUpdated( |
| 90 scoped_refptr<const chromeos::AccelerometerUpdate> update) override; | 93 scoped_refptr<const chromeos::AccelerometerUpdate> update) override; |
| 91 | 94 |
| 92 // WmDisplayObserver: | 95 // WmDisplayObserver: |
| 93 void OnDisplayConfigurationChanged() override; | 96 void OnDisplayConfigurationChanged() override; |
| 94 | 97 |
| 95 // ShellObserver: | 98 // ShellObserver: |
| 96 void OnMaximizeModeStarted() override; | 99 void OnMaximizeModeStarted() override; |
| 97 void OnMaximizeModeEnded() override; | 100 void OnMaximizeModeEnded() override; |
| 98 | 101 |
| 99 private: | 102 private: |
| 103 friend class test::ScreenOrientationControllerTestApi; | |
| 104 | |
| 105 // Sets the display rotation for the given |source|. The new |rotation| will | |
| 106 // also become active. Display changed notifications are surpressed for this | |
| 107 // change. | |
| 108 void SetDisplayRotation(display::Display::Rotation rotation, | |
| 109 display::Display::RotationSource source); | |
| 110 | |
| 111 void SetRotationLockedInternal(bool rotation_locked); | |
| 112 | |
| 100 // Sets the display rotation to |rotation|. Future accelerometer updates | 113 // Sets the display rotation to |rotation|. Future accelerometer updates |
| 101 // should not be used to change the rotation. SetRotationLocked(false) removes | 114 // should not be used to change the rotation. SetRotationLocked(false) removes |
| 102 // the rotation lock. | 115 // the rotation lock. |
| 103 void LockRotation(display::Display::Rotation rotation, | 116 void LockRotation(display::Display::Rotation rotation, |
| 104 display::Display::RotationSource source); | 117 display::Display::RotationSource source); |
| 105 | 118 |
| 106 // Sets the display rotation based on |lock_orientation|. Future accelerometer | 119 // Sets the display rotation based on |lock_orientation|. Future accelerometer |
| 107 // updates should not be used to change the rotation. SetRotationLocked(false) | 120 // updates should not be used to change the rotation. SetRotationLocked(false) |
| 108 // removes the rotation lock. | 121 // removes the rotation lock. |
| 109 void LockRotationToOrientation( | 122 void LockRotationToOrientation( |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 // When true then accelerometer updates should not rotate the display. | 172 // When true then accelerometer updates should not rotate the display. |
| 160 bool rotation_locked_; | 173 bool rotation_locked_; |
| 161 | 174 |
| 162 // The orientation to which the current |rotation_locked_| was applied. | 175 // The orientation to which the current |rotation_locked_| was applied. |
| 163 blink::WebScreenOrientationLockType rotation_locked_orientation_; | 176 blink::WebScreenOrientationLockType rotation_locked_orientation_; |
| 164 | 177 |
| 165 // The rotation of the display set by the user. This rotation will be | 178 // The rotation of the display set by the user. This rotation will be |
| 166 // restored upon exiting maximize mode. | 179 // restored upon exiting maximize mode. |
| 167 display::Display::Rotation user_rotation_; | 180 display::Display::Rotation user_rotation_; |
| 168 | 181 |
| 182 // The orientation of the device locked by the user. | |
| 183 blink::WebScreenOrientationLockType user_locked_orientation_ = | |
| 184 blink::WebScreenOrientationLockAny; | |
| 185 | |
| 169 // The current rotation set by ScreenOrientationController for the internal | 186 // The current rotation set by ScreenOrientationController for the internal |
| 170 // display. | 187 // display. |
| 171 display::Display::Rotation current_rotation_; | 188 display::Display::Rotation current_rotation_; |
| 172 | 189 |
| 173 // Rotation Lock observers. | 190 // Rotation Lock observers. |
| 174 base::ObserverList<Observer> observers_; | 191 base::ObserverList<Observer> observers_; |
| 175 | 192 |
| 176 // Tracks all windows that have requested a lock, as well as the requested | 193 // Tracks all windows that have requested a lock, as well as the requested |
| 177 // orientation. | 194 // orientation. |
| 178 std::map<WmWindow*, blink::WebScreenOrientationLockType> locking_windows_; | 195 std::map<WmWindow*, blink::WebScreenOrientationLockType> locking_windows_; |
| 179 | 196 |
| 180 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationController); | 197 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationController); |
| 181 }; | 198 }; |
| 182 | 199 |
| 183 } // namespace ash | 200 } // namespace ash |
| 184 | 201 |
| 185 #endif // ASH_DISPLAY_SCREEN_ORIENTATION_CONTROLLER_CHROMEOS_H_ | 202 #endif // ASH_DISPLAY_SCREEN_ORIENTATION_CONTROLLER_CHROMEOS_H_ |
| OLD | NEW |