| 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_activation_observer.h" | 12 #include "ash/common/wm_activation_observer.h" |
| 13 #include "ash/common/wm_display_observer.h" | 13 #include "ash/common/wm_display_observer.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
| 16 #include "chromeos/accelerometer/accelerometer_reader.h" | 16 #include "chromeos/accelerometer/accelerometer_reader.h" |
| 17 #include "chromeos/accelerometer/accelerometer_types.h" | 17 #include "chromeos/accelerometer/accelerometer_types.h" |
| 18 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree
nOrientationLockType.h" | 18 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree
nOrientationLockType.h" |
| 19 #include "ui/aura/window_observer.h" | 19 #include "ui/aura/window_observer.h" |
| 20 #include "ui/display/display.h" | 20 #include "ui/display/display.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 WmActivationObserver, | 29 : public WmActivationObserver, |
| 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(); |
| 78 | 81 |
| 79 // WmActivationObserver: | 82 // WmActivationObserver: |
| 80 void OnWindowActivated(WmWindow* gained_active, | 83 void OnWindowActivated(WmWindow* gained_active, |
| 81 WmWindow* lost_active) override; | 84 WmWindow* lost_active) override; |
| 82 | 85 |
| 83 // aura::WindowObserver: | 86 // aura::WindowObserver: |
| 84 void OnWindowDestroying(aura::Window* window) override; | 87 void OnWindowDestroying(aura::Window* window) override; |
| 85 void OnWindowVisibilityChanged(aura::Window* window, bool visible) override; | 88 void OnWindowVisibilityChanged(aura::Window* window, bool visible) override; |
| 86 | 89 |
| 87 // chromeos::AccelerometerReader::Observer: | 90 // chromeos::AccelerometerReader::Observer: |
| 88 void OnAccelerometerUpdated( | 91 void OnAccelerometerUpdated( |
| 89 scoped_refptr<const chromeos::AccelerometerUpdate> update) override; | 92 scoped_refptr<const chromeos::AccelerometerUpdate> update) override; |
| 90 | 93 |
| 91 // WmDisplayObserver: | 94 // WmDisplayObserver: |
| 92 void OnDisplayConfigurationChanged() override; | 95 void OnDisplayConfigurationChanged() override; |
| 93 | 96 |
| 94 // ShellObserver: | 97 // ShellObserver: |
| 95 void OnMaximizeModeStarted() override; | 98 void OnMaximizeModeStarted() override; |
| 96 void OnMaximizeModeEnded() override; | 99 void OnMaximizeModeEnded() override; |
| 97 | 100 |
| 98 private: | 101 private: |
| 102 friend class test::ScreenOrientationControllerTestApi; |
| 103 |
| 104 // Sets the display rotation for the given |source|. The new |rotation| will |
| 105 // also become active. Display changed notifications are surpressed for this |
| 106 // change. |
| 107 void SetDisplayRotation(display::Display::Rotation rotation, |
| 108 display::Display::RotationSource source); |
| 109 |
| 110 void SetRotationLockedInternal(bool rotation_locked); |
| 111 |
| 99 // Sets the display rotation to |rotation|. Future accelerometer updates | 112 // Sets the display rotation to |rotation|. Future accelerometer updates |
| 100 // should not be used to change the rotation. SetRotationLocked(false) removes | 113 // should not be used to change the rotation. SetRotationLocked(false) removes |
| 101 // the rotation lock. | 114 // the rotation lock. |
| 102 void LockRotation(display::Display::Rotation rotation, | 115 void LockRotation(display::Display::Rotation rotation, |
| 103 display::Display::RotationSource source); | 116 display::Display::RotationSource source); |
| 104 | 117 |
| 105 // Sets the display rotation based on |lock_orientation|. Future accelerometer | 118 // Sets the display rotation based on |lock_orientation|. Future accelerometer |
| 106 // updates should not be used to change the rotation. SetRotationLocked(false) | 119 // updates should not be used to change the rotation. SetRotationLocked(false) |
| 107 // removes the rotation lock. | 120 // removes the rotation lock. |
| 108 void LockRotationToOrientation( | 121 void LockRotationToOrientation( |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 // When true then accelerometer updates should not rotate the display. | 171 // When true then accelerometer updates should not rotate the display. |
| 159 bool rotation_locked_; | 172 bool rotation_locked_; |
| 160 | 173 |
| 161 // The orientation to which the current |rotation_locked_| was applied. | 174 // The orientation to which the current |rotation_locked_| was applied. |
| 162 blink::WebScreenOrientationLockType rotation_locked_orientation_; | 175 blink::WebScreenOrientationLockType rotation_locked_orientation_; |
| 163 | 176 |
| 164 // The rotation of the display set by the user. This rotation will be | 177 // The rotation of the display set by the user. This rotation will be |
| 165 // restored upon exiting maximize mode. | 178 // restored upon exiting maximize mode. |
| 166 display::Display::Rotation user_rotation_; | 179 display::Display::Rotation user_rotation_; |
| 167 | 180 |
| 181 // The orientation of the device locked by the user. |
| 182 blink::WebScreenOrientationLockType user_locked_orientation_ = |
| 183 blink::WebScreenOrientationLockAny; |
| 184 |
| 168 // The current rotation set by ScreenOrientationController for the internal | 185 // The current rotation set by ScreenOrientationController for the internal |
| 169 // display. | 186 // display. |
| 170 display::Display::Rotation current_rotation_; | 187 display::Display::Rotation current_rotation_; |
| 171 | 188 |
| 172 // Rotation Lock observers. | 189 // Rotation Lock observers. |
| 173 base::ObserverList<Observer> observers_; | 190 base::ObserverList<Observer> observers_; |
| 174 | 191 |
| 175 // Tracks all windows that have requested a lock, as well as the requested | 192 // Tracks all windows that have requested a lock, as well as the requested |
| 176 // orientation. | 193 // orientation. |
| 177 std::map<WmWindow*, blink::WebScreenOrientationLockType> locking_windows_; | 194 std::map<WmWindow*, blink::WebScreenOrientationLockType> locking_windows_; |
| 178 | 195 |
| 179 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationController); | 196 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationController); |
| 180 }; | 197 }; |
| 181 | 198 |
| 182 } // namespace ash | 199 } // namespace ash |
| 183 | 200 |
| 184 #endif // ASH_DISPLAY_SCREEN_ORIENTATION_CONTROLLER_CHROMEOS_H_ | 201 #endif // ASH_DISPLAY_SCREEN_ORIENTATION_CONTROLLER_CHROMEOS_H_ |
| OLD | NEW |