OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/events/ozone/evdev/input_controller_evdev.h" | 5 #include "ui/events/ozone/evdev/input_controller_evdev.h" |
6 | 6 |
7 #include <algorithm> | |
7 #include <linux/input.h> | 8 #include <linux/input.h> |
8 #include <vector> | 9 #include <vector> |
9 | 10 |
11 #include "base/strings/stringprintf.h" | |
10 #include "ui/events/ozone/evdev/event_factory_evdev.h" | 12 #include "ui/events/ozone/evdev/event_factory_evdev.h" |
11 #include "ui/events/ozone/evdev/mouse_button_map_evdev.h" | 13 #include "ui/events/ozone/evdev/mouse_button_map_evdev.h" |
12 | 14 |
13 #if defined(USE_EVDEV_GESTURES) | 15 #if defined(USE_EVDEV_GESTURES) |
14 #include "ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h" | 16 #include "ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h" |
15 #endif | 17 #endif |
16 | 18 |
17 namespace ui { | 19 namespace ui { |
18 | 20 |
19 namespace { | 21 namespace { |
(...skipping 13 matching lines...) Expand all Loading... | |
33 void SetGestureBoolProperty(GesturePropertyProvider* provider, | 35 void SetGestureBoolProperty(GesturePropertyProvider* provider, |
34 int id, | 36 int id, |
35 const std::string& name, | 37 const std::string& name, |
36 bool value) { | 38 bool value) { |
37 GesturesProp* property = provider->GetProperty(id, name); | 39 GesturesProp* property = provider->GetProperty(id, name); |
38 if (property) { | 40 if (property) { |
39 std::vector<bool> values(1, value); | 41 std::vector<bool> values(1, value); |
40 property->SetBoolValue(values); | 42 property->SetBoolValue(values); |
41 } | 43 } |
42 } | 44 } |
45 | |
achuithb
2015/01/22 20:42:12
Add a function comment
Shecky Lin
2015/01/23 07:46:46
Done.
| |
46 template <typename T> | |
47 std::string DumpArrayProperty(const std::vector<T>& value, const char* format) { | |
48 std::string ret; | |
49 for (size_t i = 0; i < value.size(); ++i) { | |
50 if (i > 0) | |
51 ret.append(", "); | |
52 ret.append(base::StringPrintf(format, value[i])); | |
53 } | |
54 return ret; | |
55 } | |
56 | |
57 std::string DumpGesturePropertyValue(GesturesProp* property) { | |
achuithb
2015/01/22 20:42:12
Add a function comment
Shecky Lin
2015/01/23 07:46:46
Done.
| |
58 switch (property->type()) { | |
59 case GesturePropertyProvider::PT_INT: | |
60 return DumpArrayProperty(property->GetIntValue(), "%d"); | |
61 break; | |
62 case GesturePropertyProvider::PT_SHORT: | |
63 return DumpArrayProperty(property->GetShortValue(), "%d"); | |
64 break; | |
65 case GesturePropertyProvider::PT_BOOL: | |
66 return DumpArrayProperty(property->GetBoolValue(), "%d"); | |
67 break; | |
68 case GesturePropertyProvider::PT_STRING: | |
69 return "\"" + property->GetStringValue() + "\""; | |
70 break; | |
71 case GesturePropertyProvider::PT_REAL: | |
72 return DumpArrayProperty(property->GetDoubleValue(), "%lf"); | |
73 break; | |
74 default: | |
75 NOTREACHED(); | |
76 break; | |
77 } | |
78 return std::string(); | |
79 } | |
80 | |
43 #endif | 81 #endif |
44 | 82 |
45 } // namespace | 83 } // namespace |
46 | 84 |
47 InputControllerEvdev::InputControllerEvdev( | 85 InputControllerEvdev::InputControllerEvdev( |
48 EventFactoryEvdev* event_factory, | 86 EventFactoryEvdev* event_factory, |
49 KeyboardEvdev* keyboard, | 87 KeyboardEvdev* keyboard, |
50 MouseButtonMapEvdev* button_map | 88 MouseButtonMapEvdev* button_map |
51 #if defined(USE_EVDEV_GESTURES) | 89 #if defined(USE_EVDEV_GESTURES) |
52 , | 90 , |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 | 215 |
178 void InputControllerEvdev::SetPrimaryButtonRight(bool right) { | 216 void InputControllerEvdev::SetPrimaryButtonRight(bool right) { |
179 button_map_->UpdateButtonMap(BTN_LEFT, right ? BTN_RIGHT : BTN_LEFT); | 217 button_map_->UpdateButtonMap(BTN_LEFT, right ? BTN_RIGHT : BTN_LEFT); |
180 button_map_->UpdateButtonMap(BTN_RIGHT, right ? BTN_LEFT : BTN_RIGHT); | 218 button_map_->UpdateButtonMap(BTN_RIGHT, right ? BTN_LEFT : BTN_RIGHT); |
181 } | 219 } |
182 | 220 |
183 void InputControllerEvdev::SetTapToClickPaused(bool state) { | 221 void InputControllerEvdev::SetTapToClickPaused(bool state) { |
184 SetBoolPropertyForOneType(DT_TOUCHPAD, "Tap Paused", state); | 222 SetBoolPropertyForOneType(DT_TOUCHPAD, "Tap Paused", state); |
185 } | 223 } |
186 | 224 |
225 std::string InputControllerEvdev::GetGestureDeviceStatus() { | |
226 std::string ret; | |
227 #if defined(USE_EVDEV_GESTURES) | |
228 // We use DT_ALL since we want gesture property values for all devices that | |
229 // run with the gesture library, not just mice or touchpads. | |
230 std::vector<int> ids; | |
231 event_factory_->GetDeviceIdsByType(DT_ALL, &ids); | |
232 | |
233 // Dump the property names and values for each device. | |
234 for (size_t i = 0; i < ids.size(); ++i) { | |
235 std::vector<std::string> names = | |
236 gesture_property_provider_->GetPropertyNamesById(ids[i]); | |
237 ret.append("\n"); | |
238 ret.append(base::StringPrintf("ID %d:\n", ids[i])); | |
239 ret.append(base::StringPrintf( | |
240 "Device \'%s\':\n", | |
241 gesture_property_provider_->GetDeviceNameById(ids[i]).c_str())); | |
242 | |
243 // Note that, unlike X11, we don't maintain the "atom" concept here. | |
244 // Therefore, the property name indices we output here shouldn't be treated | |
245 // as unique identifiers of the properties. | |
246 std::sort(names.begin(), names.end()); | |
247 for (size_t j = 0; j < names.size(); ++j) { | |
248 ret.append(base::StringPrintf("\t%s (%lu):", names[j].c_str(), j)); | |
249 GesturesProp* property = | |
250 gesture_property_provider_->GetProperty(ids[i], names[j]); | |
251 ret.append("\t" + DumpGesturePropertyValue(property) + '\n'); | |
252 } | |
253 } | |
254 #endif | |
255 return ret; | |
256 } | |
257 | |
187 } // namespace ui | 258 } // namespace ui |
OLD | NEW |