Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_ |
| 6 #define ASH_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_ | 6 #define ASH_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include "ash/ash_export.h" | 8 #include "ash/ash_export.h" |
| 9 #include "ash/display/display_controller.h" | |
| 10 #include "ash/display/display_manager.h" | |
| 11 #include "ash/shell_observer.h" | 9 #include "ash/shell_observer.h" |
| 12 #include "base/macros.h" | 10 #include "base/macros.h" |
| 13 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/observer_list.h" | 12 #include "base/time/time.h" |
| 15 #include "ui/gfx/display.h" | 13 #include "ui/gfx/display.h" |
| 14 #include "ui/gfx/geometry/vector3d_f.h" | |
|
oshima
2015/01/09 21:23:55
forward decl?
jonross
2015/01/12 14:46:49
Removed
| |
| 16 | 15 |
| 17 #if defined(OS_CHROMEOS) | 16 #if defined(OS_CHROMEOS) |
| 18 #include "chromeos/accelerometer/accelerometer_reader.h" | 17 #include "chromeos/accelerometer/accelerometer_reader.h" |
| 19 #include "chromeos/dbus/power_manager_client.h" | 18 #include "chromeos/dbus/power_manager_client.h" |
| 20 #endif // OS_CHROMEOS | 19 #endif // OS_CHROMEOS |
| 21 | 20 |
| 22 namespace base { | 21 namespace base { |
| 23 class TickClock; | 22 class TickClock; |
| 24 } | 23 } |
| 25 | 24 |
| 26 namespace ui { | 25 namespace ui { |
| 27 class EventHandler; | 26 class EventHandler; |
| 28 } | 27 } |
| 29 | 28 |
| 30 namespace ash { | 29 namespace ash { |
| 31 | 30 |
| 32 class MaximizeModeControllerTest; | 31 class MaximizeModeControllerTest; |
| 33 class ScopedDisableInternalMouseAndKeyboard; | 32 class ScopedDisableInternalMouseAndKeyboard; |
| 34 class MaximizeModeWindowManager; | 33 class MaximizeModeWindowManager; |
| 35 class MaximizeModeWindowManagerTest; | 34 class MaximizeModeWindowManagerTest; |
| 36 namespace test { | 35 namespace test { |
| 37 class MultiUserWindowManagerChromeOSTest; | 36 class MultiUserWindowManagerChromeOSTest; |
| 38 } | 37 } |
| 39 | 38 |
| 40 // MaximizeModeController listens to accelerometer events and automatically | 39 // MaximizeModeController listens to accelerometer events and automatically |
| 41 // enters and exits maximize mode when the lid is opened beyond the triggering | 40 // enters and exits maximize mode when the lid is opened beyond the triggering |
| 42 // angle and rotates the display to match the device when in maximize mode. | 41 // angle and rotates the display to match the device when in maximize mode. |
| 43 class ASH_EXPORT MaximizeModeController | 42 class ASH_EXPORT MaximizeModeController : |
| 44 : public ShellObserver, | |
| 45 #if defined(OS_CHROMEOS) | 43 #if defined(OS_CHROMEOS) |
| 46 public chromeos::AccelerometerReader::Observer, | 44 public chromeos::AccelerometerReader::Observer, |
| 47 public chromeos::PowerManagerClient::Observer, | 45 public chromeos::PowerManagerClient::Observer, |
| 48 #endif // OS_CHROMEOS | 46 #endif // OS_CHROMEOS |
| 49 public DisplayController::Observer { | 47 public ShellObserver { |
| 50 public: | 48 public: |
| 51 // Observer that reports changes to the state of MaximizeModeController's | |
| 52 // rotation lock. | |
| 53 class Observer { | |
| 54 public: | |
| 55 // Invoked whenever |rotation_locked_| is changed. | |
| 56 virtual void OnRotationLockChanged(bool rotation_locked) {} | |
| 57 | |
| 58 protected: | |
| 59 virtual ~Observer() {} | |
| 60 }; | |
| 61 | |
| 62 MaximizeModeController(); | 49 MaximizeModeController(); |
| 63 ~MaximizeModeController() override; | 50 ~MaximizeModeController() override; |
| 64 | 51 |
| 65 bool ignore_display_configuration_updates() const { | |
| 66 return ignore_display_configuration_updates_; | |
| 67 } | |
| 68 | |
| 69 // True if |rotation_lock_| has been set, and OnAccelerometerUpdated will not | |
| 70 // change the display rotation. | |
| 71 bool rotation_locked() { | |
| 72 return rotation_locked_; | |
| 73 } | |
| 74 | |
| 75 // If |rotation_locked| future calls to OnAccelerometerUpdated will not | |
| 76 // change the display rotation. | |
| 77 void SetRotationLocked(bool rotation_locked); | |
| 78 | |
| 79 // Sets the display rotation to |rotation| and prevents future calls to | |
| 80 // OnAccelerometerUpdated from changing the rotation. SetRotationLocked(false) | |
| 81 // removes the rotation lock. | |
| 82 void LockRotation(gfx::Display::Rotation rotation); | |
| 83 | |
| 84 // Add/Remove observers. | |
| 85 void AddObserver(Observer* observer); | |
| 86 void RemoveObserver(Observer* observer); | |
| 87 | |
| 88 // True if it is possible to enter maximize mode in the current | 52 // True if it is possible to enter maximize mode in the current |
| 89 // configuration. If this returns false, it should never be the case that | 53 // configuration. If this returns false, it should never be the case that |
| 90 // maximize mode becomes enabled. | 54 // maximize mode becomes enabled. |
| 91 bool CanEnterMaximizeMode(); | 55 bool CanEnterMaximizeMode(); |
| 92 | 56 |
| 93 // TODO(jonross): Merge this with EnterMaximizeMode. Currently these are | 57 // TODO(jonross): Merge this with EnterMaximizeMode. Currently these are |
| 94 // separate for several reasons: there is no internal display when running | 58 // separate for several reasons: there is no internal display when running |
| 95 // unittests; the event blocker prevents keyboard input when running ChromeOS | 59 // unittests; the event blocker prevents keyboard input when running ChromeOS |
| 96 // on linux. http://crbug.com/362881 | 60 // on linux. http://crbug.com/362881 |
| 97 // Turn the always maximize mode window manager on or off. | 61 // Turn the always maximize mode window manager on or off. |
| 98 void EnableMaximizeModeWindowManager(bool enable); | 62 void EnableMaximizeModeWindowManager(bool enable); |
| 99 | 63 |
| 100 // Test if the MaximizeModeWindowManager is enabled or not. | 64 // Test if the MaximizeModeWindowManager is enabled or not. |
| 101 bool IsMaximizeModeWindowManagerEnabled() const; | 65 bool IsMaximizeModeWindowManagerEnabled() const; |
| 102 | 66 |
| 103 // Add a special window to the MaximizeModeWindowManager for tracking. This is | 67 // Add a special window to the MaximizeModeWindowManager for tracking. This is |
| 104 // only required for special windows which are handled by other window | 68 // only required for special windows which are handled by other window |
| 105 // managers like the |MultiUserWindowManager|. | 69 // managers like the |MultiUserWindowManager|. |
| 106 // If the maximize mode is not enabled no action will be performed. | 70 // If the maximize mode is not enabled no action will be performed. |
| 107 void AddWindow(aura::Window* window); | 71 void AddWindow(aura::Window* window); |
| 108 | 72 |
| 109 // TODO(jonross): move this into the destructor. Currently separated as | |
| 110 // ShellOberver notifies of maximize mode ending, and the observers end up | |
| 111 // attempting to access MaximizeModeController via the Shell. If done in | |
| 112 // destructor the controller is null, and the observers segfault. | |
| 113 // Shuts down down the MaximizeModeWindowManager and notifies all observers. | |
| 114 void Shutdown(); | |
| 115 | |
| 116 // ShellObserver: | 73 // ShellObserver: |
| 117 void OnAppTerminating() override; | 74 void OnAppTerminating() override; |
| 118 void OnMaximizeModeStarted() override; | 75 void OnMaximizeModeStarted() override; |
| 119 void OnMaximizeModeEnded() override; | 76 void OnMaximizeModeEnded() override; |
| 120 | 77 |
| 121 // DisplayController::Observer: | |
| 122 void OnDisplayConfigurationChanged() override; | |
| 123 | |
| 124 #if defined(OS_CHROMEOS) | 78 #if defined(OS_CHROMEOS) |
| 125 // chromeos::AccelerometerReader::Observer: | 79 // chromeos::AccelerometerReader::Observer: |
| 126 void OnAccelerometerUpdated(const ui::AccelerometerUpdate& update) override; | 80 void OnAccelerometerUpdated(const ui::AccelerometerUpdate& update) override; |
| 127 | 81 |
| 128 // PowerManagerClient::Observer: | 82 // PowerManagerClient::Observer: |
| 129 void LidEventReceived(bool open, const base::TimeTicks& time) override; | 83 void LidEventReceived(bool open, const base::TimeTicks& time) override; |
| 130 void SuspendImminent() override; | 84 void SuspendImminent() override; |
| 131 void SuspendDone(const base::TimeDelta& sleep_duration) override; | 85 void SuspendDone(const base::TimeDelta& sleep_duration) override; |
| 132 #endif // OS_CHROMEOS | 86 #endif // OS_CHROMEOS |
| 133 | 87 |
| 134 private: | 88 private: |
| 135 friend class MaximizeModeControllerTest; | 89 friend class MaximizeModeControllerTest; |
| 136 friend class MaximizeModeWindowManagerTest; | 90 friend class MaximizeModeWindowManagerTest; |
| 137 friend class test::MultiUserWindowManagerChromeOSTest; | 91 friend class test::MultiUserWindowManagerChromeOSTest; |
| 138 | 92 |
| 139 // Set the TickClock. This is only to be used by tests that need to | 93 // Set the TickClock. This is only to be used by tests that need to |
| 140 // artificially and deterministically control the current time. | 94 // artificially and deterministically control the current time. |
| 141 void SetTickClockForTest(scoped_ptr<base::TickClock> tick_clock); | 95 void SetTickClockForTest(scoped_ptr<base::TickClock> tick_clock); |
| 142 | 96 |
| 143 // Detect hinge rotation from |base| and |lid| accelerometers and | 97 // Detect hinge rotation from |base| and |lid| accelerometers and |
| 144 // automatically start / stop maximize mode. | 98 // automatically start / stop maximize mode. |
| 145 void HandleHingeRotation(const gfx::Vector3dF& base, | 99 void HandleHingeRotation(const gfx::Vector3dF& base, |
| 146 const gfx::Vector3dF& lid); | 100 const gfx::Vector3dF& lid); |
| 147 | 101 |
| 148 // Detect screen rotation from |lid| accelerometer and automatically rotate | |
| 149 // screen. | |
| 150 void HandleScreenRotation(const gfx::Vector3dF& lid); | |
| 151 | |
| 152 // Sets the display rotation and suppresses display notifications. | |
| 153 void SetDisplayRotation(DisplayManager* display_manager, | |
| 154 gfx::Display::Rotation rotation); | |
| 155 | |
| 156 // Returns true if the lid was recently opened. | 102 // Returns true if the lid was recently opened. |
| 157 bool WasLidOpenedRecently() const; | 103 bool WasLidOpenedRecently() const; |
| 158 | 104 |
| 159 // Enables MaximizeModeWindowManager, and determines the current state of | 105 // Enables MaximizeModeWindowManager, and determines the current state of |
| 160 // rotation lock. | 106 // rotation lock. |
| 161 void EnterMaximizeMode(); | 107 void EnterMaximizeMode(); |
| 162 | 108 |
| 163 // Removes MaximizeModeWindowManager and resets the display rotation if there | 109 // Removes MaximizeModeWindowManager and resets the display rotation if there |
| 164 // is no rotation lock. | 110 // is no rotation lock. |
| 165 void LeaveMaximizeMode(); | 111 void LeaveMaximizeMode(); |
| 166 | 112 |
| 167 // Record UMA stats tracking touchview usage. | 113 // Record UMA stats tracking touchview usage. |
| 168 void RecordTouchViewStateTransition(); | 114 void RecordTouchViewStateTransition(); |
| 169 | 115 |
| 170 // Checks DisplayManager for registered rotation lock, and rotation, | |
| 171 // preferences. These are then applied. | |
| 172 void LoadDisplayRotationProperties(); | |
| 173 | |
| 174 // The maximized window manager (if enabled). | 116 // The maximized window manager (if enabled). |
| 175 scoped_ptr<MaximizeModeWindowManager> maximize_mode_window_manager_; | 117 scoped_ptr<MaximizeModeWindowManager> maximize_mode_window_manager_; |
| 176 | 118 |
| 177 // A helper class which when instantiated will block native events from the | 119 // A helper class which when instantiated will block native events from the |
| 178 // internal keyboard and touchpad. | 120 // internal keyboard and touchpad. |
| 179 scoped_ptr<ScopedDisableInternalMouseAndKeyboard> event_blocker_; | 121 scoped_ptr<ScopedDisableInternalMouseAndKeyboard> event_blocker_; |
| 180 | 122 |
| 181 // When true calls to OnAccelerometerUpdated will not rotate the display. | |
| 182 bool rotation_locked_; | |
| 183 | |
| 184 // Whether we have ever seen accelerometer data. | 123 // Whether we have ever seen accelerometer data. |
| 185 bool have_seen_accelerometer_data_; | 124 bool have_seen_accelerometer_data_; |
| 186 | 125 |
| 187 // True when changes being applied cause OnDisplayConfigurationChanged() to be | |
| 188 // called, and for which these changes should be ignored. | |
| 189 bool ignore_display_configuration_updates_; | |
| 190 | |
| 191 // True when the hinge angle has been detected past 180 degrees. | 126 // True when the hinge angle has been detected past 180 degrees. |
| 192 bool lid_open_past_180_; | 127 bool lid_open_past_180_; |
| 193 | 128 |
| 194 // True when Shutdown has been called. When shutting down the non maximize | |
| 195 // mode state should be restored, however user preferences should not be | |
| 196 // altered. | |
| 197 bool shutting_down_; | |
| 198 | |
| 199 // The rotation of the display set by the user. This rotation will be | |
| 200 // restored upon exiting maximize mode. | |
| 201 gfx::Display::Rotation user_rotation_; | |
| 202 | |
| 203 // The current rotation set by MaximizeModeController for the internal | |
| 204 // display. Compared in OnDisplayConfigurationChanged to determine user | |
| 205 // display setting changes. | |
| 206 gfx::Display::Rotation current_rotation_; | |
| 207 | |
| 208 // Rotation Lock observers. | |
| 209 ObserverList<Observer> observers_; | |
| 210 | |
| 211 // Tracks time spent in (and out of) touchview mode. | 129 // Tracks time spent in (and out of) touchview mode. |
| 212 base::Time last_touchview_transition_time_; | 130 base::Time last_touchview_transition_time_; |
| 213 base::TimeDelta total_touchview_time_; | 131 base::TimeDelta total_touchview_time_; |
| 214 base::TimeDelta total_non_touchview_time_; | 132 base::TimeDelta total_non_touchview_time_; |
| 215 | 133 |
| 216 // Tracks the last time we received a lid open event. This is used to suppress | 134 // Tracks the last time we received a lid open event. This is used to suppress |
| 217 // erroneous accelerometer readings as the lid is opened but the accelerometer | 135 // erroneous accelerometer readings as the lid is opened but the accelerometer |
| 218 // reports readings that make the lid to appear near fully open. | 136 // reports readings that make the lid to appear near fully open. |
| 219 base::TimeTicks last_lid_open_time_; | 137 base::TimeTicks last_lid_open_time_; |
| 220 | 138 |
| 221 // Source for the current time in base::TimeTicks. | 139 // Source for the current time in base::TimeTicks. |
| 222 scoped_ptr<base::TickClock> tick_clock_; | 140 scoped_ptr<base::TickClock> tick_clock_; |
| 223 | 141 |
| 224 // Tracks when the lid is closed. Used to prevent entering maximize mode. | 142 // Tracks when the lid is closed. Used to prevent entering maximize mode. |
| 225 bool lid_is_closed_; | 143 bool lid_is_closed_; |
| 226 | 144 |
| 227 DISALLOW_COPY_AND_ASSIGN(MaximizeModeController); | 145 DISALLOW_COPY_AND_ASSIGN(MaximizeModeController); |
| 228 }; | 146 }; |
| 229 | 147 |
| 230 } // namespace ash | 148 } // namespace ash |
| 231 | 149 |
| 232 #endif // ASH_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_ | 150 #endif // ASH_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_ |
| OLD | NEW |