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

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

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

Powered by Google App Engine
This is Rietveld 408576698