OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef ASH_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_ | |
6 #define ASH_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_ | |
7 | |
8 #include <memory> | |
9 | |
10 #include "ash/ash_export.h" | |
11 #include "ash/public/interfaces/touch_view.mojom.h" | |
12 #include "ash/session/session_observer.h" | |
13 #include "ash/shell_observer.h" | |
14 #include "ash/wm_display_observer.h" | |
15 #include "base/compiler_specific.h" | |
16 #include "base/macros.h" | |
17 #include "base/memory/weak_ptr.h" | |
18 #include "base/time/time.h" | |
19 #include "chromeos/accelerometer/accelerometer_reader.h" | |
20 #include "chromeos/accelerometer/accelerometer_types.h" | |
21 #include "chromeos/dbus/power_manager_client.h" | |
22 #include "mojo/public/cpp/bindings/binding_set.h" | |
23 #include "mojo/public/cpp/bindings/interface_ptr_set.h" | |
24 #include "ui/gfx/geometry/vector3d_f.h" | |
25 | |
26 namespace aura { | |
27 class Window; | |
28 } | |
29 | |
30 namespace base { | |
31 class TickClock; | |
32 } | |
33 | |
34 namespace gfx { | |
35 class Vector3dF; | |
36 } | |
37 | |
38 namespace ash { | |
39 | |
40 class MaximizeModeControllerTest; | |
41 class ScopedDisableInternalMouseAndKeyboard; | |
42 class MaximizeModeWindowManager; | |
43 class MaximizeModeWindowManagerTest; | |
44 | |
45 namespace test { | |
46 class MultiUserWindowManagerChromeOSTest; | |
47 class VirtualKeyboardControllerTest; | |
48 } | |
49 | |
50 // MaximizeModeController listens to accelerometer events and automatically | |
51 // enters and exits maximize mode when the lid is opened beyond the triggering | |
52 // angle and rotates the display to match the device when in maximize mode. | |
53 class ASH_EXPORT MaximizeModeController | |
54 : public chromeos::AccelerometerReader::Observer, | |
55 public chromeos::PowerManagerClient::Observer, | |
56 NON_EXPORTED_BASE(public mojom::TouchViewManager), | |
57 public ShellObserver, | |
58 public WmDisplayObserver, | |
59 public SessionObserver { | |
60 public: | |
61 // Used for keeping track if the user wants the machine to behave as a | |
62 // clamshell/touchview regardless of hardware orientation. | |
63 enum class ForceTabletMode { | |
64 NONE = 0, | |
65 CLAMSHELL, | |
66 TOUCHVIEW, | |
67 }; | |
68 | |
69 MaximizeModeController(); | |
70 ~MaximizeModeController() override; | |
71 | |
72 // True if it is possible to enter maximize mode in the current | |
73 // configuration. If this returns false, it should never be the case that | |
74 // maximize mode becomes enabled. | |
75 bool CanEnterMaximizeMode(); | |
76 | |
77 // TODO(jonross): Merge this with EnterMaximizeMode. Currently these are | |
78 // separate for several reasons: there is no internal display when running | |
79 // unittests; the event blocker prevents keyboard input when running ChromeOS | |
80 // on linux. http://crbug.com/362881 | |
81 // Turn the always maximize mode window manager on or off. | |
82 void EnableMaximizeModeWindowManager(bool should_enable); | |
83 | |
84 // Test if the MaximizeModeWindowManager is enabled or not. | |
85 bool IsMaximizeModeWindowManagerEnabled() const; | |
86 | |
87 // Add a special window to the MaximizeModeWindowManager for tracking. This is | |
88 // only required for special windows which are handled by other window | |
89 // managers like the |MultiUserWindowManager|. | |
90 // If the maximize mode is not enabled no action will be performed. | |
91 void AddWindow(aura::Window* window); | |
92 | |
93 // Binds the mojom::TouchViewManager interface request to this object. | |
94 void BindRequest(mojom::TouchViewManagerRequest request); | |
95 | |
96 // ShellObserver: | |
97 void OnMaximizeModeStarted() override; | |
98 void OnMaximizeModeEnded() override; | |
99 void OnShellInitialized() override; | |
100 | |
101 // WmDisplayObserver: | |
102 void OnDisplayConfigurationChanged() override; | |
103 | |
104 // SessionObserver: | |
105 void OnChromeTerminating() override; | |
106 | |
107 // chromeos::AccelerometerReader::Observer: | |
108 void OnAccelerometerUpdated( | |
109 scoped_refptr<const chromeos::AccelerometerUpdate> update) override; | |
110 | |
111 // chromeos::PowerManagerClient::Observer: | |
112 void LidEventReceived(chromeos::PowerManagerClient::LidState state, | |
113 const base::TimeTicks& time) override; | |
114 void TabletModeEventReceived(chromeos::PowerManagerClient::TabletMode mode, | |
115 const base::TimeTicks& time) override; | |
116 void SuspendImminent() override; | |
117 void SuspendDone(const base::TimeDelta& sleep_duration) override; | |
118 | |
119 private: | |
120 friend class MaximizeModeControllerTest; | |
121 friend class MaximizeModeWindowManagerTest; | |
122 friend class test::MultiUserWindowManagerChromeOSTest; | |
123 friend class test::VirtualKeyboardControllerTest; | |
124 | |
125 // Used for recording metrics for intervals of time spent in | |
126 // and out of TouchView. | |
127 enum TouchViewIntervalType { | |
128 TOUCH_VIEW_INTERVAL_INACTIVE, | |
129 TOUCH_VIEW_INTERVAL_ACTIVE | |
130 }; | |
131 | |
132 // Set the TickClock. This is only to be used by tests that need to | |
133 // artificially and deterministically control the current time. | |
134 void SetTickClockForTest(std::unique_ptr<base::TickClock> tick_clock); | |
135 | |
136 // Detect hinge rotation from base and lid accelerometers and automatically | |
137 // start / stop maximize mode. | |
138 void HandleHingeRotation( | |
139 scoped_refptr<const chromeos::AccelerometerUpdate> update); | |
140 | |
141 void OnGetSwitchStates(chromeos::PowerManagerClient::LidState lid_state, | |
142 chromeos::PowerManagerClient::TabletMode tablet_mode); | |
143 | |
144 // Returns true if the lid was recently opened. | |
145 bool WasLidOpenedRecently() const; | |
146 | |
147 // Enables MaximizeModeWindowManager, and determines the current state of | |
148 // rotation lock. | |
149 void EnterMaximizeMode(); | |
150 | |
151 // Removes MaximizeModeWindowManager and resets the display rotation if there | |
152 // is no rotation lock. | |
153 void LeaveMaximizeMode(); | |
154 | |
155 // Record UMA stats tracking TouchView usage. If |type| is | |
156 // TOUCH_VIEW_INTERVAL_INACTIVE, then record that TouchView has been | |
157 // inactive from |touchview_usage_interval_start_time_| until now. | |
158 // Similarly, record that TouchView has been active if |type| is | |
159 // TOUCH_VIEW_INTERVAL_ACTIVE. | |
160 void RecordTouchViewUsageInterval(TouchViewIntervalType type); | |
161 | |
162 // Returns TOUCH_VIEW_INTERVAL_ACTIVE if TouchView is currently active, | |
163 // otherwise returns TOUCH_VIEW_INTERNAL_INACTIVE. | |
164 TouchViewIntervalType CurrentTouchViewIntervalType(); | |
165 | |
166 // mojom::TouchViewManager: | |
167 void AddObserver(mojom::TouchViewObserverPtr observer) override; | |
168 | |
169 // Checks whether we want to allow entering and exiting maximize mode. This | |
170 // returns false if the user set a flag for the software to behave in a | |
171 // certain way regardless of configuration. | |
172 bool AllowEnterExitMaximizeMode() const; | |
173 | |
174 // The maximized window manager (if enabled). | |
175 std::unique_ptr<MaximizeModeWindowManager> maximize_mode_window_manager_; | |
176 | |
177 // A helper class which when instantiated will block native events from the | |
178 // internal keyboard and touchpad. | |
179 std::unique_ptr<ScopedDisableInternalMouseAndKeyboard> event_blocker_; | |
180 | |
181 // Whether we have ever seen accelerometer data. | |
182 bool have_seen_accelerometer_data_; | |
183 | |
184 // Whether both accelerometers are available. | |
185 bool can_detect_lid_angle_; | |
186 | |
187 // Tracks time spent in (and out of) touchview mode. | |
188 base::Time touchview_usage_interval_start_time_; | |
189 base::TimeDelta total_touchview_time_; | |
190 base::TimeDelta total_non_touchview_time_; | |
191 | |
192 // Tracks the last time we received a lid open event. This is used to suppress | |
193 // erroneous accelerometer readings as the lid is opened but the accelerometer | |
194 // reports readings that make the lid to appear near fully open. | |
195 base::TimeTicks last_lid_open_time_; | |
196 | |
197 // Source for the current time in base::TimeTicks. | |
198 std::unique_ptr<base::TickClock> tick_clock_; | |
199 | |
200 // Set when tablet mode switch is on. This is used to force maximize mode. | |
201 bool tablet_mode_switch_is_on_; | |
202 | |
203 // Tracks when the lid is closed. Used to prevent entering maximize mode. | |
204 bool lid_is_closed_; | |
205 | |
206 // Tracks smoothed accelerometer data over time. This is done when the hinge | |
207 // is approaching vertical to remove abrupt acceleration that can lead to | |
208 // incorrect calculations of hinge angles. | |
209 gfx::Vector3dF base_smoothed_; | |
210 gfx::Vector3dF lid_smoothed_; | |
211 | |
212 // Bindings for the TouchViewManager interface. | |
213 mojo::BindingSet<mojom::TouchViewManager> bindings_; | |
214 | |
215 // The set of touchview observers to be notified about mode changes. | |
216 mojo::InterfacePtrSet<mojom::TouchViewObserver> observers_; | |
217 | |
218 // Tracks whether a flag is used to force maximize mode. | |
219 ForceTabletMode force_tablet_mode_ = ForceTabletMode::NONE; | |
220 | |
221 ScopedSessionObserver scoped_session_observer_; | |
222 | |
223 base::WeakPtrFactory<MaximizeModeController> weak_factory_; | |
224 | |
225 DISALLOW_COPY_AND_ASSIGN(MaximizeModeController); | |
226 }; | |
227 | |
228 } // namespace ash | |
229 | |
230 #endif // ASH_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_ | |
OLD | NEW |