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 e02162049645fa807b1c05ebaa16b49cdcd6df77..5c15eb7a42281fe395eaefd7a570740b06bc69e6 100644 |
--- a/ui/events/devices/x11/device_data_manager_x11.cc |
+++ b/ui/events/devices/x11/device_data_manager_x11.cc |
@@ -215,6 +215,7 @@ bool DeviceDataManagerX11::IsXInput2Available() const { |
void DeviceDataManagerX11::UpdateDeviceList(Display* display) { |
cmt_devices_.reset(); |
touchpads_.reset(); |
+ scrollclass_devices_.reset(); |
master_pointers_.clear(); |
for (int i = 0; i < kMaxDeviceNum; ++i) { |
valuator_count_[i] = 0; |
@@ -222,6 +223,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; |
sadrul
2016/01/04 18:51:21
This should reset |seen| too?
Will Shackleton
2016/01/04 21:07:41
Acknowledged.
|
for (int j = 0; j < kMaxSlotNum; j++) |
last_seen_valuator_[i][j].clear(); |
} |
@@ -277,21 +280,14 @@ 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); |
} |
} |
@@ -300,6 +296,46 @@ void DeviceDataManagerX11::UpdateDeviceList(Display* display) { |
} |
} |
+bool DeviceDataManagerX11::UpdateValuatorClassDevice( |
sadrul
2016/01/04 18:51:21
This should be farther down (the function order in
|
+ XIValuatorClassInfo* valuator_class_info, |
+ Atom* atoms, |
+ int deviceid) { |
+ DCHECK(deviceid >= 0 && deviceid < kMaxDeviceNum); |
+ 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)) |
+ return true; |
+ } |
sadrul
2016/01/04 18:51:21
The old code breaks out of the loop here. We shoul
Will Shackleton
2016/01/04 21:07:41
Acknowledged.
|
+ } |
+ return false; |
+} |
+ |
+void DeviceDataManagerX11::UpdateScrollClassDevice( |
+ XIScrollClassInfo* scroll_class_info, |
+ int deviceid) { |
+ DCHECK(deviceid >= 0 && deviceid < kMaxDeviceNum); |
+ 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)) { |
@@ -422,6 +458,42 @@ 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]; |
sadrul
2016/01/04 18:51:21
const &
(but we probably don't need this function
|
+ 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) || |
@@ -514,6 +586,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; |
sadrul
2016/01/04 18:51:21
DCHECK_NE(NO_SCROLL, GetScrollClassEventDetail(nat
Will Shackleton
2016/01/04 21:07:41
Acknowledged.
|
+ 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]; |
sadrul
2016/01/04 18:51:21
Use a pointer here instead.
|
+ |
+ 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)) |
+ continue; |
+ 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); |
sadrul
2016/01/04 18:51:21
We already have |info| here. Any reason we can't j
Will Shackleton
2016/01/04 21:07:41
It originally did more iirc. Deleting.
|
+ } 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; |
sadrul
2016/01/04 18:51:21
Let's have a helper function:
if (i == horizont
Will Shackleton
2016/01/04 21:07:41
Acknowledged.
|
+ 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, |
@@ -607,6 +737,22 @@ 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, |