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

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

Issue 191223007: Move touch CTM from X into Chrome (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: fix all the unittests 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
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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 int valuator_count = ui::DeviceDataManager::DT_LAST_ENTRY; 88 int valuator_count = ui::DeviceDataManager::DT_LAST_ENTRY;
89 xiev->valuators.mask_len = (valuator_count / 8) + 1; 89 xiev->valuators.mask_len = (valuator_count / 8) + 1;
90 xiev->valuators.mask = new unsigned char[xiev->valuators.mask_len]; 90 xiev->valuators.mask = new unsigned char[xiev->valuators.mask_len];
91 memset(xiev->valuators.mask, 0, xiev->valuators.mask_len); 91 memset(xiev->valuators.mask, 0, xiev->valuators.mask_len);
92 xiev->valuators.values = new double[valuator_count]; 92 xiev->valuators.values = new double[valuator_count];
93 } 93 }
94 94
95 XEvent* CreateXInput2Event(int deviceid, 95 XEvent* CreateXInput2Event(int deviceid,
96 int evtype, 96 int evtype,
97 int tracking_id, 97 int tracking_id,
98 const gfx::Point& location) { 98 const gfx::Point& location,
99 ::Window target) {
99 XEvent* event = new XEvent; 100 XEvent* event = new XEvent;
100 memset(event, 0, sizeof(*event)); 101 memset(event, 0, sizeof(*event));
101 event->type = GenericEvent; 102 event->type = GenericEvent;
102 event->xcookie.data = new XIDeviceEvent; 103 event->xcookie.data = new XIDeviceEvent;
103 XIDeviceEvent* xiev = 104 XIDeviceEvent* xiev =
104 static_cast<XIDeviceEvent*>(event->xcookie.data); 105 static_cast<XIDeviceEvent*>(event->xcookie.data);
105 memset(xiev, 0, sizeof(XIDeviceEvent)); 106 memset(xiev, 0, sizeof(XIDeviceEvent));
106 xiev->deviceid = deviceid; 107 xiev->deviceid = deviceid;
107 xiev->sourceid = deviceid; 108 xiev->sourceid = deviceid;
108 xiev->evtype = evtype; 109 xiev->evtype = evtype;
109 xiev->detail = tracking_id; 110 xiev->detail = tracking_id;
110 xiev->event_x = location.x(); 111 xiev->event_x = location.x();
111 xiev->event_y = location.y(); 112 xiev->event_y = location.y();
113 xiev->event = target;
sadrul 2014/05/07 20:00:27 Can we always set this to DefaultRootWindow() with
Yufeng Shen (Slow to review) 2014/05/07 22:02:58 Done.
112 if (evtype == XI_ButtonPress || evtype == XI_ButtonRelease) { 114 if (evtype == XI_ButtonPress || evtype == XI_ButtonRelease) {
113 xiev->buttons.mask_len = 8; 115 xiev->buttons.mask_len = 8;
114 xiev->buttons.mask = new unsigned char[xiev->buttons.mask_len]; 116 xiev->buttons.mask = new unsigned char[xiev->buttons.mask_len];
115 memset(xiev->buttons.mask, 0, xiev->buttons.mask_len); 117 memset(xiev->buttons.mask, 0, xiev->buttons.mask_len);
116 } 118 }
117 return event; 119 return event;
118 } 120 }
119 121
120 } // namespace 122 } // namespace
121 123
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 event_->xkey.state = XEventState(flags); 164 event_->xkey.state = XEventState(flags);
163 event_->xkey.keycode = XKeyEventKeyCode(key_code, flags, display); 165 event_->xkey.keycode = XKeyEventKeyCode(key_code, flags, display);
164 event_->xkey.same_screen = 1; 166 event_->xkey.same_screen = 1;
165 } 167 }
166 168
167 void ScopedXI2Event::InitGenericButtonEvent(int deviceid, 169 void ScopedXI2Event::InitGenericButtonEvent(int deviceid,
168 EventType type, 170 EventType type,
169 const gfx::Point& location, 171 const gfx::Point& location,
170 int flags) { 172 int flags) {
171 event_.reset(CreateXInput2Event(deviceid, 173 event_.reset(CreateXInput2Event(deviceid,
172 XIButtonEventType(type), 0, gfx::Point())); 174 XIButtonEventType(type), 0, gfx::Point(),
175 ::Window()));
173 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(event_->xcookie.data); 176 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(event_->xcookie.data);
174 xievent->mods.effective = XEventState(flags); 177 xievent->mods.effective = XEventState(flags);
175 xievent->detail = XButtonEventButton(type, flags); 178 xievent->detail = XButtonEventButton(type, flags);
176 xievent->event_x = location.x(); 179 xievent->event_x = location.x();
177 xievent->event_y = location.y(); 180 xievent->event_y = location.y();
178 XISetMask(xievent->buttons.mask, xievent->detail); 181 XISetMask(xievent->buttons.mask, xievent->detail);
179 // Setup an empty valuator list for generic button events. 182 // Setup an empty valuator list for generic button events.
180 SetUpValuators(std::vector<Valuator>()); 183 SetUpValuators(std::vector<Valuator>());
181 } 184 }
182 185
183 void ScopedXI2Event::InitGenericMouseWheelEvent(int deviceid, 186 void ScopedXI2Event::InitGenericMouseWheelEvent(int deviceid,
184 int wheel_delta, 187 int wheel_delta,
185 int flags) { 188 int flags) {
186 InitGenericButtonEvent(deviceid, ui::ET_MOUSEWHEEL, gfx::Point(), flags); 189 InitGenericButtonEvent(deviceid, ui::ET_MOUSEWHEEL, gfx::Point(), flags);
187 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(event_->xcookie.data); 190 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(event_->xcookie.data);
188 xievent->detail = wheel_delta > 0 ? Button4 : Button5; 191 xievent->detail = wheel_delta > 0 ? Button4 : Button5;
189 } 192 }
190 193
191 void ScopedXI2Event::InitScrollEvent(int deviceid, 194 void ScopedXI2Event::InitScrollEvent(int deviceid,
192 int x_offset, 195 int x_offset,
193 int y_offset, 196 int y_offset,
194 int x_offset_ordinal, 197 int x_offset_ordinal,
195 int y_offset_ordinal, 198 int y_offset_ordinal,
196 int finger_count) { 199 int finger_count) {
197 event_.reset(CreateXInput2Event(deviceid, XI_Motion, 0, gfx::Point())); 200 event_.reset(CreateXInput2Event(deviceid, XI_Motion, 0, gfx::Point(),
201 ::Window()));
198 202
199 Valuator valuators[] = { 203 Valuator valuators[] = {
200 Valuator(DeviceDataManager::DT_CMT_SCROLL_X, x_offset), 204 Valuator(DeviceDataManager::DT_CMT_SCROLL_X, x_offset),
201 Valuator(DeviceDataManager::DT_CMT_SCROLL_Y, y_offset), 205 Valuator(DeviceDataManager::DT_CMT_SCROLL_Y, y_offset),
202 Valuator(DeviceDataManager::DT_CMT_ORDINAL_X, x_offset_ordinal), 206 Valuator(DeviceDataManager::DT_CMT_ORDINAL_X, x_offset_ordinal),
203 Valuator(DeviceDataManager::DT_CMT_ORDINAL_Y, y_offset_ordinal), 207 Valuator(DeviceDataManager::DT_CMT_ORDINAL_Y, y_offset_ordinal),
204 Valuator(DeviceDataManager::DT_CMT_FINGER_COUNT, finger_count) 208 Valuator(DeviceDataManager::DT_CMT_FINGER_COUNT, finger_count)
205 }; 209 };
206 SetUpValuators( 210 SetUpValuators(
207 std::vector<Valuator>(valuators, valuators + arraysize(valuators))); 211 std::vector<Valuator>(valuators, valuators + arraysize(valuators)));
208 } 212 }
209 213
210 void ScopedXI2Event::InitFlingScrollEvent(int deviceid, 214 void ScopedXI2Event::InitFlingScrollEvent(int deviceid,
211 int x_velocity, 215 int x_velocity,
212 int y_velocity, 216 int y_velocity,
213 int x_velocity_ordinal, 217 int x_velocity_ordinal,
214 int y_velocity_ordinal, 218 int y_velocity_ordinal,
215 bool is_cancel) { 219 bool is_cancel) {
216 event_.reset(CreateXInput2Event(deviceid, XI_Motion, deviceid, gfx::Point())); 220 event_.reset(CreateXInput2Event(deviceid, XI_Motion, deviceid, gfx::Point(),
221 ::Window()));
217 222
218 Valuator valuators[] = { 223 Valuator valuators[] = {
219 Valuator(DeviceDataManager::DT_CMT_FLING_STATE, is_cancel ? 1 : 0), 224 Valuator(DeviceDataManager::DT_CMT_FLING_STATE, is_cancel ? 1 : 0),
220 Valuator(DeviceDataManager::DT_CMT_FLING_Y, y_velocity), 225 Valuator(DeviceDataManager::DT_CMT_FLING_Y, y_velocity),
221 Valuator(DeviceDataManager::DT_CMT_ORDINAL_Y, y_velocity_ordinal), 226 Valuator(DeviceDataManager::DT_CMT_ORDINAL_Y, y_velocity_ordinal),
222 Valuator(DeviceDataManager::DT_CMT_FLING_X, x_velocity), 227 Valuator(DeviceDataManager::DT_CMT_FLING_X, x_velocity),
223 Valuator(DeviceDataManager::DT_CMT_ORDINAL_X, x_velocity_ordinal) 228 Valuator(DeviceDataManager::DT_CMT_ORDINAL_X, x_velocity_ordinal)
224 }; 229 };
225 230
226 SetUpValuators( 231 SetUpValuators(
227 std::vector<Valuator>(valuators, valuators + arraysize(valuators))); 232 std::vector<Valuator>(valuators, valuators + arraysize(valuators)));
228 } 233 }
229 234
230 void ScopedXI2Event::InitTouchEvent(int deviceid, 235 void ScopedXI2Event::InitTouchEvent(int deviceid,
231 int evtype, 236 int evtype,
232 int tracking_id, 237 int tracking_id,
233 const gfx::Point& location, 238 const gfx::Point& location,
234 const std::vector<Valuator>& valuators) { 239 const std::vector<Valuator>& valuators,
235 event_.reset(CreateXInput2Event(deviceid, evtype, tracking_id, location)); 240 ::Window target) {
241 event_.reset(CreateXInput2Event(deviceid, evtype, tracking_id, location,
242 target));
236 SetUpValuators(valuators); 243 SetUpValuators(valuators);
237 } 244 }
238 245
239 void ScopedXI2Event::SetUpValuators(const std::vector<Valuator>& valuators) { 246 void ScopedXI2Event::SetUpValuators(const std::vector<Valuator>& valuators) {
240 CHECK(event_.get()); 247 CHECK(event_.get());
241 CHECK_EQ(GenericEvent, event_->type); 248 CHECK_EQ(GenericEvent, event_->type);
242 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(event_->xcookie.data); 249 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(event_->xcookie.data);
243 InitValuatorsForXIDeviceEvent(xiev); 250 InitValuatorsForXIDeviceEvent(xiev);
244 ui::DeviceDataManager* manager = ui::DeviceDataManager::GetInstance(); 251 ui::DeviceDataManager* manager = ui::DeviceDataManager::GetInstance();
245 for (size_t i = 0; i < valuators.size(); ++i) { 252 for (size_t i = 0; i < valuators.size(); ++i) {
(...skipping 11 matching lines...) Expand all
257 manager->SetDeviceListForTest(std::vector<unsigned int>(), device_list); 264 manager->SetDeviceListForTest(std::vector<unsigned int>(), device_list);
258 } 265 }
259 266
260 void SetUpTouchDevicesForTest(const std::vector<unsigned int>& devices) { 267 void SetUpTouchDevicesForTest(const std::vector<unsigned int>& devices) {
261 TouchFactory::GetInstance()->SetTouchDeviceForTest(devices); 268 TouchFactory::GetInstance()->SetTouchDeviceForTest(devices);
262 ui::DeviceDataManager* manager = ui::DeviceDataManager::GetInstance(); 269 ui::DeviceDataManager* manager = ui::DeviceDataManager::GetInstance();
263 manager->SetDeviceListForTest(devices, std::vector<unsigned int>()); 270 manager->SetDeviceListForTest(devices, std::vector<unsigned int>());
264 } 271 }
265 272
266 } // namespace ui 273 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698