Updating XTBs based on .GRDs from branch master
[chromium-blink-merge.git] / ash / wm / maximize_mode / maximize_mode_controller.h
blobfc69b6d673aeb11b7b1deb4a02d4804ed3f21c77
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.
5 #ifndef ASH_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_
6 #define ASH_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_
8 #include "ash/ash_export.h"
9 #include "ash/shell_observer.h"
10 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/time/time.h"
13 #include "ui/gfx/display.h"
14 #include "ui/gfx/geometry/vector3d_f.h"
16 #if defined(OS_CHROMEOS)
17 #include "chromeos/accelerometer/accelerometer_reader.h"
18 #include "chromeos/accelerometer/accelerometer_types.h"
19 #include "chromeos/dbus/power_manager_client.h"
20 #endif // OS_CHROMEOS
22 namespace base {
23 class TickClock;
26 namespace gfx {
27 class Vector3dF;
30 namespace ui {
31 class EventHandler;
34 namespace ash {
36 class MaximizeModeControllerTest;
37 class ScopedDisableInternalMouseAndKeyboard;
38 class MaximizeModeWindowManager;
39 class MaximizeModeWindowManagerTest;
40 namespace test {
41 class MultiUserWindowManagerChromeOSTest;
42 class VirtualKeyboardControllerTest;
45 // MaximizeModeController listens to accelerometer events and automatically
46 // enters and exits maximize mode when the lid is opened beyond the triggering
47 // angle and rotates the display to match the device when in maximize mode.
48 class ASH_EXPORT MaximizeModeController :
49 #if defined(OS_CHROMEOS)
50 public chromeos::AccelerometerReader::Observer,
51 public chromeos::PowerManagerClient::Observer,
52 #endif // OS_CHROMEOS
53 public ShellObserver {
54 public:
55 MaximizeModeController();
56 ~MaximizeModeController() override;
58 // True if it is possible to enter maximize mode in the current
59 // configuration. If this returns false, it should never be the case that
60 // maximize mode becomes enabled.
61 bool CanEnterMaximizeMode();
63 // TODO(jonross): Merge this with EnterMaximizeMode. Currently these are
64 // separate for several reasons: there is no internal display when running
65 // unittests; the event blocker prevents keyboard input when running ChromeOS
66 // on linux. http://crbug.com/362881
67 // Turn the always maximize mode window manager on or off.
68 void EnableMaximizeModeWindowManager(bool should_enable);
70 // Test if the MaximizeModeWindowManager is enabled or not.
71 bool IsMaximizeModeWindowManagerEnabled() const;
73 // Add a special window to the MaximizeModeWindowManager for tracking. This is
74 // only required for special windows which are handled by other window
75 // managers like the |MultiUserWindowManager|.
76 // If the maximize mode is not enabled no action will be performed.
77 void AddWindow(aura::Window* window);
79 // ShellObserver:
80 void OnAppTerminating() override;
81 void OnMaximizeModeStarted() override;
82 void OnMaximizeModeEnded() override;
84 #if defined(OS_CHROMEOS)
85 // chromeos::AccelerometerReader::Observer:
86 void OnAccelerometerUpdated(
87 scoped_refptr<const chromeos::AccelerometerUpdate> update) override;
89 // PowerManagerClient::Observer:
90 void LidEventReceived(bool open, const base::TimeTicks& time) override;
91 void SuspendImminent() override;
92 void SuspendDone(const base::TimeDelta& sleep_duration) override;
93 #endif // OS_CHROMEOS
95 private:
96 friend class MaximizeModeControllerTest;
97 friend class MaximizeModeWindowManagerTest;
98 friend class test::MultiUserWindowManagerChromeOSTest;
99 friend class test::VirtualKeyboardControllerTest;
101 // Used for recording metrics for intervals of time spent in
102 // and out of TouchView.
103 enum TouchViewIntervalType {
104 TOUCH_VIEW_INTERVAL_INACTIVE,
105 TOUCH_VIEW_INTERVAL_ACTIVE
108 // Set the TickClock. This is only to be used by tests that need to
109 // artificially and deterministically control the current time.
110 void SetTickClockForTest(scoped_ptr<base::TickClock> tick_clock);
112 #if defined(OS_CHROMEOS)
113 // Detect hinge rotation from base and lid accelerometers and automatically
114 // start / stop maximize mode.
115 void HandleHingeRotation(
116 scoped_refptr<const chromeos::AccelerometerUpdate> update);
117 #endif
119 // Returns true if the lid was recently opened.
120 bool WasLidOpenedRecently() const;
122 // Enables MaximizeModeWindowManager, and determines the current state of
123 // rotation lock.
124 void EnterMaximizeMode();
126 // Removes MaximizeModeWindowManager and resets the display rotation if there
127 // is no rotation lock.
128 void LeaveMaximizeMode();
130 // Record UMA stats tracking TouchView usage. If |type| is
131 // TOUCH_VIEW_INTERVAL_INACTIVE, then record that TouchView has been
132 // inactive from |touchview_usage_interval_start_time_| until now.
133 // Similarly, record that TouchView has been active if |type| is
134 // TOUCH_VIEW_INTERVAL_ACTIVE.
135 void RecordTouchViewUsageInterval(TouchViewIntervalType type);
137 // Returns TOUCH_VIEW_INTERVAL_ACTIVE if TouchView is currently active,
138 // otherwise returns TOUCH_VIEW_INTERNAL_INACTIVE.
139 TouchViewIntervalType CurrentTouchViewIntervalType();
141 // The maximized window manager (if enabled).
142 scoped_ptr<MaximizeModeWindowManager> maximize_mode_window_manager_;
144 // A helper class which when instantiated will block native events from the
145 // internal keyboard and touchpad.
146 scoped_ptr<ScopedDisableInternalMouseAndKeyboard> event_blocker_;
148 // Whether we have ever seen accelerometer data.
149 bool have_seen_accelerometer_data_;
151 // True when the hinge angle has been detected past 180 degrees.
152 bool lid_open_past_180_;
154 // Tracks time spent in (and out of) touchview mode.
155 base::Time touchview_usage_interval_start_time_;
156 base::TimeDelta total_touchview_time_;
157 base::TimeDelta total_non_touchview_time_;
159 // Tracks the last time we received a lid open event. This is used to suppress
160 // erroneous accelerometer readings as the lid is opened but the accelerometer
161 // reports readings that make the lid to appear near fully open.
162 base::TimeTicks last_lid_open_time_;
164 // Source for the current time in base::TimeTicks.
165 scoped_ptr<base::TickClock> tick_clock_;
167 // Tracks when the lid is closed. Used to prevent entering maximize mode.
168 bool lid_is_closed_;
170 // Tracks smoothed accelerometer data over time. This is done when the hinge
171 // is approaching vertical to remove abrupt acceleration that can lead to
172 // incorrect calculations of hinge angles.
173 gfx::Vector3dF base_smoothed_;
174 gfx::Vector3dF lid_smoothed_;
176 DISALLOW_COPY_AND_ASSIGN(MaximizeModeController);
179 } // namespace ash
181 #endif // ASH_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_