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

Side by Side Diff: ui/events/ozone/evdev/touch_event_converter_evdev.cc

Issue 509713002: ozone: evdev: Fix TouchEvent radius (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add test Created 6 years, 3 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 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
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
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 TuxelToPixelSize(float val, float num_tuxels, float num_pixels) {
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
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 TuxelToPixelSize(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 TuxelToPixelSize(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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 287
279 void TouchEventConverterEvdev::ReportEvents(base::TimeDelta delta) { 288 void TouchEventConverterEvdev::ReportEvents(base::TimeDelta delta) {
280 for (int i = 0; i < MAX_FINGERS; i++) { 289 for (int i = 0; i < MAX_FINGERS; i++) {
281 if (altered_slots_[i]) { 290 if (altered_slots_[i]) {
282 // TODO(rikroege): Support elliptical finger regions. 291 // TODO(rikroege): Support elliptical finger regions.
283 TouchEvent evt(events_[i].type_, 292 TouchEvent evt(events_[i].type_,
284 gfx::PointF(events_[i].x_, events_[i].y_), 293 gfx::PointF(events_[i].x_, events_[i].y_),
285 /* flags */ 0, 294 /* flags */ 0,
286 /* touch_id */ events_[i].finger_, 295 /* touch_id */ events_[i].finger_,
287 delta, 296 delta,
288 events_[i].pressure_ * kFingerWidth, 297 /* radius_x */ events_[i].radius_x_,
289 events_[i].pressure_ * kFingerWidth, 298 /* radius_y */ events_[i].radius_y_,
290 /* angle */ 0., 299 /* angle */ 0.,
291 events_[i].pressure_); 300 events_[i].pressure_);
292 DispatchEventToCallback(&evt); 301 DispatchEventToCallback(&evt);
293 302
294 // Subsequent events for this finger will be touch-move until it 303 // Subsequent events for this finger will be touch-move until it
295 // is released. 304 // is released.
296 events_[i].type_ = ET_TOUCH_MOVED; 305 events_[i].type_ = ET_TOUCH_MOVED;
297 } 306 }
298 } 307 }
299 altered_slots_.reset(); 308 altered_slots_.reset();
300 } 309 }
301 310
302 } // namespace ui 311 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/ozone/evdev/touch_event_converter_evdev.h ('k') | ui/events/ozone/evdev/touch_event_converter_evdev_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698