OLD | NEW |
---|---|
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" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 #if defined(USE_EVDEV_GESTURES) | 55 #if defined(USE_EVDEV_GESTURES) |
56 bool UseGesturesLibraryForDevice(const EventDeviceInfo& devinfo) { | 56 bool UseGesturesLibraryForDevice(const EventDeviceInfo& devinfo) { |
57 if (devinfo.HasTouchpad()) | 57 if (devinfo.HasTouchpad()) |
58 return true; | 58 return true; |
59 | 59 |
60 if (devinfo.HasRelXY()) | 60 if (devinfo.HasRelXY()) |
61 return true; // mouse | 61 return true; // mouse |
62 | 62 |
63 return false; | 63 return false; |
64 } | 64 } |
65 | |
66 void SetGestureIntProperty(GesturePropertyProvider* provider, | |
67 int id, | |
68 const std::string& name, | |
69 int value) { | |
70 GesturesProp* property = provider->GetProperty(id, name); | |
71 if (property) { | |
72 std::vector<int> values(1, value); | |
73 property->SetIntValue(values); | |
74 } | |
75 } | |
76 | |
77 void SetGestureBoolProperty(GesturePropertyProvider* provider, | |
78 int id, | |
79 const std::string& name, | |
80 bool value) { | |
81 GesturesProp* property = provider->GetProperty(id, name); | |
82 if (property) { | |
83 std::vector<bool> values(1, value); | |
84 property->SetBoolValue(values); | |
85 } | |
86 } | |
65 #endif | 87 #endif |
66 | 88 |
67 scoped_ptr<EventConverterEvdev> CreateConverter( | 89 scoped_ptr<EventConverterEvdev> CreateConverter( |
68 const OpenInputDeviceParams& params, | 90 const OpenInputDeviceParams& params, |
69 int fd, | 91 int fd, |
70 InputDeviceType type, | 92 InputDeviceType type, |
71 const EventDeviceInfo& devinfo) { | 93 const EventDeviceInfo& devinfo) { |
72 #if defined(USE_EVDEV_GESTURES) | 94 #if defined(USE_EVDEV_GESTURES) |
73 // Touchpad or mouse: use gestures library. | 95 // Touchpad or mouse: use gestures library. |
74 // EventReaderLibevdevCros -> GestureInterpreterLibevdevCros -> DispatchEvent | 96 // EventReaderLibevdevCros -> GestureInterpreterLibevdevCros -> DispatchEvent |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
152 scoped_ptr<EventConverterEvdev> converter) { | 174 scoped_ptr<EventConverterEvdev> converter) { |
153 TRACE_EVENT1("ozone", "CloseInputDevice", "path", path.value()); | 175 TRACE_EVENT1("ozone", "CloseInputDevice", "path", path.value()); |
154 converter.reset(); | 176 converter.reset(); |
155 } | 177 } |
156 | 178 |
157 } // namespace | 179 } // namespace |
158 | 180 |
159 InputDeviceFactoryEvdev::InputDeviceFactoryEvdev( | 181 InputDeviceFactoryEvdev::InputDeviceFactoryEvdev( |
160 DeviceEventDispatcherEvdev* dispatcher, | 182 DeviceEventDispatcherEvdev* dispatcher, |
161 scoped_refptr<base::SingleThreadTaskRunner> dispatch_runner, | 183 scoped_refptr<base::SingleThreadTaskRunner> dispatch_runner, |
162 #if defined(USE_EVDEV_GESTURES) | |
163 GesturePropertyProvider* gesture_property_provider, | |
alexst (slow to review)
2015/01/27 20:25:28
So this is never used and created anew below, one
| |
164 #endif | |
165 CursorDelegateEvdev* cursor) | 184 CursorDelegateEvdev* cursor) |
166 : ui_task_runner_(dispatch_runner), | 185 : ui_task_runner_(dispatch_runner), |
167 cursor_(cursor), | 186 cursor_(cursor), |
168 #if defined(USE_EVDEV_GESTURES) | 187 #if defined(USE_EVDEV_GESTURES) |
169 gesture_property_provider_(new GesturePropertyProvider), | 188 gesture_property_provider_(new GesturePropertyProvider), |
170 #endif | 189 #endif |
171 dispatcher_(dispatcher), | 190 dispatcher_(dispatcher), |
172 weak_ptr_factory_(this) { | 191 weak_ptr_factory_(this) { |
173 } | 192 } |
174 | 193 |
175 InputDeviceFactoryEvdev::~InputDeviceFactoryEvdev() { | 194 InputDeviceFactoryEvdev::~InputDeviceFactoryEvdev() { |
176 STLDeleteValues(&converters_); | 195 STLDeleteValues(&converters_); |
177 } | 196 } |
178 | 197 |
179 void InputDeviceFactoryEvdev::AddInputDevice(int id, | 198 void InputDeviceFactoryEvdev::AddInputDevice(int id, |
180 const base::FilePath& path) { | 199 const base::FilePath& path) { |
181 scoped_ptr<OpenInputDeviceParams> params(new OpenInputDeviceParams); | 200 scoped_ptr<OpenInputDeviceParams> params(new OpenInputDeviceParams); |
182 params->id = id; | 201 params->id = id; |
183 params->path = path; | 202 params->path = path; |
184 params->cursor = cursor_; | 203 params->cursor = cursor_; |
185 params->dispatcher = dispatcher_; | 204 params->dispatcher = dispatcher_; |
186 | 205 |
187 #if defined(USE_EVDEV_GESTURES) | 206 #if defined(USE_EVDEV_GESTURES) |
188 params->gesture_property_provider = gesture_property_provider_; | 207 params->gesture_property_provider = gesture_property_provider_.get(); |
189 #endif | 208 #endif |
190 | 209 |
191 OpenInputDeviceReplyCallback reply_callback = | 210 OpenInputDeviceReplyCallback reply_callback = |
192 base::Bind(&InputDeviceFactoryEvdev::AttachInputDevice, | 211 base::Bind(&InputDeviceFactoryEvdev::AttachInputDevice, |
193 weak_ptr_factory_.GetWeakPtr()); | 212 weak_ptr_factory_.GetWeakPtr()); |
194 | 213 |
195 // Dispatch task to open from the worker pool, since open may block. | 214 // Dispatch task to open from the worker pool, since open may block. |
196 base::WorkerPool::PostTask(FROM_HERE, | 215 base::WorkerPool::PostTask(FROM_HERE, |
197 base::Bind(&OpenInputDevice, base::Passed(¶ms), | 216 base::Bind(&OpenInputDevice, base::Passed(¶ms), |
198 ui_task_runner_, reply_callback), | 217 ui_task_runner_, reply_callback), |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
280 void InputDeviceFactoryEvdev::EnableInternalKeyboard() { | 299 void InputDeviceFactoryEvdev::EnableInternalKeyboard() { |
281 for (const auto& it : converters_) { | 300 for (const auto& it : converters_) { |
282 EventConverterEvdev* converter = it.second; | 301 EventConverterEvdev* converter = it.second; |
283 if (converter->type() == InputDeviceType::INPUT_DEVICE_INTERNAL && | 302 if (converter->type() == InputDeviceType::INPUT_DEVICE_INTERNAL && |
284 converter->HasKeyboard()) { | 303 converter->HasKeyboard()) { |
285 converter->AllowAllKeys(); | 304 converter->AllowAllKeys(); |
286 } | 305 } |
287 } | 306 } |
288 } | 307 } |
289 | 308 |
309 bool InputDeviceFactoryEvdev::HasMouse() { | |
310 return GetDeviceIdsByType(DT_MOUSE, NULL); | |
311 } | |
312 | |
313 bool InputDeviceFactoryEvdev::HasTouchpad() { | |
314 return GetDeviceIdsByType(DT_TOUCHPAD, NULL); | |
315 } | |
316 | |
317 void InputDeviceFactoryEvdev::SetTouchpadSensitivity(int value) { | |
318 SetIntPropertyForOneType(DT_TOUCHPAD, "Pointer Sensitivity", value); | |
319 SetIntPropertyForOneType(DT_TOUCHPAD, "Scroll Sensitivity", value); | |
320 } | |
321 | |
322 void InputDeviceFactoryEvdev::SetTapToClick(bool enabled) { | |
323 SetBoolPropertyForOneType(DT_TOUCHPAD, "Tap Enable", enabled); | |
324 } | |
325 | |
326 void InputDeviceFactoryEvdev::SetThreeFingerClick(bool enabled) { | |
327 SetBoolPropertyForOneType(DT_TOUCHPAD, "T5R2 Three Finger Click Enable", | |
328 enabled); | |
329 } | |
330 | |
331 void InputDeviceFactoryEvdev::SetTapDragging(bool enabled) { | |
332 SetBoolPropertyForOneType(DT_TOUCHPAD, "Tap Drag Enable", enabled); | |
333 } | |
334 | |
335 void InputDeviceFactoryEvdev::SetNaturalScroll(bool enabled) { | |
336 SetBoolPropertyForOneType(DT_MULTITOUCH, "Australian Scrolling", enabled); | |
337 } | |
338 | |
339 void InputDeviceFactoryEvdev::SetMouseSensitivity(int value) { | |
340 SetIntPropertyForOneType(DT_MOUSE, "Pointer Sensitivity", value); | |
341 SetIntPropertyForOneType(DT_MOUSE, "Scroll Sensitivity", value); | |
342 } | |
343 | |
344 void InputDeviceFactoryEvdev::SetTapToClickPaused(bool state) { | |
345 SetBoolPropertyForOneType(DT_TOUCHPAD, "Tap Paused", state); | |
346 } | |
347 | |
290 void InputDeviceFactoryEvdev::NotifyDeviceChange( | 348 void InputDeviceFactoryEvdev::NotifyDeviceChange( |
291 const EventConverterEvdev& converter) { | 349 const EventConverterEvdev& converter) { |
292 if (converter.HasTouchscreen()) | 350 if (converter.HasTouchscreen()) |
293 NotifyTouchscreensUpdated(); | 351 NotifyTouchscreensUpdated(); |
294 | 352 |
295 if (converter.HasKeyboard()) | 353 if (converter.HasKeyboard()) |
296 NotifyKeyboardsUpdated(); | 354 NotifyKeyboardsUpdated(); |
297 } | 355 } |
298 | 356 |
299 void InputDeviceFactoryEvdev::NotifyTouchscreensUpdated() { | 357 void InputDeviceFactoryEvdev::NotifyTouchscreensUpdated() { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
336 // Ask GesturePropertyProvider for matching devices. | 394 // Ask GesturePropertyProvider for matching devices. |
337 gesture_property_provider_->GetDeviceIdsByType(type, &ids); | 395 gesture_property_provider_->GetDeviceIdsByType(type, &ids); |
338 #endif | 396 #endif |
339 // In the future we can add other device matching logics here. | 397 // In the future we can add other device matching logics here. |
340 | 398 |
341 if (device_ids) | 399 if (device_ids) |
342 device_ids->assign(ids.begin(), ids.end()); | 400 device_ids->assign(ids.begin(), ids.end()); |
343 return !ids.empty(); | 401 return !ids.empty(); |
344 } | 402 } |
345 | 403 |
404 void InputDeviceFactoryEvdev::SetIntPropertyForOneType( | |
405 const EventDeviceType type, | |
406 const std::string& name, | |
407 int value) { | |
408 #if defined(USE_EVDEV_GESTURES) | |
409 std::vector<int> ids; | |
410 gesture_property_provider_->GetDeviceIdsByType(type, &ids); | |
411 for (size_t i = 0; i < ids.size(); ++i) { | |
412 SetGestureIntProperty(gesture_property_provider_.get(), ids[i], name, | |
413 value); | |
414 } | |
415 #endif | |
416 // In the future, we may add property setting codes for other non-gesture | |
417 // devices. One example would be keyboard settings. | |
418 // TODO(sheckylin): See http://crbug.com/398518 for example. | |
419 } | |
420 | |
421 void InputDeviceFactoryEvdev::SetBoolPropertyForOneType( | |
422 const EventDeviceType type, | |
423 const std::string& name, | |
424 bool value) { | |
425 #if defined(USE_EVDEV_GESTURES) | |
426 std::vector<int> ids; | |
427 gesture_property_provider_->GetDeviceIdsByType(type, &ids); | |
428 for (size_t i = 0; i < ids.size(); ++i) { | |
429 SetGestureBoolProperty(gesture_property_provider_.get(), ids[i], name, | |
430 value); | |
431 } | |
432 #endif | |
433 } | |
434 | |
346 } // namespace ui | 435 } // namespace ui |
OLD | NEW |