Qiang Xu | f1400a36 | 2017-09-14 02:28:30 | [diff] [blame] | 1 | // Copyright 2017 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_TOUCH_TOUCH_DEVICES_CONTROLLER_H_ |
| 6 | #define ASH_TOUCH_TOUCH_DEVICES_CONTROLLER_H_ |
| 7 | |
| 8 | #include <memory> |
| 9 | |
| 10 | #include "ash/ash_export.h" |
Mitsuru Oshima | e3e29b3 | 2020-07-07 17:29:17 | [diff] [blame] | 11 | #include "ash/public/cpp/session/session_observer.h" |
Qiang Xu | 6b7b184 | 2018-03-12 19:00:08 | [diff] [blame] | 12 | #include "base/callback.h" |
Qiang Xu | f1400a36 | 2017-09-14 02:28:30 | [diff] [blame] | 13 | |
Qiang Xu | 7e7dd6b | 2018-03-06 05:27:51 | [diff] [blame] | 14 | class AccountId; |
Qiang Xu | f1400a36 | 2017-09-14 02:28:30 | [diff] [blame] | 15 | class PrefChangeRegistrar; |
| 16 | class PrefRegistrySimple; |
| 17 | class PrefService; |
| 18 | |
| 19 | namespace ash { |
| 20 | |
Jun Mukai | c82ae4e7 | 2018-04-03 03:08:13 | [diff] [blame] | 21 | // Different sources for requested touchscreen/touchpad enabled/disabled state. |
| 22 | enum class TouchDeviceEnabledSource { |
Qiang Xu | f1400a36 | 2017-09-14 02:28:30 | [diff] [blame] | 23 | // User-requested state set via a debug accelerator and stored in a pref. |
| 24 | USER_PREF, |
| 25 | // Transient global state used to disable touchscreen via power button. |
| 26 | GLOBAL, |
| 27 | }; |
| 28 | |
James Cook | 0ba192bf | 2017-12-01 20:53:11 | [diff] [blame] | 29 | // Controls the enabled state of touchpad and touchscreen. Must be initialized |
| 30 | // after Shell and SessionController. |
Qiang Xu | f1400a36 | 2017-09-14 02:28:30 | [diff] [blame] | 31 | class ASH_EXPORT TouchDevicesController : public SessionObserver { |
| 32 | public: |
| 33 | TouchDevicesController(); |
| 34 | ~TouchDevicesController() override; |
| 35 | |
Ana Salazar | eb7c2571 | 2020-02-03 20:27:26 | [diff] [blame] | 36 | static void RegisterProfilePrefs(PrefRegistrySimple* registry, bool for_test); |
Qiang Xu | 7e7dd6b | 2018-03-06 05:27:51 | [diff] [blame] | 37 | |
Qiang Xu | f1400a36 | 2017-09-14 02:28:30 | [diff] [blame] | 38 | // Toggles the status of touchpad between enabled and disabled. |
| 39 | void ToggleTouchpad(); |
| 40 | |
Jun Mukai | c82ae4e7 | 2018-04-03 03:08:13 | [diff] [blame] | 41 | // Returns the current touchpad enabled status as specified by |source|. |
| 42 | bool GetTouchpadEnabled(TouchDeviceEnabledSource source) const; |
| 43 | |
| 44 | // Updates the current touchpad status for |source| to |enabled|. |
| 45 | void SetTouchpadEnabled(bool enabled, TouchDeviceEnabledSource source); |
| 46 | |
Qiang Xu | f1400a36 | 2017-09-14 02:28:30 | [diff] [blame] | 47 | // Returns the current touchscreen enabled status as specified by |source|. |
| 48 | // Note that the actual state of the touchscreen device is automatically |
| 49 | // determined based on the requests of multiple sources. |
Jun Mukai | c82ae4e7 | 2018-04-03 03:08:13 | [diff] [blame] | 50 | bool GetTouchscreenEnabled(TouchDeviceEnabledSource source) const; |
Qiang Xu | f1400a36 | 2017-09-14 02:28:30 | [diff] [blame] | 51 | |
| 52 | // Sets |source|'s requested touchscreen enabled status to |enabled|. Note |
| 53 | // that the actual state of the touchscreen device is automatically determined |
| 54 | // based on the requests of multiple sources. |
Jun Mukai | c82ae4e7 | 2018-04-03 03:08:13 | [diff] [blame] | 55 | void SetTouchscreenEnabled(bool enabled, TouchDeviceEnabledSource source); |
Qiang Xu | f1400a36 | 2017-09-14 02:28:30 | [diff] [blame] | 56 | |
James Cook | 827225bb | 2018-03-22 19:28:44 | [diff] [blame] | 57 | bool tap_dragging_enabled_for_test() { return tap_dragging_enabled_; } |
| 58 | |
Qiang Xu | f1400a36 | 2017-09-14 02:28:30 | [diff] [blame] | 59 | private: |
| 60 | // Overridden from SessionObserver: |
Qiang Xu | 7e7dd6b | 2018-03-06 05:27:51 | [diff] [blame] | 61 | void OnUserSessionAdded(const AccountId& account_id) override; |
Qiang Xu | f1400a36 | 2017-09-14 02:28:30 | [diff] [blame] | 62 | void OnSigninScreenPrefServiceInitialized(PrefService* prefs) override; |
| 63 | void OnActiveUserPrefServiceChanged(PrefService* prefs) override; |
| 64 | |
| 65 | // Observes either the signin screen prefs or active user prefs and loads |
| 66 | // initial state. |
| 67 | void ObservePrefs(PrefService* prefs); |
| 68 | |
Qiang Xu | 7e7dd6b | 2018-03-06 05:27:51 | [diff] [blame] | 69 | // Updates tap dragging enabled state from prefs. |
| 70 | void UpdateTapDraggingEnabled(); |
| 71 | |
Qiang Xu | f1400a36 | 2017-09-14 02:28:30 | [diff] [blame] | 72 | // Updates the actual enabled/disabled status of the touchpad. |
| 73 | void UpdateTouchpadEnabled(); |
| 74 | |
| 75 | // Updates the actual enabled/disabled status of the touchscreen. Touchscreen |
| 76 | // is enabled if all the touchscreen enabled sources are enabled. |
| 77 | void UpdateTouchscreenEnabled(); |
| 78 | |
Jun Mukai | c82ae4e7 | 2018-04-03 03:08:13 | [diff] [blame] | 79 | // The internal touchpad state which is associated with the global touch |
| 80 | // device enabled source. |
| 81 | bool global_touchpad_enabled_ = true; |
| 82 | |
Qiang Xu | 7e7dd6b | 2018-03-06 05:27:51 | [diff] [blame] | 83 | // Saves the tap dragging enabled state from prefs. |
| 84 | bool tap_dragging_enabled_ = false; |
| 85 | |
Jun Mukai | c82ae4e7 | 2018-04-03 03:08:13 | [diff] [blame] | 86 | // The touchscreen state which is associated with the global touch device |
Qiang Xu | f1400a36 | 2017-09-14 02:28:30 | [diff] [blame] | 87 | // enabled source. |
Daniel Erat | 37fd6d7 | 2017-10-26 19:28:52 | [diff] [blame] | 88 | bool global_touchscreen_enabled_ = true; |
Qiang Xu | f1400a36 | 2017-09-14 02:28:30 | [diff] [blame] | 89 | |
| 90 | // Observes user profile prefs for touch devices. |
| 91 | std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_; |
| 92 | |
Qiang Xu | 6b7b184 | 2018-03-12 19:00:08 | [diff] [blame] | 93 | // Used to record pref started UMA, bound on user session added and run on |
| 94 | // active user pref service changed. The goal is to record the initial state |
| 95 | // of the feature. |
| 96 | base::OnceCallback<void(PrefService* prefs)> uma_record_callback_; |
Qiang Xu | 7e7dd6b | 2018-03-06 05:27:51 | [diff] [blame] | 97 | |
Qiang Xu | f1400a36 | 2017-09-14 02:28:30 | [diff] [blame] | 98 | DISALLOW_COPY_AND_ASSIGN(TouchDevicesController); |
| 99 | }; |
| 100 | |
| 101 | } // namespace ash |
| 102 | |
| 103 | #endif // ASH_TOUCH_TOUCH_DEVICES_CONTROLLER_H_ |