Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(389)

Side by Side Diff: ui/events/x/events_x.cc

Issue 688253002: Implemented smooth scrolling using xinput2 in X11. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed device hotplugging, initialised variable Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 } 433 }
434 case XI_Motion: { 434 case XI_Motion: {
435 bool is_cancel; 435 bool is_cancel;
436 DeviceDataManagerX11* devices = DeviceDataManagerX11::GetInstance(); 436 DeviceDataManagerX11* devices = DeviceDataManagerX11::GetInstance();
437 if (GetFlingData(native_event, NULL, NULL, NULL, NULL, &is_cancel)) 437 if (GetFlingData(native_event, NULL, NULL, NULL, NULL, &is_cancel))
438 return is_cancel ? ET_SCROLL_FLING_CANCEL : ET_SCROLL_FLING_START; 438 return is_cancel ? ET_SCROLL_FLING_CANCEL : ET_SCROLL_FLING_START;
439 if (devices->IsScrollEvent(native_event)) { 439 if (devices->IsScrollEvent(native_event)) {
440 return devices->IsTouchpadXInputEvent(native_event) ? ET_SCROLL 440 return devices->IsTouchpadXInputEvent(native_event) ? ET_SCROLL
441 : ET_MOUSEWHEEL; 441 : ET_MOUSEWHEEL;
442 } 442 }
443 if (devices->GetScrollClassEventDetail(native_event) !=
444 SCROLL_TYPE_NO_SCROLL)
445 return ET_MOUSEWHEEL;
443 if (devices->IsCMTMetricsEvent(native_event)) 446 if (devices->IsCMTMetricsEvent(native_event))
444 return ET_UMA_DATA; 447 return ET_UMA_DATA;
445 if (GetButtonMaskForX2Event(xievent)) 448 if (GetButtonMaskForX2Event(xievent))
446 return ET_MOUSE_DRAGGED; 449 return ET_MOUSE_DRAGGED;
447 if (DeviceDataManagerX11::GetInstance()->HasEventData( 450 if (DeviceDataManagerX11::GetInstance()->HasEventData(
448 xievent, DeviceDataManagerX11::DT_CMT_SCROLL_X) || 451 xievent, DeviceDataManagerX11::DT_CMT_SCROLL_X) ||
449 DeviceDataManagerX11::GetInstance()->HasEventData( 452 DeviceDataManagerX11::GetInstance()->HasEventData(
450 xievent, DeviceDataManagerX11::DT_CMT_SCROLL_Y)) { 453 xievent, DeviceDataManagerX11::DT_CMT_SCROLL_Y)) {
451 // Don't produce mouse move events for mousewheel scrolls. 454 // Don't produce mouse move events for mousewheel scrolls.
452 return ET_UNKNOWN; 455 return ET_UNKNOWN;
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 float x_offset, y_offset; 687 float x_offset, y_offset;
685 if (GetScrollOffsets( 688 if (GetScrollOffsets(
686 native_event, &x_offset, &y_offset, NULL, NULL, NULL)) { 689 native_event, &x_offset, &y_offset, NULL, NULL, NULL)) {
687 return gfx::Vector2d(static_cast<int>(x_offset), 690 return gfx::Vector2d(static_cast<int>(x_offset),
688 static_cast<int>(y_offset)); 691 static_cast<int>(y_offset));
689 } 692 }
690 693
691 int button = native_event->type == GenericEvent ? 694 int button = native_event->type == GenericEvent ?
692 EventButtonFromNative(native_event) : native_event->xbutton.button; 695 EventButtonFromNative(native_event) : native_event->xbutton.button;
693 696
697 int scroll_class_type =
698 DeviceDataManagerX11::GetInstance()->GetScrollClassDeviceDetail(
699 native_event);
700 bool vertical_scroll_class = scroll_class_type & SCROLL_TYPE_VERTICAL;
701 bool horizontal_scroll_class = scroll_class_type & SCROLL_TYPE_HORIZONTAL;
sadrul 2016/01/04 18:51:21 GetScrollOffsets() above should already take care
Will Shackleton 2016/01/04 21:07:42 In the current design this is needed - GetScrollOf
sadrul 2016/01/05 16:46:23 ugh, x11 ... OK. In that case, can we use only Ge
Will Shackleton 2016/01/05 21:27:02 wooooo so even though I've done this and it works
Will Shackleton 2016/01/05 21:27:02 That seems like a better way of doing this.
702
694 switch (button) { 703 switch (button) {
695 case 4: 704 case 4:
696 return gfx::Vector2d(0, kWheelScrollAmount); 705 return gfx::Vector2d(0, vertical_scroll_class ? 0 : kWheelScrollAmount);
697 case 5: 706 case 5:
698 return gfx::Vector2d(0, -kWheelScrollAmount); 707 return gfx::Vector2d(0, vertical_scroll_class ? 0 : -kWheelScrollAmount);
699 case 6: 708 case 6:
700 return gfx::Vector2d(kWheelScrollAmount, 0); 709 return gfx::Vector2d(horizontal_scroll_class ? 0 : kWheelScrollAmount, 0);
701 case 7: 710 case 7:
702 return gfx::Vector2d(-kWheelScrollAmount, 0); 711 return gfx::Vector2d(horizontal_scroll_class ? 0 : -kWheelScrollAmount,
712 0);
703 default: 713 default:
704 return gfx::Vector2d(); 714 return gfx::Vector2d();
705 } 715 }
706 } 716 }
707 717
708 base::NativeEvent CopyNativeEvent(const base::NativeEvent& event) { 718 base::NativeEvent CopyNativeEvent(const base::NativeEvent& event) {
709 if (!event || event->type == GenericEvent) 719 if (!event || event->type == GenericEvent)
710 return NULL; 720 return NULL;
711 XEvent* copy = new XEvent; 721 XEvent* copy = new XEvent;
712 *copy = *event; 722 *copy = *event;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 force = 0.0; 786 force = 0.0;
777 return force; 787 return force;
778 } 788 }
779 789
780 bool GetScrollOffsets(const base::NativeEvent& native_event, 790 bool GetScrollOffsets(const base::NativeEvent& native_event,
781 float* x_offset, 791 float* x_offset,
782 float* y_offset, 792 float* y_offset,
783 float* x_offset_ordinal, 793 float* x_offset_ordinal,
784 float* y_offset_ordinal, 794 float* y_offset_ordinal,
785 int* finger_count) { 795 int* finger_count) {
786 if (!DeviceDataManagerX11::GetInstance()->IsScrollEvent(native_event)) 796 if (DeviceDataManagerX11::GetInstance()->IsScrollEvent(native_event)) {
787 return false; 797 // Temp values to prevent passing NULLs to DeviceDataManager.
798 float x_offset_, y_offset_;
799 float x_offset_ordinal_, y_offset_ordinal_;
800 int finger_count_;
801 if (!x_offset)
802 x_offset = &x_offset_;
803 if (!y_offset)
804 y_offset = &y_offset_;
805 if (!x_offset_ordinal)
806 x_offset_ordinal = &x_offset_ordinal_;
807 if (!y_offset_ordinal)
808 y_offset_ordinal = &y_offset_ordinal_;
809 if (!finger_count)
810 finger_count = &finger_count_;
788 811
789 // Temp values to prevent passing NULLs to DeviceDataManager. 812 DeviceDataManagerX11::GetInstance()->GetScrollOffsets(
790 float x_offset_, y_offset_; 813 native_event, x_offset, y_offset, x_offset_ordinal, y_offset_ordinal,
791 float x_offset_ordinal_, y_offset_ordinal_; 814 finger_count);
792 int finger_count_; 815 return true;
793 if (!x_offset) 816 }
794 x_offset = &x_offset_;
795 if (!y_offset)
796 y_offset = &y_offset_;
797 if (!x_offset_ordinal)
798 x_offset_ordinal = &x_offset_ordinal_;
799 if (!y_offset_ordinal)
800 y_offset_ordinal = &y_offset_ordinal_;
801 if (!finger_count)
802 finger_count = &finger_count_;
803 817
804 DeviceDataManagerX11::GetInstance()->GetScrollOffsets( 818 if (DeviceDataManagerX11::GetInstance()->GetScrollClassEventDetail(
805 native_event, 819 native_event) != SCROLL_TYPE_NO_SCROLL) {
806 x_offset, y_offset, 820 double x_scroll_offset, y_scroll_offset;
807 x_offset_ordinal, y_offset_ordinal, 821 DeviceDataManagerX11::GetInstance()->GetScrollClassOffsets(
808 finger_count); 822 native_event, &x_scroll_offset, &y_scroll_offset);
809 return true; 823 *x_offset = x_scroll_offset * kWheelScrollAmount;
824 *y_offset = y_scroll_offset * kWheelScrollAmount;
825 return true;
826 }
827 return false;
810 } 828 }
811 829
812 bool GetFlingData(const base::NativeEvent& native_event, 830 bool GetFlingData(const base::NativeEvent& native_event,
813 float* vx, 831 float* vx,
814 float* vy, 832 float* vy,
815 float* vx_ordinal, 833 float* vx_ordinal,
816 float* vy_ordinal, 834 float* vy_ordinal,
817 bool* is_cancel) { 835 bool* is_cancel) {
818 if (!DeviceDataManagerX11::GetInstance()->IsFlingEvent(native_event)) 836 if (!DeviceDataManagerX11::GetInstance()->IsFlingEvent(native_event))
819 return false; 837 return false;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 xievent->detail = 898 xievent->detail =
881 UpdateX11EventButton(event->changed_button_flags(), xievent->detail); 899 UpdateX11EventButton(event->changed_button_flags(), xievent->detail);
882 break; 900 break;
883 } 901 }
884 default: 902 default:
885 break; 903 break;
886 } 904 }
887 } 905 }
888 906
889 } // namespace ui 907 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698