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/libgestures_glue/gesture_interpreter_libevdev_cr
os.h" | 5 #include "ui/events/ozone/evdev/libgestures_glue/gesture_interpreter_libevdev_cr
os.h" |
6 | 6 |
7 #include <gestures/gestures.h> | 7 #include <gestures/gestures.h> |
8 #include <libevdev/libevdev.h> | 8 #include <libevdev/libevdev.h> |
9 #include <linux/input.h> | 9 #include <linux/input.h> |
10 | 10 |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "base/timer/timer.h" | 12 #include "base/timer/timer.h" |
13 #include "ui/events/event.h" | 13 #include "ui/events/event.h" |
14 #include "ui/events/keycodes/dom4/keycode_converter.h" | 14 #include "ui/events/keycodes/dom4/keycode_converter.h" |
15 #include "ui/events/ozone/evdev/cursor_delegate_evdev.h" | 15 #include "ui/events/ozone/evdev/cursor_delegate_evdev.h" |
| 16 #include "ui/events/ozone/evdev/device_event_dispatcher_evdev.h" |
16 #include "ui/events/ozone/evdev/event_device_info.h" | 17 #include "ui/events/ozone/evdev/event_device_info.h" |
17 #include "ui/events/ozone/evdev/event_device_util.h" | 18 #include "ui/events/ozone/evdev/event_device_util.h" |
18 #include "ui/events/ozone/evdev/keyboard_util_evdev.h" | 19 #include "ui/events/ozone/evdev/keyboard_util_evdev.h" |
19 #include "ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h" | 20 #include "ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h" |
20 #include "ui/events/ozone/evdev/libgestures_glue/gesture_timer_provider.h" | 21 #include "ui/events/ozone/evdev/libgestures_glue/gesture_timer_provider.h" |
21 #include "ui/gfx/geometry/point_f.h" | 22 #include "ui/gfx/geometry/point_f.h" |
22 | 23 |
23 namespace ui { | 24 namespace ui { |
24 | 25 |
25 namespace { | 26 namespace { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 | 83 |
83 // Number of fingers for swipe gestures. | 84 // Number of fingers for swipe gestures. |
84 const int kGestureSwipeFingerCount = 3; | 85 const int kGestureSwipeFingerCount = 3; |
85 | 86 |
86 } // namespace | 87 } // namespace |
87 | 88 |
88 GestureInterpreterLibevdevCros::GestureInterpreterLibevdevCros( | 89 GestureInterpreterLibevdevCros::GestureInterpreterLibevdevCros( |
89 int id, | 90 int id, |
90 CursorDelegateEvdev* cursor, | 91 CursorDelegateEvdev* cursor, |
91 GesturePropertyProvider* property_provider, | 92 GesturePropertyProvider* property_provider, |
92 const KeyEventDispatchCallback& key_callback, | 93 DeviceEventDispatcherEvdev* dispatcher) |
93 const MouseMoveEventDispatchCallback& mouse_move_callback, | |
94 const MouseButtonEventDispatchCallback& mouse_button_callback, | |
95 const MouseWheelEventDispatchCallback& mouse_wheel_callback, | |
96 const ScrollEventDispatchCallback& scroll_callback) | |
97 : id_(id), | 94 : id_(id), |
98 is_mouse_(false), | 95 is_mouse_(false), |
99 cursor_(cursor), | 96 cursor_(cursor), |
100 property_provider_(property_provider), | 97 property_provider_(property_provider), |
101 key_callback_(key_callback), | 98 dispatcher_(dispatcher), |
102 mouse_move_callback_(mouse_move_callback), | |
103 mouse_button_callback_(mouse_button_callback), | |
104 mouse_wheel_callback_(mouse_wheel_callback), | |
105 scroll_callback_(scroll_callback), | |
106 interpreter_(NULL), | 99 interpreter_(NULL), |
107 evdev_(NULL), | 100 evdev_(NULL), |
108 device_properties_(new GestureDeviceProperties) { | 101 device_properties_(new GestureDeviceProperties) { |
109 memset(&prev_key_state_, 0, sizeof(prev_key_state_)); | 102 memset(&prev_key_state_, 0, sizeof(prev_key_state_)); |
110 } | 103 } |
111 | 104 |
112 GestureInterpreterLibevdevCros::~GestureInterpreterLibevdevCros() { | 105 GestureInterpreterLibevdevCros::~GestureInterpreterLibevdevCros() { |
113 // Note that this destructor got called after the evdev device node has been | 106 // Note that this destructor got called after the evdev device node has been |
114 // closed. Therefore, all clean-up codes here shouldn't depend on the device | 107 // closed. Therefore, all clean-up codes here shouldn't depend on the device |
115 // information (except for the pointer address itself). | 108 // information (except for the pointer address itself). |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 move->dx, | 263 move->dx, |
271 move->dy, | 264 move->dy, |
272 move->ordinal_dx, | 265 move->ordinal_dx, |
273 move->ordinal_dy); | 266 move->ordinal_dy); |
274 if (!cursor_) | 267 if (!cursor_) |
275 return; // No cursor! | 268 return; // No cursor! |
276 | 269 |
277 cursor_->MoveCursor(gfx::Vector2dF(move->dx, move->dy)); | 270 cursor_->MoveCursor(gfx::Vector2dF(move->dx, move->dy)); |
278 // TODO(spang): Use move->ordinal_dx, move->ordinal_dy | 271 // TODO(spang): Use move->ordinal_dx, move->ordinal_dy |
279 // TODO(spang): Use move->start_time, move->end_time | 272 // TODO(spang): Use move->start_time, move->end_time |
280 mouse_move_callback_.Run(MouseMoveEventParams(id_, cursor_->GetLocation())); | 273 dispatcher_->DispatchMouseMoveEvent( |
| 274 MouseMoveEventParams(id_, cursor_->GetLocation())); |
281 } | 275 } |
282 | 276 |
283 void GestureInterpreterLibevdevCros::OnGestureScroll( | 277 void GestureInterpreterLibevdevCros::OnGestureScroll( |
284 const Gesture* gesture, | 278 const Gesture* gesture, |
285 const GestureScroll* scroll) { | 279 const GestureScroll* scroll) { |
286 DVLOG(3) << base::StringPrintf("Gesture Scroll: (%f, %f) [%f, %f]", | 280 DVLOG(3) << base::StringPrintf("Gesture Scroll: (%f, %f) [%f, %f]", |
287 scroll->dx, | 281 scroll->dx, |
288 scroll->dy, | 282 scroll->dy, |
289 scroll->ordinal_dx, | 283 scroll->ordinal_dx, |
290 scroll->ordinal_dy); | 284 scroll->ordinal_dy); |
291 if (!cursor_) | 285 if (!cursor_) |
292 return; // No cursor! | 286 return; // No cursor! |
293 | 287 |
294 // TODO(spang): Use scroll->start_time | 288 // TODO(spang): Use scroll->start_time |
295 if (is_mouse_) { | 289 if (is_mouse_) { |
296 mouse_wheel_callback_.Run(MouseWheelEventParams( | 290 dispatcher_->DispatchMouseWheelEvent(MouseWheelEventParams( |
297 id_, cursor_->GetLocation(), gfx::Vector2d(scroll->dx, scroll->dy))); | 291 id_, cursor_->GetLocation(), gfx::Vector2d(scroll->dx, scroll->dy))); |
298 } else { | 292 } else { |
299 scroll_callback_.Run(ScrollEventParams( | 293 dispatcher_->DispatchScrollEvent(ScrollEventParams( |
300 id_, ET_SCROLL, cursor_->GetLocation(), | 294 id_, ET_SCROLL, cursor_->GetLocation(), |
301 gfx::Vector2dF(scroll->dx, scroll->dy), | 295 gfx::Vector2dF(scroll->dx, scroll->dy), |
302 gfx::Vector2dF(scroll->ordinal_dx, scroll->ordinal_dy), | 296 gfx::Vector2dF(scroll->ordinal_dx, scroll->ordinal_dy), |
303 kGestureScrollFingerCount, StimeToTimedelta(gesture->end_time))); | 297 kGestureScrollFingerCount, StimeToTimedelta(gesture->end_time))); |
304 } | 298 } |
305 } | 299 } |
306 | 300 |
307 void GestureInterpreterLibevdevCros::OnGestureButtonsChange( | 301 void GestureInterpreterLibevdevCros::OnGestureButtonsChange( |
308 const Gesture* gesture, | 302 const Gesture* gesture, |
309 const GestureButtonsChange* buttons) { | 303 const GestureButtonsChange* buttons) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 fling->fling_state); | 339 fling->fling_state); |
346 | 340 |
347 if (!cursor_) | 341 if (!cursor_) |
348 return; // No cursor! | 342 return; // No cursor! |
349 | 343 |
350 EventType type = | 344 EventType type = |
351 (fling->fling_state == GESTURES_FLING_START ? ET_SCROLL_FLING_START | 345 (fling->fling_state == GESTURES_FLING_START ? ET_SCROLL_FLING_START |
352 : ET_SCROLL_FLING_CANCEL); | 346 : ET_SCROLL_FLING_CANCEL); |
353 | 347 |
354 // Fling is like 2-finger scrolling but with velocity instead of displacement. | 348 // Fling is like 2-finger scrolling but with velocity instead of displacement. |
355 scroll_callback_.Run(ScrollEventParams( | 349 dispatcher_->DispatchScrollEvent(ScrollEventParams( |
356 id_, type, cursor_->GetLocation(), gfx::Vector2dF(fling->vx, fling->vy), | 350 id_, type, cursor_->GetLocation(), gfx::Vector2dF(fling->vx, fling->vy), |
357 gfx::Vector2dF(fling->ordinal_vx, fling->ordinal_vy), | 351 gfx::Vector2dF(fling->ordinal_vx, fling->ordinal_vy), |
358 kGestureScrollFingerCount, StimeToTimedelta(gesture->end_time))); | 352 kGestureScrollFingerCount, StimeToTimedelta(gesture->end_time))); |
359 } | 353 } |
360 | 354 |
361 void GestureInterpreterLibevdevCros::OnGestureSwipe(const Gesture* gesture, | 355 void GestureInterpreterLibevdevCros::OnGestureSwipe(const Gesture* gesture, |
362 const GestureSwipe* swipe) { | 356 const GestureSwipe* swipe) { |
363 DVLOG(3) << base::StringPrintf("Gesture Swipe: (%f, %f) [%f, %f]", | 357 DVLOG(3) << base::StringPrintf("Gesture Swipe: (%f, %f) [%f, %f]", |
364 swipe->dx, | 358 swipe->dx, |
365 swipe->dy, | 359 swipe->dy, |
366 swipe->ordinal_dx, | 360 swipe->ordinal_dx, |
367 swipe->ordinal_dy); | 361 swipe->ordinal_dy); |
368 | 362 |
369 if (!cursor_) | 363 if (!cursor_) |
370 return; // No cursor! | 364 return; // No cursor! |
371 | 365 |
372 // Swipe is 3-finger scrolling. | 366 // Swipe is 3-finger scrolling. |
373 scroll_callback_.Run(ScrollEventParams( | 367 dispatcher_->DispatchScrollEvent(ScrollEventParams( |
374 id_, ET_SCROLL, cursor_->GetLocation(), | 368 id_, ET_SCROLL, cursor_->GetLocation(), |
375 gfx::Vector2dF(swipe->dx, swipe->dy), | 369 gfx::Vector2dF(swipe->dx, swipe->dy), |
376 gfx::Vector2dF(swipe->ordinal_dx, swipe->ordinal_dy), | 370 gfx::Vector2dF(swipe->ordinal_dx, swipe->ordinal_dy), |
377 kGestureSwipeFingerCount, StimeToTimedelta(gesture->end_time))); | 371 kGestureSwipeFingerCount, StimeToTimedelta(gesture->end_time))); |
378 } | 372 } |
379 | 373 |
380 void GestureInterpreterLibevdevCros::OnGestureSwipeLift( | 374 void GestureInterpreterLibevdevCros::OnGestureSwipeLift( |
381 const Gesture* gesture, | 375 const Gesture* gesture, |
382 const GestureSwipeLift* swipelift) { | 376 const GestureSwipeLift* swipelift) { |
383 DVLOG(3) << base::StringPrintf("Gesture Swipe Lift"); | 377 DVLOG(3) << base::StringPrintf("Gesture Swipe Lift"); |
384 | 378 |
385 if (!cursor_) | 379 if (!cursor_) |
386 return; // No cursor! | 380 return; // No cursor! |
387 | 381 |
388 // Turn a swipe lift into a fling start. | 382 // Turn a swipe lift into a fling start. |
389 // TODO(spang): Figure out why and put it in this comment. | 383 // TODO(spang): Figure out why and put it in this comment. |
390 | 384 |
391 scroll_callback_.Run(ScrollEventParams( | 385 dispatcher_->DispatchScrollEvent(ScrollEventParams( |
392 id_, ET_SCROLL_FLING_START, cursor_->GetLocation(), | 386 id_, ET_SCROLL_FLING_START, cursor_->GetLocation(), |
393 gfx::Vector2dF() /* delta */, gfx::Vector2dF() /* ordinal_delta */, | 387 gfx::Vector2dF() /* delta */, gfx::Vector2dF() /* ordinal_delta */, |
394 kGestureScrollFingerCount, StimeToTimedelta(gesture->end_time))); | 388 kGestureScrollFingerCount, StimeToTimedelta(gesture->end_time))); |
395 } | 389 } |
396 | 390 |
397 void GestureInterpreterLibevdevCros::OnGesturePinch(const Gesture* gesture, | 391 void GestureInterpreterLibevdevCros::OnGesturePinch(const Gesture* gesture, |
398 const GesturePinch* pinch) { | 392 const GesturePinch* pinch) { |
399 DVLOG(3) << base::StringPrintf( | 393 DVLOG(3) << base::StringPrintf( |
400 "Gesture Pinch: dz=%f [%f]", pinch->dz, pinch->ordinal_dz); | 394 "Gesture Pinch: dz=%f [%f]", pinch->dz, pinch->ordinal_dz); |
401 | 395 |
402 if (!cursor_) | 396 if (!cursor_) |
403 return; // No cursor! | 397 return; // No cursor! |
404 | 398 |
405 NOTIMPLEMENTED(); | 399 NOTIMPLEMENTED(); |
406 } | 400 } |
407 | 401 |
408 void GestureInterpreterLibevdevCros::OnGestureMetrics( | 402 void GestureInterpreterLibevdevCros::OnGestureMetrics( |
409 const Gesture* gesture, | 403 const Gesture* gesture, |
410 const GestureMetrics* metrics) { | 404 const GestureMetrics* metrics) { |
411 DVLOG(3) << base::StringPrintf("Gesture Metrics: [%f, %f] type=%d", | 405 DVLOG(3) << base::StringPrintf("Gesture Metrics: [%f, %f] type=%d", |
412 metrics->data[0], | 406 metrics->data[0], |
413 metrics->data[1], | 407 metrics->data[1], |
414 metrics->type); | 408 metrics->type); |
415 NOTIMPLEMENTED(); | 409 NOTIMPLEMENTED(); |
416 } | 410 } |
417 | 411 |
418 void GestureInterpreterLibevdevCros::DispatchMouseButton(unsigned int button, | 412 void GestureInterpreterLibevdevCros::DispatchMouseButton(unsigned int button, |
419 bool down) { | 413 bool down) { |
420 bool allow_remap = is_mouse_; | 414 bool allow_remap = is_mouse_; |
421 mouse_button_callback_.Run(MouseButtonEventParams(id_, cursor_->GetLocation(), | 415 dispatcher_->DispatchMouseButtonEvent(MouseButtonEventParams( |
422 button, down, allow_remap)); | 416 id_, cursor_->GetLocation(), button, down, allow_remap)); |
423 } | 417 } |
424 | 418 |
425 void GestureInterpreterLibevdevCros::DispatchChangedKeys(Evdev* evdev, | 419 void GestureInterpreterLibevdevCros::DispatchChangedKeys(Evdev* evdev, |
426 const timeval& time) { | 420 const timeval& time) { |
427 unsigned long key_state_diff[EVDEV_BITS_TO_LONGS(KEY_CNT)]; | 421 unsigned long key_state_diff[EVDEV_BITS_TO_LONGS(KEY_CNT)]; |
428 | 422 |
429 // Find changed keys. | 423 // Find changed keys. |
430 for (unsigned long i = 0; i < arraysize(key_state_diff); ++i) | 424 for (unsigned long i = 0; i < arraysize(key_state_diff); ++i) |
431 key_state_diff[i] = evdev->key_state_bitmask[i] ^ prev_key_state_[i]; | 425 key_state_diff[i] = evdev->key_state_bitmask[i] ^ prev_key_state_[i]; |
432 | 426 |
433 // Dispatch events for changed keys. | 427 // Dispatch events for changed keys. |
434 for (unsigned long key = 0; key < KEY_CNT; ++key) { | 428 for (unsigned long key = 0; key < KEY_CNT; ++key) { |
435 if (EvdevBitIsSet(key_state_diff, key)) { | 429 if (EvdevBitIsSet(key_state_diff, key)) { |
436 bool value = EvdevBitIsSet(evdev->key_state_bitmask, key); | 430 bool value = EvdevBitIsSet(evdev->key_state_bitmask, key); |
437 | 431 |
438 // Mouse buttons are handled by DispatchMouseButton. | 432 // Mouse buttons are handled by DispatchMouseButton. |
439 if (key >= BTN_MOUSE && key < BTN_JOYSTICK) | 433 if (key >= BTN_MOUSE && key < BTN_JOYSTICK) |
440 continue; | 434 continue; |
441 | 435 |
442 // Ignore digi buttons (e.g. BTN_TOOL_FINGER). | 436 // Ignore digi buttons (e.g. BTN_TOOL_FINGER). |
443 if (key >= BTN_DIGI && key < BTN_WHEEL) | 437 if (key >= BTN_DIGI && key < BTN_WHEEL) |
444 continue; | 438 continue; |
445 | 439 |
446 if (allowed_keys_ && !allowed_keys_->count(key)) | 440 if (allowed_keys_ && !allowed_keys_->count(key)) |
447 continue; | 441 continue; |
448 | 442 |
449 // Dispatch key press or release to keyboard. | 443 // Dispatch key press or release to keyboard. |
450 key_callback_.Run(KeyEventParams(id_, key, value)); | 444 dispatcher_->DispatchKeyEvent(KeyEventParams(id_, key, value)); |
451 } | 445 } |
452 } | 446 } |
453 | 447 |
454 // Update internal key state. | 448 // Update internal key state. |
455 for (unsigned long i = 0; i < EVDEV_BITS_TO_LONGS(KEY_CNT); ++i) | 449 for (unsigned long i = 0; i < EVDEV_BITS_TO_LONGS(KEY_CNT); ++i) |
456 prev_key_state_[i] = evdev->key_state_bitmask[i]; | 450 prev_key_state_[i] = evdev->key_state_bitmask[i]; |
457 } | 451 } |
458 | 452 |
459 } // namespace ui | 453 } // namespace ui |
OLD | NEW |