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 12 matching lines...) Expand all Loading... | |
23 #include "base/strings/string_number_conversions.h" | 23 #include "base/strings/string_number_conversions.h" |
24 #include "base/strings/string_util.h" | 24 #include "base/strings/string_util.h" |
25 #include "base/strings/stringprintf.h" | 25 #include "base/strings/stringprintf.h" |
26 #include "ui/events/event.h" | 26 #include "ui/events/event.h" |
27 #include "ui/events/event_constants.h" | 27 #include "ui/events/event_constants.h" |
28 #include "ui/events/event_switches.h" | 28 #include "ui/events/event_switches.h" |
29 #include "ui/gfx/screen.h" | 29 #include "ui/gfx/screen.h" |
30 | 30 |
31 namespace { | 31 namespace { |
32 | 32 |
33 // Number is determined empirically. | |
34 // TODO(rjkroege): Configure this per device. | |
35 const float kFingerWidth = 25.f; | |
36 | |
37 struct TouchCalibration { | 33 struct TouchCalibration { |
38 int bezel_left; | 34 int bezel_left; |
39 int bezel_right; | 35 int bezel_right; |
40 int bezel_top; | 36 int bezel_top; |
41 int bezel_bottom; | 37 int bezel_bottom; |
42 }; | 38 }; |
43 | 39 |
44 void GetTouchCalibration(TouchCalibration* cal) { | 40 void GetTouchCalibration(TouchCalibration* cal) { |
45 std::vector<std::string> parts; | 41 std::vector<std::string> parts; |
46 if (Tokenize(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 42 if (Tokenize(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
(...skipping 14 matching lines...) Expand all Loading... | |
61 float TuxelsToPixels(float val, | 57 float TuxelsToPixels(float val, |
62 float min_tuxels, | 58 float min_tuxels, |
63 float num_tuxels, | 59 float num_tuxels, |
64 float min_pixels, | 60 float min_pixels, |
65 float num_pixels) { | 61 float num_pixels) { |
66 // Map [min_tuxels, min_tuxels + num_tuxels) to | 62 // Map [min_tuxels, min_tuxels + num_tuxels) to |
67 // [min_pixels, min_pixels + num_pixels). | 63 // [min_pixels, min_pixels + num_pixels). |
68 return min_pixels + (val - min_tuxels) * num_pixels / num_tuxels; | 64 return min_pixels + (val - min_tuxels) * num_pixels / num_tuxels; |
69 } | 65 } |
70 | 66 |
67 float TuxelToPizelSize(float val, float num_tuxels, float num_pixels) { | |
alexst (slow to review)
2014/08/26 23:51:26
Pizel Size -> Pizza Size? Pixel Size? :)
| |
68 return val * num_pixels / num_tuxels; | |
69 } | |
70 | |
71 } // namespace | 71 } // namespace |
72 | 72 |
73 namespace ui { | 73 namespace ui { |
74 | 74 |
75 TouchEventConverterEvdev::TouchEventConverterEvdev( | 75 TouchEventConverterEvdev::TouchEventConverterEvdev( |
76 int fd, | 76 int fd, |
77 base::FilePath path, | 77 base::FilePath path, |
78 const EventDeviceInfo& info, | 78 const EventDeviceInfo& info, |
79 const EventDispatchCallback& callback) | 79 const EventDispatchCallback& callback) |
80 : EventConverterEvdev(callback), | 80 : EventConverterEvdev(callback), |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
194 } | 194 } |
195 } else { | 195 } else { |
196 NOTIMPLEMENTED() << "invalid type: " << input.type; | 196 NOTIMPLEMENTED() << "invalid type: " << input.type; |
197 } | 197 } |
198 } | 198 } |
199 | 199 |
200 void TouchEventConverterEvdev::ProcessAbs(const input_event& input) { | 200 void TouchEventConverterEvdev::ProcessAbs(const input_event& input) { |
201 switch (input.code) { | 201 switch (input.code) { |
202 case ABS_MT_TOUCH_MAJOR: | 202 case ABS_MT_TOUCH_MAJOR: |
203 altered_slots_.set(current_slot_); | 203 altered_slots_.set(current_slot_); |
204 events_[current_slot_].major_ = input.value; | 204 // TODO(spang): If we have all of major, minor, and orientation, |
205 // we can scale the ellipse correctly. However on the Pixel we get | |
206 // neither minor nor orientation, so this is all we can do. | |
207 events_[current_slot_].radius_x_ = | |
208 TuxelToPizelSize(input.value, x_num_tuxels_, x_num_pixels_) / 2.0f; | |
209 break; | |
210 case ABS_MT_TOUCH_MINOR: | |
211 altered_slots_.set(current_slot_); | |
212 events_[current_slot_].radius_y_ = | |
213 TuxelToPizelSize(input.value, y_num_tuxels_, y_num_pixels_) / 2.0f; | |
205 break; | 214 break; |
206 case ABS_MT_POSITION_X: | 215 case ABS_MT_POSITION_X: |
207 altered_slots_.set(current_slot_); | 216 altered_slots_.set(current_slot_); |
208 events_[current_slot_].x_ = TuxelsToPixels(input.value, | 217 events_[current_slot_].x_ = TuxelsToPixels(input.value, |
209 x_min_tuxels_, | 218 x_min_tuxels_, |
210 x_num_tuxels_, | 219 x_num_tuxels_, |
211 x_min_pixels_, | 220 x_min_pixels_, |
212 x_num_pixels_); | 221 x_num_pixels_); |
213 break; | 222 break; |
214 case ABS_MT_POSITION_Y: | 223 case ABS_MT_POSITION_Y: |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
279 | 288 |
280 void TouchEventConverterEvdev::ReportEvents(base::TimeDelta delta) { | 289 void TouchEventConverterEvdev::ReportEvents(base::TimeDelta delta) { |
281 for (int i = 0; i < MAX_FINGERS; i++) { | 290 for (int i = 0; i < MAX_FINGERS; i++) { |
282 if (altered_slots_[i]) { | 291 if (altered_slots_[i]) { |
283 // TODO(rikroege): Support elliptical finger regions. | 292 // TODO(rikroege): Support elliptical finger regions. |
284 TouchEvent evt(events_[i].type_, | 293 TouchEvent evt(events_[i].type_, |
285 gfx::PointF(events_[i].x_, events_[i].y_), | 294 gfx::PointF(events_[i].x_, events_[i].y_), |
286 /* flags */ 0, | 295 /* flags */ 0, |
287 /* touch_id */ events_[i].finger_, | 296 /* touch_id */ events_[i].finger_, |
288 delta, | 297 delta, |
289 events_[i].pressure_ * kFingerWidth, | 298 /* radius_x */ events_[i].radius_x_, |
290 events_[i].pressure_ * kFingerWidth, | 299 /* radius_y */ events_[i].radius_y_, |
291 /* angle */ 0., | 300 /* angle */ 0., |
292 events_[i].pressure_); | 301 events_[i].pressure_); |
293 DispatchEventToCallback(&evt); | 302 DispatchEventToCallback(&evt); |
294 | 303 |
295 // Subsequent events for this finger will be touch-move until it | 304 // Subsequent events for this finger will be touch-move until it |
296 // is released. | 305 // is released. |
297 events_[i].type_ = ET_TOUCH_MOVED; | 306 events_[i].type_ = ET_TOUCH_MOVED; |
298 } | 307 } |
299 } | 308 } |
300 altered_slots_.reset(); | 309 altered_slots_.reset(); |
301 } | 310 } |
302 | 311 |
303 } // namespace ui | 312 } // namespace ui |
OLD | NEW |