blob: 0f853b214db1081cfadf414718e478ac4b5118b9 [file] [log] [blame]
Qiang Xuf1400a362017-09-14 02:28:301// 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 Oshimae3e29b32020-07-07 17:29:1711#include "ash/public/cpp/session/session_observer.h"
Qiang Xu6b7b1842018-03-12 19:00:0812#include "base/callback.h"
Qiang Xuf1400a362017-09-14 02:28:3013
Qiang Xu7e7dd6b2018-03-06 05:27:5114class AccountId;
Qiang Xuf1400a362017-09-14 02:28:3015class PrefChangeRegistrar;
16class PrefRegistrySimple;
17class PrefService;
18
19namespace ash {
20
Jun Mukaic82ae4e72018-04-03 03:08:1321// Different sources for requested touchscreen/touchpad enabled/disabled state.
22enum class TouchDeviceEnabledSource {
Qiang Xuf1400a362017-09-14 02:28:3023 // 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 Cook0ba192bf2017-12-01 20:53:1129// Controls the enabled state of touchpad and touchscreen. Must be initialized
30// after Shell and SessionController.
Qiang Xuf1400a362017-09-14 02:28:3031class ASH_EXPORT TouchDevicesController : public SessionObserver {
32 public:
33 TouchDevicesController();
34 ~TouchDevicesController() override;
35
Ana Salazareb7c25712020-02-03 20:27:2636 static void RegisterProfilePrefs(PrefRegistrySimple* registry, bool for_test);
Qiang Xu7e7dd6b2018-03-06 05:27:5137
Qiang Xuf1400a362017-09-14 02:28:3038 // Toggles the status of touchpad between enabled and disabled.
39 void ToggleTouchpad();
40
Jun Mukaic82ae4e72018-04-03 03:08:1341 // 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 Xuf1400a362017-09-14 02:28:3047 // 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 Mukaic82ae4e72018-04-03 03:08:1350 bool GetTouchscreenEnabled(TouchDeviceEnabledSource source) const;
Qiang Xuf1400a362017-09-14 02:28:3051
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 Mukaic82ae4e72018-04-03 03:08:1355 void SetTouchscreenEnabled(bool enabled, TouchDeviceEnabledSource source);
Qiang Xuf1400a362017-09-14 02:28:3056
James Cook827225bb2018-03-22 19:28:4457 bool tap_dragging_enabled_for_test() { return tap_dragging_enabled_; }
58
Qiang Xuf1400a362017-09-14 02:28:3059 private:
60 // Overridden from SessionObserver:
Qiang Xu7e7dd6b2018-03-06 05:27:5161 void OnUserSessionAdded(const AccountId& account_id) override;
Qiang Xuf1400a362017-09-14 02:28:3062 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 Xu7e7dd6b2018-03-06 05:27:5169 // Updates tap dragging enabled state from prefs.
70 void UpdateTapDraggingEnabled();
71
Qiang Xuf1400a362017-09-14 02:28:3072 // 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 Mukaic82ae4e72018-04-03 03:08:1379 // The internal touchpad state which is associated with the global touch
80 // device enabled source.
81 bool global_touchpad_enabled_ = true;
82
Qiang Xu7e7dd6b2018-03-06 05:27:5183 // Saves the tap dragging enabled state from prefs.
84 bool tap_dragging_enabled_ = false;
85
Jun Mukaic82ae4e72018-04-03 03:08:1386 // The touchscreen state which is associated with the global touch device
Qiang Xuf1400a362017-09-14 02:28:3087 // enabled source.
Daniel Erat37fd6d72017-10-26 19:28:5288 bool global_touchscreen_enabled_ = true;
Qiang Xuf1400a362017-09-14 02:28:3089
90 // Observes user profile prefs for touch devices.
91 std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_;
92
Qiang Xu6b7b1842018-03-12 19:00:0893 // 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 Xu7e7dd6b2018-03-06 05:27:5197
Qiang Xuf1400a362017-09-14 02:28:3098 DISALLOW_COPY_AND_ASSIGN(TouchDevicesController);
99};
100
101} // namespace ash
102
103#endif // ASH_TOUCH_TOUCH_DEVICES_CONTROLLER_H_