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

Side by Side Diff: ash/wm/tablet_mode/tablet_mode_controller.h

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

Powered by Google App Engine
This is Rietveld 408576698