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/devices/x11/device_data_manager_x11.h" | 5 #include "ui/events/devices/x11/device_data_manager_x11.h" |
6 | 6 |
7 #include <X11/extensions/XInput.h> | 7 #include <X11/extensions/XInput.h> |
8 #include <X11/extensions/XInput2.h> | 8 #include <X11/extensions/XInput2.h> |
9 #include <X11/Xlib.h> | 9 #include <X11/Xlib.h> |
10 | 10 |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 return true; | 360 return true; |
361 } else if (IsTouchDataType(type)) { | 361 } else if (IsTouchDataType(type)) { |
362 if (GetSlotNumber(xiev, &slot) && slot >= 0 && slot < kMaxSlotNum) | 362 if (GetSlotNumber(xiev, &slot) && slot >= 0 && slot < kMaxSlotNum) |
363 *value = last_seen_valuator_[sourceid][slot][type]; | 363 *value = last_seen_valuator_[sourceid][slot][type]; |
364 } | 364 } |
365 } | 365 } |
366 | 366 |
367 return false; | 367 return false; |
368 } | 368 } |
369 | 369 |
370 bool DeviceDataManagerX11::IsXIDeviceEvent( | 370 bool DeviceDataManagerX11::IsXIDeviceEvent(const XEvent* native_event) const { |
371 const base::NativeEvent& native_event) const { | |
372 if (native_event->type != GenericEvent || | 371 if (native_event->type != GenericEvent || |
373 native_event->xcookie.extension != xi_opcode_) | 372 native_event->xcookie.extension != xi_opcode_) |
374 return false; | 373 return false; |
375 return xi_device_event_types_[native_event->xcookie.evtype]; | 374 return xi_device_event_types_[native_event->xcookie.evtype]; |
376 } | 375 } |
377 | 376 |
378 bool DeviceDataManagerX11::IsTouchpadXInputEvent( | 377 bool DeviceDataManagerX11::IsTouchpadXInputEvent( |
379 const base::NativeEvent& native_event) const { | 378 const XEvent* native_event) const { |
380 if (native_event->type != GenericEvent) | 379 if (native_event->type != GenericEvent) |
381 return false; | 380 return false; |
382 | 381 |
383 XIDeviceEvent* xievent = | 382 XIDeviceEvent* xievent = |
384 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 383 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
385 if (xievent->sourceid >= kMaxDeviceNum) | 384 if (xievent->sourceid >= kMaxDeviceNum) |
386 return false; | 385 return false; |
387 return touchpads_[xievent->sourceid]; | 386 return touchpads_[xievent->sourceid]; |
388 } | 387 } |
389 | 388 |
390 bool DeviceDataManagerX11::IsCMTDeviceEvent( | 389 bool DeviceDataManagerX11::IsCMTDeviceEvent(const XEvent* native_event) const { |
391 const base::NativeEvent& native_event) const { | |
392 if (native_event->type != GenericEvent) | 390 if (native_event->type != GenericEvent) |
393 return false; | 391 return false; |
394 | 392 |
395 XIDeviceEvent* xievent = | 393 XIDeviceEvent* xievent = |
396 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 394 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
397 if (xievent->sourceid >= kMaxDeviceNum) | 395 if (xievent->sourceid >= kMaxDeviceNum) |
398 return false; | 396 return false; |
399 return cmt_devices_[xievent->sourceid]; | 397 return cmt_devices_[xievent->sourceid]; |
400 } | 398 } |
401 | 399 |
402 bool DeviceDataManagerX11::IsCMTGestureEvent( | 400 bool DeviceDataManagerX11::IsCMTGestureEvent(const XEvent* native_event) const { |
403 const base::NativeEvent& native_event) const { | |
404 return (IsScrollEvent(native_event) || | 401 return (IsScrollEvent(native_event) || |
405 IsFlingEvent(native_event) || | 402 IsFlingEvent(native_event) || |
406 IsCMTMetricsEvent(native_event)); | 403 IsCMTMetricsEvent(native_event)); |
407 } | 404 } |
408 | 405 |
409 bool DeviceDataManagerX11::HasEventData( | 406 bool DeviceDataManagerX11::HasEventData( |
410 const XIDeviceEvent* xiev, const DataType type) const { | 407 const XIDeviceEvent* xiev, const DataType type) const { |
411 const int idx = valuator_lookup_[xiev->sourceid][type]; | 408 const int idx = valuator_lookup_[xiev->sourceid][type]; |
412 return (idx >= 0) && XIMaskIsSet(xiev->valuators.mask, idx); | 409 return (idx >= 0) && XIMaskIsSet(xiev->valuators.mask, idx); |
413 } | 410 } |
414 | 411 |
415 bool DeviceDataManagerX11::IsScrollEvent( | 412 bool DeviceDataManagerX11::IsScrollEvent(const XEvent* native_event) const { |
416 const base::NativeEvent& native_event) const { | |
417 if (!IsCMTDeviceEvent(native_event)) | 413 if (!IsCMTDeviceEvent(native_event)) |
418 return false; | 414 return false; |
419 | 415 |
420 XIDeviceEvent* xiev = | 416 XIDeviceEvent* xiev = |
421 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 417 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
422 return (HasEventData(xiev, DT_CMT_SCROLL_X) || | 418 return (HasEventData(xiev, DT_CMT_SCROLL_X) || |
423 HasEventData(xiev, DT_CMT_SCROLL_Y)); | 419 HasEventData(xiev, DT_CMT_SCROLL_Y)); |
424 } | 420 } |
425 | 421 |
426 bool DeviceDataManagerX11::IsFlingEvent( | 422 bool DeviceDataManagerX11::IsFlingEvent(const XEvent* native_event) const { |
427 const base::NativeEvent& native_event) const { | |
428 if (!IsCMTDeviceEvent(native_event)) | 423 if (!IsCMTDeviceEvent(native_event)) |
429 return false; | 424 return false; |
430 | 425 |
431 XIDeviceEvent* xiev = | 426 XIDeviceEvent* xiev = |
432 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 427 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
433 return (HasEventData(xiev, DT_CMT_FLING_X) && | 428 return (HasEventData(xiev, DT_CMT_FLING_X) && |
434 HasEventData(xiev, DT_CMT_FLING_Y) && | 429 HasEventData(xiev, DT_CMT_FLING_Y) && |
435 HasEventData(xiev, DT_CMT_FLING_STATE)); | 430 HasEventData(xiev, DT_CMT_FLING_STATE)); |
436 } | 431 } |
437 | 432 |
438 bool DeviceDataManagerX11::IsCMTMetricsEvent( | 433 bool DeviceDataManagerX11::IsCMTMetricsEvent(const XEvent* native_event) const { |
439 const base::NativeEvent& native_event) const { | |
440 if (!IsCMTDeviceEvent(native_event)) | 434 if (!IsCMTDeviceEvent(native_event)) |
441 return false; | 435 return false; |
442 | 436 |
443 XIDeviceEvent* xiev = | 437 XIDeviceEvent* xiev = |
444 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 438 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
445 return (HasEventData(xiev, DT_CMT_METRICS_TYPE) && | 439 return (HasEventData(xiev, DT_CMT_METRICS_TYPE) && |
446 HasEventData(xiev, DT_CMT_METRICS_DATA1) && | 440 HasEventData(xiev, DT_CMT_METRICS_DATA1) && |
447 HasEventData(xiev, DT_CMT_METRICS_DATA2)); | 441 HasEventData(xiev, DT_CMT_METRICS_DATA2)); |
448 } | 442 } |
449 | 443 |
450 bool DeviceDataManagerX11::HasGestureTimes( | 444 bool DeviceDataManagerX11::HasGestureTimes(const XEvent* native_event) const { |
451 const base::NativeEvent& native_event) const { | |
452 if (!IsCMTDeviceEvent(native_event)) | 445 if (!IsCMTDeviceEvent(native_event)) |
453 return false; | 446 return false; |
454 | 447 |
455 XIDeviceEvent* xiev = | 448 XIDeviceEvent* xiev = |
456 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 449 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
457 return (HasEventData(xiev, DT_CMT_START_TIME) && | 450 return (HasEventData(xiev, DT_CMT_START_TIME) && |
458 HasEventData(xiev, DT_CMT_END_TIME)); | 451 HasEventData(xiev, DT_CMT_END_TIME)); |
459 } | 452 } |
460 | 453 |
461 void DeviceDataManagerX11::GetScrollOffsets( | 454 void DeviceDataManagerX11::GetScrollOffsets(const XEvent* native_event, |
462 const base::NativeEvent& native_event, | 455 float* x_offset, |
463 float* x_offset, | 456 float* y_offset, |
464 float* y_offset, | 457 float* x_offset_ordinal, |
465 float* x_offset_ordinal, | 458 float* y_offset_ordinal, |
466 float* y_offset_ordinal, | 459 int* finger_count) { |
467 int* finger_count) { | |
468 *x_offset = 0; | 460 *x_offset = 0; |
469 *y_offset = 0; | 461 *y_offset = 0; |
470 *x_offset_ordinal = 0; | 462 *x_offset_ordinal = 0; |
471 *y_offset_ordinal = 0; | 463 *y_offset_ordinal = 0; |
472 *finger_count = 2; | 464 *finger_count = 2; |
473 | 465 |
474 EventData data; | 466 EventData data; |
475 GetEventRawData(*native_event, &data); | 467 GetEventRawData(*native_event, &data); |
476 | 468 |
477 if (data.find(DT_CMT_SCROLL_X) != data.end()) | 469 if (data.find(DT_CMT_SCROLL_X) != data.end()) |
478 *x_offset = data[DT_CMT_SCROLL_X]; | 470 *x_offset = data[DT_CMT_SCROLL_X]; |
479 if (data.find(DT_CMT_SCROLL_Y) != data.end()) | 471 if (data.find(DT_CMT_SCROLL_Y) != data.end()) |
480 *y_offset = data[DT_CMT_SCROLL_Y]; | 472 *y_offset = data[DT_CMT_SCROLL_Y]; |
481 if (data.find(DT_CMT_ORDINAL_X) != data.end()) | 473 if (data.find(DT_CMT_ORDINAL_X) != data.end()) |
482 *x_offset_ordinal = data[DT_CMT_ORDINAL_X]; | 474 *x_offset_ordinal = data[DT_CMT_ORDINAL_X]; |
483 if (data.find(DT_CMT_ORDINAL_Y) != data.end()) | 475 if (data.find(DT_CMT_ORDINAL_Y) != data.end()) |
484 *y_offset_ordinal = data[DT_CMT_ORDINAL_Y]; | 476 *y_offset_ordinal = data[DT_CMT_ORDINAL_Y]; |
485 if (data.find(DT_CMT_FINGER_COUNT) != data.end()) | 477 if (data.find(DT_CMT_FINGER_COUNT) != data.end()) |
486 *finger_count = static_cast<int>(data[DT_CMT_FINGER_COUNT]); | 478 *finger_count = static_cast<int>(data[DT_CMT_FINGER_COUNT]); |
487 } | 479 } |
488 | 480 |
489 void DeviceDataManagerX11::GetFlingData( | 481 void DeviceDataManagerX11::GetFlingData(const XEvent* native_event, |
490 const base::NativeEvent& native_event, | 482 float* vx, |
491 float* vx, | 483 float* vy, |
492 float* vy, | 484 float* vx_ordinal, |
493 float* vx_ordinal, | 485 float* vy_ordinal, |
494 float* vy_ordinal, | 486 bool* is_cancel) { |
495 bool* is_cancel) { | |
496 *vx = 0; | 487 *vx = 0; |
497 *vy = 0; | 488 *vy = 0; |
498 *vx_ordinal = 0; | 489 *vx_ordinal = 0; |
499 *vy_ordinal = 0; | 490 *vy_ordinal = 0; |
500 *is_cancel = false; | 491 *is_cancel = false; |
501 | 492 |
502 EventData data; | 493 EventData data; |
503 GetEventRawData(*native_event, &data); | 494 GetEventRawData(*native_event, &data); |
504 | 495 |
505 if (data.find(DT_CMT_FLING_X) != data.end()) | 496 if (data.find(DT_CMT_FLING_X) != data.end()) |
506 *vx = data[DT_CMT_FLING_X]; | 497 *vx = data[DT_CMT_FLING_X]; |
507 if (data.find(DT_CMT_FLING_Y) != data.end()) | 498 if (data.find(DT_CMT_FLING_Y) != data.end()) |
508 *vy = data[DT_CMT_FLING_Y]; | 499 *vy = data[DT_CMT_FLING_Y]; |
509 if (data.find(DT_CMT_FLING_STATE) != data.end()) | 500 if (data.find(DT_CMT_FLING_STATE) != data.end()) |
510 *is_cancel = !!static_cast<unsigned int>(data[DT_CMT_FLING_STATE]); | 501 *is_cancel = !!static_cast<unsigned int>(data[DT_CMT_FLING_STATE]); |
511 if (data.find(DT_CMT_ORDINAL_X) != data.end()) | 502 if (data.find(DT_CMT_ORDINAL_X) != data.end()) |
512 *vx_ordinal = data[DT_CMT_ORDINAL_X]; | 503 *vx_ordinal = data[DT_CMT_ORDINAL_X]; |
513 if (data.find(DT_CMT_ORDINAL_Y) != data.end()) | 504 if (data.find(DT_CMT_ORDINAL_Y) != data.end()) |
514 *vy_ordinal = data[DT_CMT_ORDINAL_Y]; | 505 *vy_ordinal = data[DT_CMT_ORDINAL_Y]; |
515 } | 506 } |
516 | 507 |
517 void DeviceDataManagerX11::GetMetricsData( | 508 void DeviceDataManagerX11::GetMetricsData(const XEvent* native_event, |
518 const base::NativeEvent& native_event, | 509 GestureMetricsType* type, |
519 GestureMetricsType* type, | 510 float* data1, |
520 float* data1, | 511 float* data2) { |
521 float* data2) { | |
522 *type = kGestureMetricsTypeUnknown; | 512 *type = kGestureMetricsTypeUnknown; |
523 *data1 = 0; | 513 *data1 = 0; |
524 *data2 = 0; | 514 *data2 = 0; |
525 | 515 |
526 EventData data; | 516 EventData data; |
527 GetEventRawData(*native_event, &data); | 517 GetEventRawData(*native_event, &data); |
528 | 518 |
529 if (data.find(DT_CMT_METRICS_TYPE) != data.end()) { | 519 if (data.find(DT_CMT_METRICS_TYPE) != data.end()) { |
530 int val = static_cast<int>(data[DT_CMT_METRICS_TYPE]); | 520 int val = static_cast<int>(data[DT_CMT_METRICS_TYPE]); |
531 if (val == 0) | 521 if (val == 0) |
(...skipping 11 matching lines...) Expand all Loading... |
543 return button > 0 && button <= button_map_count_ ? button_map_[button - 1] : | 533 return button > 0 && button <= button_map_count_ ? button_map_[button - 1] : |
544 button; | 534 button; |
545 } | 535 } |
546 | 536 |
547 void DeviceDataManagerX11::UpdateButtonMap() { | 537 void DeviceDataManagerX11::UpdateButtonMap() { |
548 button_map_count_ = XGetPointerMapping(gfx::GetXDisplay(), | 538 button_map_count_ = XGetPointerMapping(gfx::GetXDisplay(), |
549 button_map_, | 539 button_map_, |
550 arraysize(button_map_)); | 540 arraysize(button_map_)); |
551 } | 541 } |
552 | 542 |
553 void DeviceDataManagerX11::GetGestureTimes( | 543 void DeviceDataManagerX11::GetGestureTimes(const XEvent* native_event, |
554 const base::NativeEvent& native_event, | 544 double* start_time, |
555 double* start_time, | 545 double* end_time) { |
556 double* end_time) { | |
557 *start_time = 0; | 546 *start_time = 0; |
558 *end_time = 0; | 547 *end_time = 0; |
559 | 548 |
560 EventData data; | 549 EventData data; |
561 GetEventRawData(*native_event, &data); | 550 GetEventRawData(*native_event, &data); |
562 | 551 |
563 if (data.find(DT_CMT_START_TIME) != data.end()) | 552 if (data.find(DT_CMT_START_TIME) != data.end()) |
564 *start_time = data[DT_CMT_START_TIME]; | 553 *start_time = data[DT_CMT_START_TIME]; |
565 if (data.find(DT_CMT_END_TIME) != data.end()) | 554 if (data.find(DT_CMT_END_TIME) != data.end()) |
566 *end_time = data[DT_CMT_END_TIME]; | 555 *end_time = data[DT_CMT_END_TIME]; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
702 blocked_keyboards_.find(deviceid); | 691 blocked_keyboards_.find(deviceid); |
703 if (it != blocked_keyboards_.end()) { | 692 if (it != blocked_keyboards_.end()) { |
704 std::vector<KeyboardDevice> devices = keyboard_devices(); | 693 std::vector<KeyboardDevice> devices = keyboard_devices(); |
705 // Add device to current list of active devices. | 694 // Add device to current list of active devices. |
706 devices.push_back((*it).second); | 695 devices.push_back((*it).second); |
707 blocked_keyboards_.erase(it); | 696 blocked_keyboards_.erase(it); |
708 DeviceDataManager::OnKeyboardDevicesUpdated(devices); | 697 DeviceDataManager::OnKeyboardDevicesUpdated(devices); |
709 } | 698 } |
710 } | 699 } |
711 | 700 |
712 bool DeviceDataManagerX11::IsEventBlocked( | 701 bool DeviceDataManagerX11::IsEventBlocked(const XEvent* native_event) { |
713 const base::NativeEvent& native_event) { | |
714 // Only check XI2 events which have a source device id. | 702 // Only check XI2 events which have a source device id. |
715 if (native_event->type != GenericEvent) | 703 if (native_event->type != GenericEvent) |
716 return false; | 704 return false; |
717 | 705 |
718 XIDeviceEvent* xievent = | 706 XIDeviceEvent* xievent = |
719 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 707 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
720 // Allow any key events from blocked_keyboard_allowed_keys_. | 708 // Allow any key events from blocked_keyboard_allowed_keys_. |
721 if (blocked_keyboard_allowed_keys_ && | 709 if (blocked_keyboard_allowed_keys_ && |
722 (xievent->evtype == XI_KeyPress || xievent->evtype == XI_KeyRelease) && | 710 (xievent->evtype == XI_KeyPress || xievent->evtype == XI_KeyRelease) && |
723 blocked_keyboard_allowed_keys_->find( | 711 blocked_keyboard_allowed_keys_->find( |
(...skipping 25 matching lines...) Expand all Loading... |
749 } else { | 737 } else { |
750 keyboards.erase(it); | 738 keyboards.erase(it); |
751 ++blocked_iter; | 739 ++blocked_iter; |
752 } | 740 } |
753 } | 741 } |
754 // Notify base class of updated list. | 742 // Notify base class of updated list. |
755 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); | 743 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); |
756 } | 744 } |
757 | 745 |
758 } // namespace ui | 746 } // namespace ui |
OLD | NEW |