touch_devices_controller.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. #ifndef ASH_TOUCH_TOUCH_DEVICES_CONTROLLER_H_
  5. #define ASH_TOUCH_TOUCH_DEVICES_CONTROLLER_H_
  6. #include <memory>
  7. #include "ash/ash_export.h"
  8. #include "ash/public/cpp/session/session_observer.h"
  9. #include "base/callback.h"
  10. class AccountId;
  11. class PrefChangeRegistrar;
  12. class PrefRegistrySimple;
  13. class PrefService;
  14. namespace ash {
  15. // Different sources for requested touchscreen/touchpad enabled/disabled state.
  16. enum class TouchDeviceEnabledSource {
  17. // User-requested state set via a debug accelerator and stored in a pref.
  18. USER_PREF,
  19. // Transient global state used to disable touchscreen via power button.
  20. GLOBAL,
  21. };
  22. // Controls the enabled state of touchpad and touchscreen. Must be initialized
  23. // after Shell and SessionController.
  24. class ASH_EXPORT TouchDevicesController : public SessionObserver {
  25. public:
  26. TouchDevicesController();
  27. TouchDevicesController(const TouchDevicesController&) = delete;
  28. TouchDevicesController& operator=(const TouchDevicesController&) = delete;
  29. ~TouchDevicesController() override;
  30. static void RegisterProfilePrefs(PrefRegistrySimple* registry, bool for_test);
  31. // Toggles the status of touchpad between enabled and disabled.
  32. void ToggleTouchpad();
  33. // Returns the current touchpad enabled status as specified by |source|.
  34. bool GetTouchpadEnabled(TouchDeviceEnabledSource source) const;
  35. // Updates the current touchpad status for |source| to |enabled|.
  36. void SetTouchpadEnabled(bool enabled, TouchDeviceEnabledSource source);
  37. // Returns the current touchscreen enabled status as specified by |source|.
  38. // Note that the actual state of the touchscreen device is automatically
  39. // determined based on the requests of multiple sources.
  40. bool GetTouchscreenEnabled(TouchDeviceEnabledSource source) const;
  41. // Sets |source|'s requested touchscreen enabled status to |enabled|. Note
  42. // that the actual state of the touchscreen device is automatically determined
  43. // based on the requests of multiple sources.
  44. void SetTouchscreenEnabled(bool enabled, TouchDeviceEnabledSource source);
  45. bool tap_dragging_enabled_for_test() { return tap_dragging_enabled_; }
  46. private:
  47. // Overridden from SessionObserver:
  48. void OnUserSessionAdded(const AccountId& account_id) override;
  49. void OnSigninScreenPrefServiceInitialized(PrefService* prefs) override;
  50. void OnActiveUserPrefServiceChanged(PrefService* prefs) override;
  51. // Observes either the signin screen prefs or active user prefs and loads
  52. // initial state.
  53. void ObservePrefs(PrefService* prefs);
  54. // Updates tap dragging enabled state from prefs.
  55. void UpdateTapDraggingEnabled();
  56. // Updates the actual enabled/disabled status of the touchpad.
  57. void UpdateTouchpadEnabled();
  58. // Updates the actual enabled/disabled status of the touchscreen. Touchscreen
  59. // is enabled if all the touchscreen enabled sources are enabled.
  60. void UpdateTouchscreenEnabled();
  61. // The internal touchpad state which is associated with the global touch
  62. // device enabled source.
  63. bool global_touchpad_enabled_ = true;
  64. // Saves the tap dragging enabled state from prefs.
  65. bool tap_dragging_enabled_ = false;
  66. // The touchscreen state which is associated with the global touch device
  67. // enabled source.
  68. bool global_touchscreen_enabled_ = true;
  69. // Observes user profile prefs for touch devices.
  70. std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_;
  71. // Used to record pref started UMA, bound on user session added and run on
  72. // active user pref service changed. The goal is to record the initial state
  73. // of the feature.
  74. base::OnceCallback<void(PrefService* prefs)> uma_record_callback_;
  75. };
  76. } // namespace ash
  77. #endif // ASH_TOUCH_TOUCH_DEVICES_CONTROLLER_H_