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

Side by Side Diff: ui/events/test/events_test_utils_x11.cc

Issue 289283015: Extract touchscreen device management into a generic manager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 7 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/events/test/events_test_utils_x11.h" 5 #include "ui/events/test/events_test_utils_x11.h"
6 6
7 #include <X11/extensions/XI2.h> 7 #include <X11/extensions/XI2.h>
8 #include <X11/keysym.h> 8 #include <X11/keysym.h>
9 #include <X11/X.h> 9 #include <X11/X.h>
10 #include <X11/Xlib.h> 10 #include <X11/Xlib.h>
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 return Button1; 82 return Button1;
83 if (flags & ui::EF_MIDDLE_MOUSE_BUTTON) 83 if (flags & ui::EF_MIDDLE_MOUSE_BUTTON)
84 return Button2; 84 return Button2;
85 if (flags & ui::EF_RIGHT_MOUSE_BUTTON) 85 if (flags & ui::EF_RIGHT_MOUSE_BUTTON)
86 return Button3; 86 return Button3;
87 87
88 return 0; 88 return 0;
89 } 89 }
90 90
91 void InitValuatorsForXIDeviceEvent(XIDeviceEvent* xiev) { 91 void InitValuatorsForXIDeviceEvent(XIDeviceEvent* xiev) {
92 int valuator_count = ui::DeviceDataManager::DT_LAST_ENTRY; 92 int valuator_count = ui::DeviceDataManagerX11::DT_LAST_ENTRY;
93 xiev->valuators.mask_len = (valuator_count / 8) + 1; 93 xiev->valuators.mask_len = (valuator_count / 8) + 1;
94 xiev->valuators.mask = new unsigned char[xiev->valuators.mask_len]; 94 xiev->valuators.mask = new unsigned char[xiev->valuators.mask_len];
95 memset(xiev->valuators.mask, 0, xiev->valuators.mask_len); 95 memset(xiev->valuators.mask, 0, xiev->valuators.mask_len);
96 xiev->valuators.values = new double[valuator_count]; 96 xiev->valuators.values = new double[valuator_count];
97 } 97 }
98 98
99 XEvent* CreateXInput2Event(int deviceid, 99 XEvent* CreateXInput2Event(int deviceid,
100 int evtype, 100 int evtype,
101 int tracking_id, 101 int tracking_id,
102 const gfx::Point& location) { 102 const gfx::Point& location) {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 195
196 void ScopedXI2Event::InitScrollEvent(int deviceid, 196 void ScopedXI2Event::InitScrollEvent(int deviceid,
197 int x_offset, 197 int x_offset,
198 int y_offset, 198 int y_offset,
199 int x_offset_ordinal, 199 int x_offset_ordinal,
200 int y_offset_ordinal, 200 int y_offset_ordinal,
201 int finger_count) { 201 int finger_count) {
202 event_.reset(CreateXInput2Event(deviceid, XI_Motion, 0, gfx::Point())); 202 event_.reset(CreateXInput2Event(deviceid, XI_Motion, 0, gfx::Point()));
203 203
204 Valuator valuators[] = { 204 Valuator valuators[] = {
205 Valuator(DeviceDataManager::DT_CMT_SCROLL_X, x_offset), 205 Valuator(DeviceDataManagerX11::DT_CMT_SCROLL_X, x_offset),
206 Valuator(DeviceDataManager::DT_CMT_SCROLL_Y, y_offset), 206 Valuator(DeviceDataManagerX11::DT_CMT_SCROLL_Y, y_offset),
207 Valuator(DeviceDataManager::DT_CMT_ORDINAL_X, x_offset_ordinal), 207 Valuator(DeviceDataManagerX11::DT_CMT_ORDINAL_X, x_offset_ordinal),
208 Valuator(DeviceDataManager::DT_CMT_ORDINAL_Y, y_offset_ordinal), 208 Valuator(DeviceDataManagerX11::DT_CMT_ORDINAL_Y, y_offset_ordinal),
209 Valuator(DeviceDataManager::DT_CMT_FINGER_COUNT, finger_count) 209 Valuator(DeviceDataManagerX11::DT_CMT_FINGER_COUNT, finger_count)
210 }; 210 };
211 SetUpValuators( 211 SetUpValuators(
212 std::vector<Valuator>(valuators, valuators + arraysize(valuators))); 212 std::vector<Valuator>(valuators, valuators + arraysize(valuators)));
213 } 213 }
214 214
215 void ScopedXI2Event::InitFlingScrollEvent(int deviceid, 215 void ScopedXI2Event::InitFlingScrollEvent(int deviceid,
216 int x_velocity, 216 int x_velocity,
217 int y_velocity, 217 int y_velocity,
218 int x_velocity_ordinal, 218 int x_velocity_ordinal,
219 int y_velocity_ordinal, 219 int y_velocity_ordinal,
220 bool is_cancel) { 220 bool is_cancel) {
221 event_.reset(CreateXInput2Event(deviceid, XI_Motion, deviceid, gfx::Point())); 221 event_.reset(CreateXInput2Event(deviceid, XI_Motion, deviceid, gfx::Point()));
222 222
223 Valuator valuators[] = { 223 Valuator valuators[] = {
224 Valuator(DeviceDataManager::DT_CMT_FLING_STATE, is_cancel ? 1 : 0), 224 Valuator(DeviceDataManagerX11::DT_CMT_FLING_STATE, is_cancel ? 1 : 0),
225 Valuator(DeviceDataManager::DT_CMT_FLING_Y, y_velocity), 225 Valuator(DeviceDataManagerX11::DT_CMT_FLING_Y, y_velocity),
226 Valuator(DeviceDataManager::DT_CMT_ORDINAL_Y, y_velocity_ordinal), 226 Valuator(DeviceDataManagerX11::DT_CMT_ORDINAL_Y, y_velocity_ordinal),
227 Valuator(DeviceDataManager::DT_CMT_FLING_X, x_velocity), 227 Valuator(DeviceDataManagerX11::DT_CMT_FLING_X, x_velocity),
228 Valuator(DeviceDataManager::DT_CMT_ORDINAL_X, x_velocity_ordinal) 228 Valuator(DeviceDataManagerX11::DT_CMT_ORDINAL_X, x_velocity_ordinal)
229 }; 229 };
230 230
231 SetUpValuators( 231 SetUpValuators(
232 std::vector<Valuator>(valuators, valuators + arraysize(valuators))); 232 std::vector<Valuator>(valuators, valuators + arraysize(valuators)));
233 } 233 }
234 234
235 void ScopedXI2Event::InitTouchEvent(int deviceid, 235 void ScopedXI2Event::InitTouchEvent(int deviceid,
236 int evtype, 236 int evtype,
237 int tracking_id, 237 int tracking_id,
238 const gfx::Point& location, 238 const gfx::Point& location,
239 const std::vector<Valuator>& valuators) { 239 const std::vector<Valuator>& valuators) {
240 event_.reset(CreateXInput2Event(deviceid, evtype, tracking_id, location)); 240 event_.reset(CreateXInput2Event(deviceid, evtype, tracking_id, location));
241 SetUpValuators(valuators); 241 SetUpValuators(valuators);
242 } 242 }
243 243
244 void ScopedXI2Event::SetUpValuators(const std::vector<Valuator>& valuators) { 244 void ScopedXI2Event::SetUpValuators(const std::vector<Valuator>& valuators) {
245 CHECK(event_.get()); 245 CHECK(event_.get());
246 CHECK_EQ(GenericEvent, event_->type); 246 CHECK_EQ(GenericEvent, event_->type);
247 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(event_->xcookie.data); 247 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(event_->xcookie.data);
248 InitValuatorsForXIDeviceEvent(xiev); 248 InitValuatorsForXIDeviceEvent(xiev);
249 ui::DeviceDataManager* manager = ui::DeviceDataManager::GetInstance(); 249 ui::DeviceDataManagerX11* manager = ui::DeviceDataManagerX11::GetInstance();
250 for (size_t i = 0; i < valuators.size(); ++i) { 250 for (size_t i = 0; i < valuators.size(); ++i) {
251 manager->SetValuatorDataForTest(xiev, valuators[i].data_type, 251 manager->SetValuatorDataForTest(xiev, valuators[i].data_type,
252 valuators[i].value); 252 valuators[i].value);
253 } 253 }
254 } 254 }
255 255
256 void SetUpTouchPadForTest(unsigned int deviceid) { 256 void SetUpTouchPadForTest(unsigned int deviceid) {
257 std::vector<unsigned int> device_list; 257 std::vector<unsigned int> device_list;
258 device_list.push_back(deviceid); 258 device_list.push_back(deviceid);
259 259
260 TouchFactory::GetInstance()->SetPointerDeviceForTest(device_list); 260 TouchFactory::GetInstance()->SetPointerDeviceForTest(device_list);
261 ui::DeviceDataManager* manager = ui::DeviceDataManager::GetInstance(); 261 ui::DeviceDataManagerX11* manager = ui::DeviceDataManagerX11::GetInstance();
262 manager->SetDeviceListForTest(std::vector<unsigned int>(), device_list); 262 manager->SetDeviceListForTest(std::vector<unsigned int>(), device_list);
263 } 263 }
264 264
265 void SetUpTouchDevicesForTest(const std::vector<unsigned int>& devices) { 265 void SetUpTouchDevicesForTest(const std::vector<unsigned int>& devices) {
266 TouchFactory::GetInstance()->SetTouchDeviceForTest(devices); 266 TouchFactory::GetInstance()->SetTouchDeviceForTest(devices);
267 ui::DeviceDataManager* manager = ui::DeviceDataManager::GetInstance(); 267 ui::DeviceDataManagerX11* manager = ui::DeviceDataManagerX11::GetInstance();
268 manager->SetDeviceListForTest(devices, std::vector<unsigned int>()); 268 manager->SetDeviceListForTest(devices, std::vector<unsigned int>());
269 } 269 }
270 270
271 } // namespace ui 271 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698