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

Unified Diff: ui/events/devices/x11/device_data_manager_x11.cc

Issue 688253002: Implemented smooth scrolling using xinput2 in X11. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 5 years, 7 months 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 side-by-side diff with in-line comments
Download patch
Index: ui/events/devices/x11/device_data_manager_x11.cc
diff --git a/ui/events/devices/x11/device_data_manager_x11.cc b/ui/events/devices/x11/device_data_manager_x11.cc
index 85704437dfd2a84923762d0c9d770d7f18649661..22cbeadc91e8dad7c27042177911f95b7b7bff95 100644
--- a/ui/events/devices/x11/device_data_manager_x11.cc
+++ b/ui/events/devices/x11/device_data_manager_x11.cc
@@ -209,6 +209,8 @@ void DeviceDataManagerX11::UpdateDeviceList(Display* display) {
data_type_lookup_[i].clear();
valuator_min_[i].clear();
valuator_max_[i].clear();
+ scroll_data_[i].horizontal.number = -1;
+ scroll_data_[i].vertical.number = -1;
for (int j = 0; j < kMaxSlotNum; j++)
last_seen_valuator_[i][j].clear();
}
@@ -264,21 +266,15 @@ void DeviceDataManagerX11::UpdateDeviceList(Display* display) {
for (int j = 0; j < kMaxSlotNum; j++)
last_seen_valuator_[deviceid][j].resize(DT_LAST_ENTRY, 0);
for (int j = 0; j < info.num_classes; ++j) {
- if (info.classes[j]->type != XIValuatorClass)
- continue;
-
- XIValuatorClassInfo* v =
- reinterpret_cast<XIValuatorClassInfo*>(info.classes[j]);
- for (int data_type = 0; data_type < DT_LAST_ENTRY; ++data_type) {
- if (v->label == atoms[data_type]) {
- valuator_lookup_[deviceid][data_type] = v->number;
- data_type_lookup_[deviceid][v->number] = data_type;
- valuator_min_[deviceid][data_type] = v->min;
- valuator_max_[deviceid][data_type] = v->max;
- if (IsCMTDataType(data_type))
- possible_cmt = true;
- break;
- }
+ if (info.classes[j]->type == XIValuatorClass) {
+ if (UpdateValuatorClassDevice(
+ reinterpret_cast<XIValuatorClassInfo*>(info.classes[j]),
+ atoms,
+ deviceid))
+ possible_cmt = true;
+ } else if (info.classes[j]->type == XIScrollClass) {
+ UpdateScrollClassDevice(
+ reinterpret_cast<XIScrollClassInfo*>(info.classes[j]), deviceid);
}
}
@@ -287,6 +283,44 @@ void DeviceDataManagerX11::UpdateDeviceList(Display* display) {
}
}
+bool DeviceDataManagerX11::UpdateValuatorClassDevice(
+ XIValuatorClassInfo* valuator_class_info,
+ Atom *atoms,
+ int deviceid) {
sadrul 2015/08/18 16:57:45 Add a DCHECK here that deviceid is valid.
Will Shackleton 2015/08/26 19:52:48 Acknowledged.
+ for (int data_type = 0; data_type < DT_LAST_ENTRY; ++data_type) {
+ if (valuator_class_info->label == atoms[data_type]) {
+ valuator_lookup_[deviceid][data_type] = valuator_class_info->number;
+ data_type_lookup_[deviceid][valuator_class_info->number] = data_type;
+ valuator_min_[deviceid][data_type] = valuator_class_info->min;
+ valuator_max_[deviceid][data_type] = valuator_class_info->max;
+ if (IsCMTDataType(data_type))
sadrul 2015/08/18 16:57:45 Can you clarify why cmt-data type matters here?
Will Shackleton 2015/08/26 19:52:48 This method is moved from above (line 279, left) -
+ return true;
+ }
+ }
+ return false;
+}
+
+void DeviceDataManagerX11::UpdateScrollClassDevice(
+ XIScrollClassInfo* scroll_class_info,
+ int deviceid) {
sadrul 2015/08/18 16:57:45 DCHECK for deviceid
Will Shackleton 2015/08/26 19:52:48 Acknowledged.
+ ScrollInfo& info = scroll_data_[deviceid];
+ switch (scroll_class_info->scroll_type) {
+ case XIScrollTypeVertical:
+ info.vertical.number = scroll_class_info->number;
+ info.vertical.increment = scroll_class_info->increment;
+ info.vertical.position = 0;
+ info.vertical.seen = false;
+ break;
+ case XIScrollTypeHorizontal:
+ info.horizontal.number = scroll_class_info->number;
+ info.horizontal.increment = scroll_class_info->increment;
+ info.horizontal.position = 0;
+ info.horizontal.seen = false;
+ break;
+ }
+ scrollclass_devices_[deviceid] = true;
+}
+
bool DeviceDataManagerX11::GetSlotNumber(const XIDeviceEvent* xiev, int* slot) {
ui::TouchFactory* factory = ui::TouchFactory::GetInstance();
if (!factory->IsMultiTouchDevice(xiev->sourceid)) {
@@ -409,6 +443,40 @@ bool DeviceDataManagerX11::IsCMTDeviceEvent(
return cmt_devices_[xievent->sourceid];
}
+int DeviceDataManagerX11::GetScrollClassEventDetail(const base::NativeEvent&
+ native_event) const {
+ if (native_event->type != GenericEvent)
+ return SCROLL_TYPE_NO_SCROLL;
+
+ XIDeviceEvent* xievent =
+ static_cast<XIDeviceEvent*>(native_event->xcookie.data);
+ if (xievent->sourceid >= kMaxDeviceNum)
+ return SCROLL_TYPE_NO_SCROLL;
+ if (!scrollclass_devices_[xievent->sourceid])
+ return SCROLL_TYPE_NO_SCROLL;
+ int horizontal_id = scroll_data_[xievent->sourceid].horizontal.number;
+ int vertical_id = scroll_data_[xievent->sourceid].vertical.number;
+ return (XIMaskIsSet(xievent->valuators.mask, horizontal_id) ?
+ SCROLL_TYPE_HORIZONTAL : 0) |
+ (XIMaskIsSet(xievent->valuators.mask, vertical_id) ?
+ SCROLL_TYPE_VERTICAL : 0);
+}
+
+int DeviceDataManagerX11::GetScrollClassDeviceDetail(
+ const base::NativeEvent& native_event) const {
+ XEvent& xev = *native_event;
+ if (xev.type != GenericEvent)
+ return SCROLL_TYPE_NO_SCROLL;
+
+ XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev.xcookie.data);
+ if (xiev->sourceid >= kMaxDeviceNum || xiev->deviceid >= kMaxDeviceNum)
+ return SCROLL_TYPE_NO_SCROLL;
+ const int sourceid = xiev->sourceid;
+ ScrollInfo device_data = scroll_data_[sourceid];
+ return (device_data.vertical.number >= 0 ? SCROLL_TYPE_VERTICAL : 0) |
+ (device_data.horizontal.number >= 0 ? SCROLL_TYPE_HORIZONTAL : 0);
+}
+
bool DeviceDataManagerX11::IsCMTGestureEvent(
const base::NativeEvent& native_event) const {
return (IsScrollEvent(native_event) ||
@@ -496,6 +564,64 @@ void DeviceDataManagerX11::GetScrollOffsets(
*finger_count = static_cast<int>(data[DT_CMT_FINGER_COUNT]);
}
+void DeviceDataManagerX11::GetScrollClassOffsets(
+ const base::NativeEvent& native_event,
+ double* x_offset,
+ double* y_offset) {
+ XEvent& xev = *native_event;
+ if (xev.type != GenericEvent)
+ return;
+
+ *x_offset = 0;
+ *y_offset = 0;
+
+ XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev.xcookie.data);
+ if (xiev->sourceid >= kMaxDeviceNum || xiev->deviceid >= kMaxDeviceNum)
+ return;
+ const int sourceid = xiev->sourceid;
+ double* valuators = xiev->valuators.values;
+
+ ScrollInfo& info = scroll_data_[sourceid];
+
+ const int horizontal_number = info.horizontal.number;
+ const int vertical_number = info.vertical.number;
+
+ for (int i = 0; i <= valuator_count_[sourceid]; ++i) {
+ if (XIMaskIsSet(xiev->valuators.mask, i)) {
sadrul 2015/08/18 16:57:45 if (!mask-set) continue;
Will Shackleton 2015/08/26 19:52:48 Acknowledged.
+ if (i == horizontal_number) {
+ double value = *valuators;
+ double delta = 0;
+
+ if (info.horizontal.seen)
+ delta = info.horizontal.position - value;
+
+ info.horizontal.seen = true;
+ info.horizontal.position = value;
+ *x_offset = delta;
+ NormalizeScrollData(sourceid, true, x_offset);
+ } else if (i == vertical_number) {
+ double value = *valuators;
+ double delta = 0;
+ if (info.vertical.seen)
+ delta = info.vertical.position - value;
+
+ info.vertical.seen = true;
+ info.vertical.position = value;
+ *y_offset = delta;
+ NormalizeScrollData(sourceid, false, y_offset);
+ }
+ valuators++;
+ }
+ }
+}
+
+void DeviceDataManagerX11::InvalidateScrollClasses() {
+ for (int i = 0; i < kMaxDeviceNum; i++) {
+ scroll_data_[i].horizontal.seen = false;
+ scroll_data_[i].vertical.seen = false;
+ }
+}
+
void DeviceDataManagerX11::GetFlingData(
const base::NativeEvent& native_event,
float* vx,
@@ -589,6 +715,23 @@ bool DeviceDataManagerX11::NormalizeData(int deviceid,
return false;
}
+bool DeviceDataManagerX11::NormalizeScrollData(unsigned int deviceid,
+ bool horizontal,
+ double* value) {
+ if (deviceid >= static_cast<unsigned int>(kMaxDeviceNum))
+ return false;
+ if (horizontal && scroll_data_[deviceid].horizontal.number < 0)
+ return false;
+ if (!horizontal && scroll_data_[deviceid].vertical.number < 0)
+ return false;
+ double increment = horizontal ?
+ scroll_data_[deviceid].horizontal.increment :
+ scroll_data_[deviceid].vertical.increment;
+
+ *value /= increment;
+ return true;
+}
+
bool DeviceDataManagerX11::GetDataRange(int deviceid,
const DataType type,
double* min,

Powered by Google App Engine
This is Rietveld 408576698