1 // Copyright (c) 2012 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.
5 #ifndef CHROME_BROWSER_CHROMEOS_SYSTEM_INPUT_DEVICE_SETTINGS_H_
6 #define CHROME_BROWSER_CHROMEOS_SYSTEM_INPUT_DEVICE_SETTINGS_H_
8 #include "base/callback.h"
9 #include "base/logging.h"
10 #include "chromeos/chromeos_export.h"
15 class InputDeviceSettings
;
19 // Objects of this class are intended to store values of type T, but might have
20 // "unset" state. Object will be in "unset" state until Set is called first
25 Optional() : value_(), is_set_(false) {}
27 Optional
& operator=(const Optional
& other
) {
29 value_
= other
.value_
;
30 is_set_
= other
.is_set_
;
35 void Set(const T
& value
) {
40 bool is_set() const { return is_set_
; }
47 // Tries to update |this| with |update|. If |update| is unset or has same
48 // value as |this| method returns false. Otherwise |this| takes value of
49 // |update| and returns true.
50 bool Update(const Optional
& update
) {
51 if (update
.is_set_
&& (!is_set_
|| value_
!= update
.value_
)) {
52 value_
= update
.value_
;
64 } // namespace internal
66 // Min/max possible pointer sensitivity values.
67 const int kMinPointerSensitivity
= 1;
68 const int kMaxPointerSensitivity
= 5;
70 // Auxiliary class used to update several touchpad settings at a time. User
71 // should set any number of settings and pass object to UpdateTouchpadSettings
72 // method of InputDeviceSettings.
73 // Objects of this class have no default values for settings, so it is error
74 // to call Get* method before calling corresponding Set* method at least
76 class TouchpadSettings
{
79 TouchpadSettings
& operator=(const TouchpadSettings
& other
);
81 void SetSensitivity(int value
);
82 int GetSensitivity() const;
83 bool IsSensitivitySet() const;
85 void SetTapToClick(bool enabled
);
86 bool GetTapToClick() const;
87 bool IsTapToClickSet() const;
89 void SetThreeFingerClick(bool enabled
);
90 bool GetThreeFingerClick() const;
91 bool IsThreeFingerClickSet() const;
93 void SetTapDragging(bool enabled
);
94 bool GetTapDragging() const;
95 bool IsTapDraggingSet() const;
97 void SetNaturalScroll(bool enabled
);
98 bool GetNaturalScroll() const;
99 bool IsNaturalScrollSet() const;
101 // Updates |this| with |settings|. If at least one setting was updated returns
103 bool Update(const TouchpadSettings
& settings
);
105 // Apply |settings| to input devices.
106 static void Apply(const TouchpadSettings
& touchpad_settings
,
107 InputDeviceSettings
* input_device_settings
);
110 internal::Optional
<int> sensitivity_
;
111 internal::Optional
<bool> tap_to_click_
;
112 internal::Optional
<bool> three_finger_click_
;
113 internal::Optional
<bool> tap_dragging_
;
114 internal::Optional
<bool> natural_scroll_
;
117 // Auxiliary class used to update several mouse settings at a time. User
118 // should set any number of settings and pass object to UpdateMouseSettings
119 // method of InputDeviceSettings.
120 // Objects of this class have no default values for settings, so it is error
121 // to call Get* method before calling corresponding Set* method at least
123 class MouseSettings
{
126 MouseSettings
& operator=(const MouseSettings
& other
);
128 void SetSensitivity(int value
);
129 int GetSensitivity() const;
130 bool IsSensitivitySet() const;
132 void SetPrimaryButtonRight(bool right
);
133 bool GetPrimaryButtonRight() const;
134 bool IsPrimaryButtonRightSet() const;
136 // Updates |this| with |settings|. If at least one setting was updated returns
138 bool Update(const MouseSettings
& settings
);
140 // Apply |settings| to input devices.
141 static void Apply(const MouseSettings
& mouse_settings
,
142 InputDeviceSettings
* input_device_settings
);
145 internal::Optional
<int> sensitivity_
;
146 internal::Optional
<bool> primary_button_right_
;
149 // Interface for configuring input device settings.
150 class CHROMEOS_EXPORT InputDeviceSettings
{
152 typedef base::Callback
<void(bool)> DeviceExistsCallback
;
154 virtual ~InputDeviceSettings() {}
156 // Returns current instance of InputDeviceSettings.
157 static InputDeviceSettings
* Get();
159 // Replaces current instance with |test_settings|. Takes ownership of
160 // |test_settings|. Default implementation could be returned back by passing
161 // NULL to this method.
162 static void SetSettingsForTesting(InputDeviceSettings
* test_settings
);
164 // Returns true if UI should implement enhanced keyboard support for cases
165 // where other input devices like mouse are absent.
166 static bool ForceKeyboardDrivenUINavigation();
168 // Calls |callback| asynchronously after determining if a touchpad is
170 virtual void TouchpadExists(const DeviceExistsCallback
& callback
) = 0;
172 // Updates several touchpad settings at a time. Updates only settings that
173 // are set in |settings| object. It is more efficient to use this method to
174 // update several settings then calling Set* methods one by one.
175 virtual void UpdateTouchpadSettings(const TouchpadSettings
& settings
) = 0;
177 // Sets the touchpad sensitivity in the range [kMinPointerSensitivity,
178 // kMaxPointerSensitivity].
179 virtual void SetTouchpadSensitivity(int value
) = 0;
181 // Turns tap to click on/off.
182 virtual void SetTapToClick(bool enabled
) = 0;
184 // Switch for three-finger click.
185 virtual void SetThreeFingerClick(bool enabled
) = 0;
187 // Turns tap-dragging on/off.
188 virtual void SetTapDragging(bool enabled
) = 0;
190 // Turns natural scrolling on/off for all devices except wheel mice
191 virtual void SetNaturalScroll(bool enabled
) = 0;
193 // Calls |callback| asynchronously after determining if a mouse is connected.
194 virtual void MouseExists(const DeviceExistsCallback
& callback
) = 0;
196 // Updates several mouse settings at a time. Updates only settings that
197 // are set in |settings| object. It is more efficient to use this method to
198 // update several settings then calling Set* methods one by one.
199 virtual void UpdateMouseSettings(const MouseSettings
& settings
) = 0;
201 // Sets the mouse sensitivity in the range [kMinPointerSensitivity,
202 // kMaxPointerSensitivity].
203 virtual void SetMouseSensitivity(int value
) = 0;
205 // Sets the primary mouse button to the right button if |right| is true.
206 virtual void SetPrimaryButtonRight(bool right
) = 0;
208 // Reapplies previously set touchpad settings.
209 virtual void ReapplyTouchpadSettings() = 0;
211 // Reapplies previously set mouse settings.
212 virtual void ReapplyMouseSettings() = 0;
215 } // namespace system
216 } // namespace chromeos
218 #endif // CHROME_BROWSER_CHROMEOS_SYSTEM_INPUT_DEVICE_SETTINGS_H_