Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/event_constants.h" | 5 #include "ui/events/event_constants.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 #include <X11/extensions/XInput.h> | 8 #include <X11/extensions/XInput.h> |
| 9 #include <X11/extensions/XInput2.h> | 9 #include <X11/extensions/XInput2.h> |
| 10 #include <X11/XKBlib.h> | 10 #include <X11/XKBlib.h> |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 431 } | 431 } |
| 432 case XI_Motion: { | 432 case XI_Motion: { |
| 433 bool is_cancel; | 433 bool is_cancel; |
| 434 DeviceDataManagerX11* devices = DeviceDataManagerX11::GetInstance(); | 434 DeviceDataManagerX11* devices = DeviceDataManagerX11::GetInstance(); |
| 435 if (GetFlingData(native_event, NULL, NULL, NULL, NULL, &is_cancel)) | 435 if (GetFlingData(native_event, NULL, NULL, NULL, NULL, &is_cancel)) |
| 436 return is_cancel ? ET_SCROLL_FLING_CANCEL : ET_SCROLL_FLING_START; | 436 return is_cancel ? ET_SCROLL_FLING_CANCEL : ET_SCROLL_FLING_START; |
| 437 if (devices->IsScrollEvent(native_event)) { | 437 if (devices->IsScrollEvent(native_event)) { |
| 438 return devices->IsTouchpadXInputEvent(native_event) ? ET_SCROLL | 438 return devices->IsTouchpadXInputEvent(native_event) ? ET_SCROLL |
| 439 : ET_MOUSEWHEEL; | 439 : ET_MOUSEWHEEL; |
| 440 } | 440 } |
| 441 if (devices->GetScrollClassEventDetail(native_event) != | |
| 442 SCROLL_TYPE_NO_SCROLL) | |
| 443 return ET_MOUSEWHEEL; | |
|
sadrul
2015/08/18 16:57:46
Should IsScrollEvent() return true in this case, s
Will Shackleton
2015/08/26 19:52:48
IsScrollEvent() detects XInput 1 scroll events - t
sadrul
2015/08/26 19:55:57
Is there a reason to have separate API for this? I
| |
| 441 if (devices->IsCMTMetricsEvent(native_event)) | 444 if (devices->IsCMTMetricsEvent(native_event)) |
| 442 return ET_UMA_DATA; | 445 return ET_UMA_DATA; |
| 443 if (GetButtonMaskForX2Event(xievent)) | 446 if (GetButtonMaskForX2Event(xievent)) |
| 444 return ET_MOUSE_DRAGGED; | 447 return ET_MOUSE_DRAGGED; |
| 445 return ET_MOUSE_MOVED; | 448 return ET_MOUSE_MOVED; |
| 446 } | 449 } |
| 447 case XI_KeyPress: | 450 case XI_KeyPress: |
| 448 return ET_KEY_PRESSED; | 451 return ET_KEY_PRESSED; |
| 449 case XI_KeyRelease: | 452 case XI_KeyRelease: |
| 450 return ET_KEY_RELEASED; | 453 return ET_KEY_RELEASED; |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 704 float x_offset, y_offset; | 707 float x_offset, y_offset; |
| 705 if (GetScrollOffsets( | 708 if (GetScrollOffsets( |
| 706 native_event, &x_offset, &y_offset, NULL, NULL, NULL)) { | 709 native_event, &x_offset, &y_offset, NULL, NULL, NULL)) { |
| 707 return gfx::Vector2d(static_cast<int>(x_offset), | 710 return gfx::Vector2d(static_cast<int>(x_offset), |
| 708 static_cast<int>(y_offset)); | 711 static_cast<int>(y_offset)); |
| 709 } | 712 } |
| 710 | 713 |
| 711 int button = native_event->type == GenericEvent ? | 714 int button = native_event->type == GenericEvent ? |
| 712 EventButtonFromNative(native_event) : native_event->xbutton.button; | 715 EventButtonFromNative(native_event) : native_event->xbutton.button; |
| 713 | 716 |
| 717 int scroll_class_type = | |
| 718 DeviceDataManagerX11::GetInstance() | |
| 719 ->GetScrollClassDeviceDetail(native_event); | |
|
sadrul
2015/08/18 16:57:46
Indenting here is off (you can use 'git cl format'
| |
| 720 bool vertical_scroll_class = scroll_class_type & SCROLL_TYPE_VERTICAL; | |
| 721 bool horizontal_scroll_class = scroll_class_type & SCROLL_TYPE_HORIZONTAL; | |
| 722 | |
| 714 switch (button) { | 723 switch (button) { |
| 715 case 4: | 724 case 4: |
| 716 return gfx::Vector2d(0, kWheelScrollAmount); | 725 return gfx::Vector2d(0, vertical_scroll_class ? 0 : kWheelScrollAmount); |
| 717 case 5: | 726 case 5: |
| 718 return gfx::Vector2d(0, -kWheelScrollAmount); | 727 return gfx::Vector2d(0, vertical_scroll_class ? 0 : -kWheelScrollAmount); |
| 719 case 6: | 728 case 6: |
| 720 return gfx::Vector2d(kWheelScrollAmount, 0); | 729 return gfx::Vector2d(horizontal_scroll_class ? 0 : kWheelScrollAmount, 0); |
| 721 case 7: | 730 case 7: |
| 722 return gfx::Vector2d(-kWheelScrollAmount, 0); | 731 return gfx::Vector2d(horizontal_scroll_class ? 0 : -kWheelScrollAmount, |
| 732 0); | |
| 723 default: | 733 default: |
| 724 return gfx::Vector2d(); | 734 return gfx::Vector2d(); |
| 725 } | 735 } |
| 726 } | 736 } |
| 727 | 737 |
| 728 base::NativeEvent CopyNativeEvent(const base::NativeEvent& event) { | 738 base::NativeEvent CopyNativeEvent(const base::NativeEvent& event) { |
| 729 if (!event || event->type == GenericEvent) | 739 if (!event || event->type == GenericEvent) |
| 730 return NULL; | 740 return NULL; |
| 731 XEvent* copy = new XEvent; | 741 XEvent* copy = new XEvent; |
| 732 *copy = *event; | 742 *copy = *event; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 796 force = 0.0; | 806 force = 0.0; |
| 797 return force; | 807 return force; |
| 798 } | 808 } |
| 799 | 809 |
| 800 bool GetScrollOffsets(const base::NativeEvent& native_event, | 810 bool GetScrollOffsets(const base::NativeEvent& native_event, |
| 801 float* x_offset, | 811 float* x_offset, |
| 802 float* y_offset, | 812 float* y_offset, |
| 803 float* x_offset_ordinal, | 813 float* x_offset_ordinal, |
| 804 float* y_offset_ordinal, | 814 float* y_offset_ordinal, |
| 805 int* finger_count) { | 815 int* finger_count) { |
| 806 if (!DeviceDataManagerX11::GetInstance()->IsScrollEvent(native_event)) | 816 if (DeviceDataManagerX11::GetInstance()->IsScrollEvent(native_event)) { |
| 807 return false; | 817 // Temp values to prevent passing NULLs to DeviceDataManager. |
| 818 float x_offset_, y_offset_; | |
| 819 float x_offset_ordinal_, y_offset_ordinal_; | |
| 820 int finger_count_; | |
| 821 if (!x_offset) | |
| 822 x_offset = &x_offset_; | |
| 823 if (!y_offset) | |
| 824 y_offset = &y_offset_; | |
| 825 if (!x_offset_ordinal) | |
| 826 x_offset_ordinal = &x_offset_ordinal_; | |
| 827 if (!y_offset_ordinal) | |
| 828 y_offset_ordinal = &y_offset_ordinal_; | |
| 829 if (!finger_count) | |
| 830 finger_count = &finger_count_; | |
| 808 | 831 |
| 809 // Temp values to prevent passing NULLs to DeviceDataManager. | 832 DeviceDataManagerX11::GetInstance()->GetScrollOffsets( |
| 810 float x_offset_, y_offset_; | 833 native_event, |
| 811 float x_offset_ordinal_, y_offset_ordinal_; | 834 x_offset, y_offset, |
| 812 int finger_count_; | 835 x_offset_ordinal, y_offset_ordinal, |
| 813 if (!x_offset) | 836 finger_count); |
| 814 x_offset = &x_offset_; | 837 return true; |
| 815 if (!y_offset) | 838 } |
| 816 y_offset = &y_offset_; | |
| 817 if (!x_offset_ordinal) | |
| 818 x_offset_ordinal = &x_offset_ordinal_; | |
| 819 if (!y_offset_ordinal) | |
| 820 y_offset_ordinal = &y_offset_ordinal_; | |
| 821 if (!finger_count) | |
| 822 finger_count = &finger_count_; | |
| 823 | 839 |
| 824 DeviceDataManagerX11::GetInstance()->GetScrollOffsets( | 840 if (DeviceDataManagerX11::GetInstance()-> |
| 825 native_event, | 841 GetScrollClassEventDetail(native_event) != SCROLL_TYPE_NO_SCROLL) { |
| 826 x_offset, y_offset, | 842 double x_scroll_offset, y_scroll_offset; |
| 827 x_offset_ordinal, y_offset_ordinal, | 843 DeviceDataManagerX11::GetInstance()->GetScrollClassOffsets( |
| 828 finger_count); | 844 native_event, |
| 829 return true; | 845 &x_scroll_offset, &y_scroll_offset); |
| 846 *x_offset = x_scroll_offset * kWheelScrollAmount; | |
| 847 *y_offset = y_scroll_offset * kWheelScrollAmount; | |
| 848 return true; | |
| 849 } | |
| 850 return false; | |
| 830 } | 851 } |
| 831 | 852 |
| 832 bool GetFlingData(const base::NativeEvent& native_event, | 853 bool GetFlingData(const base::NativeEvent& native_event, |
| 833 float* vx, | 854 float* vx, |
| 834 float* vy, | 855 float* vy, |
| 835 float* vx_ordinal, | 856 float* vx_ordinal, |
| 836 float* vy_ordinal, | 857 float* vy_ordinal, |
| 837 bool* is_cancel) { | 858 bool* is_cancel) { |
| 838 if (!DeviceDataManagerX11::GetInstance()->IsFlingEvent(native_event)) | 859 if (!DeviceDataManagerX11::GetInstance()->IsFlingEvent(native_event)) |
| 839 return false; | 860 return false; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 900 xievent->detail = | 921 xievent->detail = |
| 901 UpdateX11EventButton(event->changed_button_flags(), xievent->detail); | 922 UpdateX11EventButton(event->changed_button_flags(), xievent->detail); |
| 902 break; | 923 break; |
| 903 } | 924 } |
| 904 default: | 925 default: |
| 905 break; | 926 break; |
| 906 } | 927 } |
| 907 } | 928 } |
| 908 | 929 |
| 909 } // namespace ui | 930 } // namespace ui |
| OLD | NEW |