Chromium Code Reviews| 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..01b8f39df32bd7a3b3e6dff8ae679457901b7314 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_horizontal_number_[i] = -1; |
| + scroll_vertical_number_[i] = -1; |
| for (int j = 0; j < kMaxSlotNum; j++) |
| last_seen_valuator_[i][j].clear(); |
| } |
| @@ -266,21 +268,38 @@ 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]); |
| + switch (v->scroll_type) { |
| + case XIScrollTypeVertical: |
| + scroll_vertical_number_[deviceid] = v->number; |
| + scroll_vertical_increment_[deviceid] = v->increment; |
| + scroll_vertical_position_[deviceid] = 0; |
| + scroll_vertical_seen_[deviceid] = false; |
| + break; |
| + case XIScrollTypeHorizontal: |
| + scroll_horizontal_number_[deviceid] = v->number; |
| + scroll_horizontal_increment_[deviceid] = v->increment; |
| + scroll_horizontal_position_[deviceid] = 0; |
| + scroll_horizontal_seen_[deviceid] = false; |
| + break; |
| + } |
| + scrollclass_devices_[deviceid] = true; |
| } |
| } |
| @@ -410,6 +429,49 @@ bool DeviceDataManagerX11::IsCMTDeviceEvent( |
| return cmt_devices_[xievent->sourceid]; |
| } |
| +bool DeviceDataManagerX11::IsScrollClassEvent( |
| + const base::NativeEvent& native_event) const { |
| + if (native_event->type != GenericEvent) |
| + return false; |
| + |
| + XIDeviceEvent* xievent = |
| + static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
| + if (xievent->sourceid >= kMaxDeviceNum) |
| + return false; |
| + if (!scrollclass_devices_[xievent->sourceid]) |
| + return false; |
| + int horizontal_id = scroll_horizontal_number_[xievent->sourceid]; |
| + int vertical_id = scroll_vertical_number_[xievent->sourceid]; |
| + return XIMaskIsSet(xievent->valuators.mask, horizontal_id) || |
| + XIMaskIsSet(xievent->valuators.mask, vertical_id); |
| +} |
| + |
| +bool DeviceDataManagerX11::IsScrollClassVerticalDevice( |
| + const base::NativeEvent& native_event) const { |
| + XEvent& xev = *native_event; |
| + if (xev.type != GenericEvent) |
| + return false; |
| + |
| + XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev.xcookie.data); |
| + if (xiev->sourceid >= kMaxDeviceNum || xiev->deviceid >= kMaxDeviceNum) |
| + return false; |
| + const int sourceid = xiev->sourceid; |
| + return scroll_vertical_number_[sourceid] >= 0; |
| +} |
| + |
| +bool DeviceDataManagerX11::IsScrollClassHorizontalDevice( |
| + const base::NativeEvent& native_event) const { |
| + XEvent& xev = *native_event; |
| + if (xev.type != GenericEvent) |
| + return false; |
| + |
| + XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev.xcookie.data); |
| + if (xiev->sourceid >= kMaxDeviceNum || xiev->deviceid >= kMaxDeviceNum) |
| + return false; |
| + const int sourceid = xiev->sourceid; |
| + return scroll_horizontal_number_[sourceid] >= 0; |
| +} |
| + |
| bool DeviceDataManagerX11::IsCMTGestureEvent( |
| const base::NativeEvent& native_event) const { |
| return (IsScrollEvent(native_event) || |
| @@ -497,6 +559,62 @@ 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; |
| + |
| + const int horizontal_number = scroll_horizontal_number_[sourceid]; |
| + const int vertical_number = scroll_vertical_number_[sourceid]; |
| + |
| + 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 (scroll_horizontal_seen_[sourceid]) |
| + delta = scroll_horizontal_position_[sourceid] - value; |
|
sadrul
2014/12/22 17:11:12
Does this mean the first such scroll event is igno
|
| + |
| + scroll_horizontal_seen_[sourceid] = true; |
| + scroll_horizontal_position_[sourceid] = value; |
| + *x_offset = delta; |
| + NormalizeScrollData(sourceid, true, x_offset); |
| + } else if (i == vertical_number) { |
| + double value = *valuators; |
| + double delta = 0; |
| + if (scroll_vertical_seen_[sourceid]) |
| + delta = scroll_vertical_position_[sourceid] - value; |
| + |
| + scroll_vertical_seen_[sourceid] = true; |
| + scroll_vertical_position_[sourceid] = value; |
| + *y_offset = delta; |
| + NormalizeScrollData(sourceid, false, y_offset); |
| + } |
| + valuators++; |
| + } |
| + } |
| +} |
| + |
| +void DeviceDataManagerX11::InvalidateScrollClasses() { |
| + for (int i = 0; i < kMaxDeviceNum; i++) { |
| + scroll_horizontal_seen_[i] = false; |
| + scroll_vertical_seen_[i] = false; |
| + } |
| +} |
| + |
| void DeviceDataManagerX11::GetFlingData( |
| const base::NativeEvent& native_event, |
| float* vx, |
| @@ -590,6 +708,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_horizontal_number_[deviceid] < 0) |
| + return false; |
| + if (!horizontal && scroll_vertical_number_[deviceid] < 0) |
| + return false; |
| + double increment = horizontal ? |
| + scroll_horizontal_increment_[deviceid] : |
| + scroll_vertical_increment_[deviceid]; |
| + |
| + *value /= increment; |
| + return true; |
| +} |
| + |
| bool DeviceDataManagerX11::GetDataRange(unsigned int deviceid, |
| const DataType type, |
| double* min, |