Chromium Code Reviews| 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/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
| 14 #include "ui/events/base_event_utils.h" | |
| 14 #include "ui/events/event.h" | 15 #include "ui/events/event.h" |
| 15 #include "ui/events/event_utils.h" | 16 #include "ui/events/event_utils.h" |
| 16 #include "ui/events/keycodes/dom/keycode_converter.h" | 17 #include "ui/events/keycodes/dom/keycode_converter.h" |
| 17 #include "ui/events/ozone/evdev/cursor_delegate_evdev.h" | 18 #include "ui/events/ozone/evdev/cursor_delegate_evdev.h" |
| 18 #include "ui/events/ozone/evdev/device_event_dispatcher_evdev.h" | 19 #include "ui/events/ozone/evdev/device_event_dispatcher_evdev.h" |
| 19 #include "ui/events/ozone/evdev/event_device_info.h" | 20 #include "ui/events/ozone/evdev/event_device_info.h" |
| 20 #include "ui/events/ozone/evdev/event_device_util.h" | 21 #include "ui/events/ozone/evdev/event_device_util.h" |
| 21 #include "ui/events/ozone/evdev/keyboard_util_evdev.h" | 22 #include "ui/events/ozone/evdev/keyboard_util_evdev.h" |
| 22 #include "ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h" | 23 #include "ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h" |
| 23 #include "ui/events/ozone/evdev/libgestures_glue/gesture_timer_provider.h" | 24 #include "ui/events/ozone/evdev/libgestures_glue/gesture_timer_provider.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 } | 72 } |
| 72 | 73 |
| 73 // Callback from libgestures when a gesture is ready. | 74 // Callback from libgestures when a gesture is ready. |
| 74 void OnGestureReadyHelper(void* client_data, const Gesture* gesture) { | 75 void OnGestureReadyHelper(void* client_data, const Gesture* gesture) { |
| 75 GestureInterpreterLibevdevCros* interpreter = | 76 GestureInterpreterLibevdevCros* interpreter = |
| 76 static_cast<GestureInterpreterLibevdevCros*>(client_data); | 77 static_cast<GestureInterpreterLibevdevCros*>(client_data); |
| 77 interpreter->OnGestureReady(gesture); | 78 interpreter->OnGestureReady(gesture); |
| 78 } | 79 } |
| 79 | 80 |
| 80 // Convert gestures timestamp (stime_t) to ui::Event timestamp. | 81 // Convert gestures timestamp (stime_t) to ui::Event timestamp. |
| 81 base::TimeDelta StimeToTimedelta(stime_t timestamp) { | 82 base::TimeTicks StimeToTimeTicks(stime_t timestamp) { |
| 82 return base::TimeDelta::FromMicroseconds(timestamp * | 83 return ui::EventTimeStampFromSeconds(timestamp); |
|
miu
2016/05/16 20:05:35
Same thing here too (regarding this remaining in-l
| |
| 83 base::Time::kMicrosecondsPerSecond); | |
| 84 } | 84 } |
| 85 | 85 |
| 86 // Number of fingers for scroll gestures. | 86 // Number of fingers for scroll gestures. |
| 87 const int kGestureScrollFingerCount = 2; | 87 const int kGestureScrollFingerCount = 2; |
| 88 | 88 |
| 89 // Number of fingers for swipe gestures. | 89 // Number of fingers for swipe gestures. |
| 90 const int kGestureSwipeFingerCount = 3; | 90 const int kGestureSwipeFingerCount = 3; |
| 91 | 91 |
| 92 } // namespace | 92 } // namespace |
| 93 | 93 |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 move->ordinal_dx, | 267 move->ordinal_dx, |
| 268 move->ordinal_dy); | 268 move->ordinal_dy); |
| 269 if (!cursor_) | 269 if (!cursor_) |
| 270 return; // No cursor! | 270 return; // No cursor! |
| 271 | 271 |
| 272 cursor_->MoveCursor(gfx::Vector2dF(move->dx, move->dy)); | 272 cursor_->MoveCursor(gfx::Vector2dF(move->dx, move->dy)); |
| 273 // TODO(spang): Use move->ordinal_dx, move->ordinal_dy | 273 // TODO(spang): Use move->ordinal_dx, move->ordinal_dy |
| 274 dispatcher_->DispatchMouseMoveEvent( | 274 dispatcher_->DispatchMouseMoveEvent( |
| 275 MouseMoveEventParams(id_, cursor_->GetLocation(), | 275 MouseMoveEventParams(id_, cursor_->GetLocation(), |
| 276 PointerDetails(EventPointerType::POINTER_TYPE_MOUSE), | 276 PointerDetails(EventPointerType::POINTER_TYPE_MOUSE), |
| 277 StimeToTimedelta(gesture->end_time))); | 277 StimeToTimeTicks(gesture->end_time))); |
| 278 } | 278 } |
| 279 | 279 |
| 280 void GestureInterpreterLibevdevCros::OnGestureScroll( | 280 void GestureInterpreterLibevdevCros::OnGestureScroll( |
| 281 const Gesture* gesture, | 281 const Gesture* gesture, |
| 282 const GestureScroll* scroll) { | 282 const GestureScroll* scroll) { |
| 283 DVLOG(3) << base::StringPrintf("Gesture Scroll: (%f, %f) [%f, %f]", | 283 DVLOG(3) << base::StringPrintf("Gesture Scroll: (%f, %f) [%f, %f]", |
| 284 scroll->dx, | 284 scroll->dx, |
| 285 scroll->dy, | 285 scroll->dy, |
| 286 scroll->ordinal_dx, | 286 scroll->ordinal_dx, |
| 287 scroll->ordinal_dy); | 287 scroll->ordinal_dy); |
| 288 if (!cursor_) | 288 if (!cursor_) |
| 289 return; // No cursor! | 289 return; // No cursor! |
| 290 | 290 |
| 291 if (is_mouse_) { | 291 if (is_mouse_) { |
| 292 dispatcher_->DispatchMouseWheelEvent(MouseWheelEventParams( | 292 dispatcher_->DispatchMouseWheelEvent(MouseWheelEventParams( |
| 293 id_, cursor_->GetLocation(), gfx::Vector2d(scroll->dx, scroll->dy), | 293 id_, cursor_->GetLocation(), gfx::Vector2d(scroll->dx, scroll->dy), |
| 294 StimeToTimedelta(gesture->end_time))); | 294 StimeToTimeTicks(gesture->end_time))); |
| 295 } else { | 295 } else { |
| 296 dispatcher_->DispatchScrollEvent(ScrollEventParams( | 296 dispatcher_->DispatchScrollEvent(ScrollEventParams( |
| 297 id_, ET_SCROLL, cursor_->GetLocation(), | 297 id_, ET_SCROLL, cursor_->GetLocation(), |
| 298 gfx::Vector2dF(scroll->dx, scroll->dy), | 298 gfx::Vector2dF(scroll->dx, scroll->dy), |
| 299 gfx::Vector2dF(scroll->ordinal_dx, scroll->ordinal_dy), | 299 gfx::Vector2dF(scroll->ordinal_dx, scroll->ordinal_dy), |
| 300 kGestureScrollFingerCount, StimeToTimedelta(gesture->end_time))); | 300 kGestureScrollFingerCount, StimeToTimeTicks(gesture->end_time))); |
| 301 } | 301 } |
| 302 } | 302 } |
| 303 | 303 |
| 304 void GestureInterpreterLibevdevCros::OnGestureButtonsChange( | 304 void GestureInterpreterLibevdevCros::OnGestureButtonsChange( |
| 305 const Gesture* gesture, | 305 const Gesture* gesture, |
| 306 const GestureButtonsChange* buttons) { | 306 const GestureButtonsChange* buttons) { |
| 307 DVLOG(3) << base::StringPrintf("Gesture Button Change: down=0x%02x up=0x%02x", | 307 DVLOG(3) << base::StringPrintf("Gesture Button Change: down=0x%02x up=0x%02x", |
| 308 buttons->down, | 308 buttons->down, |
| 309 buttons->up); | 309 buttons->up); |
| 310 | 310 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 334 return; // No cursor! | 334 return; // No cursor! |
| 335 | 335 |
| 336 EventType type = | 336 EventType type = |
| 337 (fling->fling_state == GESTURES_FLING_START ? ET_SCROLL_FLING_START | 337 (fling->fling_state == GESTURES_FLING_START ? ET_SCROLL_FLING_START |
| 338 : ET_SCROLL_FLING_CANCEL); | 338 : ET_SCROLL_FLING_CANCEL); |
| 339 | 339 |
| 340 // Fling is like 2-finger scrolling but with velocity instead of displacement. | 340 // Fling is like 2-finger scrolling but with velocity instead of displacement. |
| 341 dispatcher_->DispatchScrollEvent(ScrollEventParams( | 341 dispatcher_->DispatchScrollEvent(ScrollEventParams( |
| 342 id_, type, cursor_->GetLocation(), gfx::Vector2dF(fling->vx, fling->vy), | 342 id_, type, cursor_->GetLocation(), gfx::Vector2dF(fling->vx, fling->vy), |
| 343 gfx::Vector2dF(fling->ordinal_vx, fling->ordinal_vy), | 343 gfx::Vector2dF(fling->ordinal_vx, fling->ordinal_vy), |
| 344 kGestureScrollFingerCount, StimeToTimedelta(gesture->end_time))); | 344 kGestureScrollFingerCount, StimeToTimeTicks(gesture->end_time))); |
| 345 } | 345 } |
| 346 | 346 |
| 347 void GestureInterpreterLibevdevCros::OnGestureSwipe(const Gesture* gesture, | 347 void GestureInterpreterLibevdevCros::OnGestureSwipe(const Gesture* gesture, |
| 348 const GestureSwipe* swipe) { | 348 const GestureSwipe* swipe) { |
| 349 DVLOG(3) << base::StringPrintf("Gesture Swipe: (%f, %f) [%f, %f]", | 349 DVLOG(3) << base::StringPrintf("Gesture Swipe: (%f, %f) [%f, %f]", |
| 350 swipe->dx, | 350 swipe->dx, |
| 351 swipe->dy, | 351 swipe->dy, |
| 352 swipe->ordinal_dx, | 352 swipe->ordinal_dx, |
| 353 swipe->ordinal_dy); | 353 swipe->ordinal_dy); |
| 354 | 354 |
| 355 if (!cursor_) | 355 if (!cursor_) |
| 356 return; // No cursor! | 356 return; // No cursor! |
| 357 | 357 |
| 358 // Swipe is 3-finger scrolling. | 358 // Swipe is 3-finger scrolling. |
| 359 dispatcher_->DispatchScrollEvent(ScrollEventParams( | 359 dispatcher_->DispatchScrollEvent(ScrollEventParams( |
| 360 id_, ET_SCROLL, cursor_->GetLocation(), | 360 id_, ET_SCROLL, cursor_->GetLocation(), |
| 361 gfx::Vector2dF(swipe->dx, swipe->dy), | 361 gfx::Vector2dF(swipe->dx, swipe->dy), |
| 362 gfx::Vector2dF(swipe->ordinal_dx, swipe->ordinal_dy), | 362 gfx::Vector2dF(swipe->ordinal_dx, swipe->ordinal_dy), |
| 363 kGestureSwipeFingerCount, StimeToTimedelta(gesture->end_time))); | 363 kGestureSwipeFingerCount, StimeToTimeTicks(gesture->end_time))); |
| 364 } | 364 } |
| 365 | 365 |
| 366 void GestureInterpreterLibevdevCros::OnGestureSwipeLift( | 366 void GestureInterpreterLibevdevCros::OnGestureSwipeLift( |
| 367 const Gesture* gesture, | 367 const Gesture* gesture, |
| 368 const GestureSwipeLift* swipelift) { | 368 const GestureSwipeLift* swipelift) { |
| 369 DVLOG(3) << base::StringPrintf("Gesture Swipe Lift"); | 369 DVLOG(3) << base::StringPrintf("Gesture Swipe Lift"); |
| 370 | 370 |
| 371 if (!cursor_) | 371 if (!cursor_) |
| 372 return; // No cursor! | 372 return; // No cursor! |
| 373 | 373 |
| 374 // Turn a swipe lift into a fling start. | 374 // Turn a swipe lift into a fling start. |
| 375 // TODO(spang): Figure out why and put it in this comment. | 375 // TODO(spang): Figure out why and put it in this comment. |
| 376 | 376 |
| 377 dispatcher_->DispatchScrollEvent(ScrollEventParams( | 377 dispatcher_->DispatchScrollEvent(ScrollEventParams( |
| 378 id_, ET_SCROLL_FLING_START, cursor_->GetLocation(), | 378 id_, ET_SCROLL_FLING_START, cursor_->GetLocation(), |
| 379 gfx::Vector2dF() /* delta */, gfx::Vector2dF() /* ordinal_delta */, | 379 gfx::Vector2dF() /* delta */, gfx::Vector2dF() /* ordinal_delta */, |
| 380 kGestureScrollFingerCount, StimeToTimedelta(gesture->end_time))); | 380 kGestureScrollFingerCount, StimeToTimeTicks(gesture->end_time))); |
| 381 } | 381 } |
| 382 | 382 |
| 383 void GestureInterpreterLibevdevCros::OnGesturePinch(const Gesture* gesture, | 383 void GestureInterpreterLibevdevCros::OnGesturePinch(const Gesture* gesture, |
| 384 const GesturePinch* pinch) { | 384 const GesturePinch* pinch) { |
| 385 DVLOG(3) << base::StringPrintf( | 385 DVLOG(3) << base::StringPrintf( |
| 386 "Gesture Pinch: dz=%f [%f]", pinch->dz, pinch->ordinal_dz); | 386 "Gesture Pinch: dz=%f [%f]", pinch->dz, pinch->ordinal_dz); |
| 387 | 387 |
| 388 if (!cursor_) | 388 if (!cursor_) |
| 389 return; // No cursor! | 389 return; // No cursor! |
| 390 | 390 |
| 391 dispatcher_->DispatchPinchEvent( | 391 dispatcher_->DispatchPinchEvent( |
| 392 PinchEventParams(id_, ET_GESTURE_PINCH_UPDATE, cursor_->GetLocation(), | 392 PinchEventParams(id_, ET_GESTURE_PINCH_UPDATE, cursor_->GetLocation(), |
| 393 pinch->dz, StimeToTimedelta(gesture->end_time))); | 393 pinch->dz, StimeToTimeTicks(gesture->end_time))); |
| 394 } | 394 } |
| 395 | 395 |
| 396 void GestureInterpreterLibevdevCros::OnGestureMetrics( | 396 void GestureInterpreterLibevdevCros::OnGestureMetrics( |
| 397 const Gesture* gesture, | 397 const Gesture* gesture, |
| 398 const GestureMetrics* metrics) { | 398 const GestureMetrics* metrics) { |
| 399 DVLOG(3) << base::StringPrintf("Gesture Metrics: [%f, %f] type=%d", | 399 DVLOG(3) << base::StringPrintf("Gesture Metrics: [%f, %f] type=%d", |
| 400 metrics->data[0], | 400 metrics->data[0], |
| 401 metrics->data[1], | 401 metrics->data[1], |
| 402 metrics->type); | 402 metrics->type); |
| 403 | 403 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 421 void GestureInterpreterLibevdevCros::DispatchMouseButton(unsigned int button, | 421 void GestureInterpreterLibevdevCros::DispatchMouseButton(unsigned int button, |
| 422 bool down, | 422 bool down, |
| 423 stime_t time) { | 423 stime_t time) { |
| 424 if (!SetMouseButtonState(button, down)) | 424 if (!SetMouseButtonState(button, down)) |
| 425 return; // No change. | 425 return; // No change. |
| 426 | 426 |
| 427 bool allow_remap = is_mouse_; | 427 bool allow_remap = is_mouse_; |
| 428 dispatcher_->DispatchMouseButtonEvent(MouseButtonEventParams( | 428 dispatcher_->DispatchMouseButtonEvent(MouseButtonEventParams( |
| 429 id_, cursor_->GetLocation(), button, down, allow_remap, | 429 id_, cursor_->GetLocation(), button, down, allow_remap, |
| 430 PointerDetails(EventPointerType::POINTER_TYPE_MOUSE), | 430 PointerDetails(EventPointerType::POINTER_TYPE_MOUSE), |
| 431 StimeToTimedelta(time))); | 431 StimeToTimeTicks(time))); |
| 432 } | 432 } |
| 433 | 433 |
| 434 void GestureInterpreterLibevdevCros::DispatchChangedKeys( | 434 void GestureInterpreterLibevdevCros::DispatchChangedKeys( |
| 435 unsigned long* new_key_state, | 435 unsigned long* new_key_state, |
| 436 stime_t timestamp) { | 436 stime_t timestamp) { |
| 437 unsigned long key_state_diff[EVDEV_BITS_TO_LONGS(KEY_CNT)]; | 437 unsigned long key_state_diff[EVDEV_BITS_TO_LONGS(KEY_CNT)]; |
| 438 | 438 |
| 439 // Find changed keys. | 439 // Find changed keys. |
| 440 for (unsigned long i = 0; i < arraysize(key_state_diff); ++i) | 440 for (unsigned long i = 0; i < arraysize(key_state_diff); ++i) |
| 441 key_state_diff[i] = new_key_state[i] ^ prev_key_state_[i]; | 441 key_state_diff[i] = new_key_state[i] ^ prev_key_state_[i]; |
| 442 | 442 |
| 443 // Dispatch events for changed keys. | 443 // Dispatch events for changed keys. |
| 444 for (unsigned long key = 0; key < KEY_CNT; ++key) { | 444 for (unsigned long key = 0; key < KEY_CNT; ++key) { |
| 445 if (EvdevBitIsSet(key_state_diff, key)) { | 445 if (EvdevBitIsSet(key_state_diff, key)) { |
| 446 bool value = EvdevBitIsSet(new_key_state, key); | 446 bool value = EvdevBitIsSet(new_key_state, key); |
| 447 | 447 |
| 448 // Mouse buttons are handled by DispatchMouseButton. | 448 // Mouse buttons are handled by DispatchMouseButton. |
| 449 if (key >= BTN_MOUSE && key < BTN_JOYSTICK) | 449 if (key >= BTN_MOUSE && key < BTN_JOYSTICK) |
| 450 continue; | 450 continue; |
| 451 | 451 |
| 452 // Ignore digi buttons (e.g. BTN_TOOL_FINGER). | 452 // Ignore digi buttons (e.g. BTN_TOOL_FINGER). |
| 453 if (key >= BTN_DIGI && key < BTN_WHEEL) | 453 if (key >= BTN_DIGI && key < BTN_WHEEL) |
| 454 continue; | 454 continue; |
| 455 | 455 |
| 456 // Dispatch key press or release to keyboard. | 456 // Dispatch key press or release to keyboard. |
| 457 dispatcher_->DispatchKeyEvent( | 457 dispatcher_->DispatchKeyEvent( |
| 458 KeyEventParams(id_, key, value, false /* suppress_auto_repeat */, | 458 KeyEventParams(id_, key, value, false /* suppress_auto_repeat */, |
| 459 StimeToTimedelta(timestamp))); | 459 StimeToTimeTicks(timestamp))); |
| 460 } | 460 } |
| 461 } | 461 } |
| 462 | 462 |
| 463 // Update internal key state. | 463 // Update internal key state. |
| 464 for (unsigned long i = 0; i < EVDEV_BITS_TO_LONGS(KEY_CNT); ++i) | 464 for (unsigned long i = 0; i < EVDEV_BITS_TO_LONGS(KEY_CNT); ++i) |
| 465 prev_key_state_[i] = new_key_state[i]; | 465 prev_key_state_[i] = new_key_state[i]; |
| 466 } | 466 } |
| 467 | 467 |
| 468 void GestureInterpreterLibevdevCros::ReleaseKeys(stime_t timestamp) { | 468 void GestureInterpreterLibevdevCros::ReleaseKeys(stime_t timestamp) { |
| 469 unsigned long new_key_state[EVDEV_BITS_TO_LONGS(KEY_CNT)]; | 469 unsigned long new_key_state[EVDEV_BITS_TO_LONGS(KEY_CNT)]; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 488 | 488 |
| 489 void GestureInterpreterLibevdevCros::ReleaseMouseButtons(stime_t timestamp) { | 489 void GestureInterpreterLibevdevCros::ReleaseMouseButtons(stime_t timestamp) { |
| 490 DispatchMouseButton(BTN_LEFT, false /* down */, timestamp); | 490 DispatchMouseButton(BTN_LEFT, false /* down */, timestamp); |
| 491 DispatchMouseButton(BTN_MIDDLE, false /* down */, timestamp); | 491 DispatchMouseButton(BTN_MIDDLE, false /* down */, timestamp); |
| 492 DispatchMouseButton(BTN_RIGHT, false /* down */, timestamp); | 492 DispatchMouseButton(BTN_RIGHT, false /* down */, timestamp); |
| 493 DispatchMouseButton(BTN_BACK, false /* down */, timestamp); | 493 DispatchMouseButton(BTN_BACK, false /* down */, timestamp); |
| 494 DispatchMouseButton(BTN_FORWARD, false /* down */, timestamp); | 494 DispatchMouseButton(BTN_FORWARD, false /* down */, timestamp); |
| 495 } | 495 } |
| 496 | 496 |
| 497 } // namespace ui | 497 } // namespace ui |
| OLD | NEW |