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