OLD | NEW |
---|---|
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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/x/events_x_utils.h" | 5 #include "ui/events/x/events_x_utils.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
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 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
619 gfx::Vector2d GetMouseWheelOffsetFromXEvent(const XEvent& xev) { | 619 gfx::Vector2d GetMouseWheelOffsetFromXEvent(const XEvent& xev) { |
620 float x_offset, y_offset; | 620 float x_offset, y_offset; |
621 if (GetScrollOffsetsFromXEvent(xev, &x_offset, &y_offset, NULL, NULL, NULL)) { | 621 if (GetScrollOffsetsFromXEvent(xev, &x_offset, &y_offset, NULL, NULL, NULL)) { |
622 return gfx::Vector2d(static_cast<int>(x_offset), | 622 return gfx::Vector2d(static_cast<int>(x_offset), |
623 static_cast<int>(y_offset)); | 623 static_cast<int>(y_offset)); |
624 } | 624 } |
625 | 625 |
626 int button = xev.type == GenericEvent ? EventButtonFromXEvent(xev) | 626 int button = xev.type == GenericEvent ? EventButtonFromXEvent(xev) |
627 : xev.xbutton.button; | 627 : xev.xbutton.button; |
628 | 628 |
629 // If this is an xinput1 scroll event from an xinput2 mouse then we need to | |
630 // block the legacy scroll events for the necessary axes. | |
sadrul
2016/04/19 14:28:24
For mouse-press/releases on a normal mouse device,
| |
631 int scroll_class_type = | |
632 DeviceDataManagerX11::GetInstance()->GetScrollClassDeviceDetail(xev); | |
633 bool xi2_vertical = scroll_class_type & SCROLL_TYPE_VERTICAL; | |
634 bool xi2_horizontal = scroll_class_type & SCROLL_TYPE_HORIZONTAL; | |
635 | |
629 switch (button) { | 636 switch (button) { |
630 case 4: | 637 case 4: |
631 return gfx::Vector2d(0, kWheelScrollAmount); | 638 return gfx::Vector2d(0, xi2_vertical ? 0 : kWheelScrollAmount); |
632 case 5: | 639 case 5: |
633 return gfx::Vector2d(0, -kWheelScrollAmount); | 640 return gfx::Vector2d(0, xi2_vertical ? 0 : -kWheelScrollAmount); |
634 case 6: | 641 case 6: |
635 return gfx::Vector2d(kWheelScrollAmount, 0); | 642 return gfx::Vector2d(xi2_horizontal ? 0 : kWheelScrollAmount, 0); |
636 case 7: | 643 case 7: |
637 return gfx::Vector2d(-kWheelScrollAmount, 0); | 644 return gfx::Vector2d(xi2_horizontal ? 0 : -kWheelScrollAmount, 0); |
638 default: | 645 default: |
639 return gfx::Vector2d(); | 646 return gfx::Vector2d(); |
640 } | 647 } |
641 } | 648 } |
642 | 649 |
643 void ClearTouchIdIfReleasedFromXEvent(const XEvent& xev) { | 650 void ClearTouchIdIfReleasedFromXEvent(const XEvent& xev) { |
644 ui::EventType type = ui::EventTypeFromXEvent(xev); | 651 ui::EventType type = ui::EventTypeFromXEvent(xev); |
645 if (type == ui::ET_TOUCH_CANCELLED || type == ui::ET_TOUCH_RELEASED) { | 652 if (type == ui::ET_TOUCH_CANCELLED || type == ui::ET_TOUCH_RELEASED) { |
646 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); | 653 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); |
647 ui::DeviceDataManagerX11* manager = ui::DeviceDataManagerX11::GetInstance(); | 654 ui::DeviceDataManagerX11* manager = ui::DeviceDataManagerX11::GetInstance(); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
724 y_offset_ordinal = &y_offset_ordinal_; | 731 y_offset_ordinal = &y_offset_ordinal_; |
725 if (!finger_count) | 732 if (!finger_count) |
726 finger_count = &finger_count_; | 733 finger_count = &finger_count_; |
727 | 734 |
728 DeviceDataManagerX11::GetInstance()->GetScrollOffsets( | 735 DeviceDataManagerX11::GetInstance()->GetScrollOffsets( |
729 xev, x_offset, y_offset, x_offset_ordinal, y_offset_ordinal, | 736 xev, x_offset, y_offset, x_offset_ordinal, y_offset_ordinal, |
730 finger_count); | 737 finger_count); |
731 return true; | 738 return true; |
732 } | 739 } |
733 | 740 |
734 if (DeviceDataManagerX11::GetInstance()->GetScrollClassDeviceDetail(xev) != | 741 if (DeviceDataManagerX11::GetInstance()->GetScrollClassEventDetail(xev) != |
735 SCROLL_TYPE_NO_SCROLL) { | 742 SCROLL_TYPE_NO_SCROLL) { |
736 double x_scroll_offset, y_scroll_offset; | 743 double x_scroll_offset, y_scroll_offset; |
737 DeviceDataManagerX11::GetInstance()->GetScrollClassOffsets( | 744 DeviceDataManagerX11::GetInstance()->GetScrollClassOffsets( |
738 xev, &x_scroll_offset, &y_scroll_offset); | 745 xev, &x_scroll_offset, &y_scroll_offset); |
739 *x_offset = x_scroll_offset * kWheelScrollAmount; | 746 *x_offset = x_scroll_offset * kWheelScrollAmount; |
740 *y_offset = y_scroll_offset * kWheelScrollAmount; | 747 *y_offset = y_scroll_offset * kWheelScrollAmount; |
741 return true; | 748 return true; |
742 } | 749 } |
743 return false; | 750 return false; |
744 } | 751 } |
(...skipping 25 matching lines...) Expand all Loading... | |
770 vy_ordinal, is_cancel); | 777 vy_ordinal, is_cancel); |
771 return true; | 778 return true; |
772 } | 779 } |
773 | 780 |
774 void ResetTimestampRolloverCountersForTesting() { | 781 void ResetTimestampRolloverCountersForTesting() { |
775 g_last_seen_timestamp_ms_ = 0; | 782 g_last_seen_timestamp_ms_ = 0; |
776 g_rollover_ms_ = 0; | 783 g_rollover_ms_ = 0; |
777 } | 784 } |
778 | 785 |
779 } // namespace ui | 786 } // namespace ui |
OLD | NEW |