| 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_COMMON_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_ | 5 #ifndef ASH_COMMON_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_ |
| 6 #define ASH_COMMON_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_ | 6 #define ASH_COMMON_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "ash/ash_export.h" | 10 #include "ash/ash_export.h" |
| 11 #include "ash/common/shell_observer.h" | 11 #include "ash/common/shell_observer.h" |
| 12 #include "ash/common/wm_display_observer.h" | 12 #include "ash/common/wm_display_observer.h" |
| 13 #include "ash/public/interfaces/touch_view.mojom.h" | 13 #include "ash/public/interfaces/touch_view.mojom.h" |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/time/time.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" |
| 17 #include "mojo/public/cpp/bindings/binding_set.h" | 20 #include "mojo/public/cpp/bindings/binding_set.h" |
| 18 #include "mojo/public/cpp/bindings/interface_ptr_set.h" | 21 #include "mojo/public/cpp/bindings/interface_ptr_set.h" |
| 19 #include "ui/gfx/geometry/vector3d_f.h" | 22 #include "ui/gfx/geometry/vector3d_f.h" |
| 20 | 23 |
| 21 #if defined(OS_CHROMEOS) | |
| 22 #include "chromeos/accelerometer/accelerometer_reader.h" | |
| 23 #include "chromeos/accelerometer/accelerometer_types.h" | |
| 24 #include "chromeos/dbus/power_manager_client.h" | |
| 25 #endif // OS_CHROMEOS | |
| 26 | |
| 27 namespace base { | 24 namespace base { |
| 28 class TickClock; | 25 class TickClock; |
| 29 } | 26 } |
| 30 | 27 |
| 31 namespace gfx { | 28 namespace gfx { |
| 32 class Vector3dF; | 29 class Vector3dF; |
| 33 } | 30 } |
| 34 | 31 |
| 35 namespace ash { | 32 namespace ash { |
| 36 | 33 |
| 37 class MaximizeModeControllerTest; | 34 class MaximizeModeControllerTest; |
| 38 class ScopedDisableInternalMouseAndKeyboard; | 35 class ScopedDisableInternalMouseAndKeyboard; |
| 39 class MaximizeModeWindowManager; | 36 class MaximizeModeWindowManager; |
| 40 class MaximizeModeWindowManagerTest; | 37 class MaximizeModeWindowManagerTest; |
| 41 class WmWindow; | 38 class WmWindow; |
| 42 namespace test { | 39 namespace test { |
| 43 class MultiUserWindowManagerChromeOSTest; | 40 class MultiUserWindowManagerChromeOSTest; |
| 44 class VirtualKeyboardControllerTest; | 41 class VirtualKeyboardControllerTest; |
| 45 } | 42 } |
| 46 | 43 |
| 47 // MaximizeModeController listens to accelerometer events and automatically | 44 // MaximizeModeController listens to accelerometer events and automatically |
| 48 // enters and exits maximize mode when the lid is opened beyond the triggering | 45 // 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. | 46 // angle and rotates the display to match the device when in maximize mode. |
| 50 class ASH_EXPORT MaximizeModeController : | 47 class ASH_EXPORT MaximizeModeController : |
| 51 #if defined(OS_CHROMEOS) | |
| 52 public chromeos::AccelerometerReader::Observer, | 48 public chromeos::AccelerometerReader::Observer, |
| 53 public chromeos::PowerManagerClient::Observer, | 49 public chromeos::PowerManagerClient::Observer, |
| 54 #endif // OS_CHROMEOS | |
| 55 NON_EXPORTED_BASE(public mojom::TouchViewManager), | 50 NON_EXPORTED_BASE(public mojom::TouchViewManager), |
| 56 public ShellObserver, | 51 public ShellObserver, |
| 57 public WmDisplayObserver { | 52 public WmDisplayObserver { |
| 58 public: | 53 public: |
| 59 MaximizeModeController(); | 54 MaximizeModeController(); |
| 60 ~MaximizeModeController() override; | 55 ~MaximizeModeController() override; |
| 61 | 56 |
| 62 // True if it is possible to enter maximize mode in the current | 57 // True if it is possible to enter maximize mode in the current |
| 63 // configuration. If this returns false, it should never be the case that | 58 // configuration. If this returns false, it should never be the case that |
| 64 // maximize mode becomes enabled. | 59 // maximize mode becomes enabled. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 84 void BindRequest(mojom::TouchViewManagerRequest request); | 79 void BindRequest(mojom::TouchViewManagerRequest request); |
| 85 | 80 |
| 86 // ShellObserver: | 81 // ShellObserver: |
| 87 void OnAppTerminating() override; | 82 void OnAppTerminating() override; |
| 88 void OnMaximizeModeStarted() override; | 83 void OnMaximizeModeStarted() override; |
| 89 void OnMaximizeModeEnded() override; | 84 void OnMaximizeModeEnded() override; |
| 90 | 85 |
| 91 // WmDisplayObserver: | 86 // WmDisplayObserver: |
| 92 void OnDisplayConfigurationChanged() override; | 87 void OnDisplayConfigurationChanged() override; |
| 93 | 88 |
| 94 #if defined(OS_CHROMEOS) | |
| 95 // chromeos::AccelerometerReader::Observer: | 89 // chromeos::AccelerometerReader::Observer: |
| 96 void OnAccelerometerUpdated( | 90 void OnAccelerometerUpdated( |
| 97 scoped_refptr<const chromeos::AccelerometerUpdate> update) override; | 91 scoped_refptr<const chromeos::AccelerometerUpdate> update) override; |
| 98 | 92 |
| 99 // PowerManagerClient::Observer: | 93 // PowerManagerClient::Observer: |
| 100 void LidEventReceived(bool open, const base::TimeTicks& time) override; | 94 void LidEventReceived(bool open, const base::TimeTicks& time) override; |
| 101 void TabletModeEventReceived(bool on, const base::TimeTicks& time) override; | 95 void TabletModeEventReceived(bool on, const base::TimeTicks& time) override; |
| 102 void SuspendImminent() override; | 96 void SuspendImminent() override; |
| 103 void SuspendDone(const base::TimeDelta& sleep_duration) override; | 97 void SuspendDone(const base::TimeDelta& sleep_duration) override; |
| 104 #endif // OS_CHROMEOS | |
| 105 | 98 |
| 106 private: | 99 private: |
| 107 friend class MaximizeModeControllerTest; | 100 friend class MaximizeModeControllerTest; |
| 108 friend class MaximizeModeWindowManagerTest; | 101 friend class MaximizeModeWindowManagerTest; |
| 109 friend class test::MultiUserWindowManagerChromeOSTest; | 102 friend class test::MultiUserWindowManagerChromeOSTest; |
| 110 friend class test::VirtualKeyboardControllerTest; | 103 friend class test::VirtualKeyboardControllerTest; |
| 111 | 104 |
| 112 // Used for recording metrics for intervals of time spent in | 105 // Used for recording metrics for intervals of time spent in |
| 113 // and out of TouchView. | 106 // and out of TouchView. |
| 114 enum TouchViewIntervalType { | 107 enum TouchViewIntervalType { |
| 115 TOUCH_VIEW_INTERVAL_INACTIVE, | 108 TOUCH_VIEW_INTERVAL_INACTIVE, |
| 116 TOUCH_VIEW_INTERVAL_ACTIVE | 109 TOUCH_VIEW_INTERVAL_ACTIVE |
| 117 }; | 110 }; |
| 118 | 111 |
| 119 // Set the TickClock. This is only to be used by tests that need to | 112 // Set the TickClock. This is only to be used by tests that need to |
| 120 // artificially and deterministically control the current time. | 113 // artificially and deterministically control the current time. |
| 121 void SetTickClockForTest(std::unique_ptr<base::TickClock> tick_clock); | 114 void SetTickClockForTest(std::unique_ptr<base::TickClock> tick_clock); |
| 122 | 115 |
| 123 #if defined(OS_CHROMEOS) | |
| 124 // Detect hinge rotation from base and lid accelerometers and automatically | 116 // Detect hinge rotation from base and lid accelerometers and automatically |
| 125 // start / stop maximize mode. | 117 // start / stop maximize mode. |
| 126 void HandleHingeRotation( | 118 void HandleHingeRotation( |
| 127 scoped_refptr<const chromeos::AccelerometerUpdate> update); | 119 scoped_refptr<const chromeos::AccelerometerUpdate> update); |
| 128 #endif | |
| 129 | 120 |
| 130 // Returns true if the lid was recently opened. | 121 // Returns true if the lid was recently opened. |
| 131 bool WasLidOpenedRecently() const; | 122 bool WasLidOpenedRecently() const; |
| 132 | 123 |
| 133 // Enables MaximizeModeWindowManager, and determines the current state of | 124 // Enables MaximizeModeWindowManager, and determines the current state of |
| 134 // rotation lock. | 125 // rotation lock. |
| 135 void EnterMaximizeMode(); | 126 void EnterMaximizeMode(); |
| 136 | 127 |
| 137 // Removes MaximizeModeWindowManager and resets the display rotation if there | 128 // Removes MaximizeModeWindowManager and resets the display rotation if there |
| 138 // is no rotation lock. | 129 // is no rotation lock. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 168 base::TimeDelta total_non_touchview_time_; | 159 base::TimeDelta total_non_touchview_time_; |
| 169 | 160 |
| 170 // Tracks the last time we received a lid open event. This is used to suppress | 161 // Tracks the last time we received a lid open event. This is used to suppress |
| 171 // erroneous accelerometer readings as the lid is opened but the accelerometer | 162 // erroneous accelerometer readings as the lid is opened but the accelerometer |
| 172 // reports readings that make the lid to appear near fully open. | 163 // reports readings that make the lid to appear near fully open. |
| 173 base::TimeTicks last_lid_open_time_; | 164 base::TimeTicks last_lid_open_time_; |
| 174 | 165 |
| 175 // Source for the current time in base::TimeTicks. | 166 // Source for the current time in base::TimeTicks. |
| 176 std::unique_ptr<base::TickClock> tick_clock_; | 167 std::unique_ptr<base::TickClock> tick_clock_; |
| 177 | 168 |
| 178 #if defined(OS_CHROMEOS) | |
| 179 // Set when tablet mode switch is on. This is used to force maximize mode. | 169 // Set when tablet mode switch is on. This is used to force maximize mode. |
| 180 bool tablet_mode_switch_is_on_; | 170 bool tablet_mode_switch_is_on_; |
| 181 #endif | |
| 182 | 171 |
| 183 // Tracks when the lid is closed. Used to prevent entering maximize mode. | 172 // Tracks when the lid is closed. Used to prevent entering maximize mode. |
| 184 bool lid_is_closed_; | 173 bool lid_is_closed_; |
| 185 | 174 |
| 186 // Tracks smoothed accelerometer data over time. This is done when the hinge | 175 // Tracks smoothed accelerometer data over time. This is done when the hinge |
| 187 // is approaching vertical to remove abrupt acceleration that can lead to | 176 // is approaching vertical to remove abrupt acceleration that can lead to |
| 188 // incorrect calculations of hinge angles. | 177 // incorrect calculations of hinge angles. |
| 189 gfx::Vector3dF base_smoothed_; | 178 gfx::Vector3dF base_smoothed_; |
| 190 gfx::Vector3dF lid_smoothed_; | 179 gfx::Vector3dF lid_smoothed_; |
| 191 | 180 |
| 192 // Bindings for the TouchViewManager interface. | 181 // Bindings for the TouchViewManager interface. |
| 193 mojo::BindingSet<mojom::TouchViewManager> bindings_; | 182 mojo::BindingSet<mojom::TouchViewManager> bindings_; |
| 194 | 183 |
| 195 // The set of touchview observers to be notified about mode changes. | 184 // The set of touchview observers to be notified about mode changes. |
| 196 mojo::InterfacePtrSet<mojom::TouchViewObserver> observers_; | 185 mojo::InterfacePtrSet<mojom::TouchViewObserver> observers_; |
| 197 | 186 |
| 198 DISALLOW_COPY_AND_ASSIGN(MaximizeModeController); | 187 DISALLOW_COPY_AND_ASSIGN(MaximizeModeController); |
| 199 }; | 188 }; |
| 200 | 189 |
| 201 } // namespace ash | 190 } // namespace ash |
| 202 | 191 |
| 203 #endif // ASH_COMMON_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_ | 192 #endif // ASH_COMMON_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_ |
| OLD | NEW |