| 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 |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 hwstate.buttons_down |= GESTURES_BUTTON_MIDDLE; | 201 hwstate.buttons_down |= GESTURES_BUTTON_MIDDLE; |
| 202 if (Event_Get_Button_Right(evdev)) | 202 if (Event_Get_Button_Right(evdev)) |
| 203 hwstate.buttons_down |= GESTURES_BUTTON_RIGHT; | 203 hwstate.buttons_down |= GESTURES_BUTTON_RIGHT; |
| 204 | 204 |
| 205 GestureInterpreterPushHardwareState(interpreter_, &hwstate); | 205 GestureInterpreterPushHardwareState(interpreter_, &hwstate); |
| 206 } | 206 } |
| 207 | 207 |
| 208 void GestureInterpreterLibevdevCros::OnLibEvdevCrosStopped( | 208 void GestureInterpreterLibevdevCros::OnLibEvdevCrosStopped( |
| 209 Evdev* evdev, | 209 Evdev* evdev, |
| 210 EventStateRec* state) { | 210 EventStateRec* state) { |
| 211 ReleaseKeys(); | 211 stime_t timestamp = StimeNow(); |
| 212 |
| 213 ReleaseKeys(timestamp); |
| 214 ReleaseMouseButtons(timestamp); |
| 212 } | 215 } |
| 213 | 216 |
| 214 void GestureInterpreterLibevdevCros::SetAllowedKeys( | 217 void GestureInterpreterLibevdevCros::SetAllowedKeys( |
| 215 scoped_ptr<std::set<DomCode>> allowed_keys) { | 218 scoped_ptr<std::set<DomCode>> allowed_keys) { |
| 216 if (!allowed_keys) { | 219 if (!allowed_keys) { |
| 217 allowed_keys_.reset(); | 220 allowed_keys_.reset(); |
| 218 return; | 221 return; |
| 219 } | 222 } |
| 220 | 223 |
| 221 allowed_keys_.reset(new std::set<int>()); | 224 allowed_keys_.reset(new std::set<int>()); |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 DVLOG(3) << base::StringPrintf("Gesture Metrics: [%f, %f] type=%d", | 415 DVLOG(3) << base::StringPrintf("Gesture Metrics: [%f, %f] type=%d", |
| 413 metrics->data[0], | 416 metrics->data[0], |
| 414 metrics->data[1], | 417 metrics->data[1], |
| 415 metrics->type); | 418 metrics->type); |
| 416 NOTIMPLEMENTED(); | 419 NOTIMPLEMENTED(); |
| 417 } | 420 } |
| 418 | 421 |
| 419 void GestureInterpreterLibevdevCros::DispatchMouseButton(unsigned int button, | 422 void GestureInterpreterLibevdevCros::DispatchMouseButton(unsigned int button, |
| 420 bool down, | 423 bool down, |
| 421 stime_t time) { | 424 stime_t time) { |
| 425 if (!SetMouseButtonState(button, down)) |
| 426 return; // No change. |
| 427 |
| 422 bool allow_remap = is_mouse_; | 428 bool allow_remap = is_mouse_; |
| 423 dispatcher_->DispatchMouseButtonEvent( | 429 dispatcher_->DispatchMouseButtonEvent( |
| 424 MouseButtonEventParams(id_, cursor_->GetLocation(), button, down, | 430 MouseButtonEventParams(id_, cursor_->GetLocation(), button, down, |
| 425 allow_remap, StimeToTimedelta(time))); | 431 allow_remap, StimeToTimedelta(time))); |
| 426 } | 432 } |
| 427 | 433 |
| 428 void GestureInterpreterLibevdevCros::DispatchChangedKeys( | 434 void GestureInterpreterLibevdevCros::DispatchChangedKeys( |
| 429 unsigned long* new_key_state, | 435 unsigned long* new_key_state, |
| 430 stime_t timestamp) { | 436 stime_t timestamp) { |
| 431 unsigned long key_state_diff[EVDEV_BITS_TO_LONGS(KEY_CNT)]; | 437 unsigned long key_state_diff[EVDEV_BITS_TO_LONGS(KEY_CNT)]; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 454 dispatcher_->DispatchKeyEvent( | 460 dispatcher_->DispatchKeyEvent( |
| 455 KeyEventParams(id_, key, value, StimeToTimedelta(timestamp))); | 461 KeyEventParams(id_, key, value, StimeToTimedelta(timestamp))); |
| 456 } | 462 } |
| 457 } | 463 } |
| 458 | 464 |
| 459 // Update internal key state. | 465 // Update internal key state. |
| 460 for (unsigned long i = 0; i < EVDEV_BITS_TO_LONGS(KEY_CNT); ++i) | 466 for (unsigned long i = 0; i < EVDEV_BITS_TO_LONGS(KEY_CNT); ++i) |
| 461 prev_key_state_[i] = new_key_state[i]; | 467 prev_key_state_[i] = new_key_state[i]; |
| 462 } | 468 } |
| 463 | 469 |
| 464 void GestureInterpreterLibevdevCros::ReleaseKeys() { | 470 void GestureInterpreterLibevdevCros::ReleaseKeys(stime_t timestamp) { |
| 465 unsigned long new_key_state[EVDEV_BITS_TO_LONGS(KEY_CNT)]; | 471 unsigned long new_key_state[EVDEV_BITS_TO_LONGS(KEY_CNT)]; |
| 466 memset(&new_key_state, 0, sizeof(new_key_state)); | 472 memset(&new_key_state, 0, sizeof(new_key_state)); |
| 467 | 473 |
| 468 DispatchChangedKeys(new_key_state, StimeNow()); | 474 DispatchChangedKeys(new_key_state, timestamp); |
| 475 } |
| 476 |
| 477 bool GestureInterpreterLibevdevCros::SetMouseButtonState(unsigned int button, |
| 478 bool down) { |
| 479 DCHECK(BTN_MOUSE <= button && button < BTN_JOYSTICK); |
| 480 int button_offset = button - BTN_MOUSE; |
| 481 |
| 482 if (mouse_button_state_.test(button_offset) == down) |
| 483 return false; |
| 484 |
| 485 // State transition: !(down) -> (down) |
| 486 if (down) |
| 487 mouse_button_state_.set(button_offset); |
| 488 else |
| 489 mouse_button_state_.reset(button_offset); |
| 490 |
| 491 return true; |
| 492 } |
| 493 |
| 494 void GestureInterpreterLibevdevCros::ReleaseMouseButtons(stime_t timestamp) { |
| 495 DispatchMouseButton(BTN_LEFT, false /* down */, timestamp); |
| 496 DispatchMouseButton(BTN_MIDDLE, false /* down */, timestamp); |
| 497 DispatchMouseButton(BTN_RIGHT, false /* down */, timestamp); |
| 469 } | 498 } |
| 470 | 499 |
| 471 } // namespace ui | 500 } // namespace ui |
| OLD | NEW |