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

Side by Side Diff: ui/events/ozone/evdev/libgestures_glue/gesture_interpreter_libevdev_cros.cc

Issue 869613003: [PATCH 5/11] ozone: evdev: Replace dispatch callbacks with an interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updates for events_unittests Created 5 years, 11 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
OLDNEW
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
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
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(id_, cursor_->GetLocation()); 273 dispatcher_->DispatchMouseMoveEvent(id_, cursor_->GetLocation());
281 } 274 }
282 275
283 void GestureInterpreterLibevdevCros::OnGestureScroll( 276 void GestureInterpreterLibevdevCros::OnGestureScroll(
284 const Gesture* gesture, 277 const Gesture* gesture,
285 const GestureScroll* scroll) { 278 const GestureScroll* scroll) {
286 DVLOG(3) << base::StringPrintf("Gesture Scroll: (%f, %f) [%f, %f]", 279 DVLOG(3) << base::StringPrintf("Gesture Scroll: (%f, %f) [%f, %f]",
287 scroll->dx, 280 scroll->dx,
288 scroll->dy, 281 scroll->dy,
289 scroll->ordinal_dx, 282 scroll->ordinal_dx,
290 scroll->ordinal_dy); 283 scroll->ordinal_dy);
291 if (!cursor_) 284 if (!cursor_)
292 return; // No cursor! 285 return; // No cursor!
293 286
294 // TODO(spang): Use scroll->start_time 287 // TODO(spang): Use scroll->start_time
295 if (is_mouse_) { 288 if (is_mouse_) {
296 mouse_wheel_callback_.Run(id_, cursor_->GetLocation(), 289 dispatcher_->DispatchMouseWheelEvent(id_, cursor_->GetLocation(),
297 gfx::Vector2d(scroll->dx, scroll->dy)); 290 gfx::Vector2d(scroll->dx, scroll->dy));
298 } else { 291 } else {
299 scroll_callback_.Run(ScrollEventParams( 292 dispatcher_->DispatchScrollEvent(ScrollEventParams(
300 id_, ET_SCROLL, cursor_->GetLocation(), 293 id_, ET_SCROLL, cursor_->GetLocation(),
301 gfx::Vector2dF(scroll->dx, scroll->dy), 294 gfx::Vector2dF(scroll->dx, scroll->dy),
302 gfx::Vector2dF(scroll->ordinal_dx, scroll->ordinal_dy), 295 gfx::Vector2dF(scroll->ordinal_dx, scroll->ordinal_dy),
303 kGestureScrollFingerCount, StimeToTimedelta(gesture->end_time))); 296 kGestureScrollFingerCount, StimeToTimedelta(gesture->end_time)));
304 } 297 }
305 } 298 }
306 299
307 void GestureInterpreterLibevdevCros::OnGestureButtonsChange( 300 void GestureInterpreterLibevdevCros::OnGestureButtonsChange(
308 const Gesture* gesture, 301 const Gesture* gesture,
309 const GestureButtonsChange* buttons) { 302 const GestureButtonsChange* buttons) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 fling->fling_state); 338 fling->fling_state);
346 339
347 if (!cursor_) 340 if (!cursor_)
348 return; // No cursor! 341 return; // No cursor!
349 342
350 EventType type = 343 EventType type =
351 (fling->fling_state == GESTURES_FLING_START ? ET_SCROLL_FLING_START 344 (fling->fling_state == GESTURES_FLING_START ? ET_SCROLL_FLING_START
352 : ET_SCROLL_FLING_CANCEL); 345 : ET_SCROLL_FLING_CANCEL);
353 346
354 // Fling is like 2-finger scrolling but with velocity instead of displacement. 347 // Fling is like 2-finger scrolling but with velocity instead of displacement.
355 scroll_callback_.Run(ScrollEventParams( 348 dispatcher_->DispatchScrollEvent(ScrollEventParams(
356 id_, type, cursor_->GetLocation(), gfx::Vector2dF(fling->vx, fling->vy), 349 id_, type, cursor_->GetLocation(), gfx::Vector2dF(fling->vx, fling->vy),
357 gfx::Vector2dF(fling->ordinal_vx, fling->ordinal_vy), 350 gfx::Vector2dF(fling->ordinal_vx, fling->ordinal_vy),
358 kGestureScrollFingerCount, StimeToTimedelta(gesture->end_time))); 351 kGestureScrollFingerCount, StimeToTimedelta(gesture->end_time)));
359 } 352 }
360 353
361 void GestureInterpreterLibevdevCros::OnGestureSwipe(const Gesture* gesture, 354 void GestureInterpreterLibevdevCros::OnGestureSwipe(const Gesture* gesture,
362 const GestureSwipe* swipe) { 355 const GestureSwipe* swipe) {
363 DVLOG(3) << base::StringPrintf("Gesture Swipe: (%f, %f) [%f, %f]", 356 DVLOG(3) << base::StringPrintf("Gesture Swipe: (%f, %f) [%f, %f]",
364 swipe->dx, 357 swipe->dx,
365 swipe->dy, 358 swipe->dy,
366 swipe->ordinal_dx, 359 swipe->ordinal_dx,
367 swipe->ordinal_dy); 360 swipe->ordinal_dy);
368 361
369 if (!cursor_) 362 if (!cursor_)
370 return; // No cursor! 363 return; // No cursor!
371 364
372 // Swipe is 3-finger scrolling. 365 // Swipe is 3-finger scrolling.
373 scroll_callback_.Run(ScrollEventParams( 366 dispatcher_->DispatchScrollEvent(ScrollEventParams(
374 id_, ET_SCROLL, cursor_->GetLocation(), 367 id_, ET_SCROLL, cursor_->GetLocation(),
375 gfx::Vector2dF(swipe->dx, swipe->dy), 368 gfx::Vector2dF(swipe->dx, swipe->dy),
376 gfx::Vector2dF(swipe->ordinal_dx, swipe->ordinal_dy), 369 gfx::Vector2dF(swipe->ordinal_dx, swipe->ordinal_dy),
377 kGestureSwipeFingerCount, StimeToTimedelta(gesture->end_time))); 370 kGestureSwipeFingerCount, StimeToTimedelta(gesture->end_time)));
378 } 371 }
379 372
380 void GestureInterpreterLibevdevCros::OnGestureSwipeLift( 373 void GestureInterpreterLibevdevCros::OnGestureSwipeLift(
381 const Gesture* gesture, 374 const Gesture* gesture,
382 const GestureSwipeLift* swipelift) { 375 const GestureSwipeLift* swipelift) {
383 DVLOG(3) << base::StringPrintf("Gesture Swipe Lift"); 376 DVLOG(3) << base::StringPrintf("Gesture Swipe Lift");
384 377
385 if (!cursor_) 378 if (!cursor_)
386 return; // No cursor! 379 return; // No cursor!
387 380
388 // Turn a swipe lift into a fling start. 381 // Turn a swipe lift into a fling start.
389 // TODO(spang): Figure out why and put it in this comment. 382 // TODO(spang): Figure out why and put it in this comment.
390 383
391 scroll_callback_.Run(ScrollEventParams( 384 dispatcher_->DispatchScrollEvent(ScrollEventParams(
392 id_, ET_SCROLL_FLING_START, cursor_->GetLocation(), 385 id_, ET_SCROLL_FLING_START, cursor_->GetLocation(),
393 gfx::Vector2dF() /* delta */, gfx::Vector2dF() /* ordinal_delta */, 386 gfx::Vector2dF() /* delta */, gfx::Vector2dF() /* ordinal_delta */,
394 kGestureScrollFingerCount, StimeToTimedelta(gesture->end_time))); 387 kGestureScrollFingerCount, StimeToTimedelta(gesture->end_time)));
395 } 388 }
396 389
397 void GestureInterpreterLibevdevCros::OnGesturePinch(const Gesture* gesture, 390 void GestureInterpreterLibevdevCros::OnGesturePinch(const Gesture* gesture,
398 const GesturePinch* pinch) { 391 const GesturePinch* pinch) {
399 DVLOG(3) << base::StringPrintf( 392 DVLOG(3) << base::StringPrintf(
400 "Gesture Pinch: dz=%f [%f]", pinch->dz, pinch->ordinal_dz); 393 "Gesture Pinch: dz=%f [%f]", pinch->dz, pinch->ordinal_dz);
401 394
402 if (!cursor_) 395 if (!cursor_)
403 return; // No cursor! 396 return; // No cursor!
404 397
405 NOTIMPLEMENTED(); 398 NOTIMPLEMENTED();
406 } 399 }
407 400
408 void GestureInterpreterLibevdevCros::OnGestureMetrics( 401 void GestureInterpreterLibevdevCros::OnGestureMetrics(
409 const Gesture* gesture, 402 const Gesture* gesture,
410 const GestureMetrics* metrics) { 403 const GestureMetrics* metrics) {
411 DVLOG(3) << base::StringPrintf("Gesture Metrics: [%f, %f] type=%d", 404 DVLOG(3) << base::StringPrintf("Gesture Metrics: [%f, %f] type=%d",
412 metrics->data[0], 405 metrics->data[0],
413 metrics->data[1], 406 metrics->data[1],
414 metrics->type); 407 metrics->type);
415 NOTIMPLEMENTED(); 408 NOTIMPLEMENTED();
416 } 409 }
417 410
418 void GestureInterpreterLibevdevCros::DispatchMouseButton(unsigned int button, 411 void GestureInterpreterLibevdevCros::DispatchMouseButton(unsigned int button,
419 bool down) { 412 bool down) {
420 bool allow_remap = is_mouse_; 413 bool allow_remap = is_mouse_;
421 mouse_button_callback_.Run(id_, cursor_->GetLocation(), button, down, 414 dispatcher_->DispatchMouseButtonEvent(id_, cursor_->GetLocation(), button,
422 allow_remap); 415 down, allow_remap);
423 } 416 }
424 417
425 void GestureInterpreterLibevdevCros::DispatchChangedKeys(Evdev* evdev, 418 void GestureInterpreterLibevdevCros::DispatchChangedKeys(Evdev* evdev,
426 const timeval& time) { 419 const timeval& time) {
427 unsigned long key_state_diff[EVDEV_BITS_TO_LONGS(KEY_CNT)]; 420 unsigned long key_state_diff[EVDEV_BITS_TO_LONGS(KEY_CNT)];
428 421
429 // Find changed keys. 422 // Find changed keys.
430 for (unsigned long i = 0; i < arraysize(key_state_diff); ++i) 423 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]; 424 key_state_diff[i] = evdev->key_state_bitmask[i] ^ prev_key_state_[i];
432 425
433 // Dispatch events for changed keys. 426 // Dispatch events for changed keys.
434 for (unsigned long key = 0; key < KEY_CNT; ++key) { 427 for (unsigned long key = 0; key < KEY_CNT; ++key) {
435 if (EvdevBitIsSet(key_state_diff, key)) { 428 if (EvdevBitIsSet(key_state_diff, key)) {
436 bool value = EvdevBitIsSet(evdev->key_state_bitmask, key); 429 bool value = EvdevBitIsSet(evdev->key_state_bitmask, key);
437 430
438 // Mouse buttons are handled by DispatchMouseButton. 431 // Mouse buttons are handled by DispatchMouseButton.
439 if (key >= BTN_MOUSE && key < BTN_JOYSTICK) 432 if (key >= BTN_MOUSE && key < BTN_JOYSTICK)
440 continue; 433 continue;
441 434
442 // Ignore digi buttons (e.g. BTN_TOOL_FINGER). 435 // Ignore digi buttons (e.g. BTN_TOOL_FINGER).
443 if (key >= BTN_DIGI && key < BTN_WHEEL) 436 if (key >= BTN_DIGI && key < BTN_WHEEL)
444 continue; 437 continue;
445 438
446 if (allowed_keys_ && !allowed_keys_->count(key)) 439 if (allowed_keys_ && !allowed_keys_->count(key))
447 continue; 440 continue;
448 441
449 // Dispatch key press or release to keyboard. 442 // Dispatch key press or release to keyboard.
450 key_callback_.Run(id_, key, value); 443 dispatcher_->DispatchKeyEvent(id_, key, value);
451 } 444 }
452 } 445 }
453 446
454 // Update internal key state. 447 // Update internal key state.
455 for (unsigned long i = 0; i < EVDEV_BITS_TO_LONGS(KEY_CNT); ++i) 448 for (unsigned long i = 0; i < EVDEV_BITS_TO_LONGS(KEY_CNT); ++i)
456 prev_key_state_[i] = evdev->key_state_bitmask[i]; 449 prev_key_state_[i] = evdev->key_state_bitmask[i];
457 } 450 }
458 451
459 } // namespace ui 452 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698