Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / chromeos / system / input_device_settings.h
blobba938a13d1256af7700ec17edbc673a0c03a56de
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 <string>
9 #include <vector>
11 #include "base/callback.h"
12 #include "base/logging.h"
14 namespace chromeos {
15 namespace system {
17 namespace internal {
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
21 // time.
22 template <typename T>
23 class Optional {
24 public:
25 Optional()
26 : value_(),
27 is_set_(false) {
30 Optional& operator=(const Optional& other) {
31 if (&other != this) {
32 value_ = other.value_;
33 is_set_ = other.is_set_;
35 return *this;
38 void Set(const T& value) {
39 is_set_ = true;
40 value_ = value;
43 bool is_set() const {
44 return is_set_;
47 T value() const {
48 DCHECK(is_set());
49 return value_;
52 // Tries to update |this| with |update|. If |update| is unset or has same
53 // value as |this| method returns false. Otherwise |this| takes value of
54 // |update| and returns true.
55 bool Update(const Optional& update) {
56 if (update.is_set_ && (!is_set_ || value_ != update.value_)) {
57 value_ = update.value_;
58 is_set_ = true;
59 return true;
61 return false;
64 private:
65 T value_;
66 bool is_set_;
69 } // namespace internal
71 // Min/max possible pointer sensitivity values. Defined in CrOS inputcontrol
72 // scripts (see kTpControl/kMouseControl in the source file).
73 const int kMinPointerSensitivity = 1;
74 const int kMaxPointerSensitivity = 5;
76 // Auxiliary class used to update several touchpad settings at a time. User
77 // should set any number of settings and pass object to UpdateTouchpadSettings
78 // method of InputDeviceSettings.
79 // Objects of this class have no default values for settings, so it is error
80 // to call Get* method before calling corresponding Set* method at least
81 // once.
82 class TouchpadSettings {
83 public:
84 TouchpadSettings();
85 TouchpadSettings& operator=(const TouchpadSettings& other);
87 void SetSensitivity(int value);
88 int GetSensitivity() const;
90 void SetTapToClick(bool enabled);
91 bool GetTapToClick() const;
93 void SetThreeFingerClick(bool enabled);
94 bool GetThreeFingerClick() const;
96 void SetTapDragging(bool enabled);
97 bool GetTapDragging() const;
99 void SetNaturalScroll(bool enabled);
100 bool GetNaturalScroll() const;
102 // Updates |this| with |settings|. If at least one setting was updated returns
103 // true.
104 // |argv| is filled with arguments of script, that should be launched in order
105 // to apply update. This argument is optional and could be NULL.
106 bool Update(const TouchpadSettings& settings, std::vector<std::string>* argv);
108 private:
109 internal::Optional<int> sensitivity_;
110 internal::Optional<bool> tap_to_click_;
111 internal::Optional<bool> three_finger_click_;
112 internal::Optional<bool> tap_dragging_;
113 internal::Optional<bool> natural_scroll_;
116 // Auxiliary class used to update several mouse settings at a time. User
117 // should set any number of settings and pass object to UpdateMouseSettings
118 // method of InputDeviceSettings.
119 // Objects of this class have no default values for settings, so it is error
120 // to call Get* method before calling corresponding Set* method at least
121 // once.
122 class MouseSettings {
123 public:
124 MouseSettings();
125 MouseSettings& operator=(const MouseSettings& other);
127 void SetSensitivity(int value);
128 int GetSensitivity() const;
130 void SetPrimaryButtonRight(bool right);
131 bool GetPrimaryButtonRight() const;
133 // Updates |this| with |settings|. If at least one setting was updated returns
134 // true.
135 // |argv| is filled with arguments of script, that should be launched in order
136 // to apply update. This argument is optional and could be NULL.
137 bool Update(const MouseSettings& update, std::vector<std::string>* argv);
139 private:
140 internal::Optional<int> sensitivity_;
141 internal::Optional<bool> primary_button_right_;
144 class InputDeviceSettings {
145 public:
146 typedef base::Callback<void(bool)> DeviceExistsCallback;
148 virtual ~InputDeviceSettings() {}
150 // Returns current instance of InputDeviceSettings.
151 static InputDeviceSettings* Get();
153 // Replaces current instance with |test_settings|. Takes ownership of
154 // |test_settings|. Default implementation could be returned back by passing
155 // NULL to this method.
156 static void SetSettingsForTesting(InputDeviceSettings* test_settings);
158 // Calls |callback| asynchronously after determining if a touchpad is
159 // connected.
160 virtual void TouchpadExists(const DeviceExistsCallback& callback) = 0;
162 // Updates several touchpad settings at a time. Updates only settings that
163 // are set in |settings| object. It is more efficient to use this method to
164 // update several settings then calling Set* methods one by one.
165 virtual void UpdateTouchpadSettings(const TouchpadSettings& settings) = 0;
167 // Sets the touchpad sensitivity in the range [kMinPointerSensitivity,
168 // kMaxPointerSensitivity].
169 virtual void SetTouchpadSensitivity(int value) = 0;
171 // Turns tap to click on/off.
172 virtual void SetTapToClick(bool enabled) = 0;
174 // Switch for three-finger click.
175 virtual void SetThreeFingerClick(bool enabled) = 0;
177 // Turns tap-dragging on/off.
178 virtual void SetTapDragging(bool enabled) = 0;
180 // Turns natural scrolling on/off for all devices except wheel mice
181 virtual void SetNaturalScroll(bool enabled) = 0;
183 // Calls |callback| asynchronously after determining if a mouse is connected.
184 virtual void MouseExists(const DeviceExistsCallback& callback) = 0;
186 // Updates several mouse settings at a time. Updates only settings that
187 // are set in |settings| object. It is more efficient to use this method to
188 // update several settings then calling Set* methods one by one.
189 virtual void UpdateMouseSettings(const MouseSettings& settings) = 0;
191 // Sets the mouse sensitivity in the range [kMinPointerSensitivity,
192 // kMaxPointerSensitivity].
193 virtual void SetMouseSensitivity(int value) = 0;
195 // Sets the primary mouse button to the right button if |right| is true.
196 virtual void SetPrimaryButtonRight(bool right) = 0;
198 // Returns true if UI should implement enhanced keyboard support for cases
199 // where other input devices like mouse are absent.
200 virtual bool ForceKeyboardDrivenUINavigation() = 0;
202 // Reapplies previously set touchpad settings.
203 virtual void ReapplyTouchpadSettings() = 0;
205 // Reapplies previously set mouse settings.
206 virtual void ReapplyMouseSettings() = 0;
209 } // namespace system
210 } // namespace chromeos
212 #endif // CHROME_BROWSER_CHROMEOS_SYSTEM_INPUT_DEVICE_SETTINGS_H_