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 class MaximizeModeWindowManager; | 25 class MaximizeModeWindowManager; |
24 class MaximizeModeWindowManagerTest; | 26 class MaximizeModeWindowManagerTest; |
25 | 27 |
26 // MaximizeModeController listens to accelerometer events and automatically | 28 // MaximizeModeController listens to accelerometer events and automatically |
27 // enters and exits maximize mode when the lid is opened beyond the triggering | 29 // enters and exits maximize mode when the lid is opened beyond the triggering |
28 // angle and rotates the display to match the device when in maximize mode. | 30 // angle and rotates the display to match the device when in maximize mode. |
29 class ASH_EXPORT MaximizeModeController : public AccelerometerObserver { | 31 class ASH_EXPORT MaximizeModeController : public AccelerometerObserver, |
| 32 public DisplayController::Observer { |
30 public: | 33 public: |
| 34 // Observer that reports changes to the state of MaximizeModeController's |
| 35 // rotation lock. |
| 36 class Observer { |
| 37 public: |
| 38 // Invoked whenever |rotation_locked_| is changed. |
| 39 virtual void OnRotationLockChanged(bool rotation_locked) {} |
| 40 |
| 41 protected: |
| 42 virtual ~Observer() {} |
| 43 }; |
| 44 |
31 MaximizeModeController(); | 45 MaximizeModeController(); |
32 virtual ~MaximizeModeController(); | 46 virtual ~MaximizeModeController(); |
33 | 47 |
34 bool in_set_screen_rotation() const { | 48 bool in_set_screen_rotation() const { |
35 return in_set_screen_rotation_; | 49 return in_set_screen_rotation_; |
36 } | 50 } |
37 | 51 |
38 // True if |rotation_lock_| has been set, and OnAccelerometerUpdated will not | 52 // True if |rotation_lock_| has been set, and OnAccelerometerUpdated will not |
39 // change the display rotation. | 53 // change the display rotation. |
40 bool rotation_locked() { | 54 bool rotation_locked() { |
41 return rotation_locked_; | 55 return rotation_locked_; |
42 } | 56 } |
43 | 57 |
44 // If |rotation_locked| future calls to OnAccelerometerUpdated will not | 58 // If |rotation_locked| future calls to OnAccelerometerUpdated will not |
45 // change the display rotation. | 59 // change the display rotation. |
46 void set_rotation_locked(bool rotation_locked) { | 60 void SetRotationLocked(bool rotation_locked); |
47 rotation_locked_ = rotation_locked; | 61 |
48 } | 62 // Add/Remove observers. |
| 63 void AddObserver(Observer* observer); |
| 64 void RemoveObserver(Observer* observer); |
49 | 65 |
50 // True if it is possible to enter maximize mode in the current | 66 // True if it is possible to enter maximize mode in the current |
51 // configuration. If this returns false, it should never be the case that | 67 // configuration. If this returns false, it should never be the case that |
52 // maximize mode becomes enabled. | 68 // maximize mode becomes enabled. |
53 bool CanEnterMaximizeMode(); | 69 bool CanEnterMaximizeMode(); |
54 | 70 |
55 // TODO(jonross): Merge this with EnterMaximizeMode. Currently these are | 71 // TODO(jonross): Merge this with EnterMaximizeMode. Currently these are |
56 // separate for several reasons: there is no internal display when running | 72 // separate for several reasons: there is no internal display when running |
57 // unittests; the event blocker prevents keyboard input when running ChromeOS | 73 // unittests; the event blocker prevents keyboard input when running ChromeOS |
58 // on linux. http://crbug.com/362881 | 74 // on linux. http://crbug.com/362881 |
59 // Turn the always maximize mode window manager on or off. | 75 // Turn the always maximize mode window manager on or off. |
60 void EnableMaximizeModeWindowManager(bool enable); | 76 void EnableMaximizeModeWindowManager(bool enable); |
61 | 77 |
62 // Test if the MaximizeModeWindowManager is enabled or not. | 78 // Test if the MaximizeModeWindowManager is enabled or not. |
63 bool IsMaximizeModeWindowManagerEnabled() const; | 79 bool IsMaximizeModeWindowManagerEnabled() const; |
64 | 80 |
65 // TODO(jonross): move this into the destructor. Currently separated as | 81 // TODO(jonross): move this into the destructor. Currently separated as |
66 // ShellOberver notifies of maximize mode ending, and the observers end up | 82 // ShellOberver notifies of maximize mode ending, and the observers end up |
67 // attempting to access MaximizeModeController via the Shell. If done in | 83 // attempting to access MaximizeModeController via the Shell. If done in |
68 // destructor the controller is null, and the observers segfault. | 84 // destructor the controller is null, and the observers segfault. |
69 // Shuts down down the MaximizeModeWindowManager and notifies all observers. | 85 // Shuts down down the MaximizeModeWindowManager and notifies all observers. |
70 void Shutdown(); | 86 void Shutdown(); |
71 | 87 |
72 // AccelerometerObserver: | 88 // AccelerometerObserver: |
73 virtual void OnAccelerometerUpdated(const gfx::Vector3dF& base, | 89 virtual void OnAccelerometerUpdated(const gfx::Vector3dF& base, |
74 const gfx::Vector3dF& lid) OVERRIDE; | 90 const gfx::Vector3dF& lid) OVERRIDE; |
75 | 91 |
| 92 // DisplayController::Observer: |
| 93 virtual void OnDisplayConfigurationChanged() OVERRIDE; |
| 94 |
76 private: | 95 private: |
77 friend class MaximizeModeControllerTest; | 96 friend class MaximizeModeControllerTest; |
78 friend class MaximizeModeWindowManagerTest; | 97 friend class MaximizeModeWindowManagerTest; |
79 | 98 |
80 // Detect hinge rotation from |base| and |lid| accelerometers and | 99 // Detect hinge rotation from |base| and |lid| accelerometers and |
81 // automatically start / stop maximize mode. | 100 // automatically start / stop maximize mode. |
82 void HandleHingeRotation(const gfx::Vector3dF& base, | 101 void HandleHingeRotation(const gfx::Vector3dF& base, |
83 const gfx::Vector3dF& lid); | 102 const gfx::Vector3dF& lid); |
84 | 103 |
85 // Detect screen rotation from |lid| accelerometer and automatically rotate | 104 // Detect screen rotation from |lid| accelerometer and automatically rotate |
(...skipping 28 matching lines...) Expand all Loading... |
114 // Whether we have ever seen accelerometer data. | 133 // Whether we have ever seen accelerometer data. |
115 bool have_seen_accelerometer_data_; | 134 bool have_seen_accelerometer_data_; |
116 | 135 |
117 // True when the screen's orientation is being changed. | 136 // True when the screen's orientation is being changed. |
118 bool in_set_screen_rotation_; | 137 bool in_set_screen_rotation_; |
119 | 138 |
120 // The rotation of the display set by the user. This rotation will be | 139 // The rotation of the display set by the user. This rotation will be |
121 // restored upon exiting maximize mode. | 140 // restored upon exiting maximize mode. |
122 gfx::Display::Rotation user_rotation_; | 141 gfx::Display::Rotation user_rotation_; |
123 | 142 |
| 143 // The current rotation set by MaximizeModeController for the internal |
| 144 // display. Compared in OnDisplayConfigurationChanged to determine user |
| 145 // display setting changes. |
| 146 gfx::Display::Rotation current_rotation_; |
| 147 |
| 148 // Rotation Lock observers. |
| 149 ObserverList<Observer> observers_; |
| 150 |
124 DISALLOW_COPY_AND_ASSIGN(MaximizeModeController); | 151 DISALLOW_COPY_AND_ASSIGN(MaximizeModeController); |
125 }; | 152 }; |
126 | 153 |
127 } // namespace ash | 154 } // namespace ash |
128 | 155 |
129 #endif // ASH_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_ | 156 #endif // ASH_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_ |
OLD | NEW |