File: input_device_settings.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (336 lines) | stat: -rw-r--r-- 11,843 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_ASH_SYSTEM_INPUT_DEVICE_SETTINGS_H_
#define CHROME_BROWSER_ASH_SYSTEM_INPUT_DEVICE_SETTINGS_H_

#include <optional>

#include "base/functional/callback_forward.h"

namespace ash {
namespace system {

class InputDeviceSettings;

// Sensitivity values; used for both cursor sensitivity and scroll sensitivity.
// Do not change/reuse numbers (used for IPC calls and metrics).
enum class PointerSensitivity {
  kLowest = 1,
  kLow = 2,
  kMedium = 3,
  kHigh = 4,
  kHighest = 5,
  kMaxValue = kHighest,
};

// Auxiliary class used to update several touchpad settings at a time. User
// should set any number of settings and pass object to UpdateTouchpadSettings
// method of InputDeviceSettings.
// Objects of this class have no default values for settings, so it is error
// to call Get* method before calling corresponding Set* method at least
// once.
class TouchpadSettings {
 public:
  TouchpadSettings();
  TouchpadSettings(const TouchpadSettings& other);
  TouchpadSettings& operator=(const TouchpadSettings& other);

  void SetSensitivity(int value);
  int GetSensitivity() const;
  bool IsSensitivitySet() const;

  void SetTapToClick(bool enabled);
  bool GetTapToClick() const;
  bool IsTapToClickSet() const;

  void SetThreeFingerClick(bool enabled);
  bool GetThreeFingerClick() const;
  bool IsThreeFingerClickSet() const;

  void SetTapDragging(bool enabled);
  bool GetTapDragging() const;
  bool IsTapDraggingSet() const;

  void SetAcceleration(bool enabled);
  bool GetAcceleration() const;
  bool IsAccelerationSet() const;

  void SetNaturalScroll(bool enabled);
  bool GetNaturalScroll() const;
  bool IsNaturalScrollSet() const;

  void SetScrollSensitivity(int value);
  int GetScrollSensitivity() const;
  bool IsScrollSensitivitySet() const;

  void SetScrollAcceleration(bool enabled);
  bool GetScrollAcceleration() const;
  bool IsScrollAccelerationSet() const;

  void SetHapticFeedback(bool enabled);
  bool GetHapticFeedback() const;
  bool IsHapticFeedbackSet() const;

  void SetHapticClickSensitivity(int value);
  int GetHapticClickSensitivity() const;
  bool IsHapticClickSensitivitySet() const;

  // Updates |this| with |settings|. If at least one setting was updated returns
  // true.
  bool Update(const TouchpadSettings& settings);

  // Apply |settings| to input devices.
  static void Apply(const TouchpadSettings& touchpad_settings,
                    InputDeviceSettings* input_device_settings);

 private:
  std::optional<bool> acceleration_;
  std::optional<bool> haptic_feedback_;
  std::optional<int> haptic_click_sensitivity_;
  std::optional<bool> natural_scroll_;
  std::optional<int> sensitivity_;
  std::optional<bool> scroll_acceleration_;
  std::optional<int> scroll_sensitivity_;
  std::optional<bool> tap_dragging_;
  std::optional<bool> tap_to_click_;
  std::optional<bool> three_finger_click_;
};

// Auxiliary class used to update several mouse settings at a time. User
// should set any number of settings and pass object to UpdateMouseSettings
// method of InputDeviceSettings.
// Objects of this class have no default values for settings, so it is error
// to call Get* method before calling corresponding Set* method at least
// once.
class MouseSettings {
 public:
  MouseSettings();
  MouseSettings(const MouseSettings& other);
  MouseSettings& operator=(const MouseSettings& other);

  void SetSensitivity(int value);
  int GetSensitivity() const;
  bool IsSensitivitySet() const;

  void SetPrimaryButtonRight(bool right);
  bool GetPrimaryButtonRight() const;
  bool IsPrimaryButtonRightSet() const;

  void SetAcceleration(bool enabled);
  bool GetAcceleration() const;
  bool IsAccelerationSet() const;

