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

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

Issue 867803004: [PATCH 4/11] ozone: evdev: Move EventModifiersEvdev usage to EventFactoryEvdev (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update per comments on previous patches 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
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/event_device_info.h" 16 #include "ui/events/ozone/evdev/event_device_info.h"
17 #include "ui/events/ozone/evdev/event_device_util.h" 17 #include "ui/events/ozone/evdev/event_device_util.h"
18 #include "ui/events/ozone/evdev/event_modifiers_evdev.h"
19 #include "ui/events/ozone/evdev/keyboard_util_evdev.h" 18 #include "ui/events/ozone/evdev/keyboard_util_evdev.h"
20 #include "ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h" 19 #include "ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h"
21 #include "ui/events/ozone/evdev/libgestures_glue/gesture_timer_provider.h" 20 #include "ui/events/ozone/evdev/libgestures_glue/gesture_timer_provider.h"
22 #include "ui/gfx/geometry/point_f.h" 21 #include "ui/gfx/geometry/point_f.h"
23 22
24 namespace ui { 23 namespace ui {
25 24
26 namespace { 25 namespace {
27 26
28 // Convert libevdev device class to libgestures device class. 27 // Convert libevdev device class to libgestures device class.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 // Number of fingers for scroll gestures. 80 // Number of fingers for scroll gestures.
82 const int kGestureScrollFingerCount = 2; 81 const int kGestureScrollFingerCount = 2;
83 82
84 // Number of fingers for swipe gestures. 83 // Number of fingers for swipe gestures.
85 const int kGestureSwipeFingerCount = 3; 84 const int kGestureSwipeFingerCount = 3;
86 85
87 } // namespace 86 } // namespace
88 87
89 GestureInterpreterLibevdevCros::GestureInterpreterLibevdevCros( 88 GestureInterpreterLibevdevCros::GestureInterpreterLibevdevCros(
90 int id, 89 int id,
91 EventModifiersEvdev* modifiers,
92 CursorDelegateEvdev* cursor, 90 CursorDelegateEvdev* cursor,
93 GesturePropertyProvider* property_provider, 91 GesturePropertyProvider* property_provider,
94 const KeyEventDispatchCallback& key_callback, 92 const KeyEventDispatchCallback& key_callback,
95 const MouseMoveEventDispatchCallback& mouse_move_callback, 93 const MouseMoveEventDispatchCallback& mouse_move_callback,
96 const MouseButtonEventDispatchCallback& mouse_button_callback, 94 const MouseButtonEventDispatchCallback& mouse_button_callback,
97 const EventDispatchCallback& callback) 95 const MouseWheelEventDispatchCallback& mouse_wheel_callback,
96 const ScrollEventDispatchCallback& scroll_callback)
98 : id_(id), 97 : id_(id),
99 is_mouse_(false), 98 is_mouse_(false),
100 modifiers_(modifiers),
101 cursor_(cursor), 99 cursor_(cursor),
102 property_provider_(property_provider), 100 property_provider_(property_provider),
103 key_callback_(key_callback), 101 key_callback_(key_callback),
104 mouse_move_callback_(mouse_move_callback), 102 mouse_move_callback_(mouse_move_callback),
105 mouse_button_callback_(mouse_button_callback), 103 mouse_button_callback_(mouse_button_callback),
106 dispatch_callback_(callback), 104 mouse_wheel_callback_(mouse_wheel_callback),
105 scroll_callback_(scroll_callback),
107 interpreter_(NULL), 106 interpreter_(NULL),
108 evdev_(NULL), 107 evdev_(NULL),
109 device_properties_(new GestureDeviceProperties) { 108 device_properties_(new GestureDeviceProperties) {
110 memset(&prev_key_state_, 0, sizeof(prev_key_state_)); 109 memset(&prev_key_state_, 0, sizeof(prev_key_state_));
111 } 110 }
112 111
113 GestureInterpreterLibevdevCros::~GestureInterpreterLibevdevCros() { 112 GestureInterpreterLibevdevCros::~GestureInterpreterLibevdevCros() {
114 // Note that this destructor got called after the evdev device node has been 113 // Note that this destructor got called after the evdev device node has been
115 // closed. Therefore, all clean-up codes here shouldn't depend on the device 114 // closed. Therefore, all clean-up codes here shouldn't depend on the device
116 // information (except for the pointer address itself). 115 // information (except for the pointer address itself).
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 DVLOG(3) << base::StringPrintf("Gesture Scroll: (%f, %f) [%f, %f]", 286 DVLOG(3) << base::StringPrintf("Gesture Scroll: (%f, %f) [%f, %f]",
288 scroll->dx, 287 scroll->dx,
289 scroll->dy, 288 scroll->dy,
290 scroll->ordinal_dx, 289 scroll->ordinal_dx,
291 scroll->ordinal_dy); 290 scroll->ordinal_dy);
292 if (!cursor_) 291 if (!cursor_)
293 return; // No cursor! 292 return; // No cursor!
294 293
295 // TODO(spang): Use scroll->start_time 294 // TODO(spang): Use scroll->start_time
296 if (is_mouse_) { 295 if (is_mouse_) {
297 Dispatch(make_scoped_ptr(new MouseWheelEvent( 296 mouse_wheel_callback_.Run(MouseWheelEventParams(
298 gfx::Vector2d(scroll->dx, scroll->dy), 297 id_, cursor_->GetLocation(), gfx::Vector2d(scroll->dx, scroll->dy)));
299 cursor_->GetLocation(),
300 cursor_->GetLocation(),
301 modifiers_->GetModifierFlags(),
302 0)));
303 } else { 298 } else {
304 Dispatch(make_scoped_ptr(new ScrollEvent( 299 scroll_callback_.Run(ScrollEventParams(
305 ET_SCROLL, 300 id_, ET_SCROLL, cursor_->GetLocation(),
306 cursor_->GetLocation(), 301 gfx::Vector2dF(scroll->dx, scroll->dy),
307 StimeToTimedelta(gesture->end_time), 302 gfx::Vector2dF(scroll->ordinal_dx, scroll->ordinal_dy),
308 modifiers_->GetModifierFlags(), 303 kGestureScrollFingerCount, StimeToTimedelta(gesture->end_time)));
309 scroll->dx,
310 scroll->dy,
311 scroll->ordinal_dx,
312 scroll->ordinal_dy,
313 kGestureScrollFingerCount)));
314 } 304 }
315 } 305 }
316 306
317 void GestureInterpreterLibevdevCros::OnGestureButtonsChange( 307 void GestureInterpreterLibevdevCros::OnGestureButtonsChange(
318 const Gesture* gesture, 308 const Gesture* gesture,
319 const GestureButtonsChange* buttons) { 309 const GestureButtonsChange* buttons) {
320 DVLOG(3) << base::StringPrintf("Gesture Button Change: down=0x%02x up=0x%02x", 310 DVLOG(3) << base::StringPrintf("Gesture Button Change: down=0x%02x up=0x%02x",
321 buttons->down, 311 buttons->down,
322 buttons->up); 312 buttons->up);
323 313
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 fling->fling_state); 345 fling->fling_state);
356 346
357 if (!cursor_) 347 if (!cursor_)
358 return; // No cursor! 348 return; // No cursor!
359 349
360 EventType type = 350 EventType type =
361 (fling->fling_state == GESTURES_FLING_START ? ET_SCROLL_FLING_START 351 (fling->fling_state == GESTURES_FLING_START ? ET_SCROLL_FLING_START
362 : ET_SCROLL_FLING_CANCEL); 352 : ET_SCROLL_FLING_CANCEL);
363 353
364 // Fling is like 2-finger scrolling but with velocity instead of displacement. 354 // Fling is like 2-finger scrolling but with velocity instead of displacement.
365 Dispatch(make_scoped_ptr(new ScrollEvent(type, 355 scroll_callback_.Run(ScrollEventParams(
366 cursor_->GetLocation(), 356 id_, type, cursor_->GetLocation(), gfx::Vector2dF(fling->vx, fling->vy),
367 StimeToTimedelta(gesture->end_time), 357 gfx::Vector2dF(fling->ordinal_vx, fling->ordinal_vy),
368 modifiers_->GetModifierFlags(), 358 kGestureScrollFingerCount, StimeToTimedelta(gesture->end_time)));
369 fling->vx,
370 fling->vy,
371 fling->ordinal_vx,
372 fling->ordinal_vy,
373 kGestureScrollFingerCount)));
374 } 359 }
375 360
376 void GestureInterpreterLibevdevCros::OnGestureSwipe(const Gesture* gesture, 361 void GestureInterpreterLibevdevCros::OnGestureSwipe(const Gesture* gesture,
377 const GestureSwipe* swipe) { 362 const GestureSwipe* swipe) {
378 DVLOG(3) << base::StringPrintf("Gesture Swipe: (%f, %f) [%f, %f]", 363 DVLOG(3) << base::StringPrintf("Gesture Swipe: (%f, %f) [%f, %f]",
379 swipe->dx, 364 swipe->dx,
380 swipe->dy, 365 swipe->dy,
381 swipe->ordinal_dx, 366 swipe->ordinal_dx,
382 swipe->ordinal_dy); 367 swipe->ordinal_dy);
383 368
384 if (!cursor_) 369 if (!cursor_)
385 return; // No cursor! 370 return; // No cursor!
386 371
387 // Swipe is 3-finger scrolling. 372 // Swipe is 3-finger scrolling.
388 Dispatch(make_scoped_ptr(new ScrollEvent(ET_SCROLL, 373 scroll_callback_.Run(ScrollEventParams(
389 cursor_->GetLocation(), 374 id_, ET_SCROLL, cursor_->GetLocation(),
390 StimeToTimedelta(gesture->end_time), 375 gfx::Vector2dF(swipe->dx, swipe->dy),
391 modifiers_->GetModifierFlags(), 376 gfx::Vector2dF(swipe->ordinal_dx, swipe->ordinal_dy),
392 swipe->dx, 377 kGestureSwipeFingerCount, StimeToTimedelta(gesture->end_time)));
393 swipe->dy,
394 swipe->ordinal_dx,
395 swipe->ordinal_dy,
396 kGestureSwipeFingerCount)));
397 } 378 }
398 379
399 void GestureInterpreterLibevdevCros::OnGestureSwipeLift( 380 void GestureInterpreterLibevdevCros::OnGestureSwipeLift(
400 const Gesture* gesture, 381 const Gesture* gesture,
401 const GestureSwipeLift* swipelift) { 382 const GestureSwipeLift* swipelift) {
402 DVLOG(3) << base::StringPrintf("Gesture Swipe Lift"); 383 DVLOG(3) << base::StringPrintf("Gesture Swipe Lift");
403 384
404 if (!cursor_) 385 if (!cursor_)
405 return; // No cursor! 386 return; // No cursor!
406 387
407 // Turn a swipe lift into a fling start. 388 // Turn a swipe lift into a fling start.
408 // TODO(spang): Figure out why and put it in this comment. 389 // TODO(spang): Figure out why and put it in this comment.
409 390
410 Dispatch(make_scoped_ptr(new ScrollEvent(ET_SCROLL_FLING_START, 391 scroll_callback_.Run(ScrollEventParams(
411 cursor_->GetLocation(), 392 id_, ET_SCROLL_FLING_START, cursor_->GetLocation(),
412 StimeToTimedelta(gesture->end_time), 393 gfx::Vector2dF() /* delta */, gfx::Vector2dF() /* ordinal_delta */,
413 modifiers_->GetModifierFlags(), 394 kGestureScrollFingerCount, StimeToTimedelta(gesture->end_time)));
414 /* x_offset */ 0,
415 /* y_offset */ 0,
416 /* x_offset_ordinal */ 0,
417 /* y_offset_ordinal */ 0,
418 kGestureScrollFingerCount)));
419 } 395 }
420 396
421 void GestureInterpreterLibevdevCros::OnGesturePinch(const Gesture* gesture, 397 void GestureInterpreterLibevdevCros::OnGesturePinch(const Gesture* gesture,
422 const GesturePinch* pinch) { 398 const GesturePinch* pinch) {
423 DVLOG(3) << base::StringPrintf( 399 DVLOG(3) << base::StringPrintf(
424 "Gesture Pinch: dz=%f [%f]", pinch->dz, pinch->ordinal_dz); 400 "Gesture Pinch: dz=%f [%f]", pinch->dz, pinch->ordinal_dz);
425 401
426 if (!cursor_) 402 if (!cursor_)
427 return; // No cursor! 403 return; // No cursor!
428 404
429 NOTIMPLEMENTED(); 405 NOTIMPLEMENTED();
430 } 406 }
431 407
432 void GestureInterpreterLibevdevCros::OnGestureMetrics( 408 void GestureInterpreterLibevdevCros::OnGestureMetrics(
433 const Gesture* gesture, 409 const Gesture* gesture,
434 const GestureMetrics* metrics) { 410 const GestureMetrics* metrics) {
435 DVLOG(3) << base::StringPrintf("Gesture Metrics: [%f, %f] type=%d", 411 DVLOG(3) << base::StringPrintf("Gesture Metrics: [%f, %f] type=%d",
436 metrics->data[0], 412 metrics->data[0],
437 metrics->data[1], 413 metrics->data[1],
438 metrics->type); 414 metrics->type);
439 NOTIMPLEMENTED(); 415 NOTIMPLEMENTED();
440 } 416 }
441 417
442 void GestureInterpreterLibevdevCros::Dispatch(scoped_ptr<Event> event) {
443 dispatch_callback_.Run(event.Pass());
444 }
445
446 void GestureInterpreterLibevdevCros::DispatchMouseButton(unsigned int button, 418 void GestureInterpreterLibevdevCros::DispatchMouseButton(unsigned int button,
447 bool down) { 419 bool down) {
448 bool allow_remap = is_mouse_; 420 bool allow_remap = is_mouse_;
449 mouse_button_callback_.Run(MouseButtonEventParams(id_, cursor_->GetLocation(), 421 mouse_button_callback_.Run(MouseButtonEventParams(id_, cursor_->GetLocation(),
450 button, down, allow_remap)); 422 button, down, allow_remap));
451 } 423 }
452 424
453 void GestureInterpreterLibevdevCros::DispatchChangedKeys(Evdev* evdev, 425 void GestureInterpreterLibevdevCros::DispatchChangedKeys(Evdev* evdev,
454 const timeval& time) { 426 const timeval& time) {
455 unsigned long key_state_diff[EVDEV_BITS_TO_LONGS(KEY_CNT)]; 427 unsigned long key_state_diff[EVDEV_BITS_TO_LONGS(KEY_CNT)];
(...skipping 22 matching lines...) Expand all
478 key_callback_.Run(KeyEventParams(id_, key, value)); 450 key_callback_.Run(KeyEventParams(id_, key, value));
479 } 451 }
480 } 452 }
481 453
482 // Update internal key state. 454 // Update internal key state.
483 for (unsigned long i = 0; i < EVDEV_BITS_TO_LONGS(KEY_CNT); ++i) 455 for (unsigned long i = 0; i < EVDEV_BITS_TO_LONGS(KEY_CNT); ++i)
484 prev_key_state_[i] = evdev->key_state_bitmask[i]; 456 prev_key_state_[i] = evdev->key_state_bitmask[i];
485 } 457 }
486 458
487 } // namespace ui 459 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698