OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/ozone/evdev/touch_event_converter_evdev.h" | 5 #include "ui/events/ozone/evdev/touch_event_converter_evdev.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <linux/input.h> | 9 #include <linux/input.h> |
10 #include <poll.h> | 10 #include <poll.h> |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 radius_x_(0), | 67 radius_x_(0), |
68 radius_y_(0), | 68 radius_y_(0), |
69 pressure_(0) { | 69 pressure_(0) { |
70 } | 70 } |
71 | 71 |
72 TouchEventConverterEvdev::TouchEventConverterEvdev( | 72 TouchEventConverterEvdev::TouchEventConverterEvdev( |
73 int fd, | 73 int fd, |
74 base::FilePath path, | 74 base::FilePath path, |
75 int id, | 75 int id, |
76 InputDeviceType type, | 76 InputDeviceType type, |
77 const EventDispatchCallback& callback) | 77 const TouchEventDispatchCallback& touch_callback) |
78 : EventConverterEvdev(fd, path, id, type), | 78 : EventConverterEvdev(fd, path, id, type), |
79 callback_(callback), | 79 touch_callback_(touch_callback), |
80 syn_dropped_(false), | 80 syn_dropped_(false), |
81 is_type_a_(false), | 81 is_type_a_(false), |
82 current_slot_(0) { | 82 current_slot_(0) { |
83 } | 83 } |
84 | 84 |
85 TouchEventConverterEvdev::~TouchEventConverterEvdev() { | 85 TouchEventConverterEvdev::~TouchEventConverterEvdev() { |
86 Stop(); | 86 Stop(); |
87 close(fd_); | 87 close(fd_); |
88 } | 88 } |
89 | 89 |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 // Some buffer has overrun. We ignore all events up to and | 263 // Some buffer has overrun. We ignore all events up to and |
264 // including the next SYN_REPORT. | 264 // including the next SYN_REPORT. |
265 syn_dropped_ = true; | 265 syn_dropped_ = true; |
266 break; | 266 break; |
267 default: | 267 default: |
268 NOTIMPLEMENTED() << "invalid code for EV_SYN: " << input.code; | 268 NOTIMPLEMENTED() << "invalid code for EV_SYN: " << input.code; |
269 } | 269 } |
270 } | 270 } |
271 | 271 |
272 void TouchEventConverterEvdev::ReportEvent(int touch_id, | 272 void TouchEventConverterEvdev::ReportEvent(int touch_id, |
273 const InProgressEvents& event, const base::TimeDelta& delta) { | 273 const InProgressEvents& event, |
274 float x = event.x_; | 274 const base::TimeDelta& timestamp) { |
275 float y = event.y_; | 275 touch_callback_.Run(TouchEventParams( |
276 | 276 id_, touch_id, event.type_, gfx::PointF(event.x_, event.y_), |
277 double radius_x = event.radius_x_; | 277 gfx::Vector2dF(event.radius_x_, event.radius_y_), event.pressure_, |
278 double radius_y = event.radius_y_; | 278 timestamp)); |
279 | |
280 // Transform the event according (this is used to align touches | |
281 // to the image based on display mode). | |
282 DeviceDataManager::GetInstance()->ApplyTouchTransformer( | |
283 id_, &x, &y); | |
284 DeviceDataManager::GetInstance()->ApplyTouchRadiusScale( | |
285 id_, &radius_x); | |
286 DeviceDataManager::GetInstance()->ApplyTouchRadiusScale( | |
287 id_, &radius_y); | |
288 | |
289 gfx::PointF location(x, y); | |
290 | |
291 scoped_ptr<TouchEvent> touch_event( | |
292 new TouchEvent(event.type_, location, | |
293 /* flags */ 0, | |
294 /* touch_id */ touch_id, | |
295 delta, | |
296 /* radius_x */ radius_x, | |
297 /* radius_y */ radius_y, | |
298 /* angle */ 0., | |
299 event.pressure_)); | |
300 touch_event->set_source_device_id(id_); | |
301 callback_.Run(touch_event.Pass()); | |
302 } | 279 } |
303 | 280 |
304 void TouchEventConverterEvdev::ReportEvents(base::TimeDelta delta) { | 281 void TouchEventConverterEvdev::ReportEvents(base::TimeDelta delta) { |
305 for (int i = 0; i < MAX_FINGERS; i++) { | 282 for (int i = 0; i < MAX_FINGERS; i++) { |
306 if (altered_slots_[i]) { | 283 if (altered_slots_[i]) { |
307 ReportEvent(i, events_[i], delta); | 284 ReportEvent(i, events_[i], delta); |
308 | 285 |
309 // Subsequent events for this finger will be touch-move until it | 286 // Subsequent events for this finger will be touch-move until it |
310 // is released. | 287 // is released. |
311 events_[i].type_ = ET_TOUCH_MOVED; | 288 events_[i].type_ = ET_TOUCH_MOVED; |
312 } | 289 } |
313 } | 290 } |
314 altered_slots_.reset(); | 291 altered_slots_.reset(); |
315 } | 292 } |
316 | 293 |
317 } // namespace ui | 294 } // namespace ui |
OLD | NEW |