  void SetReverseScroll(bool enabled);
  bool GetReverseScroll() const;
  bool IsReverseScrollSet() const;

  void SetScrollSensitivity(int value);
  int GetScrollSensitivity() const;
  bool IsScrollSensitivitySet() const;

  void SetScrollAcceleration(bool enabled);
  bool GetScrollAcceleration() const;
  bool IsScrollAccelerationSet() const;

  // Updates |this| with |settings|. If at least one setting was updated returns
  // true.
  bool Update(const MouseSettings& settings);

  // Apply |settings| to input devices.
  static void Apply(const MouseSettings& mouse_settings,
                    InputDeviceSettings* input_device_settings);

 private:
  std::optional<bool> acceleration_;
  std::optional<bool> primary_button_right_;
  std::optional<bool> reverse_scroll_;
  std::optional<bool> scroll_acceleration_;
  std::optional<int> scroll_sensitivity_;
  std::optional<int> sensitivity_;
};

// Auxiliary class used to update several pointing stick settings at a time.
// User should set any number of settings and pass object to
// UpdatePointingStickSettings method of InputDeviceSettings.
// Objects of this class have no default values for settings, so it is error
// to call Get* method before calling corresponding Set* method at least
// once.
class PointingStickSettings {
 public:
  PointingStickSettings();
  PointingStickSettings(const PointingStickSettings& other);
  PointingStickSettings& operator=(const PointingStickSettings& other);

  void SetSensitivity(int value);
  int GetSensitivity() const;
  bool IsSensitivitySet() const;

  void SetPrimaryButtonRight(bool right);
  bool GetPrimaryButtonRight() const;
  bool IsPrimaryButtonRightSet() const;

  void SetAcceleration(bool enabled);
  bool GetAcceleration() const;
  bool IsAccelerationSet() const;

  // Updates |this| with |settings|. If at least one setting was updated returns
  // true.
  bool Update(const PointingStickSettings& settings);

  // Apply |settings| to input devices.
  static void Apply(const PointingStickSettings& pointing_stick_settings,
                    InputDeviceSettings* input_device_settings);

 private:
  std::optional<bool> acceleration_;
  std::optional<bool> primary_button_right_;
  std::optional<int> sensitivity_;
};

// Interface for configuring input device settings.
class InputDeviceSettings {
 public:
  using DeviceExistsCallback = base::OnceCallback<void(bool)>;

  // Interface for faking touchpad and mouse. Accessed through
  // GetFakeInterface(), implemented only in FakeInputDeviceSettings.
  class FakeInterface {
   public:
    virtual void set_touchpad_exists(bool exists) = 0;
    virtual void set_haptic_touchpad_exists(bool exists) = 0;
    virtual void set_mouse_exists(bool exists) = 0;
    virtual void set_pointing_stick_exists(bool exists) = 0;
    virtual const TouchpadSettings& current_touchpad_settings() const = 0;
    virtual const MouseSettings& current_mouse_settings() const = 0;
    virtual const PointingStickSettings& current_pointing_stick_settings()
        const = 0;
  };

  virtual ~InputDeviceSettings() = default;

  // Returns current instance of InputDeviceSettings.
  static InputDeviceSettings* Get();

  // Returns true if UI should implement enhanced keyboard support for cases
  // where other input devices like mouse are absent.
  static bool ForceKeyboardDrivenUINavigation();

  // Calls |callback|, possibly asynchronously, after determining if a touchpad
  // is connected.
  virtual void TouchpadExists(DeviceExistsCallback callback) = 0;

  // Updates several touchpad settings at a time. Updates only settings that
  // are set in |settings| object. It is more efficient to use this method to
  // update several settings then calling Set* methods one by one.
  virtual void UpdateTouchpadSettings(const TouchpadSettings& settings) = 0;

  // Sets the touchpad sensitivity in the range [kMinPointerSensitivity,
  // kMaxPointerSensitivity].
  virtual void SetTouchpadSensitivity(int value) = 0;

  // Sets the touchpad scroll sensitivity in the range [kMinPointerSensitivity,
  // kMaxPointerSensitivity].
  virtual void SetTouchpadScrollSensitivity(int value) = 0;

