Chromium Code Reviews| 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 | |
| 43 #endif | 86 #endif |
| 44 | 87 |
| 88 // Dump touch device property values to a string. | |
| 89 void DumpTouchDeviceStatus(EventFactoryEvdev* event_factory, | |
| 90 #if defined(USE_EVDEV_GESTURES) | |
| 91 GesturePropertyProvider* provider, | |
| 92 #endif | |
| 93 std::string* status) { | |
| 94 #if defined(USE_EVDEV_GESTURES) | |
| 95 // We use DT_ALL since we want gesture property values for all devices that | |
| 96 // run with the gesture library, not just mice or touchpads. | |
| 97 std::vector<int> ids; | |
| 98 event_factory->GetDeviceIdsByType(DT_ALL, &ids); | |
| 99 | |
| 100 // Dump the property names and values for each device. | |
| 101 for (size_t i = 0; i < ids.size(); ++i) { | |
| 102 std::vector<std::string> names = provider->GetPropertyNamesById(ids[i]); | |
| 103 status->append("\n"); | |
| 104 status->append(base::StringPrintf("ID %d:\n", ids[i])); | |
| 105 status->append(base::StringPrintf( | |
| 106 "Device \'%s\':\n", provider->GetDeviceNameById(ids[i]).c_str())); | |
| 107 | |
| 108 // Note that, unlike X11, we don't maintain the "atom" concept here. | |
| 109 // Therefore, the property name indices we output here shouldn't be treated | |
| 110 // as unique identifiers of the properties. | |
| 111 std::sort(names.begin(), names.end()); | |
| 112 for (size_t j = 0; j < names.size(); ++j) { | |
| 113 status->append(base::StringPrintf("\t%s (%lu):", names[j].c_str(), j)); | |
| 114 GesturesProp* property = provider->GetProperty(ids[i], names[j]); | |
| 115 status->append("\t" + DumpGesturePropertyValue(property) + '\n'); | |
| 116 } | |
| 117 } | |
| 118 #endif | |
| 119 } | |
| 120 | |
| 45 } // namespace | 121 } // namespace |
| 46 | 122 |
| 47 InputControllerEvdev::InputControllerEvdev( | 123 InputControllerEvdev::InputControllerEvdev( |
| 48 EventFactoryEvdev* event_factory, | 124 EventFactoryEvdev* event_factory, |
| 49 KeyboardEvdev* keyboard, | 125 KeyboardEvdev* keyboard, |
| 50 MouseButtonMapEvdev* button_map | 126 MouseButtonMapEvdev* button_map |
| 51 #if defined(USE_EVDEV_GESTURES) | 127 #if defined(USE_EVDEV_GESTURES) |
| 52 , | 128 , |
| 53 GesturePropertyProvider* gesture_property_provider | 129 GesturePropertyProvider* gesture_property_provider |
| 54 #endif | 130 #endif |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 | 253 |
| 178 void InputControllerEvdev::SetPrimaryButtonRight(bool right) { | 254 void InputControllerEvdev::SetPrimaryButtonRight(bool right) { |
| 179 button_map_->UpdateButtonMap(BTN_LEFT, right ? BTN_RIGHT : BTN_LEFT); | 255 button_map_->UpdateButtonMap(BTN_LEFT, right ? BTN_RIGHT : BTN_LEFT); |
| 180 button_map_->UpdateButtonMap(BTN_RIGHT, right ? BTN_LEFT : BTN_RIGHT); | 256 button_map_->UpdateButtonMap(BTN_RIGHT, right ? BTN_LEFT : BTN_RIGHT); |
| 181 } | 257 } |
| 182 | 258 |
| 183 void InputControllerEvdev::SetTapToClickPaused(bool state) { | 259 void InputControllerEvdev::SetTapToClickPaused(bool state) { |
| 184 SetBoolPropertyForOneType(DT_TOUCHPAD, "Tap Paused", state); | 260 SetBoolPropertyForOneType(DT_TOUCHPAD, "Tap Paused", state); |
| 185 } | 261 } |
| 186 | 262 |
| 263 void InputControllerEvdev::GetTouchDeviceStatus( | |
| 264 const GetTouchDeviceStatusReply& reply) { | |
| 265 scoped_ptr<std::string> status(new std::string); | |
| 266 std::string* status_ptr = status.get(); | |
|
spang
2015/01/28 00:50:47
Probably better to do something like:
#if defined
Shecky Lin
2015/01/28 01:02:00
Done.
| |
| 267 base::ThreadTaskRunnerHandle::Get()->PostTaskAndReply( | |
| 268 FROM_HERE, base::Bind(&DumpTouchDeviceStatus, event_factory_, | |
| 269 #if defined(USE_EVDEV_GESTURES) | |
| 270 gesture_property_provider_, | |
| 271 #endif | |
| 272 status_ptr), | |
| 273 base::Bind(reply, base::Passed(&status))); | |
| 274 } | |
| 275 | |
| 187 } // namespace ui | 276 } // namespace ui |
| OLD | NEW |