Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Side by Side Diff: ui/events/ozone/evdev/input_device_factory_evdev.cc

Issue 868213002: [PATCH 7/11] ozone: evdev: Move GesturePropertyProvider to InputDeviceFactoryEvdev (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/events/ozone/evdev/input_device_factory_evdev.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_device_factory_evdev.h" 5 #include "ui/events/ozone/evdev/input_device_factory_evdev.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <linux/input.h> 8 #include <linux/input.h>
9 9
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "base/strings/stringprintf.h"
12 #include "base/threading/worker_pool.h" 13 #include "base/threading/worker_pool.h"
13 #include "base/time/time.h" 14 #include "base/time/time.h"
14 #include "ui/events/devices/device_data_manager.h" 15 #include "ui/events/devices/device_data_manager.h"
15 #include "ui/events/devices/device_util_linux.h" 16 #include "ui/events/devices/device_util_linux.h"
16 #include "ui/events/ozone/evdev/event_converter_evdev_impl.h" 17 #include "ui/events/ozone/evdev/event_converter_evdev_impl.h"
17 #include "ui/events/ozone/evdev/event_device_info.h" 18 #include "ui/events/ozone/evdev/event_device_info.h"
18 #include "ui/events/ozone/evdev/tablet_event_converter_evdev.h" 19 #include "ui/events/ozone/evdev/tablet_event_converter_evdev.h"
19 #include "ui/events/ozone/evdev/touch_event_converter_evdev.h" 20 #include "ui/events/ozone/evdev/touch_event_converter_evdev.h"
20 21
21 #if defined(USE_EVDEV_GESTURES) 22 #if defined(USE_EVDEV_GESTURES)
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 #if defined(USE_EVDEV_GESTURES) 56 #if defined(USE_EVDEV_GESTURES)
56 bool UseGesturesLibraryForDevice(const EventDeviceInfo& devinfo) { 57 bool UseGesturesLibraryForDevice(const EventDeviceInfo& devinfo) {
57 if (devinfo.HasTouchpad()) 58 if (devinfo.HasTouchpad())
58 return true; 59 return true;
59 60
60 if (devinfo.HasRelXY()) 61 if (devinfo.HasRelXY())
61 return true; // mouse 62 return true; // mouse
62 63
63 return false; 64 return false;
64 } 65 }
66
67 void SetGestureIntProperty(GesturePropertyProvider* provider,
68 int id,
69 const std::string& name,
70 int value) {
71 GesturesProp* property = provider->GetProperty(id, name);
72 if (property) {
73 std::vector<int> values(1, value);
74 property->SetIntValue(values);
75 }
76 }
77
78 void SetGestureBoolProperty(GesturePropertyProvider* provider,
79 int id,
80 const std::string& name,
81 bool value) {
82 GesturesProp* property = provider->GetProperty(id, name);
83 if (property) {
84 std::vector<bool> values(1, value);
85 property->SetBoolValue(values);
86 }
87 }
88
89 // Return the values in an array in one string. Used for touch logging.
90 template <typename T>
91 std::string DumpArrayProperty(const std::vector<T>& value, const char* format) {
92 std::string ret;
93 for (size_t i = 0; i < value.size(); ++i) {
94 if (i > 0)
95 ret.append(", ");
96 ret.append(base::StringPrintf(format, value[i]));
97 }
98 return ret;
99 }
100
101 // Return the values in a gesture property in one string. Used for touch
102 // logging.
103 std::string DumpGesturePropertyValue(GesturesProp* property) {
104 switch (property->type()) {
105 case GesturePropertyProvider::PT_INT:
106 return DumpArrayProperty(property->GetIntValue(), "%d");
107 break;
108 case GesturePropertyProvider::PT_SHORT:
109 return DumpArrayProperty(property->GetShortValue(), "%d");
110 break;
111 case GesturePropertyProvider::PT_BOOL:
112 return DumpArrayProperty(property->GetBoolValue(), "%d");
113 break;
114 case GesturePropertyProvider::PT_STRING:
115 return "\"" + property->GetStringValue() + "\"";
116 break;
117 case GesturePropertyProvider::PT_REAL:
118 return DumpArrayProperty(property->GetDoubleValue(), "%lf");
119 break;
120 default:
121 NOTREACHED();
122 break;
123 }
124 return std::string();
125 }
126
127 // Dump touch device property values to a string.
128 void DumpTouchDeviceStatus(InputDeviceFactoryEvdev* device_factory,
129 GesturePropertyProvider* provider,
130 std::string* status) {
131 // We use DT_ALL since we want gesture property values for all devices that
132 // run with the gesture library, not just mice or touchpads.
133 std::vector<int> ids;
134 device_factory->GetDeviceIdsByType(DT_ALL, &ids);
135
136 // Dump the property names and values for each device.
137 for (size_t i = 0; i < ids.size(); ++i) {
138 std::vector<std::string> names = provider->GetPropertyNamesById(ids[i]);
139 status->append("\n");
140 status->append(base::StringPrintf("ID %d:\n", ids[i]));
141 status->append(base::StringPrintf(
142 "Device \'%s\':\n", provider->GetDeviceNameById(ids[i]).c_str()));
143
144 // Note that, unlike X11, we don't maintain the "atom" concept here.
145 // Therefore, the property name indices we output here shouldn't be treated
146 // as unique identifiers of the properties.
147 std::sort(names.begin(), names.end());
148 for (size_t j = 0; j < names.size(); ++j) {
149 status->append(base::StringPrintf("\t%s (%zu):", names[j].c_str(), j));
150 GesturesProp* property = provider->GetProperty(ids[i], names[j]);
151 status->append("\t" + DumpGesturePropertyValue(property) + '\n');
152 }
153 }
154 }
65 #endif 155 #endif
66 156
67 scoped_ptr<EventConverterEvdev> CreateConverter( 157 scoped_ptr<EventConverterEvdev> CreateConverter(
68 const OpenInputDeviceParams& params, 158 const OpenInputDeviceParams& params,
69 int fd, 159 int fd,
70 InputDeviceType type, 160 InputDeviceType type,
71 const EventDeviceInfo& devinfo) { 161 const EventDeviceInfo& devinfo) {
72 #if defined(USE_EVDEV_GESTURES) 162 #if defined(USE_EVDEV_GESTURES)
73 // Touchpad or mouse: use gestures library. 163 // Touchpad or mouse: use gestures library.
74 // EventReaderLibevdevCros -> GestureInterpreterLibevdevCros -> DispatchEvent 164 // EventReaderLibevdevCros -> GestureInterpreterLibevdevCros -> DispatchEvent
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 scoped_ptr<EventConverterEvdev> converter) { 242 scoped_ptr<EventConverterEvdev> converter) {
153 TRACE_EVENT1("ozone", "CloseInputDevice", "path", path.value()); 243 TRACE_EVENT1("ozone", "CloseInputDevice", "path", path.value());
154 converter.reset(); 244 converter.reset();
155 } 245 }
156 246
157 } // namespace 247 } // namespace
158 248
159 InputDeviceFactoryEvdev::InputDeviceFactoryEvdev( 249 InputDeviceFactoryEvdev::InputDeviceFactoryEvdev(
160 DeviceEventDispatcherEvdev* dispatcher, 250 DeviceEventDispatcherEvdev* dispatcher,
161 scoped_refptr<base::SingleThreadTaskRunner> dispatch_runner, 251 scoped_refptr<base::SingleThreadTaskRunner> dispatch_runner,
162 #if defined(USE_EVDEV_GESTURES)
163 GesturePropertyProvider* gesture_property_provider,
164 #endif
165 CursorDelegateEvdev* cursor) 252 CursorDelegateEvdev* cursor)
166 : ui_task_runner_(dispatch_runner), 253 : ui_task_runner_(dispatch_runner),
167 cursor_(cursor), 254 cursor_(cursor),
168 #if defined(USE_EVDEV_GESTURES) 255 #if defined(USE_EVDEV_GESTURES)
169 gesture_property_provider_(gesture_property_provider), 256 gesture_property_provider_(new GesturePropertyProvider),
170 #endif 257 #endif
171 dispatcher_(dispatcher), 258 dispatcher_(dispatcher),
172 weak_ptr_factory_(this) { 259 weak_ptr_factory_(this) {
173 } 260 }
174 261
175 InputDeviceFactoryEvdev::~InputDeviceFactoryEvdev() { 262 InputDeviceFactoryEvdev::~InputDeviceFactoryEvdev() {
176 STLDeleteValues(&converters_); 263 STLDeleteValues(&converters_);
177 } 264 }
178 265
179 void InputDeviceFactoryEvdev::AddInputDevice(int id, 266 void InputDeviceFactoryEvdev::AddInputDevice(int id,
180 const base::FilePath& path) { 267 const base::FilePath& path) {
181 scoped_ptr<OpenInputDeviceParams> params(new OpenInputDeviceParams); 268 scoped_ptr<OpenInputDeviceParams> params(new OpenInputDeviceParams);
182 params->id = id; 269 params->id = id;
183 params->path = path; 270 params->path = path;
184 params->cursor = cursor_; 271 params->cursor = cursor_;
185 params->dispatcher = dispatcher_; 272 params->dispatcher = dispatcher_;
186 273
187 #if defined(USE_EVDEV_GESTURES) 274 #if defined(USE_EVDEV_GESTURES)
188 params->gesture_property_provider = gesture_property_provider_; 275 params->gesture_property_provider = gesture_property_provider_.get();
189 #endif 276 #endif
190 277
191 OpenInputDeviceReplyCallback reply_callback = 278 OpenInputDeviceReplyCallback reply_callback =
192 base::Bind(&InputDeviceFactoryEvdev::AttachInputDevice, 279 base::Bind(&InputDeviceFactoryEvdev::AttachInputDevice,
193 weak_ptr_factory_.GetWeakPtr()); 280 weak_ptr_factory_.GetWeakPtr());
194 281
195 // Dispatch task to open from the worker pool, since open may block. 282 // Dispatch task to open from the worker pool, since open may block.
196 base::WorkerPool::PostTask(FROM_HERE, 283 base::WorkerPool::PostTask(FROM_HERE,
197 base::Bind(&OpenInputDevice, base::Passed(&params), 284 base::Bind(&OpenInputDevice, base::Passed(&params),
198 ui_task_runner_, reply_callback), 285 ui_task_runner_, reply_callback),
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 void InputDeviceFactoryEvdev::EnableInternalKeyboard() { 367 void InputDeviceFactoryEvdev::EnableInternalKeyboard() {
281 for (const auto& it : converters_) { 368 for (const auto& it : converters_) {
282 EventConverterEvdev* converter = it.second; 369 EventConverterEvdev* converter = it.second;
283 if (converter->type() == InputDeviceType::INPUT_DEVICE_INTERNAL && 370 if (converter->type() == InputDeviceType::INPUT_DEVICE_INTERNAL &&
284 converter->HasKeyboard()) { 371 converter->HasKeyboard()) {
285 converter->AllowAllKeys(); 372 converter->AllowAllKeys();
286 } 373 }
287 } 374 }
288 } 375 }
289 376
377 bool InputDeviceFactoryEvdev::HasMouse() {
378 return GetDeviceIdsByType(DT_MOUSE, NULL);
379 }
380
381 bool InputDeviceFactoryEvdev::HasTouchpad() {
382 return GetDeviceIdsByType(DT_TOUCHPAD, NULL);
383 }
384
385 void InputDeviceFactoryEvdev::SetTouchpadSensitivity(int value) {
386 SetIntPropertyForOneType(DT_TOUCHPAD, "Pointer Sensitivity", value);
387 SetIntPropertyForOneType(DT_TOUCHPAD, "Scroll Sensitivity", value);
388 }
389
390 void InputDeviceFactoryEvdev::SetTapToClick(bool enabled) {
391 SetBoolPropertyForOneType(DT_TOUCHPAD, "Tap Enable", enabled);
392 }
393
394 void InputDeviceFactoryEvdev::SetThreeFingerClick(bool enabled) {
395 SetBoolPropertyForOneType(DT_TOUCHPAD, "T5R2 Three Finger Click Enable",
396 enabled);
397 }
398
399 void InputDeviceFactoryEvdev::SetTapDragging(bool enabled) {
400 SetBoolPropertyForOneType(DT_TOUCHPAD, "Tap Drag Enable", enabled);
401 }
402
403 void InputDeviceFactoryEvdev::SetNaturalScroll(bool enabled) {
404 SetBoolPropertyForOneType(DT_MULTITOUCH, "Australian Scrolling", enabled);
405 }
406
407 void InputDeviceFactoryEvdev::SetMouseSensitivity(int value) {
408 SetIntPropertyForOneType(DT_MOUSE, "Pointer Sensitivity", value);
409 SetIntPropertyForOneType(DT_MOUSE, "Scroll Sensitivity", value);
410 }
411
412 void InputDeviceFactoryEvdev::SetTapToClickPaused(bool state) {
413 SetBoolPropertyForOneType(DT_TOUCHPAD, "Tap Paused", state);
414 }
415
416 void InputDeviceFactoryEvdev::GetTouchDeviceStatus(
417 const GetTouchDeviceStatusReply& reply) {
418 scoped_ptr<std::string> status(new std::string);
419 #if defined(USE_EVDEV_GESTURES)
420 DumpTouchDeviceStatus(this, gesture_property_provider_.get(), status.get());
421 #endif
422 reply.Run(status.Pass());
423 }
424
290 void InputDeviceFactoryEvdev::NotifyDeviceChange( 425 void InputDeviceFactoryEvdev::NotifyDeviceChange(
291 const EventConverterEvdev& converter) { 426 const EventConverterEvdev& converter) {
292 if (converter.HasTouchscreen()) 427 if (converter.HasTouchscreen())
293 NotifyTouchscreensUpdated(); 428 NotifyTouchscreensUpdated();
294 429
295 if (converter.HasKeyboard()) 430 if (converter.HasKeyboard())
296 NotifyKeyboardsUpdated(); 431 NotifyKeyboardsUpdated();
297 } 432 }
298 433
299 void InputDeviceFactoryEvdev::NotifyTouchscreensUpdated() { 434 void InputDeviceFactoryEvdev::NotifyTouchscreensUpdated() {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 // Ask GesturePropertyProvider for matching devices. 471 // Ask GesturePropertyProvider for matching devices.
337 gesture_property_provider_->GetDeviceIdsByType(type, &ids); 472 gesture_property_provider_->GetDeviceIdsByType(type, &ids);
338 #endif 473 #endif
339 // In the future we can add other device matching logics here. 474 // In the future we can add other device matching logics here.
340 475
341 if (device_ids) 476 if (device_ids)
342 device_ids->assign(ids.begin(), ids.end()); 477 device_ids->assign(ids.begin(), ids.end());
343 return !ids.empty(); 478 return !ids.empty();
344 } 479 }
345 480
481 void InputDeviceFactoryEvdev::SetIntPropertyForOneType(
482 const EventDeviceType type,
483 const std::string& name,
484 int value) {
485 #if defined(USE_EVDEV_GESTURES)
486 std::vector<int> ids;
487 gesture_property_provider_->GetDeviceIdsByType(type, &ids);
488 for (size_t i = 0; i < ids.size(); ++i) {
489 SetGestureIntProperty(gesture_property_provider_.get(), ids[i], name,
490 value);
491 }
492 #endif
493 // In the future, we may add property setting codes for other non-gesture
494 // devices. One example would be keyboard settings.
495 // TODO(sheckylin): See http://crbug.com/398518 for example.
496 }
497
498 void InputDeviceFactoryEvdev::SetBoolPropertyForOneType(
499 const EventDeviceType type,
500 const std::string& name,
501 bool value) {
502 #if defined(USE_EVDEV_GESTURES)
503 std::vector<int> ids;
504 gesture_property_provider_->GetDeviceIdsByType(type, &ids);
505 for (size_t i = 0; i < ids.size(); ++i) {
506 SetGestureBoolProperty(gesture_property_provider_.get(), ids[i], name,
507 value);
508 }
509 #endif
510 }
511
346 } // namespace ui 512 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/ozone/evdev/input_device_factory_evdev.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698