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 <cmath> | 7 #include <cmath> |
8 #include <string.h> | 8 #include <string.h> |
9 #include <X11/extensions/XInput.h> | 9 #include <X11/extensions/XInput.h> |
10 #include <X11/extensions/XInput2.h> | 10 #include <X11/extensions/XInput2.h> |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 } | 437 } |
438 case XI_Motion: { | 438 case XI_Motion: { |
439 bool is_cancel; | 439 bool is_cancel; |
440 DeviceDataManagerX11* devices = DeviceDataManagerX11::GetInstance(); | 440 DeviceDataManagerX11* devices = DeviceDataManagerX11::GetInstance(); |
441 if (GetFlingData(native_event, NULL, NULL, NULL, NULL, &is_cancel)) | 441 if (GetFlingData(native_event, NULL, NULL, NULL, NULL, &is_cancel)) |
442 return is_cancel ? ET_SCROLL_FLING_CANCEL : ET_SCROLL_FLING_START; | 442 return is_cancel ? ET_SCROLL_FLING_CANCEL : ET_SCROLL_FLING_START; |
443 if (devices->IsScrollEvent(native_event)) { | 443 if (devices->IsScrollEvent(native_event)) { |
444 return devices->IsTouchpadXInputEvent(native_event) ? ET_SCROLL | 444 return devices->IsTouchpadXInputEvent(native_event) ? ET_SCROLL |
445 : ET_MOUSEWHEEL; | 445 : ET_MOUSEWHEEL; |
446 } | 446 } |
| 447 if (devices->GetScrollClassEventDetail(native_event) != |
| 448 SCROLL_TYPE_NO_SCROLL) |
| 449 return ET_MOUSEWHEEL; |
447 if (devices->IsCMTMetricsEvent(native_event)) | 450 if (devices->IsCMTMetricsEvent(native_event)) |
448 return ET_UMA_DATA; | 451 return ET_UMA_DATA; |
449 if (GetButtonMaskForX2Event(xievent)) | 452 if (GetButtonMaskForX2Event(xievent)) |
450 return ET_MOUSE_DRAGGED; | 453 return ET_MOUSE_DRAGGED; |
451 return ET_MOUSE_MOVED; | 454 return ET_MOUSE_MOVED; |
452 } | 455 } |
453 case XI_KeyPress: | 456 case XI_KeyPress: |
454 return ET_KEY_PRESSED; | 457 return ET_KEY_PRESSED; |
455 case XI_KeyRelease: | 458 case XI_KeyRelease: |
456 return ET_KEY_RELEASED; | 459 return ET_KEY_RELEASED; |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 float x_offset, y_offset; | 715 float x_offset, y_offset; |
713 if (GetScrollOffsets( | 716 if (GetScrollOffsets( |
714 native_event, &x_offset, &y_offset, NULL, NULL, NULL)) { | 717 native_event, &x_offset, &y_offset, NULL, NULL, NULL)) { |
715 return gfx::Vector2d(static_cast<int>(x_offset), | 718 return gfx::Vector2d(static_cast<int>(x_offset), |
716 static_cast<int>(y_offset)); | 719 static_cast<int>(y_offset)); |
717 } | 720 } |
718 | 721 |
719 int button = native_event->type == GenericEvent ? | 722 int button = native_event->type == GenericEvent ? |
720 EventButtonFromNative(native_event) : native_event->xbutton.button; | 723 EventButtonFromNative(native_event) : native_event->xbutton.button; |
721 | 724 |
| 725 int scroll_class_type = |
| 726 DeviceDataManagerX11::GetInstance() |
| 727 ->GetScrollClassDeviceDetail(native_event); |
| 728 bool vertical_scroll_class = scroll_class_type & SCROLL_TYPE_VERTICAL; |
| 729 bool horizontal_scroll_class = scroll_class_type & SCROLL_TYPE_HORIZONTAL; |
| 730 |
722 switch (button) { | 731 switch (button) { |
723 case 4: | 732 case 4: |
724 return gfx::Vector2d(0, kWheelScrollAmount); | 733 return gfx::Vector2d(0, vertical_scroll_class ? 0 : kWheelScrollAmount); |
725 case 5: | 734 case 5: |
726 return gfx::Vector2d(0, -kWheelScrollAmount); | 735 return gfx::Vector2d(0, vertical_scroll_class ? 0 : -kWheelScrollAmount); |
727 case 6: | 736 case 6: |
728 return gfx::Vector2d(kWheelScrollAmount, 0); | 737 return gfx::Vector2d(horizontal_scroll_class ? 0 : kWheelScrollAmount, 0); |
729 case 7: | 738 case 7: |
730 return gfx::Vector2d(-kWheelScrollAmount, 0); | 739 return gfx::Vector2d(horizontal_scroll_class ? 0 : -kWheelScrollAmount, |
| 740 0); |
731 default: | 741 default: |
732 return gfx::Vector2d(); | 742 return gfx::Vector2d(); |
733 } | 743 } |
734 } | 744 } |
735 | 745 |
736 base::NativeEvent CopyNativeEvent(const base::NativeEvent& event) { | 746 base::NativeEvent CopyNativeEvent(const base::NativeEvent& event) { |
737 if (!event || event->type == GenericEvent) | 747 if (!event || event->type == GenericEvent) |
738 return NULL; | 748 return NULL; |
739 XEvent* copy = new XEvent; | 749 XEvent* copy = new XEvent; |
740 *copy = *event; | 750 *copy = *event; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
816 force = 0.0; | 826 force = 0.0; |
817 return force; | 827 return force; |
818 } | 828 } |
819 | 829 |
820 bool GetScrollOffsets(const base::NativeEvent& native_event, | 830 bool GetScrollOffsets(const base::NativeEvent& native_event, |
821 float* x_offset, | 831 float* x_offset, |
822 float* y_offset, | 832 float* y_offset, |
823 float* x_offset_ordinal, | 833 float* x_offset_ordinal, |
824 float* y_offset_ordinal, | 834 float* y_offset_ordinal, |
825 int* finger_count) { | 835 int* finger_count) { |
826 if (!DeviceDataManagerX11::GetInstance()->IsScrollEvent(native_event)) | 836 if (DeviceDataManagerX11::GetInstance()->IsScrollEvent(native_event)) { |
827 return false; | 837 // Temp values to prevent passing NULLs to DeviceDataManager. |
| 838 float x_offset_, y_offset_; |
| 839 float x_offset_ordinal_, y_offset_ordinal_; |
| 840 int finger_count_; |
| 841 if (!x_offset) |
| 842 x_offset = &x_offset_; |
| 843 if (!y_offset) |
| 844 y_offset = &y_offset_; |
| 845 if (!x_offset_ordinal) |
| 846 x_offset_ordinal = &x_offset_ordinal_; |
| 847 if (!y_offset_ordinal) |
| 848 y_offset_ordinal = &y_offset_ordinal_; |
| 849 if (!finger_count) |
| 850 finger_count = &finger_count_; |
828 | 851 |
829 // Temp values to prevent passing NULLs to DeviceDataManager. | 852 DeviceDataManagerX11::GetInstance()->GetScrollOffsets( |
830 float x_offset_, y_offset_; | 853 native_event, |
831 float x_offset_ordinal_, y_offset_ordinal_; | 854 x_offset, y_offset, |
832 int finger_count_; | 855 x_offset_ordinal, y_offset_ordinal, |
833 if (!x_offset) | 856 finger_count); |
834 x_offset = &x_offset_; | 857 return true; |
835 if (!y_offset) | 858 } |
836 y_offset = &y_offset_; | |
837 if (!x_offset_ordinal) | |
838 x_offset_ordinal = &x_offset_ordinal_; | |
839 if (!y_offset_ordinal) | |
840 y_offset_ordinal = &y_offset_ordinal_; | |
841 if (!finger_count) | |
842 finger_count = &finger_count_; | |
843 | 859 |
844 DeviceDataManagerX11::GetInstance()->GetScrollOffsets( | 860 if (DeviceDataManagerX11::GetInstance()-> |
845 native_event, | 861 GetScrollClassEventDetail(native_event) != SCROLL_TYPE_NO_SCROLL) { |
846 x_offset, y_offset, | 862 double x_scroll_offset, y_scroll_offset; |
847 x_offset_ordinal, y_offset_ordinal, | 863 DeviceDataManagerX11::GetInstance()->GetScrollClassOffsets( |
848 finger_count); | 864 native_event, |
849 return true; | 865 &x_scroll_offset, &y_scroll_offset); |
| 866 *x_offset = x_scroll_offset * kWheelScrollAmount; |
| 867 *y_offset = y_scroll_offset * kWheelScrollAmount; |
| 868 return true; |
| 869 } |
| 870 return false; |
850 } | 871 } |
851 | 872 |
852 bool GetFlingData(const base::NativeEvent& native_event, | 873 bool GetFlingData(const base::NativeEvent& native_event, |
853 float* vx, | 874 float* vx, |
854 float* vy, | 875 float* vy, |
855 float* vx_ordinal, | 876 float* vx_ordinal, |
856 float* vy_ordinal, | 877 float* vy_ordinal, |
857 bool* is_cancel) { | 878 bool* is_cancel) { |
858 if (!DeviceDataManagerX11::GetInstance()->IsFlingEvent(native_event)) | 879 if (!DeviceDataManagerX11::GetInstance()->IsFlingEvent(native_event)) |
859 return false; | 880 return false; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
920 xievent->detail = | 941 xievent->detail = |
921 UpdateX11EventButton(event->changed_button_flags(), xievent->detail); | 942 UpdateX11EventButton(event->changed_button_flags(), xievent->detail); |
922 break; | 943 break; |
923 } | 944 } |
924 default: | 945 default: |
925 break; | 946 break; |
926 } | 947 } |
927 } | 948 } |
928 | 949 |
929 } // namespace ui | 950 } // namespace ui |
OLD | NEW |