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/bind.h" |
| 12 #include "base/strings/stringprintf.h" |
| 13 #include "base/thread_task_runner_handle.h" |
10 #include "ui/events/ozone/evdev/event_factory_evdev.h" | 14 #include "ui/events/ozone/evdev/event_factory_evdev.h" |
11 #include "ui/events/ozone/evdev/mouse_button_map_evdev.h" | 15 #include "ui/events/ozone/evdev/mouse_button_map_evdev.h" |
12 | 16 |
13 #if defined(USE_EVDEV_GESTURES) | 17 #if defined(USE_EVDEV_GESTURES) |
14 #include "ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h" | 18 #include "ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h" |
15 #endif | 19 #endif |
16 | 20 |
17 namespace ui { | 21 namespace ui { |
18 | 22 |
19 namespace { | 23 namespace { |
(...skipping 13 matching lines...) Expand all Loading... |
33 void SetGestureBoolProperty(GesturePropertyProvider* provider, | 37 void SetGestureBoolProperty(GesturePropertyProvider* provider, |
34 int id, | 38 int id, |
35 const std::string& name, | 39 const std::string& name, |
36 bool value) { | 40 bool value) { |
37 GesturesProp* property = provider->GetProperty(id, name); | 41 GesturesProp* property = provider->GetProperty(id, name); |
38 if (property) { | 42 if (property) { |
39 std::vector<bool> values(1, value); | 43 std::vector<bool> values(1, value); |
40 property->SetBoolValue(values); | 44 property->SetBoolValue(values); |
41 } | 45 } |
42 } | 46 } |
| 47 |
| 48 // Return the values in an array in one string. Used for touch logging. |
| 49 template <typename T> |
| 50 std::string DumpArrayProperty(const std::vector<T>& value, const char* format) { |
| 51 std::string ret; |
| 52 for (size_t i = 0; i < value.size(); ++i) { |
| 53 if (i > 0) |
| 54 ret.append(", "); |
| 55 ret.append(base::StringPrintf(format, value[i])); |
| 56 } |
| 57 return ret; |
| 58 } |
| 59 |
| 60 // Return the values in a gesture property in one string. Used for touch |
| 61 // logging. |
| 62 std::string DumpGesturePropertyValue(GesturesProp* property) { |
| 63 switch (property->type()) { |
| 64 case GesturePropertyProvider::PT_INT: |
| 65 return DumpArrayProperty(property->GetIntValue(), "%d"); |
| 66 break; |
| 67 case GesturePropertyProvider::PT_SHORT: |
| 68 return DumpArrayProperty(property->GetShortValue(), "%d"); |
| 69 break; |
| 70 case GesturePropertyProvider::PT_BOOL: |
| 71 return DumpArrayProperty(property->GetBoolValue(), "%d"); |
| 72 break; |
| 73 case GesturePropertyProvider::PT_STRING: |
| 74 return "\"" + property->GetStringValue() + "\""; |
| 75 break; |
| 76 case GesturePropertyProvider::PT_REAL: |
| 77 return DumpArrayProperty(property->GetDoubleValue(), "%lf"); |
| 78 break; |
| 79 default: |
| 80 NOTREACHED(); |
| 81 break; |
| 82 } |
| 83 return std::string(); |
| 84 } |
| 85 |
| 86 // Dump touch device property values to a string. |
| 87 void DumpTouchDeviceStatus(EventFactoryEvdev* event_factory, |
| 88 GesturePropertyProvider* provider, |
| 89 std::string* status) { |
| 90 // We use DT_ALL since we want gesture property values for all devices that |
| 91 // run with the gesture library, not just mice or touchpads. |
| 92 std::vector<int> ids; |
| 93 event_factory->GetDeviceIdsByType(DT_ALL, &ids); |
| 94 |
| 95 // Dump the property names and values for each device. |
| 96 for (size_t i = 0; i < ids.size(); ++i) { |
| 97 std::vector<std::string> names = provider->GetPropertyNamesById(ids[i]); |
| 98 status->append("\n"); |
| 99 status->append(base::StringPrintf("ID %d:\n", ids[i])); |
| 100 status->append(base::StringPrintf( |
| 101 "Device \'%s\':\n", provider->GetDeviceNameById(ids[i]).c_str())); |
| 102 |
| 103 // Note that, unlike X11, we don't maintain the "atom" concept here. |
| 104 // Therefore, the property name indices we output here shouldn't be treated |
| 105 // as unique identifiers of the properties. |
| 106 std::sort(names.begin(), names.end()); |
| 107 for (size_t j = 0; j < names.size(); ++j) { |
| 108 status->append(base::StringPrintf("\t%s (%zu):", names[j].c_str(), j)); |
| 109 GesturesProp* property = provider->GetProperty(ids[i], names[j]); |
| 110 status->append("\t" + DumpGesturePropertyValue(property) + '\n'); |
| 111 } |
| 112 } |
| 113 } |
| 114 |
43 #endif | 115 #endif |
44 | 116 |
45 } // namespace | 117 } // namespace |
46 | 118 |
47 InputControllerEvdev::InputControllerEvdev( | 119 InputControllerEvdev::InputControllerEvdev( |
48 EventFactoryEvdev* event_factory, | 120 EventFactoryEvdev* event_factory, |
49 KeyboardEvdev* keyboard, | 121 KeyboardEvdev* keyboard, |
50 MouseButtonMapEvdev* button_map | 122 MouseButtonMapEvdev* button_map |
51 #if defined(USE_EVDEV_GESTURES) | 123 #if defined(USE_EVDEV_GESTURES) |
52 , | 124 , |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 | 249 |
178 void InputControllerEvdev::SetPrimaryButtonRight(bool right) { | 250 void InputControllerEvdev::SetPrimaryButtonRight(bool right) { |
179 button_map_->UpdateButtonMap(BTN_LEFT, right ? BTN_RIGHT : BTN_LEFT); | 251 button_map_->UpdateButtonMap(BTN_LEFT, right ? BTN_RIGHT : BTN_LEFT); |
180 button_map_->UpdateButtonMap(BTN_RIGHT, right ? BTN_LEFT : BTN_RIGHT); | 252 button_map_->UpdateButtonMap(BTN_RIGHT, right ? BTN_LEFT : BTN_RIGHT); |
181 } | 253 } |
182 | 254 |
183 void InputControllerEvdev::SetTapToClickPaused(bool state) { | 255 void InputControllerEvdev::SetTapToClickPaused(bool state) { |
184 SetBoolPropertyForOneType(DT_TOUCHPAD, "Tap Paused", state); | 256 SetBoolPropertyForOneType(DT_TOUCHPAD, "Tap Paused", state); |
185 } | 257 } |
186 | 258 |
| 259 void InputControllerEvdev::GetTouchDeviceStatus( |
| 260 const GetTouchDeviceStatusReply& reply) { |
| 261 scoped_ptr<std::string> status(new std::string); |
| 262 #if defined(USE_EVDEV_GESTURES) |
| 263 std::string* status_ptr = status.get(); |
| 264 base::ThreadTaskRunnerHandle::Get()->PostTaskAndReply( |
| 265 FROM_HERE, base::Bind(&DumpTouchDeviceStatus, event_factory_, |
| 266 gesture_property_provider_, status_ptr), |
| 267 base::Bind(reply, base::Passed(&status))); |
| 268 #else |
| 269 reply.Run(status.Pass()); |
| 270 #endif |
| 271 } |
| 272 |
187 } // namespace ui | 273 } // namespace ui |
OLD | NEW |