| 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> | |
| 8 #include <linux/input.h> | 7 #include <linux/input.h> |
| 9 #include <vector> | 8 #include <vector> |
| 10 | 9 |
| 11 #include "base/bind.h" | |
| 12 #include "base/strings/stringprintf.h" | |
| 13 #include "base/thread_task_runner_handle.h" | |
| 14 #include "ui/events/ozone/evdev/event_factory_evdev.h" | 10 #include "ui/events/ozone/evdev/event_factory_evdev.h" |
| 15 #include "ui/events/ozone/evdev/mouse_button_map_evdev.h" | 11 #include "ui/events/ozone/evdev/mouse_button_map_evdev.h" |
| 16 | 12 |
| 17 #if defined(USE_EVDEV_GESTURES) | 13 #if defined(USE_EVDEV_GESTURES) |
| 18 #include "ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h" | 14 #include "ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h" |
| 19 #endif | 15 #endif |
| 20 | 16 |
| 21 namespace ui { | 17 namespace ui { |
| 22 | 18 |
| 23 namespace { | 19 namespace { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 37 void SetGestureBoolProperty(GesturePropertyProvider* provider, | 33 void SetGestureBoolProperty(GesturePropertyProvider* provider, |
| 38 int id, | 34 int id, |
| 39 const std::string& name, | 35 const std::string& name, |
| 40 bool value) { | 36 bool value) { |
| 41 GesturesProp* property = provider->GetProperty(id, name); | 37 GesturesProp* property = provider->GetProperty(id, name); |
| 42 if (property) { | 38 if (property) { |
| 43 std::vector<bool> values(1, value); | 39 std::vector<bool> values(1, value); |
| 44 property->SetBoolValue(values); | 40 property->SetBoolValue(values); |
| 45 } | 41 } |
| 46 } | 42 } |
| 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 (%lu):", 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 | |
| 115 #endif | 43 #endif |
| 116 | 44 |
| 117 } // namespace | 45 } // namespace |
| 118 | 46 |
| 119 InputControllerEvdev::InputControllerEvdev( | 47 InputControllerEvdev::InputControllerEvdev( |
| 120 EventFactoryEvdev* event_factory, | 48 EventFactoryEvdev* event_factory, |
| 121 KeyboardEvdev* keyboard, | 49 KeyboardEvdev* keyboard, |
| 122 MouseButtonMapEvdev* button_map | 50 MouseButtonMapEvdev* button_map |
| 123 #if defined(USE_EVDEV_GESTURES) | 51 #if defined(USE_EVDEV_GESTURES) |
| 124 , | 52 , |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 | 177 |
| 250 void InputControllerEvdev::SetPrimaryButtonRight(bool right) { | 178 void InputControllerEvdev::SetPrimaryButtonRight(bool right) { |
| 251 button_map_->UpdateButtonMap(BTN_LEFT, right ? BTN_RIGHT : BTN_LEFT); | 179 button_map_->UpdateButtonMap(BTN_LEFT, right ? BTN_RIGHT : BTN_LEFT); |
| 252 button_map_->UpdateButtonMap(BTN_RIGHT, right ? BTN_LEFT : BTN_RIGHT); | 180 button_map_->UpdateButtonMap(BTN_RIGHT, right ? BTN_LEFT : BTN_RIGHT); |
| 253 } | 181 } |
| 254 | 182 |
| 255 void InputControllerEvdev::SetTapToClickPaused(bool state) { | 183 void InputControllerEvdev::SetTapToClickPaused(bool state) { |
| 256 SetBoolPropertyForOneType(DT_TOUCHPAD, "Tap Paused", state); | 184 SetBoolPropertyForOneType(DT_TOUCHPAD, "Tap Paused", state); |
| 257 } | 185 } |
| 258 | 186 |
| 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 | |
| 273 } // namespace ui | 187 } // namespace ui |
| OLD | NEW |