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

Unified Diff: ui/events/x/device_data_manager.cc

Issue 95403006: x11: Cleanup how valuators are set for X events in tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/events/x/device_data_manager.h ('k') | ui/events/x/events_x_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/events/x/device_data_manager.cc
diff --git a/ui/events/x/device_data_manager.cc b/ui/events/x/device_data_manager.cc
index 12dfb0c834023659410c92f359ea6e9c772b6cac..e3e91deaa21066838441111593ae6a3096b717ae 100644
--- a/ui/events/x/device_data_manager.cc
+++ b/ui/events/x/device_data_manager.cc
@@ -582,9 +582,8 @@ bool DeviceDataManager::GetDataRange(unsigned int deviceid,
}
void DeviceDataManager::SetDeviceListForTest(
- const std::vector<unsigned int>& devices,
- const std::vector<unsigned int>& cmt_devices,
- const std::vector<unsigned int>& touchpads) {
+ const std::vector<unsigned int>& touchscreen,
+ const std::vector<unsigned int>& cmt_devices) {
for (int i = 0; i < kMaxDeviceNum; ++i) {
valuator_count_[i] = 0;
valuator_lookup_[i].clear();
@@ -595,44 +594,59 @@ void DeviceDataManager::SetDeviceListForTest(
last_seen_valuator_[i][j].clear();
}
- for (size_t i = 0; i < devices.size(); i++) {
- unsigned int deviceid = devices[i];
- valuator_lookup_[deviceid].resize(DT_LAST_ENTRY, -1);
- data_type_lookup_[deviceid].resize(DT_LAST_ENTRY, DT_LAST_ENTRY);
- valuator_min_[deviceid].resize(DT_LAST_ENTRY, 0);
- valuator_max_[deviceid].resize(DT_LAST_ENTRY, 0);
- for (int j = 0; j < kMaxSlotNum; j++)
- last_seen_valuator_[deviceid][j].resize(DT_LAST_ENTRY, 0);
+ for (size_t i = 0; i < touchscreen.size(); i++) {
+ unsigned int deviceid = touchscreen[i];
+ InitializeValuatorsForTest(deviceid, kTouchDataTypeStart, kTouchDataTypeEnd,
+ 0, 1000);
}
cmt_devices_.reset();
for (size_t i = 0; i < cmt_devices.size(); ++i) {
- unsigned int deviceid = devices[i];
+ unsigned int deviceid = cmt_devices[i];
cmt_devices_[deviceid] = true;
+ touchpads_[deviceid] = true;
+ InitializeValuatorsForTest(deviceid, kCMTDataTypeStart, kCMTDataTypeEnd,
+ -1000, 1000);
}
+}
- touchpads_.reset();
- for (size_t i = 0; i < touchpads.size(); ++i) {
- unsigned int deviceid = devices[i];
- touchpads_[deviceid] = true;
+void DeviceDataManager::SetValuatorDataForTest(XIDeviceEvent* xievent,
+ DataType type,
+ double value) {
+ int index = valuator_lookup_[xievent->deviceid][type];
+ CHECK(!XIMaskIsSet(xievent->valuators.mask, index));
+ CHECK(index >= 0 && index < valuator_count_[xievent->deviceid]);
+ XISetMask(xievent->valuators.mask, index);
+
+ double* valuators = xievent->valuators.values;
+ for (int i = 0; i < index; ++i) {
+ if (XIMaskIsSet(xievent->valuators.mask, i))
+ valuators++;
}
+ for (int i = valuators - xievent->valuators.values;
+ i < DT_LAST_ENTRY - 1; ++i)
+ xievent->valuators.values[i + 1] = xievent->valuators.values[i];
+ *valuators = value;
}
-void DeviceDataManager::SetDeviceValuatorForTest(int deviceid,
- int val_index,
- DataType data_type,
- double min,
- double max) {
- valuator_lookup_[deviceid][data_type] = val_index;
- data_type_lookup_[deviceid][val_index] = data_type;
- valuator_min_[deviceid][data_type] = min;
- valuator_max_[deviceid][data_type] = max;
-
- // Recalulate the number of valuators for the device.
- valuator_count_[deviceid] = 0;
- for (size_t i = 0; i < DT_LAST_ENTRY; ++i) {
- if (valuator_lookup_[deviceid][i] != -1)
- valuator_count_[deviceid]++;
+void DeviceDataManager::InitializeValuatorsForTest(int deviceid,
+ int start_valuator,
+ int end_valuator,
+ double min_value,
+ double max_value) {
+ valuator_lookup_[deviceid].resize(DT_LAST_ENTRY, -1);
+ data_type_lookup_[deviceid].resize(DT_LAST_ENTRY, DT_LAST_ENTRY);
+ valuator_min_[deviceid].resize(DT_LAST_ENTRY, 0);
+ valuator_max_[deviceid].resize(DT_LAST_ENTRY, 0);
+ for (int j = 0; j < kMaxSlotNum; j++)
+ last_seen_valuator_[deviceid][j].resize(DT_LAST_ENTRY, 0);
+ for (int j = start_valuator; j <= end_valuator; ++j) {
+ valuator_lookup_[deviceid][j] = valuator_count_[deviceid];
+ data_type_lookup_[deviceid][valuator_count_[deviceid]] = j;
+ valuator_min_[deviceid][j] = min_value;
+ valuator_max_[deviceid][j] = max_value;
+ valuator_count_[deviceid]++;
}
}
+
} // namespace ui
« no previous file with comments | « ui/events/x/device_data_manager.h ('k') | ui/events/x/events_x_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698