Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(431)

Side by Side Diff: ash/wm/maximize_mode/maximize_mode_controller.h

Issue 759063002: Move Screen Rotation from MaximizeModeController to ScreenOrientationController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_controller.h"
11 #include "ash/display/display_manager.h"
12 #include "ash/shell_observer.h" 11 #include "ash/shell_observer.h"
13 #include "base/macros.h" 12 #include "base/macros.h"
14 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
15 #include "base/observer_list.h"
16 #include "ui/gfx/display.h" 14 #include "ui/gfx/display.h"
17 15
18 #if defined(OS_CHROMEOS) 16 #if defined(OS_CHROMEOS)
17 #include "ash/content/display/screen_orientation_delegate_chromeos.h"
19 #include "chromeos/dbus/power_manager_client.h" 18 #include "chromeos/dbus/power_manager_client.h"
20 #endif // OS_CHROMEOS 19 #endif // OS_CHROMEOS
21 20
22 namespace base { 21 namespace base {
23 class TickClock; 22 class TickClock;
24 } 23 }
25 24
26 namespace ui { 25 namespace ui {
27 class EventHandler; 26 class EventHandler;
28 } 27 }
29 28
30 namespace ash { 29 namespace ash {
31 30
32 class MaximizeModeControllerTest; 31 class MaximizeModeControllerTest;
33 class ScopedDisableInternalMouseAndKeyboard; 32 class ScopedDisableInternalMouseAndKeyboard;
34 class MaximizeModeWindowManager; 33 class MaximizeModeWindowManager;
35 class MaximizeModeWindowManagerTest; 34 class MaximizeModeWindowManagerTest;
36 namespace test { 35 namespace test {
37 class MultiUserWindowManagerChromeOSTest; 36 class MultiUserWindowManagerChromeOSTest;
38 } 37 }
39 38
40 // MaximizeModeController listens to accelerometer events and automatically 39 // MaximizeModeController listens to accelerometer events and automatically
41 // enters and exits maximize mode when the lid is opened beyond the triggering 40 // enters and exits maximize mode when the lid is opened beyond the triggering
42 // angle and rotates the display to match the device when in maximize mode. 41 // angle and rotates the display to match the device when in maximize mode.
43 class ASH_EXPORT MaximizeModeController 42 class ASH_EXPORT MaximizeModeController
44 : public AccelerometerObserver, 43 : public AccelerometerObserver,
45 #if defined(OS_CHROMEOS) 44 #if defined(OS_CHROMEOS)
46 public chromeos::PowerManagerClient::Observer, 45 public chromeos::PowerManagerClient::Observer,
46 public DisplayController::Observer,
47 #endif // OS_CHROMEOS 47 #endif // OS_CHROMEOS
48 public ShellObserver, 48 public ShellObserver {
49 public DisplayController::Observer {
50 public: 49 public:
51 // Observer that reports changes to the state of MaximizeModeController's
52 // rotation lock.
53 class Observer {
54 public:
55 // Invoked whenever |rotation_locked_| is changed.
56 virtual void OnRotationLockChanged(bool rotation_locked) {}
57
58 protected:
59 virtual ~Observer() {}
60 };
61
62 MaximizeModeController(); 50 MaximizeModeController();
63 ~MaximizeModeController() override; 51 ~MaximizeModeController() override;
64 52
65 bool ignore_display_configuration_updates() const {
66 return ignore_display_configuration_updates_;
67 }
68
69 // True if |rotation_lock_| has been set, and OnAccelerometerUpdated will not
70 // change the display rotation.
71 bool rotation_locked() {
72 return rotation_locked_;
73 }
74
75 // If |rotation_locked| future calls to OnAccelerometerUpdated will not
76 // change the display rotation.
77 void SetRotationLocked(bool rotation_locked);
78
79 // Sets the display rotation to |rotation| and prevents future calls to
80 // OnAccelerometerUpdated from changing the rotation. SetRotationLocked(false)
81 // removes the rotation lock.
82 void LockRotation(gfx::Display::Rotation rotation);
83
84 // Add/Remove observers.
85 void AddObserver(Observer* observer);
86 void RemoveObserver(Observer* observer);
87
88 // True if it is possible to enter maximize mode in the current 53 // True if it is possible to enter maximize mode in the current
89 // configuration. If this returns false, it should never be the case that 54 // configuration. If this returns false, it should never be the case that
90 // maximize mode becomes enabled. 55 // maximize mode becomes enabled.
91 bool CanEnterMaximizeMode(); 56 bool CanEnterMaximizeMode();
92 57
93 // TODO(jonross): Merge this with EnterMaximizeMode. Currently these are 58 // TODO(jonross): Merge this with EnterMaximizeMode. Currently these are
94 // separate for several reasons: there is no internal display when running 59 // separate for several reasons: there is no internal display when running
95 // unittests; the event blocker prevents keyboard input when running ChromeOS 60 // unittests; the event blocker prevents keyboard input when running ChromeOS
96 // on linux. http://crbug.com/362881 61 // on linux. http://crbug.com/362881
97 // Turn the always maximize mode window manager on or off. 62 // Turn the always maximize mode window manager on or off.
(...skipping 16 matching lines...) Expand all
114 void Shutdown(); 79 void Shutdown();
115 80
116 // AccelerometerObserver: 81 // AccelerometerObserver:
117 void OnAccelerometerUpdated(const ui::AccelerometerUpdate& update) override; 82 void OnAccelerometerUpdated(const ui::AccelerometerUpdate& update) override;
118 83
119 // ShellObserver: 84 // ShellObserver:
120 void OnAppTerminating() override; 85 void OnAppTerminating() override;
121 void OnMaximizeModeStarted() override; 86 void OnMaximizeModeStarted() override;
122 void OnMaximizeModeEnded() override; 87 void OnMaximizeModeEnded() override;
123 88
89 #if defined(OS_CHROMEOS)
124 // DisplayController::Observer: 90 // DisplayController::Observer:
125 void OnDisplayConfigurationChanged() override; 91 void OnDisplayConfigurationChanged() override;
126 92
127 #if defined(OS_CHROMEOS)
128 // PowerManagerClient::Observer: 93 // PowerManagerClient::Observer:
129 virtual void LidEventReceived(bool open, 94 virtual void LidEventReceived(bool open,
130 const base::TimeTicks& time) override; 95 const base::TimeTicks& time) override;
131 virtual void SuspendImminent() override; 96 virtual void SuspendImminent() override;
132 virtual void SuspendDone(const base::TimeDelta& sleep_duration) override; 97 virtual void SuspendDone(const base::TimeDelta& sleep_duration) override;
133 #endif // OS_CHROMEOS 98 #endif // OS_CHROMEOS
134 99
135 private: 100 private:
136 friend class MaximizeModeControllerTest; 101 friend class MaximizeModeControllerTest;
137 friend class MaximizeModeWindowManagerTest; 102 friend class MaximizeModeWindowManagerTest;
138 friend class test::MultiUserWindowManagerChromeOSTest; 103 friend class test::MultiUserWindowManagerChromeOSTest;
139 104
140 // Set the TickClock. This is only to be used by tests that need to 105 // Set the TickClock. This is only to be used by tests that need to
141 // artificially and deterministically control the current time. 106 // artificially and deterministically control the current time.
142 void SetTickClockForTest(scoped_ptr<base::TickClock> tick_clock); 107 void SetTickClockForTest(scoped_ptr<base::TickClock> tick_clock);
143 108
144 // Detect hinge rotation from |base| and |lid| accelerometers and 109 // Detect hinge rotation from |base| and |lid| accelerometers and
145 // automatically start / stop maximize mode. 110 // automatically start / stop maximize mode.
146 void HandleHingeRotation(const gfx::Vector3dF& base, 111 void HandleHingeRotation(const gfx::Vector3dF& base,
147 const gfx::Vector3dF& lid); 112 const gfx::Vector3dF& lid);
148 113
149 // Detect screen rotation from |lid| accelerometer and automatically rotate
150 // screen.
151 void HandleScreenRotation(const gfx::Vector3dF& lid);
152
153 // Sets the display rotation and suppresses display notifications.
154 void SetDisplayRotation(DisplayManager* display_manager,
155 gfx::Display::Rotation rotation);
156
157 // Returns true if the lid was recently opened. 114 // Returns true if the lid was recently opened.
158 bool WasLidOpenedRecently() const; 115 bool WasLidOpenedRecently() const;
159 116
160 // Enables MaximizeModeWindowManager, and determines the current state of 117 // Enables MaximizeModeWindowManager, and determines the current state of
161 // rotation lock. 118 // rotation lock.
162 void EnterMaximizeMode(); 119 void EnterMaximizeMode();
163 120
164 // Removes MaximizeModeWindowManager and resets the display rotation if there 121 // Removes MaximizeModeWindowManager and resets the display rotation if there
165 // is no rotation lock. 122 // is no rotation lock.
166 void LeaveMaximizeMode(); 123 void LeaveMaximizeMode();
167 124
168 // Record UMA stats tracking touchview usage. 125 // Record UMA stats tracking touchview usage.
169 void RecordTouchViewStateTransition(); 126 void RecordTouchViewStateTransition();
170 127
128 #if defined(OS_CHROMEOS)
129 // Detect screen rotation from |lid| accelerometer and automatically rotate
130 // screen.
131 void HandleScreenRotation(const gfx::Vector3dF& lid);
132
133 // Sets the display rotation and suppresses display notifications.
134 void SetDisplayRotation(gfx::Display::Rotation rotation);
135
171 // Checks DisplayManager for registered rotation lock, and rotation, 136 // Checks DisplayManager for registered rotation lock, and rotation,
172 // preferences. These are then applied. 137 // preferences. These are then applied.
173 void LoadDisplayRotationProperties(); 138 void LoadDisplayRotationProperties();
139 #endif // OS_CHROMEOS
174 140
175 // The maximized window manager (if enabled). 141 // The maximized window manager (if enabled).
176 scoped_ptr<MaximizeModeWindowManager> maximize_mode_window_manager_; 142 scoped_ptr<MaximizeModeWindowManager> maximize_mode_window_manager_;
177 143
178 // A helper class which when instantiated will block native events from the 144 // A helper class which when instantiated will block native events from the
179 // internal keyboard and touchpad. 145 // internal keyboard and touchpad.
180 scoped_ptr<ScopedDisableInternalMouseAndKeyboard> event_blocker_; 146 scoped_ptr<ScopedDisableInternalMouseAndKeyboard> event_blocker_;
181 147
182 // When true calls to OnAccelerometerUpdated will not rotate the display.
183 bool rotation_locked_;
184
185 // Whether we have ever seen accelerometer data. 148 // Whether we have ever seen accelerometer data.
186 bool have_seen_accelerometer_data_; 149 bool have_seen_accelerometer_data_;
187 150
188 // True when changes being applied cause OnDisplayConfigurationChanged() to be
189 // called, and for which these changes should be ignored.
190 bool ignore_display_configuration_updates_;
191
192 // True when the hinge angle has been detected past 180 degrees. 151 // True when the hinge angle has been detected past 180 degrees.
193 bool lid_open_past_180_; 152 bool lid_open_past_180_;
194 153
195 // True when Shutdown has been called. When shutting down the non maximize 154 // True when Shutdown has been called. When shutting down the non maximize
196 // mode state should be restored, however user preferences should not be 155 // mode state should be restored, however user preferences should not be
197 // altered. 156 // altered.
198 bool shutting_down_; 157 bool shutting_down_;
199 158
200 // The rotation of the display set by the user. This rotation will be 159 // The rotation of the display set by the user. This rotation will be
201 // restored upon exiting maximize mode. 160 // restored upon exiting maximize mode.
202 gfx::Display::Rotation user_rotation_; 161 gfx::Display::Rotation user_rotation_;
203 162
204 // The current rotation set by MaximizeModeController for the internal 163 // The current rotation set by MaximizeModeController for the internal
205 // display. Compared in OnDisplayConfigurationChanged to determine user 164 // display. Compared in OnDisplayConfigurationChanged to determine user
206 // display setting changes. 165 // display setting changes.
207 gfx::Display::Rotation current_rotation_; 166 gfx::Display::Rotation current_rotation_;
208 167
209 // Rotation Lock observers.
210 ObserverList<Observer> observers_;
211
212 // Tracks time spent in (and out of) touchview mode. 168 // Tracks time spent in (and out of) touchview mode.
213 base::Time last_touchview_transition_time_; 169 base::Time last_touchview_transition_time_;
214 base::TimeDelta total_touchview_time_; 170 base::TimeDelta total_touchview_time_;
215 base::TimeDelta total_non_touchview_time_; 171 base::TimeDelta total_non_touchview_time_;
216 172
217 // Tracks the last time we received a lid open event. This is used to suppress 173 // Tracks the last time we received a lid open event. This is used to suppress
218 // erroneous accelerometer readings as the lid is opened but the accelerometer 174 // erroneous accelerometer readings as the lid is opened but the accelerometer
219 // reports readings that make the lid to appear near fully open. 175 // reports readings that make the lid to appear near fully open.
220 base::TimeTicks last_lid_open_time_; 176 base::TimeTicks last_lid_open_time_;
221 177
222 // Source for the current time in base::TimeTicks. 178 // Source for the current time in base::TimeTicks.
223 scoped_ptr<base::TickClock> tick_clock_; 179 scoped_ptr<base::TickClock> tick_clock_;
224 180
225 // Tracks when the lid is closed. Used to prevent entering maximize mode. 181 // Tracks when the lid is closed. Used to prevent entering maximize mode.
226 bool lid_is_closed_; 182 bool lid_is_closed_;
227 183
228 DISALLOW_COPY_AND_ASSIGN(MaximizeModeController); 184 DISALLOW_COPY_AND_ASSIGN(MaximizeModeController);
229 }; 185 };
230 186
231 } // namespace ash 187 } // namespace ash
232 188
233 #endif // ASH_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_ 189 #endif // ASH_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698