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

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

Issue 872683006: [PATCH 3/11] ozone: evdev: Move MouseButtonMap usage during dispatch to EventFactoryEvdev (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update per comments on previous patches 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
« no previous file with comments | « ui/events/ozone/evdev/libgestures_glue/gesture_interpreter_libevdev_cros.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 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" 18 #include "ui/events/ozone/evdev/event_modifiers_evdev.h"
19 #include "ui/events/ozone/evdev/keyboard_util_evdev.h" 19 #include "ui/events/ozone/evdev/keyboard_util_evdev.h"
20 #include "ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h" 20 #include "ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h"
21 #include "ui/events/ozone/evdev/libgestures_glue/gesture_timer_provider.h" 21 #include "ui/events/ozone/evdev/libgestures_glue/gesture_timer_provider.h"
22 #include "ui/events/ozone/evdev/mouse_button_map_evdev.h"
23 #include "ui/gfx/geometry/point_f.h" 22 #include "ui/gfx/geometry/point_f.h"
24 23
25 namespace ui { 24 namespace ui {
26 25
27 namespace { 26 namespace {
28 27
29 // Convert libevdev device class to libgestures device class. 28 // Convert libevdev device class to libgestures device class.
30 GestureInterpreterDeviceClass GestureDeviceClass(Evdev* evdev) { 29 GestureInterpreterDeviceClass GestureDeviceClass(Evdev* evdev) {
31 switch (evdev->info.evdev_class) { 30 switch (evdev->info.evdev_class) {
32 case EvdevClassMouse: 31 case EvdevClassMouse:
33 return GESTURES_DEVCLASS_MOUSE; 32 return GESTURES_DEVCLASS_MOUSE;
34 case EvdevClassMultitouchMouse: 33 case EvdevClassMultitouchMouse:
35 return GESTURES_DEVCLASS_MULTITOUCH_MOUSE; 34 return GESTURES_DEVCLASS_MULTITOUCH_MOUSE;
36 case EvdevClassTouchpad: 35 case EvdevClassTouchpad:
37 return GESTURES_DEVCLASS_TOUCHPAD; 36 return GESTURES_DEVCLASS_TOUCHPAD;
38 case EvdevClassTouchscreen: 37 case EvdevClassTouchscreen:
39 return GESTURES_DEVCLASS_TOUCHSCREEN; 38 return GESTURES_DEVCLASS_TOUCHSCREEN;
40 default: 39 default:
41 return GESTURES_DEVCLASS_UNKNOWN; 40 return GESTURES_DEVCLASS_UNKNOWN;
42 } 41 }
43 } 42 }
44 43
45 // Convert Linux button code to libgestures button code.
46 int GetGestureButton(const MouseButtonMapEvdev::Button code) {
47 switch (code) {
48 case BTN_LEFT:
49 return GESTURES_BUTTON_LEFT;
50 case BTN_RIGHT:
51 return GESTURES_BUTTON_RIGHT;
52 case BTN_MIDDLE:
53 return GESTURES_BUTTON_MIDDLE;
54 case BTN_FORWARD:
55 return GESTURES_BUTTON_FORWARD;
56 case BTN_BACK:
57 return GESTURES_BUTTON_BACK;
58 default:
59 return GESTURES_BUTTON_NONE;
60 }
61 }
62
63 // Convert libevdev state to libgestures hardware properties. 44 // Convert libevdev state to libgestures hardware properties.
64 HardwareProperties GestureHardwareProperties( 45 HardwareProperties GestureHardwareProperties(
65 Evdev* evdev, 46 Evdev* evdev,
66 const GestureDeviceProperties* props) { 47 const GestureDeviceProperties* props) {
67 HardwareProperties hwprops; 48 HardwareProperties hwprops;
68 hwprops.left = props->area_left; 49 hwprops.left = props->area_left;
69 hwprops.top = props->area_top; 50 hwprops.top = props->area_top;
70 hwprops.right = props->area_right; 51 hwprops.right = props->area_right;
71 hwprops.bottom = props->area_bottom; 52 hwprops.bottom = props->area_bottom;
72 hwprops.res_x = props->res_x; 53 hwprops.res_x = props->res_x;
(...skipping 28 matching lines...) Expand all
101 const int kGestureScrollFingerCount = 2; 82 const int kGestureScrollFingerCount = 2;
102 83
103 // Number of fingers for swipe gestures. 84 // Number of fingers for swipe gestures.
104 const int kGestureSwipeFingerCount = 3; 85 const int kGestureSwipeFingerCount = 3;
105 86
106 } // namespace 87 } // namespace
107 88
108 GestureInterpreterLibevdevCros::GestureInterpreterLibevdevCros( 89 GestureInterpreterLibevdevCros::GestureInterpreterLibevdevCros(
109 int id, 90 int id,
110 EventModifiersEvdev* modifiers, 91 EventModifiersEvdev* modifiers,
111 MouseButtonMapEvdev* button_map,
112 CursorDelegateEvdev* cursor, 92 CursorDelegateEvdev* cursor,
113 GesturePropertyProvider* property_provider, 93 GesturePropertyProvider* property_provider,
114 const KeyEventDispatchCallback& key_callback, 94 const KeyEventDispatchCallback& key_callback,
95 const MouseMoveEventDispatchCallback& mouse_move_callback,
96 const MouseButtonEventDispatchCallback& mouse_button_callback,
115 const EventDispatchCallback& callback) 97 const EventDispatchCallback& callback)
116 : id_(id), 98 : id_(id),
117 is_mouse_(false), 99 is_mouse_(false),
118 modifiers_(modifiers), 100 modifiers_(modifiers),
119 button_map_(button_map),
120 cursor_(cursor), 101 cursor_(cursor),
121 property_provider_(property_provider), 102 property_provider_(property_provider),
122 key_callback_(key_callback), 103 key_callback_(key_callback),
104 mouse_move_callback_(mouse_move_callback),
105 mouse_button_callback_(mouse_button_callback),
123 dispatch_callback_(callback), 106 dispatch_callback_(callback),
124 interpreter_(NULL), 107 interpreter_(NULL),
125 evdev_(NULL), 108 evdev_(NULL),
126 device_properties_(new GestureDeviceProperties) { 109 device_properties_(new GestureDeviceProperties) {
127 memset(&prev_key_state_, 0, sizeof(prev_key_state_)); 110 memset(&prev_key_state_, 0, sizeof(prev_key_state_));
128 } 111 }
129 112
130 GestureInterpreterLibevdevCros::~GestureInterpreterLibevdevCros() { 113 GestureInterpreterLibevdevCros::~GestureInterpreterLibevdevCros() {
131 // Note that this destructor got called after the evdev device node has been 114 // Note that this destructor got called after the evdev device node has been
132 // closed. Therefore, all clean-up codes here shouldn't depend on the device 115 // closed. Therefore, all clean-up codes here shouldn't depend on the device
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 fingers[current_finger].position_x = slot->position_x; 193 fingers[current_finger].position_x = slot->position_x;
211 fingers[current_finger].position_y = slot->position_y; 194 fingers[current_finger].position_y = slot->position_y;
212 fingers[current_finger].tracking_id = slot->tracking_id; 195 fingers[current_finger].tracking_id = slot->tracking_id;
213 current_finger++; 196 current_finger++;
214 } 197 }
215 hwstate.touch_cnt = Event_Get_Touch_Count(evdev); 198 hwstate.touch_cnt = Event_Get_Touch_Count(evdev);
216 hwstate.finger_cnt = current_finger; 199 hwstate.finger_cnt = current_finger;
217 hwstate.fingers = fingers; 200 hwstate.fingers = fingers;
218 201
219 // Buttons. 202 // Buttons.
220 // 203 if (Event_Get_Button_Left(evdev))
221 // We do button mapping for physical clicks only when the device is 204 hwstate.buttons_down |= GESTURES_BUTTON_LEFT;
222 // mouse-like (e.g., normal mouse and multi-touch mouse). 205 if (Event_Get_Button_Middle(evdev))
223 if (Event_Get_Button_Left(evdev)) { 206 hwstate.buttons_down |= GESTURES_BUTTON_MIDDLE;
224 hwstate.buttons_down |= GetGestureButton( 207 if (Event_Get_Button_Right(evdev))
225 is_mouse_ ? button_map_->GetMappedButton(BTN_LEFT) : BTN_LEFT); 208 hwstate.buttons_down |= GESTURES_BUTTON_RIGHT;
226 }
227 if (Event_Get_Button_Middle(evdev)) {
228 hwstate.buttons_down |= GetGestureButton(
229 is_mouse_ ? button_map_->GetMappedButton(BTN_MIDDLE) : BTN_MIDDLE);
230 }
231 if (Event_Get_Button_Right(evdev)) {
232 hwstate.buttons_down |= GetGestureButton(
233 is_mouse_ ? button_map_->GetMappedButton(BTN_RIGHT) : BTN_RIGHT);
234 }
235 209
236 GestureInterpreterPushHardwareState(interpreter_, &hwstate); 210 GestureInterpreterPushHardwareState(interpreter_, &hwstate);
237 } 211 }
238 212
239 void GestureInterpreterLibevdevCros::SetAllowedKeys( 213 void GestureInterpreterLibevdevCros::SetAllowedKeys(
240 scoped_ptr<std::set<DomCode>> allowed_keys) { 214 scoped_ptr<std::set<DomCode>> allowed_keys) {
241 if (!allowed_keys) { 215 if (!allowed_keys) {
242 allowed_keys_.reset(); 216 allowed_keys_.reset();
243 return; 217 return;
244 } 218 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 move->dx, 271 move->dx,
298 move->dy, 272 move->dy,
299 move->ordinal_dx, 273 move->ordinal_dx,
300 move->ordinal_dy); 274 move->ordinal_dy);
301 if (!cursor_) 275 if (!cursor_)
302 return; // No cursor! 276 return; // No cursor!
303 277
304 cursor_->MoveCursor(gfx::Vector2dF(move->dx, move->dy)); 278 cursor_->MoveCursor(gfx::Vector2dF(move->dx, move->dy));
305 // TODO(spang): Use move->ordinal_dx, move->ordinal_dy 279 // TODO(spang): Use move->ordinal_dx, move->ordinal_dy
306 // TODO(spang): Use move->start_time, move->end_time 280 // TODO(spang): Use move->start_time, move->end_time
307 Dispatch(make_scoped_ptr(new MouseEvent(ET_MOUSE_MOVED, 281 mouse_move_callback_.Run(MouseMoveEventParams(id_, cursor_->GetLocation()));
308 cursor_->GetLocation(),
309 cursor_->GetLocation(),
310 modifiers_->GetModifierFlags(),
311 /* changed_button_flags */ 0)));
312 } 282 }
313 283
314 void GestureInterpreterLibevdevCros::OnGestureScroll( 284 void GestureInterpreterLibevdevCros::OnGestureScroll(
315 const Gesture* gesture, 285 const Gesture* gesture,
316 const GestureScroll* scroll) { 286 const GestureScroll* scroll) {
317 DVLOG(3) << base::StringPrintf("Gesture Scroll: (%f, %f) [%f, %f]", 287 DVLOG(3) << base::StringPrintf("Gesture Scroll: (%f, %f) [%f, %f]",
318 scroll->dx, 288 scroll->dx,
319 scroll->dy, 289 scroll->dy,
320 scroll->ordinal_dx, 290 scroll->ordinal_dx,
321 scroll->ordinal_dy); 291 scroll->ordinal_dy);
(...skipping 27 matching lines...) Expand all
349 const GestureButtonsChange* buttons) { 319 const GestureButtonsChange* buttons) {
350 DVLOG(3) << base::StringPrintf("Gesture Button Change: down=0x%02x up=0x%02x", 320 DVLOG(3) << base::StringPrintf("Gesture Button Change: down=0x%02x up=0x%02x",
351 buttons->down, 321 buttons->down,
352 buttons->up); 322 buttons->up);
353 323
354 if (!cursor_) 324 if (!cursor_)
355 return; // No cursor! 325 return; // No cursor!
356 326
357 // TODO(spang): Use buttons->start_time, buttons->end_time 327 // TODO(spang): Use buttons->start_time, buttons->end_time
358 if (buttons->down & GESTURES_BUTTON_LEFT) 328 if (buttons->down & GESTURES_BUTTON_LEFT)
359 DispatchMouseButton(EVDEV_MODIFIER_LEFT_MOUSE_BUTTON, true); 329 DispatchMouseButton(BTN_LEFT, true);
360 if (buttons->down & GESTURES_BUTTON_MIDDLE) 330 if (buttons->down & GESTURES_BUTTON_MIDDLE)
361 DispatchMouseButton(EVDEV_MODIFIER_MIDDLE_MOUSE_BUTTON, true); 331 DispatchMouseButton(BTN_MIDDLE, true);
362 if (buttons->down & GESTURES_BUTTON_RIGHT) 332 if (buttons->down & GESTURES_BUTTON_RIGHT)
363 DispatchMouseButton(EVDEV_MODIFIER_RIGHT_MOUSE_BUTTON, true); 333 DispatchMouseButton(BTN_RIGHT, true);
364 if (buttons->up & GESTURES_BUTTON_LEFT) 334 if (buttons->up & GESTURES_BUTTON_LEFT)
365 DispatchMouseButton(EVDEV_MODIFIER_LEFT_MOUSE_BUTTON, false); 335 DispatchMouseButton(BTN_LEFT, false);
366 if (buttons->up & GESTURES_BUTTON_MIDDLE) 336 if (buttons->up & GESTURES_BUTTON_MIDDLE)
367 DispatchMouseButton(EVDEV_MODIFIER_MIDDLE_MOUSE_BUTTON, false); 337 DispatchMouseButton(BTN_MIDDLE, false);
368 if (buttons->up & GESTURES_BUTTON_RIGHT) 338 if (buttons->up & GESTURES_BUTTON_RIGHT)
369 DispatchMouseButton(EVDEV_MODIFIER_RIGHT_MOUSE_BUTTON, false); 339 DispatchMouseButton(BTN_RIGHT, false);
370 } 340 }
371 341
372 void GestureInterpreterLibevdevCros::OnGestureContactInitiated( 342 void GestureInterpreterLibevdevCros::OnGestureContactInitiated(
373 const Gesture* gesture) { 343 const Gesture* gesture) {
374 // TODO(spang): handle contact initiated. 344 // TODO(spang): handle contact initiated.
375 } 345 }
376 346
377 void GestureInterpreterLibevdevCros::OnGestureFling(const Gesture* gesture, 347 void GestureInterpreterLibevdevCros::OnGestureFling(const Gesture* gesture,
378 const GestureFling* fling) { 348 const GestureFling* fling) {
379 DVLOG(3) << base::StringPrintf( 349 DVLOG(3) << base::StringPrintf(
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 metrics->data[0], 436 metrics->data[0],
467 metrics->data[1], 437 metrics->data[1],
468 metrics->type); 438 metrics->type);
469 NOTIMPLEMENTED(); 439 NOTIMPLEMENTED();
470 } 440 }
471 441
472 void GestureInterpreterLibevdevCros::Dispatch(scoped_ptr<Event> event) { 442 void GestureInterpreterLibevdevCros::Dispatch(scoped_ptr<Event> event) {
473 dispatch_callback_.Run(event.Pass()); 443 dispatch_callback_.Run(event.Pass());
474 } 444 }
475 445
476 void GestureInterpreterLibevdevCros::DispatchMouseButton(unsigned int modifier, 446 void GestureInterpreterLibevdevCros::DispatchMouseButton(unsigned int button,
477 bool down) { 447 bool down) {
478 const gfx::PointF location = cursor_->GetLocation(); 448 bool allow_remap = is_mouse_;
479 int flag = modifiers_->GetEventFlagFromModifier(modifier); 449 mouse_button_callback_.Run(MouseButtonEventParams(id_, cursor_->GetLocation(),
480 EventType type = (down ? ET_MOUSE_PRESSED : ET_MOUSE_RELEASED); 450 button, down, allow_remap));
481 modifiers_->UpdateModifier(modifier, down);
482 Dispatch(make_scoped_ptr(new MouseEvent(
483 type, location, location, modifiers_->GetModifierFlags() | flag, flag)));
484 } 451 }
485 452
486 void GestureInterpreterLibevdevCros::DispatchChangedKeys(Evdev* evdev, 453 void GestureInterpreterLibevdevCros::DispatchChangedKeys(Evdev* evdev,
487 const timeval& time) { 454 const timeval& time) {
488 unsigned long key_state_diff[EVDEV_BITS_TO_LONGS(KEY_CNT)]; 455 unsigned long key_state_diff[EVDEV_BITS_TO_LONGS(KEY_CNT)];
489 456
490 // Find changed keys. 457 // Find changed keys.
491 for (unsigned long i = 0; i < arraysize(key_state_diff); ++i) 458 for (unsigned long i = 0; i < arraysize(key_state_diff); ++i)
492 key_state_diff[i] = evdev->key_state_bitmask[i] ^ prev_key_state_[i]; 459 key_state_diff[i] = evdev->key_state_bitmask[i] ^ prev_key_state_[i];
493 460
(...skipping 17 matching lines...) Expand all
511 key_callback_.Run(KeyEventParams(id_, key, value)); 478 key_callback_.Run(KeyEventParams(id_, key, value));
512 } 479 }
513 } 480 }
514 481
515 // Update internal key state. 482 // Update internal key state.
516 for (unsigned long i = 0; i < EVDEV_BITS_TO_LONGS(KEY_CNT); ++i) 483 for (unsigned long i = 0; i < EVDEV_BITS_TO_LONGS(KEY_CNT); ++i)
517 prev_key_state_[i] = evdev->key_state_bitmask[i]; 484 prev_key_state_[i] = evdev->key_state_bitmask[i];
518 } 485 }
519 486
520 } // namespace ui 487 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/ozone/evdev/libgestures_glue/gesture_interpreter_libevdev_cros.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698