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_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_ | 5 #ifndef ASH_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_ |
| 6 #define ASH_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_ | 6 #define ASH_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include "ash/accelerometer/accelerometer_observer.h" | 8 #include "ash/accelerometer/accelerometer_observer.h" |
| 9 #include "ash/ash_export.h" | 9 #include "ash/ash_export.h" |
| 10 #include "ash/display/display_controller.h" | |
| 10 #include "ash/display/display_manager.h" | 11 #include "ash/display/display_manager.h" |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/observer_list.h" | |
| 13 #include "ui/gfx/display.h" | 15 #include "ui/gfx/display.h" |
| 14 | 16 |
| 15 namespace ui { | 17 namespace ui { |
| 16 class EventHandler; | 18 class EventHandler; |
| 17 } | 19 } |
| 18 | 20 |
| 19 namespace ash { | 21 namespace ash { |
| 20 | 22 |
| 21 class MaximizeModeControllerTest; | 23 class MaximizeModeControllerTest; |
| 22 class MaximizeModeEventBlocker; | 24 class MaximizeModeEventBlocker; |
| 23 | 25 |
| 24 // MaximizeModeController listens to accelerometer events and automatically | 26 // MaximizeModeController listens to accelerometer events and automatically |
| 25 // enters and exits maximize mode when the lid is opened beyond the triggering | 27 // enters and exits maximize mode when the lid is opened beyond the triggering |
| 26 // angle and rotates the display to match the device when in maximize mode. | 28 // angle and rotates the display to match the device when in maximize mode. |
| 27 class ASH_EXPORT MaximizeModeController : public AccelerometerObserver { | 29 class ASH_EXPORT MaximizeModeController : public AccelerometerObserver, |
| 30 public DisplayController::Observer { | |
| 28 public: | 31 public: |
| 32 // Observer that reports changes to the state of MaximizeModeController's | |
| 33 // rotation lock. | |
| 34 class ASH_EXPORT Observer { | |
|
flackr
2014/05/28 14:48:04
I don't think ASH_EXPORT is necessary on a nested
jonross
2014/05/28 19:13:33
Done.
| |
| 35 public: | |
| 36 // Invoked whenever |rotation_locked_| is changed. | |
| 37 virtual void OnRotationLockChanged() {} | |
|
flackr
2014/05/28 14:48:04
You could pass the new rotation lock state.
jonross
2014/05/28 19:13:33
Done.
| |
| 38 | |
| 39 protected: | |
| 40 virtual ~Observer() {} | |
| 41 }; | |
| 42 | |
| 29 MaximizeModeController(); | 43 MaximizeModeController(); |
| 30 virtual ~MaximizeModeController(); | 44 virtual ~MaximizeModeController(); |
| 31 | 45 |
| 32 bool in_set_screen_rotation() const { | 46 bool in_set_screen_rotation() const { |
| 33 return in_set_screen_rotation_; | 47 return in_set_screen_rotation_; |
| 34 } | 48 } |
| 35 | 49 |
| 36 // True if |rotation_lock_| has been set, and OnAccelerometerUpdated will not | 50 // True if |rotation_lock_| has been set, and OnAccelerometerUpdated will not |
| 37 // change the display rotation. | 51 // change the display rotation. |
| 38 bool rotation_locked() { | 52 bool rotation_locked() { |
| 39 return rotation_locked_; | 53 return rotation_locked_; |
| 40 } | 54 } |
| 41 | 55 |
| 42 // If |rotation_locked| future calls to OnAccelerometerUpdated will not | 56 // If |rotation_locked| future calls to OnAccelerometerUpdated will not |
| 43 // change the display rotation. | 57 // change the display rotation. |
| 44 void set_rotation_locked(bool rotation_locked) { | 58 void SetRotationLocked(bool rotation_locked); |
| 45 rotation_locked_ = rotation_locked; | 59 |
| 46 } | 60 // Add/Remove observers. |
| 61 void AddObserver(Observer* observer); | |
| 62 void RemoveObserver(Observer* observer); | |
| 47 | 63 |
| 48 // True if it is possible to enter maximize mode in the current | 64 // True if it is possible to enter maximize mode in the current |
| 49 // configuration. If this returns false, it should never be the case that | 65 // configuration. If this returns false, it should never be the case that |
| 50 // maximize mode becomes enabled. | 66 // maximize mode becomes enabled. |
| 51 bool CanEnterMaximizeMode(); | 67 bool CanEnterMaximizeMode(); |
| 52 | 68 |
| 53 // AccelerometerObserver: | 69 // AccelerometerObserver: |
| 54 virtual void OnAccelerometerUpdated(const gfx::Vector3dF& base, | 70 virtual void OnAccelerometerUpdated(const gfx::Vector3dF& base, |
| 55 const gfx::Vector3dF& lid) OVERRIDE; | 71 const gfx::Vector3dF& lid) OVERRIDE; |
| 56 | 72 |
| 73 // DisplayController::Observer: | |
| 74 virtual void OnDisplayConfigurationChanged() OVERRIDE; | |
| 75 | |
| 57 private: | 76 private: |
| 58 friend class MaximizeModeControllerTest; | 77 friend class MaximizeModeControllerTest; |
| 59 | 78 |
| 60 // Detect hinge rotation from |base| and |lid| accelerometers and | 79 // Detect hinge rotation from |base| and |lid| accelerometers and |
| 61 // automatically start / stop maximize mode. | 80 // automatically start / stop maximize mode. |
| 62 void HandleHingeRotation(const gfx::Vector3dF& base, | 81 void HandleHingeRotation(const gfx::Vector3dF& base, |
| 63 const gfx::Vector3dF& lid); | 82 const gfx::Vector3dF& lid); |
| 64 | 83 |
| 65 // Detect screen rotation from |lid| accelerometer and automatically rotate | 84 // Detect screen rotation from |lid| accelerometer and automatically rotate |
| 66 // screen. | 85 // screen. |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 91 // Whether we have ever seen accelerometer data. | 110 // Whether we have ever seen accelerometer data. |
| 92 bool have_seen_accelerometer_data_; | 111 bool have_seen_accelerometer_data_; |
| 93 | 112 |
| 94 // True when the screen's orientation is being changed. | 113 // True when the screen's orientation is being changed. |
| 95 bool in_set_screen_rotation_; | 114 bool in_set_screen_rotation_; |
| 96 | 115 |
| 97 // The rotation of the display set by the user. This rotation will be | 116 // The rotation of the display set by the user. This rotation will be |
| 98 // restored upon exiting maximize mode. | 117 // restored upon exiting maximize mode. |
| 99 gfx::Display::Rotation user_rotation_; | 118 gfx::Display::Rotation user_rotation_; |
| 100 | 119 |
| 120 // The current rotation set by MaximizdeModeController for the internal | |
|
flackr
2014/05/28 14:48:04
s/MaxizdeModeController/MaximizeModeController
jonross
2014/05/28 19:13:33
Done.
| |
| 121 // display. Compared in OnDisplayConfigurationChanged to determine user | |
| 122 // display setting changes. | |
| 123 gfx::Display::Rotation current_rotation_; | |
| 124 | |
| 125 // Rotation Lock observers. | |
| 126 ObserverList<Observer> observers_; | |
| 127 | |
| 101 DISALLOW_COPY_AND_ASSIGN(MaximizeModeController); | 128 DISALLOW_COPY_AND_ASSIGN(MaximizeModeController); |
| 102 }; | 129 }; |
| 103 | 130 |
| 104 } // namespace ash | 131 } // namespace ash |
| 105 | 132 |
| 106 #endif // ASH_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_ | 133 #endif // ASH_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_ |
| OLD | NEW |