Index: ui/events/x/device_data_manager_x11.cc |
diff --git a/ui/events/x/device_data_manager_x11.cc b/ui/events/x/device_data_manager_x11.cc |
index 4b29631d1a4927ca41d04f6f8a4053b39846f3e9..f48703f0369b4383398ed65f28b62319cc1b79d6 100644 |
--- a/ui/events/x/device_data_manager_x11.cc |
+++ b/ui/events/x/device_data_manager_x11.cc |
@@ -214,6 +214,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(); |
} |
@@ -266,21 +268,39 @@ 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) { |
+ 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; |
+ } |
} |
+ } else if (info->classes[j]->type == XIScrollClass) { |
+ XIScrollClassInfo* v = |
+ reinterpret_cast<XIScrollClassInfo*>(info->classes[j]); |
+ ScrollInfo& info = scroll_data_[deviceid]; |
+ switch (v->scroll_type) { |
+ case XIScrollTypeVertical: |
+ info.vertical.number = v->number; |
+ info.vertical.increment = v->increment; |
+ info.vertical.position = 0; |
+ info.vertical.seen = false; |
+ break; |
+ case XIScrollTypeHorizontal: |
+ info.horizontal.number = v->number; |
+ info.horizontal.increment = v->increment; |
+ info.horizontal.position = 0; |
+ info.horizontal.seen = false; |
+ break; |
+ } |
+ scrollclass_devices_[deviceid] = true; |
} |
} |
sadrul
2015/01/30 15:49:15
Would it be possible to break this function up int
|
@@ -410,6 +430,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) || |
@@ -497,6 +551,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)) { |
+ 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, |
@@ -590,6 +702,23 @@ bool DeviceDataManagerX11::NormalizeData(unsigned 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(unsigned int deviceid, |
const DataType type, |
double* min, |