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

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

Powered by Google App Engine
This is Rietveld 408576698