| 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 | 9 |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 move->dy, | 244 move->dy, |
| 245 move->ordinal_dx, | 245 move->ordinal_dx, |
| 246 move->ordinal_dy); | 246 move->ordinal_dy); |
| 247 if (!cursor_) | 247 if (!cursor_) |
| 248 return; // No cursor! | 248 return; // No cursor! |
| 249 | 249 |
| 250 cursor_->MoveCursor(gfx::Vector2dF(move->dx, move->dy)); | 250 cursor_->MoveCursor(gfx::Vector2dF(move->dx, move->dy)); |
| 251 // TODO(spang): Use move->ordinal_dx, move->ordinal_dy | 251 // TODO(spang): Use move->ordinal_dx, move->ordinal_dy |
| 252 // TODO(spang): Use move->start_time, move->end_time | 252 // TODO(spang): Use move->start_time, move->end_time |
| 253 Dispatch(make_scoped_ptr(new MouseEvent(ET_MOUSE_MOVED, | 253 Dispatch(make_scoped_ptr(new MouseEvent(ET_MOUSE_MOVED, |
| 254 cursor_->location(), | 254 cursor_->GetLocation(), |
| 255 cursor_->location(), | 255 cursor_->GetLocation(), |
| 256 modifiers_->GetModifierFlags(), | 256 modifiers_->GetModifierFlags(), |
| 257 /* changed_button_flags */ 0))); | 257 /* changed_button_flags */ 0))); |
| 258 } | 258 } |
| 259 | 259 |
| 260 void GestureInterpreterLibevdevCros::OnGestureScroll( | 260 void GestureInterpreterLibevdevCros::OnGestureScroll( |
| 261 const Gesture* gesture, | 261 const Gesture* gesture, |
| 262 const GestureScroll* scroll) { | 262 const GestureScroll* scroll) { |
| 263 DVLOG(3) << base::StringPrintf("Gesture Scroll: (%f, %f) [%f, %f]", | 263 DVLOG(3) << base::StringPrintf("Gesture Scroll: (%f, %f) [%f, %f]", |
| 264 scroll->dx, | 264 scroll->dx, |
| 265 scroll->dy, | 265 scroll->dy, |
| 266 scroll->ordinal_dx, | 266 scroll->ordinal_dx, |
| 267 scroll->ordinal_dy); | 267 scroll->ordinal_dy); |
| 268 if (!cursor_) | 268 if (!cursor_) |
| 269 return; // No cursor! | 269 return; // No cursor! |
| 270 | 270 |
| 271 // TODO(spang): Support SetNaturalScroll | 271 // TODO(spang): Support SetNaturalScroll |
| 272 // TODO(spang): Use scroll->start_time | 272 // TODO(spang): Use scroll->start_time |
| 273 Dispatch(make_scoped_ptr(new ScrollEvent(ET_SCROLL, | 273 Dispatch(make_scoped_ptr(new ScrollEvent(ET_SCROLL, |
| 274 cursor_->location(), | 274 cursor_->GetLocation(), |
| 275 StimeToTimedelta(gesture->end_time), | 275 StimeToTimedelta(gesture->end_time), |
| 276 modifiers_->GetModifierFlags(), | 276 modifiers_->GetModifierFlags(), |
| 277 scroll->dx, | 277 scroll->dx, |
| 278 scroll->dy, | 278 scroll->dy, |
| 279 scroll->ordinal_dx, | 279 scroll->ordinal_dx, |
| 280 scroll->ordinal_dy, | 280 scroll->ordinal_dy, |
| 281 kGestureScrollFingerCount))); | 281 kGestureScrollFingerCount))); |
| 282 } | 282 } |
| 283 | 283 |
| 284 void GestureInterpreterLibevdevCros::OnGestureButtonsChange( | 284 void GestureInterpreterLibevdevCros::OnGestureButtonsChange( |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 | 331 |
| 332 if (!cursor_) | 332 if (!cursor_) |
| 333 return; // No cursor! | 333 return; // No cursor! |
| 334 | 334 |
| 335 EventType type = | 335 EventType type = |
| 336 (fling->fling_state == GESTURES_FLING_START ? ET_SCROLL_FLING_START | 336 (fling->fling_state == GESTURES_FLING_START ? ET_SCROLL_FLING_START |
| 337 : ET_SCROLL_FLING_CANCEL); | 337 : ET_SCROLL_FLING_CANCEL); |
| 338 | 338 |
| 339 // Fling is like 2-finger scrolling but with velocity instead of displacement. | 339 // Fling is like 2-finger scrolling but with velocity instead of displacement. |
| 340 Dispatch(make_scoped_ptr(new ScrollEvent(type, | 340 Dispatch(make_scoped_ptr(new ScrollEvent(type, |
| 341 cursor_->location(), | 341 cursor_->GetLocation(), |
| 342 StimeToTimedelta(gesture->end_time), | 342 StimeToTimedelta(gesture->end_time), |
| 343 modifiers_->GetModifierFlags(), | 343 modifiers_->GetModifierFlags(), |
| 344 fling->vx, | 344 fling->vx, |
| 345 fling->vy, | 345 fling->vy, |
| 346 fling->ordinal_vx, | 346 fling->ordinal_vx, |
| 347 fling->ordinal_vy, | 347 fling->ordinal_vy, |
| 348 kGestureScrollFingerCount))); | 348 kGestureScrollFingerCount))); |
| 349 } | 349 } |
| 350 | 350 |
| 351 void GestureInterpreterLibevdevCros::OnGestureSwipe(const Gesture* gesture, | 351 void GestureInterpreterLibevdevCros::OnGestureSwipe(const Gesture* gesture, |
| 352 const GestureSwipe* swipe) { | 352 const GestureSwipe* swipe) { |
| 353 DVLOG(3) << base::StringPrintf("Gesture Swipe: (%f, %f) [%f, %f]", | 353 DVLOG(3) << base::StringPrintf("Gesture Swipe: (%f, %f) [%f, %f]", |
| 354 swipe->dx, | 354 swipe->dx, |
| 355 swipe->dy, | 355 swipe->dy, |
| 356 swipe->ordinal_dx, | 356 swipe->ordinal_dx, |
| 357 swipe->ordinal_dy); | 357 swipe->ordinal_dy); |
| 358 | 358 |
| 359 if (!cursor_) | 359 if (!cursor_) |
| 360 return; // No cursor! | 360 return; // No cursor! |
| 361 | 361 |
| 362 // Swipe is 3-finger scrolling. | 362 // Swipe is 3-finger scrolling. |
| 363 Dispatch(make_scoped_ptr(new ScrollEvent(ET_SCROLL, | 363 Dispatch(make_scoped_ptr(new ScrollEvent(ET_SCROLL, |
| 364 cursor_->location(), | 364 cursor_->GetLocation(), |
| 365 StimeToTimedelta(gesture->end_time), | 365 StimeToTimedelta(gesture->end_time), |
| 366 modifiers_->GetModifierFlags(), | 366 modifiers_->GetModifierFlags(), |
| 367 swipe->dx, | 367 swipe->dx, |
| 368 swipe->dy, | 368 swipe->dy, |
| 369 swipe->ordinal_dx, | 369 swipe->ordinal_dx, |
| 370 swipe->ordinal_dy, | 370 swipe->ordinal_dy, |
| 371 kGestureSwipeFingerCount))); | 371 kGestureSwipeFingerCount))); |
| 372 } | 372 } |
| 373 | 373 |
| 374 void GestureInterpreterLibevdevCros::OnGestureSwipeLift( | 374 void GestureInterpreterLibevdevCros::OnGestureSwipeLift( |
| 375 const Gesture* gesture, | 375 const Gesture* gesture, |
| 376 const GestureSwipeLift* swipelift) { | 376 const GestureSwipeLift* swipelift) { |
| 377 DVLOG(3) << base::StringPrintf("Gesture Swipe Lift"); | 377 DVLOG(3) << base::StringPrintf("Gesture Swipe Lift"); |
| 378 | 378 |
| 379 if (!cursor_) | 379 if (!cursor_) |
| 380 return; // No cursor! | 380 return; // No cursor! |
| 381 | 381 |
| 382 // Turn a swipe lift into a fling start. | 382 // Turn a swipe lift into a fling start. |
| 383 // TODO(spang): Figure out why and put it in this comment. | 383 // TODO(spang): Figure out why and put it in this comment. |
| 384 | 384 |
| 385 Dispatch(make_scoped_ptr(new ScrollEvent(ET_SCROLL_FLING_START, | 385 Dispatch(make_scoped_ptr(new ScrollEvent(ET_SCROLL_FLING_START, |
| 386 cursor_->location(), | 386 cursor_->GetLocation(), |
| 387 StimeToTimedelta(gesture->end_time), | 387 StimeToTimedelta(gesture->end_time), |
| 388 modifiers_->GetModifierFlags(), | 388 modifiers_->GetModifierFlags(), |
| 389 /* x_offset */ 0, | 389 /* x_offset */ 0, |
| 390 /* y_offset */ 0, | 390 /* y_offset */ 0, |
| 391 /* x_offset_ordinal */ 0, | 391 /* x_offset_ordinal */ 0, |
| 392 /* y_offset_ordinal */ 0, | 392 /* y_offset_ordinal */ 0, |
| 393 kGestureScrollFingerCount))); | 393 kGestureScrollFingerCount))); |
| 394 } | 394 } |
| 395 | 395 |
| 396 void GestureInterpreterLibevdevCros::OnGesturePinch(const Gesture* gesture, | 396 void GestureInterpreterLibevdevCros::OnGesturePinch(const Gesture* gesture, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 413 metrics->type); | 413 metrics->type); |
| 414 NOTIMPLEMENTED(); | 414 NOTIMPLEMENTED(); |
| 415 } | 415 } |
| 416 | 416 |
| 417 void GestureInterpreterLibevdevCros::Dispatch(scoped_ptr<Event> event) { | 417 void GestureInterpreterLibevdevCros::Dispatch(scoped_ptr<Event> event) { |
| 418 dispatch_callback_.Run(event.Pass()); | 418 dispatch_callback_.Run(event.Pass()); |
| 419 } | 419 } |
| 420 | 420 |
| 421 void GestureInterpreterLibevdevCros::DispatchMouseButton(unsigned int modifier, | 421 void GestureInterpreterLibevdevCros::DispatchMouseButton(unsigned int modifier, |
| 422 bool down) { | 422 bool down) { |
| 423 const gfx::PointF& loc = cursor_->location(); | 423 const gfx::PointF location = cursor_->GetLocation(); |
| 424 int flag = modifiers_->GetEventFlagFromModifier(modifier); | 424 int flag = modifiers_->GetEventFlagFromModifier(modifier); |
| 425 EventType type = (down ? ET_MOUSE_PRESSED : ET_MOUSE_RELEASED); | 425 EventType type = (down ? ET_MOUSE_PRESSED : ET_MOUSE_RELEASED); |
| 426 modifiers_->UpdateModifier(modifier, down); | 426 modifiers_->UpdateModifier(modifier, down); |
| 427 Dispatch(make_scoped_ptr(new MouseEvent( | 427 Dispatch(make_scoped_ptr(new MouseEvent( |
| 428 type, loc, loc, modifiers_->GetModifierFlags() | flag, flag))); | 428 type, location, location, modifiers_->GetModifierFlags() | flag, flag))); |
| 429 } | 429 } |
| 430 | 430 |
| 431 void GestureInterpreterLibevdevCros::DispatchChangedKeys(Evdev* evdev, | 431 void GestureInterpreterLibevdevCros::DispatchChangedKeys(Evdev* evdev, |
| 432 const timeval& time) { | 432 const timeval& time) { |
| 433 unsigned long key_state_diff[EVDEV_BITS_TO_LONGS(KEY_CNT)]; | 433 unsigned long key_state_diff[EVDEV_BITS_TO_LONGS(KEY_CNT)]; |
| 434 | 434 |
| 435 // Find changed keys. | 435 // Find changed keys. |
| 436 for (unsigned long i = 0; i < arraysize(key_state_diff); ++i) | 436 for (unsigned long i = 0; i < arraysize(key_state_diff); ++i) |
| 437 key_state_diff[i] = evdev->key_state_bitmask[i] ^ prev_key_state_[i]; | 437 key_state_diff[i] = evdev->key_state_bitmask[i] ^ prev_key_state_[i]; |
| 438 | 438 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 453 keyboard_->OnKeyChange(key, value); | 453 keyboard_->OnKeyChange(key, value); |
| 454 } | 454 } |
| 455 } | 455 } |
| 456 | 456 |
| 457 // Update internal key state. | 457 // Update internal key state. |
| 458 for (unsigned long i = 0; i < EVDEV_BITS_TO_LONGS(KEY_CNT); ++i) | 458 for (unsigned long i = 0; i < EVDEV_BITS_TO_LONGS(KEY_CNT); ++i) |
| 459 prev_key_state_[i] = evdev->key_state_bitmask[i]; | 459 prev_key_state_[i] = evdev->key_state_bitmask[i]; |
| 460 } | 460 } |
| 461 | 461 |
| 462 } // namespace ui | 462 } // namespace ui |
| OLD | NEW |