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