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

Side by Side Diff: ui/base/x/events_x.cc

Issue 17049002: Revert "Merge CMTEventData and ValuatorTracker" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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
« no previous file with comments | « ui/base/x/device_data_manager.cc ('k') | ui/base/x/valuators.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/base/events/event_constants.h" 5 #include "ui/base/events/event_constants.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 #include <X11/extensions/XInput.h> 8 #include <X11/extensions/XInput.h>
9 #include <X11/extensions/XInput2.h> 9 #include <X11/extensions/XInput2.h>
10 #include <X11/Xlib.h> 10 #include <X11/Xlib.h>
11 11
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/memory/singleton.h" 14 #include "base/memory/singleton.h"
15 #include "base/message_pump_aurax11.h" 15 #include "base/message_pump_aurax11.h"
16 #include "ui/base/events/event_utils.h" 16 #include "ui/base/events/event_utils.h"
17 #include "ui/base/keycodes/keyboard_code_conversion_x.h" 17 #include "ui/base/keycodes/keyboard_code_conversion_x.h"
18 #include "ui/base/touch/touch_factory_x11.h" 18 #include "ui/base/touch/touch_factory_x11.h"
19 #include "ui/base/x/device_data_manager.h"
20 #include "ui/base/x/device_list_cache_x.h" 19 #include "ui/base/x/device_list_cache_x.h"
20 #include "ui/base/x/valuators.h"
21 #include "ui/base/x/x11_atom_cache.h" 21 #include "ui/base/x/x11_atom_cache.h"
22 #include "ui/base/x/x11_util.h" 22 #include "ui/base/x/x11_util.h"
23 #include "ui/gfx/display.h" 23 #include "ui/gfx/display.h"
24 #include "ui/gfx/point.h" 24 #include "ui/gfx/point.h"
25 #include "ui/gfx/rect.h" 25 #include "ui/gfx/rect.h"
26 #include "ui/gfx/screen.h" 26 #include "ui/gfx/screen.h"
27 27
28 // Copied from xserver-properties.h
29 #define AXIS_LABEL_PROP_REL_HWHEEL "Rel Horiz Wheel"
30 #define AXIS_LABEL_PROP_REL_WHEEL "Rel Vert Wheel"
31
32 // CMT specific timings
33 #define AXIS_LABEL_PROP_ABS_START_TIME "Abs Start Timestamp"
34 #define AXIS_LABEL_PROP_ABS_END_TIME "Abs End Timestamp"
35
36 // Ordinal values
37 #define AXIS_LABEL_PROP_ABS_DBL_ORDINAL_X "Abs Dbl Ordinal X"
38 #define AXIS_LABEL_PROP_ABS_DBL_ORDINAL_Y "Abs Dbl Ordinal Y"
39
40 // Fling properties
41 #define AXIS_LABEL_PROP_ABS_FLING_X "Abs Fling X Velocity"
42 #define AXIS_LABEL_PROP_ABS_FLING_Y "Abs Fling Y Velocity"
43 #define AXIS_LABEL_PROP_ABS_FLING_STATE "Abs Fling State"
44
45 #define AXIS_LABEL_PROP_ABS_FINGER_COUNT "Abs Finger Count"
46
47 // New versions of the valuators, with double values instead of fixed point.
48 #define AXIS_LABEL_PROP_ABS_DBL_START_TIME "Abs Dbl Start Timestamp"
49 #define AXIS_LABEL_PROP_ABS_DBL_END_TIME "Abs Dbl End Timestamp"
50 #define AXIS_LABEL_PROP_ABS_DBL_FLING_VX "Abs Dbl Fling X Velocity"
51 #define AXIS_LABEL_PROP_ABS_DBL_FLING_VY "Abs Dbl Fling Y Velocity"
52
28 namespace { 53 namespace {
29 54
30 // Scroll amount for each wheelscroll event. 53 is also the value used for GTK+. 55 // Scroll amount for each wheelscroll event. 53 is also the value used for GTK+.
31 const int kWheelScrollAmount = 53; 56 const int kWheelScrollAmount = 53;
32 57
33 const int kMinWheelButton = 4; 58 const int kMinWheelButton = 4;
34 const int kMaxWheelButton = 7; 59 const int kMaxWheelButton = 7;
35 60
61 const char* kCMTCachedAtoms[] = {
62 AXIS_LABEL_PROP_ABS_DBL_ORDINAL_X,
63 AXIS_LABEL_PROP_ABS_DBL_ORDINAL_Y,
64 AXIS_LABEL_PROP_REL_HWHEEL,
65 AXIS_LABEL_PROP_REL_WHEEL,
66 AXIS_LABEL_PROP_ABS_START_TIME,
67 AXIS_LABEL_PROP_ABS_DBL_START_TIME,
68 AXIS_LABEL_PROP_ABS_END_TIME,
69 AXIS_LABEL_PROP_ABS_DBL_END_TIME,
70 AXIS_LABEL_PROP_ABS_FLING_X,
71 AXIS_LABEL_PROP_ABS_FLING_Y,
72 AXIS_LABEL_PROP_ABS_DBL_FLING_VX,
73 AXIS_LABEL_PROP_ABS_DBL_FLING_VY,
74 AXIS_LABEL_PROP_ABS_FLING_STATE,
75 AXIS_LABEL_PROP_ABS_FINGER_COUNT,
76 NULL
77 };
78
36 // A workaround for some incorrect implemented input drivers: 79 // A workaround for some incorrect implemented input drivers:
37 // Ignore their mouse input valuators. 80 // Ignore their mouse input valuators.
38 bool IgnoreMouseValuators() { 81 bool IgnoreMouseValuators() {
39 static bool initialized = false; 82 static bool initialized = false;
40 static bool ignore_valuators = true; 83 static bool ignore_valuators = true;
41 if (initialized) 84 if (initialized)
42 return ignore_valuators; 85 return ignore_valuators;
43 ignore_valuators = 86 ignore_valuators =
44 CommandLine::ForCurrentProcess()->HasSwitch("disable-mouse-valuators"); 87 CommandLine::ForCurrentProcess()->HasSwitch("disable-mouse-valuators");
45 initialized = true; 88 initialized = true;
46 return ignore_valuators; 89 return ignore_valuators;
47 } 90 }
48 91
92 // A class to support the detection of scroll events, using X11 valuators.
93 class CMTEventData {
94 public:
95 // Returns the ScrollEventData singleton.
96 static CMTEventData* GetInstance() {
97 return Singleton<CMTEventData>::get();
98 }
99
100 // Updates the list of devices.
101 void UpdateDeviceList(Display* display) {
102 cmt_devices_.reset();
103 touchpads_.reset();
104 device_to_valuators_.clear();
105
106 #if defined(USE_XI2_MT)
107 // Find all the touchpad devices.
108 XDeviceList dev_list =
109 ui::DeviceListCacheX::GetInstance()->GetXDeviceList(display);
110 Atom xi_touchpad = XInternAtom(display, XI_TOUCHPAD, false);
111 for (int i = 0; i < dev_list.count; ++i)
112 if (dev_list[i].type == xi_touchpad)
113 touchpads_[dev_list[i].id] = true;
114
115 XIDeviceList info_list =
116 ui::DeviceListCacheX::GetInstance()->GetXI2DeviceList(display);
117 Atom x_axis = atom_cache_.GetAtom(AXIS_LABEL_PROP_REL_HWHEEL);
118 Atom y_axis = atom_cache_.GetAtom(AXIS_LABEL_PROP_REL_WHEEL);
119 Atom x_ordinal = atom_cache_.GetAtom(AXIS_LABEL_PROP_ABS_DBL_ORDINAL_X);
120 Atom y_ordinal = atom_cache_.GetAtom(AXIS_LABEL_PROP_ABS_DBL_ORDINAL_Y);
121 Atom start_time = atom_cache_.GetAtom(AXIS_LABEL_PROP_ABS_START_TIME);
122 Atom start_time_dbl =
123 atom_cache_.GetAtom(AXIS_LABEL_PROP_ABS_DBL_START_TIME);
124 Atom end_time = atom_cache_.GetAtom(AXIS_LABEL_PROP_ABS_END_TIME);
125 Atom end_time_dbl = atom_cache_.GetAtom(AXIS_LABEL_PROP_ABS_DBL_END_TIME);
126 Atom fling_vx = atom_cache_.GetAtom(AXIS_LABEL_PROP_ABS_FLING_X);
127 Atom fling_vx_dbl = atom_cache_.GetAtom(AXIS_LABEL_PROP_ABS_DBL_FLING_VX);
128 Atom fling_vy = atom_cache_.GetAtom(AXIS_LABEL_PROP_ABS_FLING_Y);
129 Atom fling_vy_dbl = atom_cache_.GetAtom(AXIS_LABEL_PROP_ABS_DBL_FLING_VY);
130 Atom fling_state = atom_cache_.GetAtom(AXIS_LABEL_PROP_ABS_FLING_STATE);
131 Atom finger_count = atom_cache_.GetAtom(AXIS_LABEL_PROP_ABS_FINGER_COUNT);
132
133 for (int i = 0; i < info_list.count; ++i) {
134 XIDeviceInfo* info = info_list.devices + i;
135
136 if (info->use != XISlavePointer && info->use != XIFloatingSlave)
137 continue;
138
139 Valuators valuators;
140 bool is_cmt = false;
141 for (int j = 0; j < info->num_classes; ++j) {
142 if (info->classes[j]->type == XIScrollClass) {
143 is_cmt = false;
144 break;
145 }
146 if (info->classes[j]->type != XIValuatorClass)
147 continue;
148
149 XIValuatorClassInfo* v =
150 reinterpret_cast<XIValuatorClassInfo*>(info->classes[j]);
151 int number = v->number;
152 if (number > valuators.max)
153 valuators.max = number;
154 if (v->label == x_axis) {
155 valuators.scroll_x = number;
156 is_cmt = true;
157 } else if (v->label == y_axis) {
158 valuators.scroll_y = number;
159 is_cmt = true;
160 } else if (v->label == x_ordinal) {
161 valuators.ordinal_x = number;
162 is_cmt = true;
163 } else if (v->label == y_ordinal) {
164 valuators.ordinal_y = number;
165 is_cmt = true;
166 } else if (v->label == finger_count) {
167 valuators.finger_count = number;
168 is_cmt = true;
169 } else if (v->label == start_time) {
170 valuators.start_time = number;
171 is_cmt = true;
172 } else if (v->label == start_time_dbl) {
173 valuators.start_time_dbl = number;
174 is_cmt = true;
175 } else if (v->label == end_time) {
176 valuators.end_time = number;
177 is_cmt = true;
178 } else if (v->label == end_time_dbl) {
179 valuators.end_time_dbl = number;
180 is_cmt = true;
181 } else if (v->label == fling_vx) {
182 valuators.fling_vx = number;
183 is_cmt = true;
184 } else if (v->label == fling_vx_dbl) {
185 valuators.fling_vx_dbl = number;
186 is_cmt = true;
187 } else if (v->label == fling_vy) {
188 valuators.fling_vy = number;
189 is_cmt = true;
190 } else if (v->label == fling_vy_dbl) {
191 valuators.fling_vy_dbl = number;
192 is_cmt = true;
193 } else if (v->label == fling_state) {
194 valuators.fling_state = number;
195 is_cmt = true;
196 }
197 }
198 if (is_cmt) {
199 // Double valuators override fixed point ones.
200 if (valuators.start_time_dbl >= 0)
201 valuators.start_time = -1;
202 if (valuators.end_time_dbl >= 0)
203 valuators.end_time = -1;
204 if (valuators.fling_vx_dbl >= 0)
205 valuators.fling_vx = -1;
206 if (valuators.fling_vy_dbl >= 0)
207 valuators.fling_vy = -1;
208 device_to_valuators_[info->deviceid] = valuators;
209 cmt_devices_[info->deviceid] = true;
210 }
211 }
212 #endif // defined(USE_XI2_MT)
213 }
214
215 bool natural_scroll_enabled() const { return natural_scroll_enabled_; }
216 void set_natural_scroll_enabled(bool enabled) {
217 natural_scroll_enabled_ = enabled;
218 }
219
220 bool IsTouchpadXInputEvent(const base::NativeEvent& native_event) {
221 if (native_event->type != GenericEvent)
222 return false;
223
224 XIDeviceEvent* xievent =
225 static_cast<XIDeviceEvent*>(native_event->xcookie.data);
226 return touchpads_[xievent->sourceid];
227 }
228
229 float GetNaturalScrollFactor(int sourceid) {
230 // Natural scroll is touchpad-only.
231 if (!touchpads_[sourceid])
232 return -1.0f;
233
234 return natural_scroll_enabled_ ? 1.0f : -1.0f;
235 }
236
237 // Returns true if this is a scroll event (a motion event with the necessary
238 // valuators. Also returns the offsets. |x_offset| and |y_offset| can be
239 // NULL.
240 bool GetScrollOffsets(const XEvent& xev,
241 float* x_offset,
242 float* y_offset,
243 float* x_offset_ordinal,
244 float* y_offset_ordinal,
245 int* finger_count) {
246 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev.xcookie.data);
247
248 if (x_offset)
249 *x_offset = 0;
250 if (y_offset)
251 *y_offset = 0;
252 if (x_offset_ordinal)
253 *x_offset_ordinal = 0;
254 if (y_offset_ordinal)
255 *y_offset_ordinal = 0;
256 if (finger_count)
257 *finger_count = 2;
258
259 const int sourceid = xiev->sourceid;
260 if (!cmt_devices_[sourceid])
261 return false;
262
263 const float natural_scroll_factor = GetNaturalScrollFactor(sourceid);
264 const Valuators v = device_to_valuators_[sourceid];
265 const bool has_x_offset = XIMaskIsSet(xiev->valuators.mask, v.scroll_x);
266 const bool has_y_offset = XIMaskIsSet(xiev->valuators.mask, v.scroll_y);
267 const bool is_scroll = has_x_offset || has_y_offset;
268
269 if (!is_scroll || (!x_offset && !y_offset))
270 return is_scroll;
271
272 double* valuators = xiev->valuators.values;
273 for (int i = 0; i <= v.max; ++i) {
274 if (XIMaskIsSet(xiev->valuators.mask, i)) {
275 if (x_offset && v.scroll_x == i)
276 *x_offset = *valuators * natural_scroll_factor;
277 else if (y_offset && v.scroll_y == i)
278 *y_offset = *valuators * natural_scroll_factor;
279 else if (x_offset_ordinal && v.ordinal_x == i)
280 *x_offset_ordinal = *valuators * natural_scroll_factor;
281 else if (y_offset_ordinal && v.ordinal_y == i)
282 *y_offset_ordinal = *valuators * natural_scroll_factor;
283 else if (finger_count && v.finger_count == i)
284 *finger_count = static_cast<int>(*valuators);
285 valuators++;
286 }
287 }
288
289 return true;
290 }
291
292 bool GetFlingData(const XEvent& xev,
293 float* vx, float* vy,
294 float* vx_ordinal, float* vy_ordinal,
295 bool* is_cancel) {
296 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev.xcookie.data);
297
298 if (vx)
299 *vx = 0;
300 if (vy)
301 *vy = 0;
302 if (vx_ordinal)
303 *vx_ordinal = 0;
304 if (vy_ordinal)
305 *vy_ordinal = 0;
306 if (is_cancel)
307 *is_cancel = false;
308
309 const int sourceid = xiev->sourceid;
310 if (!cmt_devices_[sourceid])
311 return false;
312
313 const float natural_scroll_factor = GetNaturalScrollFactor(sourceid);
314 const Valuators v = device_to_valuators_[sourceid];
315 if ((!XIMaskIsSet(xiev->valuators.mask, v.fling_vx) &&
316 !XIMaskIsSet(xiev->valuators.mask, v.fling_vx_dbl)) ||
317 (!XIMaskIsSet(xiev->valuators.mask, v.fling_vy) &&
318 !XIMaskIsSet(xiev->valuators.mask, v.fling_vy_dbl)) ||
319 !XIMaskIsSet(xiev->valuators.mask, v.fling_state))
320 return false;
321
322 double* valuators = xiev->valuators.values;
323 for (int i = 0; i <= v.max; ++i) {
324 if (XIMaskIsSet(xiev->valuators.mask, i)) {
325 // Convert values to unsigned ints representing ms before storing them,
326 // as that is how they were encoded before conversion to doubles.
327 if (vx && v.fling_vx_dbl == i) {
328 *vx = natural_scroll_factor * *valuators;
329 } else if (vx && v.fling_vx == i) {
330 *vx = natural_scroll_factor *
331 static_cast<double>(static_cast<int>(*valuators)) / 1000.0f;
332 } else if (vy && v.fling_vy_dbl == i) {
333 *vy = natural_scroll_factor * *valuators;
334 } else if (vy && v.fling_vy == i) {
335 *vy = natural_scroll_factor *
336 static_cast<double>(static_cast<int>(*valuators)) / 1000.0f;
337 } else if (is_cancel && v.fling_state == i) {
338 *is_cancel = !!static_cast<unsigned int>(*valuators);
339 } else if (vx_ordinal && v.ordinal_x == i) {
340 *vx_ordinal = *valuators * natural_scroll_factor;
341 } else if (vy_ordinal && v.ordinal_y == i) {
342 *vy_ordinal = *valuators * natural_scroll_factor;
343 }
344 valuators++;
345 }
346 }
347
348 return true;
349 }
350
351 bool GetGestureTimes(const XEvent& xev,
352 double* start_time,
353 double* end_time) {
354 *start_time = 0;
355 *end_time = 0;
356
357 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev.xcookie.data);
358 if (!cmt_devices_[xiev->sourceid])
359 return false;
360
361 Valuators v = device_to_valuators_[xiev->sourceid];
362 if ((!XIMaskIsSet(xiev->valuators.mask, v.start_time) &&
363 !XIMaskIsSet(xiev->valuators.mask, v.start_time_dbl)) ||
364 (!XIMaskIsSet(xiev->valuators.mask, v.end_time) &&
365 !XIMaskIsSet(xiev->valuators.mask, v.end_time_dbl)))
366 return false;
367
368 double* valuators = xiev->valuators.values;
369 for (int i = 0; i <= v.max; ++i) {
370 if (XIMaskIsSet(xiev->valuators.mask, i)) {
371 if (v.start_time_dbl == i) {
372 *start_time = *valuators;
373 } else if (v.start_time == i) {
374 // Convert values to unsigned ints representing ms before storing
375 // them, as that is how they were encoded before conversion
376 // to doubles.
377 *start_time =
378 static_cast<double>(
379 static_cast<unsigned int>(*valuators)) / 1000;
380 } else if (v.end_time_dbl == i) {
381 *end_time = *valuators;
382 } else if (v.end_time == i) {
383 // Convert values to unsigned ints representing ms before storing
384 // them, as that is how they were encoded before conversion
385 // to doubles.
386 *end_time =
387 static_cast<double>(
388 static_cast<unsigned int>(*valuators)) / 1000;
389 }
390 valuators++;
391 }
392 }
393
394 return true;
395 }
396
397 private:
398 // Requirement for Singleton
399 friend struct DefaultSingletonTraits<CMTEventData>;
400
401 struct Valuators {
402 int max;
403 int scroll_x;
404 int scroll_y;
405 int ordinal_x;
406 int ordinal_y;
407 int finger_count;
408 int start_time;
409 int end_time;
410 int fling_vx;
411 int fling_vy;
412 int fling_state;
413 // *_dbl valuators take precedence over the fixed precision versions.
414 int start_time_dbl;
415 int end_time_dbl;
416 int fling_vx_dbl;
417 int fling_vy_dbl;
418
419 Valuators()
420 : max(-1),
421 scroll_x(-1),
422 scroll_y(-1),
423 ordinal_x(-1),
424 ordinal_y(-1),
425 finger_count(-1),
426 start_time(-1),
427 end_time(-1),
428 fling_vx(-1),
429 fling_vy(-1),
430 fling_state(-1),
431 start_time_dbl(-1),
432 end_time_dbl(-1),
433 fling_vx_dbl(-1),
434 fling_vy_dbl(-1) {
435 }
436
437 };
438
439 CMTEventData()
440 : natural_scroll_enabled_(false),
441 atom_cache_(ui::GetXDisplay(), kCMTCachedAtoms) {
442 UpdateDeviceList(ui::GetXDisplay());
443 }
444
445 ~CMTEventData() {}
446
447 // A quick lookup table for determining if events from the pointer device
448 // should be processed.
449 static const int kMaxDeviceNum = 128;
450 bool natural_scroll_enabled_;
451 std::bitset<kMaxDeviceNum> cmt_devices_;
452 std::bitset<kMaxDeviceNum> touchpads_;
453 std::map<int, Valuators> device_to_valuators_;
454 ui::X11AtomCache atom_cache_;
455
456 DISALLOW_COPY_AND_ASSIGN(CMTEventData);
457 };
458
49 // A class to track current modifier state on master device. Only track ctrl, 459 // A class to track current modifier state on master device. Only track ctrl,
50 // alt, shift and caps lock keys currently. The tracked state can then be used 460 // alt, shift and caps lock keys currently. The tracked state can then be used
51 // by floating device. 461 // by floating device.
52 class XModifierStateWatcher{ 462 class XModifierStateWatcher{
53 public: 463 public:
54 static XModifierStateWatcher* GetInstance() { 464 static XModifierStateWatcher* GetInstance() {
55 return Singleton<XModifierStateWatcher>::get(); 465 return Singleton<XModifierStateWatcher>::get();
56 } 466 }
57 467
58 void UpdateStateFromEvent(const base::NativeEvent& native_event) { 468 void UpdateStateFromEvent(const base::NativeEvent& native_event) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 if (ui::GetTouchForce(native_event) < 1.0f) 533 if (ui::GetTouchForce(native_event) < 1.0f)
124 return false; 534 return false;
125 535
126 if (ui::EventLocationFromNative(native_event) != gfx::Point()) 536 if (ui::EventLocationFromNative(native_event) != gfx::Point())
127 return false; 537 return false;
128 538
129 // Radius is in pixels, and the valuator is the diameter in pixels. 539 // Radius is in pixels, and the valuator is the diameter in pixels.
130 double radius = ui::GetTouchRadiusX(native_event), min, max; 540 double radius = ui::GetTouchRadiusX(native_event), min, max;
131 unsigned int deviceid = 541 unsigned int deviceid =
132 static_cast<XIDeviceEvent*>(native_event->xcookie.data)->sourceid; 542 static_cast<XIDeviceEvent*>(native_event->xcookie.data)->sourceid;
133 if (!ui::DeviceDataManager::GetInstance()->GetDataRange( 543 if (!ui::ValuatorTracker::GetInstance()->GetValuatorRange(
134 deviceid, ui::DeviceDataManager::DT_TOUCH_MAJOR, &min, &max)) { 544 deviceid, ui::ValuatorTracker::VAL_TOUCH_MAJOR, &min, &max)) {
135 return false; 545 return false;
136 } 546 }
137 547
138 return radius * 2 == max; 548 return radius * 2 == max;
139 } 549 }
140 #endif 550 #endif
141 551
142 int GetEventFlagsFromXState(unsigned int state) { 552 int GetEventFlagsFromXState(unsigned int state) {
143 int flags = 0; 553 int flags = 0;
144 if (state & ControlMask) 554 if (state & ControlMask)
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 NOTREACHED(); 638 NOTREACHED();
229 } 639 }
230 } 640 }
231 641
232 DCHECK_EQ(event->evtype, XI_Motion); 642 DCHECK_EQ(event->evtype, XI_Motion);
233 643
234 // Note: We will not generate a _STATIONARY event here. It will be created, 644 // Note: We will not generate a _STATIONARY event here. It will be created,
235 // when necessary, by a RWHVV. 645 // when necessary, by a RWHVV.
236 // TODO(sad): When should _CANCELLED be generated? 646 // TODO(sad): When should _CANCELLED be generated?
237 647
238 ui::DeviceDataManager* manager = ui::DeviceDataManager::GetInstance(); 648 ui::ValuatorTracker* valuators = ui::ValuatorTracker::GetInstance();
239 649
240 double slot; 650 double slot;
241 if (!manager->GetEventData( 651 if (!valuators->ExtractValuator(
242 *native_event, ui::DeviceDataManager::DT_TOUCH_SLOT_ID, &slot)) 652 *native_event, ui::ValuatorTracker::VAL_SLOT_ID, &slot))
243 return ui::ET_UNKNOWN; 653 return ui::ET_UNKNOWN;
244 654
245 if (!factory->IsSlotUsed(slot)) { 655 if (!factory->IsSlotUsed(slot)) {
246 // This is a new touch point. 656 // This is a new touch point.
247 return ui::ET_TOUCH_PRESSED; 657 return ui::ET_TOUCH_PRESSED;
248 } 658 }
249 659
250 double tracking; 660 double tracking;
251 if (!manager->GetEventData( 661 if (!valuators->ExtractValuator(
252 *native_event, ui::DeviceDataManager::DT_TOUCH_TRACKING_ID, &tracking)) 662 *native_event, ui::ValuatorTracker::VAL_TRACKING_ID, &tracking))
253 return ui::ET_UNKNOWN; 663 return ui::ET_UNKNOWN;
254 664
255 if (tracking == 0l) { 665 if (tracking == 0l) {
256 // The touch point has been released. 666 // The touch point has been released.
257 return ui::ET_TOUCH_RELEASED; 667 return ui::ET_TOUCH_RELEASED;
258 } 668 }
259 669
260 return ui::ET_TOUCH_MOVED; 670 return ui::ET_TOUCH_MOVED;
261 #endif // defined(USE_XI2_MT) 671 #endif // defined(USE_XI2_MT)
262 } 672 }
263 673
264 double GetTouchParamFromXEvent(XEvent* xev, 674 double GetTouchParamFromXEvent(XEvent* xev,
265 ui::DeviceDataManager::DataType val, 675 ui::ValuatorTracker::Valuator val,
266 double default_value) { 676 double default_value) {
267 ui::DeviceDataManager::GetInstance()->GetEventData( 677 ui::ValuatorTracker::GetInstance()->ExtractValuator(
268 *xev, val, &default_value); 678 *xev, val, &default_value);
269 return default_value; 679 return default_value;
270 } 680 }
271 681
272 Atom GetNoopEventAtom() { 682 Atom GetNoopEventAtom() {
273 return XInternAtom( 683 return XInternAtom(
274 base::MessagePumpAuraX11::GetDefaultXDisplay(), 684 base::MessagePumpAuraX11::GetDefaultXDisplay(),
275 "noop", False); 685 "noop", False);
276 } 686 }
277 687
278 } // namespace 688 } // namespace
279 689
280 namespace ui { 690 namespace ui {
281 691
282 void UpdateDeviceList() { 692 void UpdateDeviceList() {
283 Display* display = GetXDisplay(); 693 Display* display = GetXDisplay();
284 DeviceListCacheX::GetInstance()->UpdateDeviceList(display); 694 DeviceListCacheX::GetInstance()->UpdateDeviceList(display);
695 CMTEventData::GetInstance()->UpdateDeviceList(display);
285 TouchFactory::GetInstance()->UpdateDeviceList(display); 696 TouchFactory::GetInstance()->UpdateDeviceList(display);
286 DeviceDataManager::GetInstance()->UpdateDeviceList(display); 697 ValuatorTracker::GetInstance()->SetupValuator();
287 } 698 }
288 699
289 EventType EventTypeFromNative(const base::NativeEvent& native_event) { 700 EventType EventTypeFromNative(const base::NativeEvent& native_event) {
290 switch (native_event->type) { 701 switch (native_event->type) {
291 case KeyPress: 702 case KeyPress:
292 return ET_KEY_PRESSED; 703 return ET_KEY_PRESSED;
293 case KeyRelease: 704 case KeyRelease:
294 return ET_KEY_RELEASED; 705 return ET_KEY_RELEASED;
295 case ButtonPress: 706 case ButtonPress:
296 if (static_cast<int>(native_event->xbutton.button) >= kMinWheelButton && 707 if (static_cast<int>(native_event->xbutton.button) >= kMinWheelButton &&
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 int button = EventButtonFromNative(native_event); 745 int button = EventButtonFromNative(native_event);
335 // Drop wheel events; we should've already scrolled on the press. 746 // Drop wheel events; we should've already scrolled on the press.
336 if (button >= kMinWheelButton && button <= kMaxWheelButton) 747 if (button >= kMinWheelButton && button <= kMaxWheelButton)
337 return ET_UNKNOWN; 748 return ET_UNKNOWN;
338 return ET_MOUSE_RELEASED; 749 return ET_MOUSE_RELEASED;
339 } 750 }
340 case XI_Motion: { 751 case XI_Motion: {
341 bool is_cancel; 752 bool is_cancel;
342 if (GetFlingData(native_event, NULL, NULL, NULL, NULL, &is_cancel)) { 753 if (GetFlingData(native_event, NULL, NULL, NULL, NULL, &is_cancel)) {
343 return is_cancel ? ET_SCROLL_FLING_CANCEL : ET_SCROLL_FLING_START; 754 return is_cancel ? ET_SCROLL_FLING_CANCEL : ET_SCROLL_FLING_START;
344 } else if (DeviceDataManager::GetInstance()->IsScrollEvent( 755 } else if (GetScrollOffsets(
345 native_event)) { 756 native_event, NULL, NULL, NULL, NULL, NULL)) {
346 return IsTouchpadEvent(native_event) ? ET_SCROLL : ET_MOUSEWHEEL; 757 return IsTouchpadEvent(native_event) ? ET_SCROLL : ET_MOUSEWHEEL;
347 } else if (GetButtonMaskForX2Event(xievent)) { 758 } else if (GetButtonMaskForX2Event(xievent)) {
348 return ET_MOUSE_DRAGGED; 759 return ET_MOUSE_DRAGGED;
349 } else { 760 } else {
350 return ET_MOUSE_MOVED; 761 return ET_MOUSE_MOVED;
351 } 762 }
352 } 763 }
353 } 764 }
354 } 765 }
355 default: 766 default:
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 case EnterNotify: 842 case EnterNotify:
432 case LeaveNotify: 843 case LeaveNotify:
433 return base::TimeDelta::FromMilliseconds(native_event->xcrossing.time); 844 return base::TimeDelta::FromMilliseconds(native_event->xcrossing.time);
434 break; 845 break;
435 case GenericEvent: { 846 case GenericEvent: {
436 double start, end; 847 double start, end;
437 double touch_timestamp; 848 double touch_timestamp;
438 if (GetGestureTimes(native_event, &start, &end)) { 849 if (GetGestureTimes(native_event, &start, &end)) {
439 // If the driver supports gesture times, use them. 850 // If the driver supports gesture times, use them.
440 return base::TimeDelta::FromMicroseconds(end * 1000000); 851 return base::TimeDelta::FromMicroseconds(end * 1000000);
441 } else if (DeviceDataManager::GetInstance()->GetEventData(*native_event, 852 } else if (ValuatorTracker::GetInstance()->ExtractValuator(*native_event,
442 DeviceDataManager::DT_TOUCH_RAW_TIMESTAMP, &touch_timestamp)) { 853 ValuatorTracker::VAL_TOUCH_RAW_TIMESTAMP, &touch_timestamp)) {
443 return base::TimeDelta::FromMicroseconds(touch_timestamp * 1000000); 854 return base::TimeDelta::FromMicroseconds(touch_timestamp * 1000000);
444 } else { 855 } else {
445 XIDeviceEvent* xide = 856 XIDeviceEvent* xide =
446 static_cast<XIDeviceEvent*>(native_event->xcookie.data); 857 static_cast<XIDeviceEvent*>(native_event->xcookie.data);
447 return base::TimeDelta::FromMilliseconds(xide->time); 858 return base::TimeDelta::FromMilliseconds(xide->time);
448 } 859 }
449 break; 860 break;
450 } 861 }
451 } 862 }
452 NOTREACHED(); 863 NOTREACHED();
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 break; 991 break;
581 } 992 }
582 } 993 }
583 default: 994 default:
584 break; 995 break;
585 } 996 }
586 return 0; 997 return 0;
587 } 998 }
588 999
589 gfx::Vector2d GetMouseWheelOffset(const base::NativeEvent& native_event) { 1000 gfx::Vector2d GetMouseWheelOffset(const base::NativeEvent& native_event) {
590 float x_offset, y_offset; 1001 float x_offset = 0;
591 if (GetScrollOffsets( 1002 float y_offset = 0;
592 native_event, &x_offset, &y_offset, NULL, NULL, NULL)) { 1003 if (native_event->type == GenericEvent &&
1004 GetScrollOffsets(native_event, &x_offset, &y_offset, NULL, NULL, NULL)) {
593 return gfx::Vector2d(static_cast<int>(x_offset), 1005 return gfx::Vector2d(static_cast<int>(x_offset),
594 static_cast<int>(y_offset)); 1006 static_cast<int>(y_offset));
595 } 1007 }
596 1008
597 int button = native_event->type == GenericEvent ? 1009 int button = native_event->type == GenericEvent ?
598 EventButtonFromNative(native_event) : native_event->xbutton.button; 1010 EventButtonFromNative(native_event) : native_event->xbutton.button;
599 1011
600 switch (button) { 1012 switch (button) {
601 case 4: 1013 case 4:
602 return gfx::Vector2d(0, kWheelScrollAmount); 1014 return gfx::Vector2d(0, kWheelScrollAmount);
603 case 5: 1015 case 5:
604 return gfx::Vector2d(0, -kWheelScrollAmount); 1016 return gfx::Vector2d(0, -kWheelScrollAmount);
605 default: 1017 default:
606 // TODO(derat): Do something for horizontal scrolls (buttons 6 and 7)? 1018 // TODO(derat): Do something for horizontal scrolls (buttons 6 and 7)?
607 return gfx::Vector2d(); 1019 return gfx::Vector2d();
608 } 1020 }
609 } 1021 }
610 1022
611 int GetTouchId(const base::NativeEvent& xev) { 1023 int GetTouchId(const base::NativeEvent& xev) {
612 double slot = 0; 1024 double slot = 0;
613 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); 1025 ui::TouchFactory* factory = ui::TouchFactory::GetInstance();
614 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data); 1026 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data);
615 if (!factory->IsMultiTouchDevice(xievent->sourceid)) { 1027 if (!factory->IsMultiTouchDevice(xievent->sourceid)) {
616 // TODO(sad): Come up with a way to generate touch-ids for multi-touch 1028 // TODO(sad): Come up with a way to generate touch-ids for multi-touch
617 // events when touch-events are generated from a single-touch device. 1029 // events when touch-events are generated from a single-touch device.
618 return slot; 1030 return slot;
619 } 1031 }
620 1032
621 ui::DeviceDataManager* manager = ui::DeviceDataManager::GetInstance(); 1033 ui::ValuatorTracker* valuators = ui::ValuatorTracker::GetInstance();
622 1034
623 #if defined(USE_XI2_MT) 1035 #if defined(USE_XI2_MT)
624 double tracking_id; 1036 double tracking_id;
625 if (!manager->GetEventData( 1037 if (!valuators->ExtractValuator(
626 *xev, ui::DeviceDataManager::DT_TOUCH_TRACKING_ID, &tracking_id)) { 1038 *xev, ui::ValuatorTracker::VAL_TRACKING_ID, &tracking_id)) {
627 LOG(ERROR) << "Could not get the slot ID for the event. Using 0."; 1039 LOG(ERROR) << "Could not get the slot ID for the event. Using 0.";
628 } else { 1040 } else {
629 slot = factory->GetSlotForTrackingID(tracking_id); 1041 slot = factory->GetSlotForTrackingID(tracking_id);
630 ui::EventType type = ui::EventTypeFromNative(xev); 1042 ui::EventType type = ui::EventTypeFromNative(xev);
631 if (type == ui::ET_TOUCH_CANCELLED || 1043 if (type == ui::ET_TOUCH_CANCELLED ||
632 type == ui::ET_TOUCH_RELEASED) { 1044 type == ui::ET_TOUCH_RELEASED) {
633 factory->ReleaseSlotForTrackingID(tracking_id); 1045 factory->ReleaseSlotForTrackingID(tracking_id);
634 } 1046 }
635 } 1047 }
636 #else 1048 #else
637 if (!manager->GetEventData( 1049 if (!valuators->ExtractValuator(
638 *xev, ui::DeviceDataManager::DT_TOUCH_SLOT_ID, &slot)) 1050 *xev, ui::ValuatorTracker::VAL_SLOT_ID, &slot))
639 LOG(ERROR) << "Could not get the slot ID for the event. Using 0."; 1051 LOG(ERROR) << "Could not get the slot ID for the event. Using 0.";
640 #endif 1052 #endif
641 return slot; 1053 return slot;
642 } 1054 }
643 1055
644 float GetTouchRadiusX(const base::NativeEvent& native_event) { 1056 float GetTouchRadiusX(const base::NativeEvent& native_event) {
645 return GetTouchParamFromXEvent(native_event, 1057 return GetTouchParamFromXEvent(native_event,
646 ui::DeviceDataManager::DT_TOUCH_MAJOR, 0.0) / 2.0; 1058 ui::ValuatorTracker::VAL_TOUCH_MAJOR, 0.0) / 2.0;
647 } 1059 }
648 1060
649 float GetTouchRadiusY(const base::NativeEvent& native_event) { 1061 float GetTouchRadiusY(const base::NativeEvent& native_event) {
650 return GetTouchParamFromXEvent(native_event, 1062 return GetTouchParamFromXEvent(native_event,
651 ui::DeviceDataManager::DT_TOUCH_MINOR, 0.0) / 2.0; 1063 ui::ValuatorTracker::VAL_TOUCH_MINOR, 0.0) / 2.0;
652 } 1064 }
653 1065
654 float GetTouchAngle(const base::NativeEvent& native_event) { 1066 float GetTouchAngle(const base::NativeEvent& native_event) {
655 return GetTouchParamFromXEvent(native_event, 1067 return GetTouchParamFromXEvent(native_event,
656 ui::DeviceDataManager::DT_TOUCH_ORIENTATION, 0.0) / 2.0; 1068 ui::ValuatorTracker::VAL_ORIENTATION, 0.0) / 2.0;
657 } 1069 }
658 1070
659 float GetTouchForce(const base::NativeEvent& native_event) { 1071 float GetTouchForce(const base::NativeEvent& native_event) {
660 double force = 0.0; 1072 double force = 0.0;
661 force = GetTouchParamFromXEvent(native_event, 1073 force = GetTouchParamFromXEvent(native_event,
662 ui::DeviceDataManager::DT_TOUCH_PRESSURE, 0.0); 1074 ui::ValuatorTracker::VAL_PRESSURE, 0.0);
663 unsigned int deviceid = 1075 unsigned int deviceid =
664 static_cast<XIDeviceEvent*>(native_event->xcookie.data)->sourceid; 1076 static_cast<XIDeviceEvent*>(native_event->xcookie.data)->sourceid;
665 // Force is normalized to fall into [0, 1] 1077 // Force is normalized to fall into [0, 1]
666 if (!ui::DeviceDataManager::GetInstance()->NormalizeData( 1078 if (!ui::ValuatorTracker::GetInstance()->NormalizeValuator(
667 deviceid, ui::DeviceDataManager::DT_TOUCH_PRESSURE, &force)) 1079 deviceid, ui::ValuatorTracker::VAL_PRESSURE, &force))
668 force = 0.0; 1080 force = 0.0;
669 return force; 1081 return force;
670 } 1082 }
671 1083
672 bool GetScrollOffsets(const base::NativeEvent& native_event, 1084 bool GetScrollOffsets(const base::NativeEvent& native_event,
673 float* x_offset, 1085 float* x_offset,
674 float* y_offset, 1086 float* y_offset,
675 float* x_offset_ordinal, 1087 float* x_offset_ordinal,
676 float* y_offset_ordinal, 1088 float* y_offset_ordinal,
677 int* finger_count) { 1089 int* finger_count) {
678 if (!DeviceDataManager::GetInstance()->IsScrollEvent(native_event)) 1090 return CMTEventData::GetInstance()->GetScrollOffsets(
679 return false; 1091 *native_event,
680
681 // Temp values to prevent passing NULLs to DeviceDataManager.
682 float x_offset_, y_offset_;
683 float x_offset_ordinal_, y_offset_ordinal_;
684 int finger_count_;
685 if (!x_offset)
686 x_offset = &x_offset_;
687 if (!y_offset)
688 y_offset = &y_offset_;
689 if (!x_offset_ordinal)
690 x_offset_ordinal = &x_offset_ordinal_;
691 if (!y_offset_ordinal)
692 y_offset_ordinal = &y_offset_ordinal_;
693 if (!finger_count)
694 finger_count = &finger_count_;
695
696 DeviceDataManager::GetInstance()->GetScrollOffsets(
697 native_event,
698 x_offset, y_offset, 1092 x_offset, y_offset,
699 x_offset_ordinal, y_offset_ordinal, 1093 x_offset_ordinal, y_offset_ordinal,
700 finger_count); 1094 finger_count);
701 return true;
702 } 1095 }
703 1096
704 bool GetFlingData(const base::NativeEvent& native_event, 1097 bool GetFlingData(const base::NativeEvent& native_event,
705 float* vx, 1098 float* vx,
706 float* vy, 1099 float* vy,
707 float* vx_ordinal, 1100 float* vx_ordinal,
708 float* vy_ordinal, 1101 float* vy_ordinal,
709 bool* is_cancel) { 1102 bool* is_cancel) {
710 if (!DeviceDataManager::GetInstance()->IsFlingEvent(native_event)) 1103 return CMTEventData::GetInstance()->GetFlingData(
711 return false; 1104 *native_event, vx, vy, vx_ordinal, vy_ordinal, is_cancel);
712
713 float vx_, vy_;
714 float vx_ordinal_, vy_ordinal_;
715 bool is_cancel_;
716 if (!vx)
717 vx = &vx_;
718 if (!vy)
719 vy = &vy_;
720 if (!vx_ordinal)
721 vx_ordinal = &vx_ordinal_;
722 if (!vy_ordinal)
723 vy_ordinal = &vy_ordinal_;
724 if (!is_cancel)
725 is_cancel = &is_cancel_;
726
727 DeviceDataManager::GetInstance()->GetFlingData(
728 native_event, vx, vy, vx_ordinal, vy_ordinal, is_cancel);
729 return true;
730 } 1105 }
731 1106
732 bool GetGestureTimes(const base::NativeEvent& native_event, 1107 bool GetGestureTimes(const base::NativeEvent& native_event,
733 double* start_time, 1108 double* start_time,
734 double* end_time) { 1109 double* end_time) {
735 if (!DeviceDataManager::GetInstance()->HasGestureTimes(native_event)) 1110 return CMTEventData::GetInstance()->GetGestureTimes(
736 return false; 1111 *native_event, start_time, end_time);
737
738 double start_time_, end_time_;
739 if (!start_time)
740 start_time = &start_time_;
741 if (!end_time)
742 end_time = &end_time_;
743
744 DeviceDataManager::GetInstance()->GetGestureTimes(
745 native_event, start_time, end_time);
746 return true;
747 } 1112 }
748 1113
749 void SetNaturalScroll(bool enabled) { 1114 void SetNaturalScroll(bool enabled) {
750 DeviceDataManager::GetInstance()->set_natural_scroll_enabled(enabled); 1115 CMTEventData::GetInstance()->set_natural_scroll_enabled(enabled);
751 } 1116 }
752 1117
753 bool IsNaturalScrollEnabled() { 1118 bool IsNaturalScrollEnabled() {
754 return DeviceDataManager::GetInstance()->natural_scroll_enabled(); 1119 return CMTEventData::GetInstance()->natural_scroll_enabled();
755 } 1120 }
756 1121
757 bool IsTouchpadEvent(const base::NativeEvent& event) { 1122 bool IsTouchpadEvent(const base::NativeEvent& event) {
758 return DeviceDataManager::GetInstance()->IsTouchpadXInputEvent(event); 1123 return CMTEventData::GetInstance()->IsTouchpadXInputEvent(event);
759 } 1124 }
760 1125
761 bool IsNoopEvent(const base::NativeEvent& event) { 1126 bool IsNoopEvent(const base::NativeEvent& event) {
762 return (event->type == ClientMessage && 1127 return (event->type == ClientMessage &&
763 event->xclient.message_type == GetNoopEventAtom()); 1128 event->xclient.message_type == GetNoopEventAtom());
764 } 1129 }
765 1130
766 base::NativeEvent CreateNoopEvent() { 1131 base::NativeEvent CreateNoopEvent() {
767 static XEvent* noop = NULL; 1132 static XEvent* noop = NULL;
768 if (!noop) { 1133 if (!noop) {
769 noop = new XEvent(); 1134 noop = new XEvent();
770 memset(noop, 0, sizeof(XEvent)); 1135 memset(noop, 0, sizeof(XEvent));
771 noop->xclient.type = ClientMessage; 1136 noop->xclient.type = ClientMessage;
772 noop->xclient.window = None; 1137 noop->xclient.window = None;
773 noop->xclient.format = 8; 1138 noop->xclient.format = 8;
774 DCHECK(!noop->xclient.display); 1139 DCHECK(!noop->xclient.display);
775 } 1140 }
776 // Make sure we use atom from current xdisplay, which may 1141 // Make sure we use atom from current xdisplay, which may
777 // change during the test. 1142 // change during the test.
778 noop->xclient.message_type = GetNoopEventAtom(); 1143 noop->xclient.message_type = GetNoopEventAtom();
779 return noop; 1144 return noop;
780 } 1145 }
781 1146
782 } // namespace ui 1147 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/x/device_data_manager.cc ('k') | ui/base/x/valuators.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698