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

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

Issue 1456063003: ozone: evdev: Fix tilt calculation for tablets (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix some parens Created 5 years, 1 month 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/tablet_event_converter_evdev.h" 5 #include "ui/events/ozone/evdev/tablet_event_converter_evdev.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <linux/input.h> 8 #include <linux/input.h>
9 9
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/trace_event/trace_event.h" 11 #include "base/trace_event/trace_event.h"
12 #include "ui/events/event.h" 12 #include "ui/events/event.h"
13 #include "ui/events/ozone/evdev/device_event_dispatcher_evdev.h" 13 #include "ui/events/ozone/evdev/device_event_dispatcher_evdev.h"
14 14
15 namespace ui { 15 namespace ui {
16 16
17 namespace {
18
19 // Convert tilt from [min, min + num_values) to [-90deg, +90deg)
20 float ScaleTilt(int value, int min_value, int num_values) {
21 return 180.f * (value - min_value) / num_values - 90.f;
22 }
23
24 } // namespace
25
17 TabletEventConverterEvdev::TabletEventConverterEvdev( 26 TabletEventConverterEvdev::TabletEventConverterEvdev(
18 int fd, 27 int fd,
19 base::FilePath path, 28 base::FilePath path,
20 int id, 29 int id,
21 CursorDelegateEvdev* cursor, 30 CursorDelegateEvdev* cursor,
22 const EventDeviceInfo& info, 31 const EventDeviceInfo& info,
23 DeviceEventDispatcherEvdev* dispatcher) 32 DeviceEventDispatcherEvdev* dispatcher)
24 : EventConverterEvdev(fd, 33 : EventConverterEvdev(fd,
25 path, 34 path,
26 id, 35 id,
27 info.device_type(), 36 info.device_type(),
28 info.name(), 37 info.name(),
29 info.vendor_id(), 38 info.vendor_id(),
30 info.product_id()), 39 info.product_id()),
31 cursor_(cursor), 40 cursor_(cursor),
32 dispatcher_(dispatcher) { 41 dispatcher_(dispatcher) {
33 x_abs_min_ = info.GetAbsMinimum(ABS_X); 42 x_abs_min_ = info.GetAbsMinimum(ABS_X);
34 x_abs_range_ = info.GetAbsMaximum(ABS_X) - x_abs_min_ + 1; 43 x_abs_range_ = info.GetAbsMaximum(ABS_X) - x_abs_min_ + 1;
35 y_abs_min_ = info.GetAbsMinimum(ABS_Y); 44 y_abs_min_ = info.GetAbsMinimum(ABS_Y);
36 y_abs_range_ = info.GetAbsMaximum(ABS_Y) - y_abs_min_ + 1; 45 y_abs_range_ = info.GetAbsMaximum(ABS_Y) - y_abs_min_ + 1;
37 46 tilt_x_min_ = info.GetAbsMinimum(ABS_TILT_X);
38 tilt_x_max_ = info.GetAbsMaximum(ABS_TILT_X); 47 tilt_y_min_ = info.GetAbsMinimum(ABS_TILT_Y);
39 tilt_y_max_ = info.GetAbsMaximum(ABS_TILT_Y); 48 tilt_x_range_ = info.GetAbsMaximum(ABS_TILT_X) - tilt_x_min_ + 1;
mustaq 2015/11/19 15:26:35 Have a quick question, didn't see it until CQing,
49 tilt_y_range_ = info.GetAbsMaximum(ABS_TILT_Y) - tilt_y_min_ + 1;
40 pressure_max_ = info.GetAbsMaximum(ABS_PRESSURE); 50 pressure_max_ = info.GetAbsMaximum(ABS_PRESSURE);
41 } 51 }
42 52
43 TabletEventConverterEvdev::~TabletEventConverterEvdev() { 53 TabletEventConverterEvdev::~TabletEventConverterEvdev() {
44 } 54 }
45 55
46 void TabletEventConverterEvdev::OnFileCanReadWithoutBlocking(int fd) { 56 void TabletEventConverterEvdev::OnFileCanReadWithoutBlocking(int fd) {
47 TRACE_EVENT1("evdev", 57 TRACE_EVENT1("evdev",
48 "TabletEventConverterEvdev::OnFileCanReadWithoutBlocking", "fd", 58 "TabletEventConverterEvdev::OnFileCanReadWithoutBlocking", "fd",
49 fd); 59 fd);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 switch (input.code) { 119 switch (input.code) {
110 case ABS_X: 120 case ABS_X:
111 x_abs_location_ = input.value; 121 x_abs_location_ = input.value;
112 abs_value_dirty_ = true; 122 abs_value_dirty_ = true;
113 break; 123 break;
114 case ABS_Y: 124 case ABS_Y:
115 y_abs_location_ = input.value; 125 y_abs_location_ = input.value;
116 abs_value_dirty_ = true; 126 abs_value_dirty_ = true;
117 break; 127 break;
118 case ABS_TILT_X: 128 case ABS_TILT_X:
119 tilt_x_ = (90.0f * input.value) / tilt_x_max_; 129 tilt_x_ = ScaleTilt(input.value, tilt_x_min_, tilt_x_range_);
120 abs_value_dirty_ = true; 130 abs_value_dirty_ = true;
121 break; 131 break;
122 case ABS_TILT_Y: 132 case ABS_TILT_Y:
123 tilt_y_ = (90.0f * input.value) / tilt_y_max_; 133 tilt_y_ = ScaleTilt(input.value, tilt_y_min_, tilt_y_range_);
124 abs_value_dirty_ = true; 134 abs_value_dirty_ = true;
125 break; 135 break;
126 case ABS_PRESSURE: 136 case ABS_PRESSURE:
127 pressure_ = (float)input.value / pressure_max_; 137 pressure_ = (float)input.value / pressure_max_;
128 abs_value_dirty_ = true; 138 abs_value_dirty_ = true;
129 break; 139 break;
130 } 140 }
131 } 141 }
132 142
133 void TabletEventConverterEvdev::UpdateCursor() { 143 void TabletEventConverterEvdev::UpdateCursor() {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 input_device_.id, cursor_->GetLocation(), 204 input_device_.id, cursor_->GetLocation(),
195 PointerDetails(EventPointerType::POINTER_TYPE_PEN, 205 PointerDetails(EventPointerType::POINTER_TYPE_PEN,
196 /* radius_x */ 0.0f, /* radius_y */ 0.0f, pressure_, 206 /* radius_x */ 0.0f, /* radius_y */ 0.0f, pressure_,
197 tilt_x_, tilt_y_), 207 tilt_x_, tilt_y_),
198 TimeDeltaFromInputEvent(input))); 208 TimeDeltaFromInputEvent(input)));
199 209
200 abs_value_dirty_ = false; 210 abs_value_dirty_ = false;
201 } 211 }
202 212
203 } // namespace ui 213 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/ozone/evdev/tablet_event_converter_evdev.h ('k') | ui/events/ozone/evdev/tablet_event_converter_evdev_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698