Index: ui/events/test/events_test_utils_x11.cc |
diff --git a/ui/events/test/events_test_utils_x11.cc b/ui/events/test/events_test_utils_x11.cc |
index 9b2cc5bbd1063beeaed767adf17972a0248c42b9..e647f216d684cee71f6bf97022e17fadddfe032c 100644 |
--- a/ui/events/test/events_test_utils_x11.cc |
+++ b/ui/events/test/events_test_utils_x11.cc |
@@ -16,24 +16,6 @@ |
namespace { |
-const int kScrollValuatorNum = 5; |
-const int kScrollValuatorMap[kScrollValuatorNum][4] = { |
- // { valuator_index, valuator_type, min_val, max_val } |
- { 0, ui::DeviceDataManager::DT_CMT_SCROLL_X, -100, 100 }, |
- { 1, ui::DeviceDataManager::DT_CMT_SCROLL_Y, -100, 100 }, |
- { 2, ui::DeviceDataManager::DT_CMT_ORDINAL_X, -100, 100 }, |
- { 3, ui::DeviceDataManager::DT_CMT_ORDINAL_Y, -100, 100 }, |
- { 4, ui::DeviceDataManager::DT_CMT_FINGER_COUNT, 0, 3}, |
-}; |
- |
-const int kTouchValuatorNum = 3; |
-const int kTouchValuatorMap[kTouchValuatorNum][4] = { |
- // { valuator_index, valuator_type, min_val, max_val } |
- { 0, ui::DeviceDataManager::DT_TOUCH_MAJOR, 0, 1000}, |
- { 1, ui::DeviceDataManager::DT_TOUCH_ORIENTATION, 0, 1}, |
- { 2, ui::DeviceDataManager::DT_TOUCH_PRESSURE, 0, 1000}, |
-}; |
- |
// Converts ui::EventType to state for X*Events. |
unsigned int XEventState(int flags) { |
return |
@@ -104,7 +86,8 @@ unsigned int XButtonEventButton(ui::EventType type, |
return 0; |
} |
-void InitValuatorsForXIDeviceEvent(XIDeviceEvent* xiev, int valuator_count) { |
+void InitValuatorsForXIDeviceEvent(XIDeviceEvent* xiev) { |
+ int valuator_count = ui::DeviceDataManager::DT_LAST_ENTRY; |
xiev->valuators.mask_len = (valuator_count / 8) + 1; |
xiev->valuators.mask = new unsigned char[xiev->valuators.mask_len]; |
memset(xiev->valuators.mask, 0, xiev->valuators.mask_len); |
@@ -204,18 +187,17 @@ void ScopedXI2Event::InitScrollEvent(int deviceid, |
int y_offset_ordinal, |
int finger_count) { |
Cleanup(); |
- event_.reset(CreateXInput2Event(deviceid, XI_Motion, deviceid, gfx::Point())); |
+ event_.reset(CreateXInput2Event(deviceid, XI_Motion, 0, gfx::Point())); |
- int valuator_data[kScrollValuatorNum] = |
- { x_offset, y_offset, x_offset_ordinal, y_offset_ordinal, finger_count}; |
- XIDeviceEvent* xiev = |
- static_cast<XIDeviceEvent*>(event_->xcookie.data); |
- |
- InitValuatorsForXIDeviceEvent(xiev, kScrollValuatorNum); |
- for(int i = 0; i < kScrollValuatorNum; i++) { |
- XISetMask(xiev->valuators.mask, i); |
- xiev->valuators.values[i] = valuator_data[i]; |
- } |
+ Valuator valuators[] = { |
+ Valuator(DeviceDataManager::DT_CMT_SCROLL_X, x_offset), |
+ Valuator(DeviceDataManager::DT_CMT_SCROLL_Y, y_offset), |
+ Valuator(DeviceDataManager::DT_CMT_ORDINAL_X, x_offset_ordinal), |
+ Valuator(DeviceDataManager::DT_CMT_ORDINAL_Y, y_offset_ordinal), |
+ Valuator(DeviceDataManager::DT_CMT_FINGER_COUNT, finger_count) |
+ }; |
+ SetUpValuators( |
+ std::vector<Valuator>(valuators, valuators + arraysize(valuators))); |
} |
void ScopedXI2Event::InitTouchEvent(int deviceid, |
@@ -224,22 +206,8 @@ void ScopedXI2Event::InitTouchEvent(int deviceid, |
const gfx::Point& location, |
const std::vector<Valuator>& valuators) { |
Cleanup(); |
- event_.reset(CreateXInput2Event( |
- deviceid, evtype, tracking_id, location)); |
- |
- XIDeviceEvent* xiev = |
- static_cast<XIDeviceEvent*>(event_->xcookie.data); |
- InitValuatorsForXIDeviceEvent(xiev, valuators.size()); |
- int val_count = 0; |
- for (int i = 0; i < kTouchValuatorNum; i++) { |
- for (size_t j = 0; j < valuators.size(); j++) { |
- if (valuators[j].data_type == kTouchValuatorMap[i][1]) { |
- XISetMask(xiev->valuators.mask, kTouchValuatorMap[i][0]); |
- xiev->valuators.values[val_count++] = valuators[j].value; |
- } |
- } |
- } |
- |
+ event_.reset(CreateXInput2Event(deviceid, evtype, tracking_id, location)); |
+ SetUpValuators(valuators); |
} |
void ScopedXI2Event::Cleanup() { |
@@ -255,39 +223,31 @@ void ScopedXI2Event::Cleanup() { |
event_.reset(); |
} |
- void SetUpScrollDeviceForTest(unsigned int deviceid) { |
+void ScopedXI2Event::SetUpValuators(const std::vector<Valuator>& valuators) { |
+ CHECK(event_.get()); |
+ CHECK_EQ(GenericEvent, event_->type); |
+ XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(event_->xcookie.data); |
+ InitValuatorsForXIDeviceEvent(xiev); |
+ ui::DeviceDataManager* manager = ui::DeviceDataManager::GetInstance(); |
+ for (size_t i = 0; i < valuators.size(); ++i) { |
+ manager->SetValuatorDataForTest(xiev, valuators[i].data_type, |
+ valuators[i].value); |
+ } |
+} |
+ |
+void SetUpScrollDeviceForTest(unsigned int deviceid) { |
std::vector<unsigned int> device_list; |
device_list.push_back(deviceid); |
TouchFactory::GetInstance()->SetPointerDeviceForTest(device_list); |
ui::DeviceDataManager* manager = ui::DeviceDataManager::GetInstance(); |
- manager->SetDeviceListForTest(device_list, device_list, device_list); |
- |
- for (int i = 0; i < kScrollValuatorNum; i++) { |
- manager->SetDeviceValuatorForTest( |
- deviceid, |
- kScrollValuatorMap[i][0], |
- static_cast<DeviceDataManager::DataType>(kScrollValuatorMap[i][1]), |
- kScrollValuatorMap[i][2], |
- kScrollValuatorMap[i][3]); |
- } |
+ manager->SetDeviceListForTest(std::vector<unsigned int>(), device_list); |
} |
-void SetupTouchDevicesForTest(const std::vector<unsigned int>& devices) { |
- std::vector<unsigned int> empty_list; |
+void SetUpTouchDevicesForTest(const std::vector<unsigned int>& devices) { |
TouchFactory::GetInstance()->SetTouchDeviceForTest(devices); |
ui::DeviceDataManager* manager = ui::DeviceDataManager::GetInstance(); |
- manager->SetDeviceListForTest(devices, empty_list, empty_list); |
- for (size_t i = 0; i < devices.size(); i++) { |
- for (int j = 0; j < kTouchValuatorNum; j++) { |
- manager->SetDeviceValuatorForTest( |
- devices[i], |
- kTouchValuatorMap[j][0], |
- static_cast<DeviceDataManager::DataType>(kTouchValuatorMap[j][1]), |
- kTouchValuatorMap[j][2], |
- kTouchValuatorMap[j][3]); |
- } |
- } |
+ manager->SetDeviceListForTest(devices, std::vector<unsigned int>()); |
} |
} // namespace ui |