  // Calls |callback|, possibly asynchronously, after determining if at least
  // one touchpad that supports haptics is connected.
  virtual void HapticTouchpadExists(DeviceExistsCallback callback) = 0;

  // Turns touchpad haptic feedback on/off.
  virtual void SetTouchpadHapticFeedback(bool enabled) = 0;

  // Sets the touchpad haptic click sensitivity from Soft feedback to Firm
  // feedback [1, 3, 5].
  virtual void SetTouchpadHapticClickSensitivity(int value) = 0;

  // Turns tap to click on/off.
  virtual void SetTapToClick(bool enabled) = 0;

  // Switch for three-finger click.
  virtual void SetThreeFingerClick(bool enabled) = 0;

  // Turns tap-dragging on/off.
  virtual void SetTapDragging(bool enabled) = 0;

  // Turns natural scrolling on/off for all devices except wheel mice
  virtual void SetNaturalScroll(bool enabled) = 0;

  // Calls |callback|, possibly asynchronously, after determining if a mouse is
  // connected.
  virtual void MouseExists(DeviceExistsCallback callback) = 0;

  // Updates several mouse settings at a time. Updates only settings that
  // are set in |settings| object. It is more efficient to use this method to
  // update several settings then calling Set* methods one by one.
  virtual void UpdateMouseSettings(const MouseSettings& settings) = 0;

  // Sets the mouse sensitivity in the range [kMinPointerSensitivity,
  // kMaxPointerSensitivity].
  virtual void SetMouseSensitivity(int value) = 0;

  // Sets the mouse scroll sensitivity in the range [kMinPointerSensitivity,
  // kMaxPointerSensitivity].
  virtual void SetMouseScrollSensitivity(int value) = 0;

  // Sets the primary mouse button to the right button if |right| is true.
  virtual void SetPrimaryButtonRight(bool right) = 0;

  // Turns mouse reverse scrolling on/off.
  virtual void SetMouseReverseScroll(bool enabled) = 0;

  // Turns mouse acceleration on/off.
  virtual void SetMouseAcceleration(bool enabled) = 0;

  // Turns mouse scroll acceleration on/off.
  virtual void SetMouseScrollAcceleration(bool enabled) = 0;

  // Calls |callback|, possibly asynchronously, after determining if a pointing
  // stick is connected.
  virtual void PointingStickExists(DeviceExistsCallback callback) = 0;

  // Updates several pointing stick settings at a time. Updates only settings
  // that are set in |settings| object. It is more efficient to use this method
  // to update several settings then calling Set* methods one by one.
  virtual void UpdatePointingStickSettings(
      const PointingStickSettings& settings) = 0;

  // Sets the pointing stick sensitivity in the range [kMinPointerSensitivity,
  // kMaxPointerSensitivity].
  virtual void SetPointingStickSensitivity(int value) = 0;

  // Sets the primary button for the pointing stick to the right button if
  // |right| is true.
  virtual void SetPointingStickPrimaryButtonRight(bool right) = 0;

  // Turns pointing stick acceleration on/off.
  virtual void SetPointingStickAcceleration(bool enabled) = 0;

  // Turns touchpad acceleration on/off.
  virtual void SetTouchpadAcceleration(bool enabled) = 0;

  // Turns touchpad scroll acceleration on/off.
  virtual void SetTouchpadScrollAcceleration(bool enabled) = 0;

  // Reapplies previously set touchpad settings.
  virtual void ReapplyTouchpadSettings() = 0;

  // Reapplies previously set mouse settings.
  virtual void ReapplyMouseSettings() = 0;

  // Reapplies previously set pointing stick settings.
  virtual void ReapplyPointingStickSettings() = 0;

  // Returns an interface for faking settings, or nullptr.
  virtual FakeInterface* GetFakeInterface() = 0;

 private:
  virtual void SetInternalTouchpadEnabled(bool enabled) {}
  virtual void SetTouchscreensEnabled(bool enabled) {}
};

}  // namespace system
}  // namespace ash

#endif  // CHROME_BROWSER_ASH_SYSTEM_INPUT_DEVICE_SETTINGS_H_