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_controller.h" |
11 #include "ash/display/display_manager.h" | 11 #include "ash/display/display_manager.h" |
12 #include "ash/shell_observer.h" | 12 #include "ash/shell_observer.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
16 #include "base/power_monitor/power_observer.h" | 16 #include "chromeos/dbus/power_manager_client.h" |
17 #include "ui/gfx/display.h" | 17 #include "ui/gfx/display.h" |
18 | 18 |
19 namespace ui { | 19 namespace ui { |
20 class EventHandler; | 20 class EventHandler; |
21 } | 21 } |
22 | 22 |
23 namespace ash { | 23 namespace ash { |
24 | 24 |
25 class MaximizeModeControllerTest; | 25 class MaximizeModeControllerTest; |
26 class ScopedDisableInternalMouseAndKeyboard; | 26 class ScopedDisableInternalMouseAndKeyboard; |
27 class MaximizeModeWindowManager; | 27 class MaximizeModeWindowManager; |
28 class MaximizeModeWindowManagerTest; | 28 class MaximizeModeWindowManagerTest; |
29 | 29 |
30 // MaximizeModeController listens to accelerometer events and automatically | 30 // MaximizeModeController listens to accelerometer events and automatically |
31 // enters and exits maximize mode when the lid is opened beyond the triggering | 31 // enters and exits maximize mode when the lid is opened beyond the triggering |
32 // angle and rotates the display to match the device when in maximize mode. | 32 // angle and rotates the display to match the device when in maximize mode. |
33 class ASH_EXPORT MaximizeModeController : public AccelerometerObserver, | 33 class ASH_EXPORT MaximizeModeController : public AccelerometerObserver, |
34 public base::PowerObserver, | 34 public chromeos::PowerManagerClient::Observer, |
35 public ShellObserver, | 35 public ShellObserver, |
36 public DisplayController::Observer { | 36 public DisplayController::Observer { |
37 public: | 37 public: |
38 // Observer that reports changes to the state of MaximizeModeController's | 38 // Observer that reports changes to the state of MaximizeModeController's |
39 // rotation lock. | 39 // rotation lock. |
40 class Observer { | 40 class Observer { |
41 public: | 41 public: |
42 // Invoked whenever |rotation_locked_| is changed. | 42 // Invoked whenever |rotation_locked_| is changed. |
43 virtual void OnRotationLockChanged(bool rotation_locked) {} | 43 virtual void OnRotationLockChanged(bool rotation_locked) {} |
44 | 44 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
91 | 91 |
92 // AccelerometerObserver: | 92 // AccelerometerObserver: |
93 virtual void OnAccelerometerUpdated(const gfx::Vector3dF& base, | 93 virtual void OnAccelerometerUpdated(const gfx::Vector3dF& base, |
94 const gfx::Vector3dF& lid) OVERRIDE; | 94 const gfx::Vector3dF& lid) OVERRIDE; |
95 | 95 |
96 // ShellObserver: | 96 // ShellObserver: |
97 virtual void OnAppTerminating() OVERRIDE; | 97 virtual void OnAppTerminating() OVERRIDE; |
98 virtual void OnMaximizeModeStarted() OVERRIDE; | 98 virtual void OnMaximizeModeStarted() OVERRIDE; |
99 virtual void OnMaximizeModeEnded() OVERRIDE; | 99 virtual void OnMaximizeModeEnded() OVERRIDE; |
100 | 100 |
101 // base::PowerObserver: | |
102 virtual void OnSuspend() OVERRIDE; | |
103 virtual void OnResume() OVERRIDE; | |
104 | |
105 // DisplayController::Observer: | 101 // DisplayController::Observer: |
106 virtual void OnDisplayConfigurationChanged() OVERRIDE; | 102 virtual void OnDisplayConfigurationChanged() OVERRIDE; |
107 | 103 |
104 // PowerManagerClient::Observer: | |
105 virtual void LidEventReceived(bool open, | |
106 const base::TimeTicks& time) OVERRIDE; | |
107 virtual void SuspendImminent() OVERRIDE; | |
108 virtual void SuspendDone(const base::TimeDelta& sleep_duration) OVERRIDE; | |
109 | |
108 private: | 110 private: |
109 friend class MaximizeModeControllerTest; | 111 friend class MaximizeModeControllerTest; |
110 friend class MaximizeModeWindowManagerTest; | 112 friend class MaximizeModeWindowManagerTest; |
111 | 113 |
114 // An abstraction of the current time in TimeTicks. | |
115 // This is used so that tests can artificially control the current time. | |
116 // This prevents test flakiness caused by dependencies on a true clock time. | |
117 class TimeTickProvider { | |
jonross
2014/07/24 14:22:00
I dislike the idea of changing the time provider.
| |
118 public: | |
119 TimeTickProvider() {} | |
120 virtual ~TimeTickProvider() {} | |
121 virtual base::TimeTicks Now() const = 0; | |
122 | |
123 private: | |
124 DISALLOW_COPY_AND_ASSIGN(TimeTickProvider); | |
125 }; | |
126 | |
127 // The default TimeTickProvider used by the MaximizeModeController. | |
128 class TimeTickProviderImpl : public TimeTickProvider { | |
jonross
2014/07/24 14:22:00
This class is not needed for testing, nor for any
| |
129 public: | |
130 TimeTickProviderImpl() : TimeTickProvider() {} | |
131 virtual ~TimeTickProviderImpl() {} | |
132 | |
133 // TimeTickProvider: | |
134 virtual base::TimeTicks Now() const OVERRIDE; | |
135 | |
136 private: | |
137 DISALLOW_COPY_AND_ASSIGN(TimeTickProviderImpl); | |
138 }; | |
139 | |
140 // Set the TimeTickProvider. | |
141 // This is only to be used by tests that need to artificially and | |
142 // deterministically control the current time. | |
143 // Ownership of |provider| is assumed by this. | |
144 void SetTimeTickProviderForTest(TimeTickProvider* provider); | |
145 | |
112 // Detect hinge rotation from |base| and |lid| accelerometers and | 146 // Detect hinge rotation from |base| and |lid| accelerometers and |
113 // automatically start / stop maximize mode. | 147 // automatically start / stop maximize mode. |
114 void HandleHingeRotation(const gfx::Vector3dF& base, | 148 void HandleHingeRotation(const gfx::Vector3dF& base, |
115 const gfx::Vector3dF& lid); | 149 const gfx::Vector3dF& lid); |
116 | 150 |
117 // Detect screen rotation from |lid| accelerometer and automatically rotate | 151 // Detect screen rotation from |lid| accelerometer and automatically rotate |
118 // screen. | 152 // screen. |
119 void HandleScreenRotation(const gfx::Vector3dF& lid); | 153 void HandleScreenRotation(const gfx::Vector3dF& lid); |
120 | 154 |
121 // Sets the display rotation and suppresses display notifications. | 155 // Sets the display rotation and suppresses display notifications. |
122 void SetDisplayRotation(DisplayManager* display_manager, | 156 void SetDisplayRotation(DisplayManager* display_manager, |
123 gfx::Display::Rotation rotation); | 157 gfx::Display::Rotation rotation); |
124 | 158 |
159 // Returns true if the lid was recently opened. | |
160 bool WasLidOpenedRecently() const; | |
161 | |
125 // Enables MaximizeModeWindowManager, and determines the current state of | 162 // Enables MaximizeModeWindowManager, and determines the current state of |
126 // rotation lock. | 163 // rotation lock. |
127 void EnterMaximizeMode(); | 164 void EnterMaximizeMode(); |
128 | 165 |
129 // Removes MaximizeModeWindowManager and resets the display rotation if there | 166 // Removes MaximizeModeWindowManager and resets the display rotation if there |
130 // is no rotation lock. | 167 // is no rotation lock. |
131 void LeaveMaximizeMode(); | 168 void LeaveMaximizeMode(); |
132 | 169 |
133 // Record UMA stats tracking touchview usage. | 170 // Record UMA stats tracking touchview usage. |
134 void RecordTouchViewStateTransition(); | 171 void RecordTouchViewStateTransition(); |
(...skipping 27 matching lines...) Expand all Loading... | |
162 gfx::Display::Rotation current_rotation_; | 199 gfx::Display::Rotation current_rotation_; |
163 | 200 |
164 // Rotation Lock observers. | 201 // Rotation Lock observers. |
165 ObserverList<Observer> observers_; | 202 ObserverList<Observer> observers_; |
166 | 203 |
167 // Tracks time spent in (and out of) touchview mode. | 204 // Tracks time spent in (and out of) touchview mode. |
168 base::Time last_touchview_transition_time_; | 205 base::Time last_touchview_transition_time_; |
169 base::TimeDelta total_touchview_time_; | 206 base::TimeDelta total_touchview_time_; |
170 base::TimeDelta total_non_touchview_time_; | 207 base::TimeDelta total_non_touchview_time_; |
171 | 208 |
209 // Tracks the last time we received a lid open event. | |
210 // This is used to suppress erroneous acceleromter readings as the lid | |
211 // is opened but the acceleromater reports readings that make | |
212 // the lid to appear near fully open. | |
213 base::TimeTicks last_lid_open_time_; | |
214 | |
215 // Source for the current time in base::TimeTicks. | |
216 scoped_ptr<TimeTickProvider> time_tick_provider_; | |
217 | |
218 // Tracks when the lid is closed. | |
219 // Used to prevent entering maximize mode. | |
220 bool lid_is_closed_; | |
221 | |
172 DISALLOW_COPY_AND_ASSIGN(MaximizeModeController); | 222 DISALLOW_COPY_AND_ASSIGN(MaximizeModeController); |
173 }; | 223 }; |
174 | 224 |
175 } // namespace ash | 225 } // namespace ash |
176 | 226 |
177 #endif // ASH_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_ | 227 #endif // ASH_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_ |
OLD | NEW |