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/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 #include <stddef.h> | 9 #include <stddef.h> |
10 | 10 |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
13 #include "ui/events/event.h" | 13 #include "ui/events/event.h" |
14 #include "ui/events/ozone/evdev/device_event_dispatcher_evdev.h" | 14 #include "ui/events/ozone/evdev/device_event_dispatcher_evdev.h" |
15 | 15 |
16 namespace ui { | 16 namespace ui { |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 // Convert tilt from [min, min + num_values) to [-90deg, +90deg) | 20 // Convert tilt from [min, min + num_values) to [-90deg, +90deg) |
21 float ScaleTilt(int value, int min_value, int num_values) { | 21 float ScaleTilt(int value, int min_value, int num_values) { |
22 return 180.f * (value - min_value) / num_values - 90.f; | 22 return 180.f * (value - min_value) / num_values - 90.f; |
23 } | 23 } |
24 | 24 |
25 EventPointerType GetToolType(int button_tool) { | |
26 if (button_tool == BTN_TOOL_RUBBER) | |
27 return EventPointerType::POINTER_TYPE_ERASER; | |
28 return EventPointerType::POINTER_TYPE_PEN; | |
29 } | |
30 | |
31 } // namespace | 25 } // namespace |
32 | 26 |
33 TabletEventConverterEvdev::TabletEventConverterEvdev( | 27 TabletEventConverterEvdev::TabletEventConverterEvdev( |
34 int fd, | 28 int fd, |
35 base::FilePath path, | 29 base::FilePath path, |
36 int id, | 30 int id, |
37 CursorDelegateEvdev* cursor, | 31 CursorDelegateEvdev* cursor, |
38 const EventDeviceInfo& info, | 32 const EventDeviceInfo& info, |
39 DeviceEventDispatcherEvdev* dispatcher) | 33 DeviceEventDispatcherEvdev* dispatcher) |
40 : EventConverterEvdev(fd, | 34 : EventConverterEvdev(fd, |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 if (abs_value_dirty_) { | 173 if (abs_value_dirty_) { |
180 UpdateCursor(); | 174 UpdateCursor(); |
181 abs_value_dirty_ = false; | 175 abs_value_dirty_ = false; |
182 } | 176 } |
183 | 177 |
184 bool down = input.value; | 178 bool down = input.value; |
185 | 179 |
186 dispatcher_->DispatchMouseButtonEvent(MouseButtonEventParams( | 180 dispatcher_->DispatchMouseButtonEvent(MouseButtonEventParams( |
187 input_device_.id, EF_NONE, cursor_->GetLocation(), button, down, | 181 input_device_.id, EF_NONE, cursor_->GetLocation(), button, down, |
188 false /* allow_remap */, | 182 false /* allow_remap */, |
189 PointerDetails(GetToolType(stylus_), | 183 PointerDetails(EventPointerType::POINTER_TYPE_PEN, |
190 /* radius_x */ 0.0f, /* radius_y */ 0.0f, pressure_, | 184 /* radius_x */ 0.0f, /* radius_y */ 0.0f, pressure_, |
191 tilt_x_, tilt_y_), | 185 tilt_x_, tilt_y_), |
192 TimeTicksFromInputEvent(input))); | 186 TimeTicksFromInputEvent(input))); |
193 } | 187 } |
194 | 188 |
195 void TabletEventConverterEvdev::FlushEvents(const input_event& input) { | 189 void TabletEventConverterEvdev::FlushEvents(const input_event& input) { |
196 if (!cursor_) | 190 if (!cursor_) |
197 return; | 191 return; |
198 | 192 |
199 // Prevent propagation of invalid data on stylus lift off | 193 // Prevent propagation of invalid data on stylus lift off |
200 if (stylus_ == 0) { | 194 if (stylus_ == 0) { |
201 abs_value_dirty_ = false; | 195 abs_value_dirty_ = false; |
202 return; | 196 return; |
203 } | 197 } |
204 | 198 |
205 if (!abs_value_dirty_) | 199 if (!abs_value_dirty_) |
206 return; | 200 return; |
207 | 201 |
208 UpdateCursor(); | 202 UpdateCursor(); |
209 | 203 |
210 dispatcher_->DispatchMouseMoveEvent(MouseMoveEventParams( | 204 dispatcher_->DispatchMouseMoveEvent(MouseMoveEventParams( |
211 input_device_.id, EF_NONE, cursor_->GetLocation(), | 205 input_device_.id, EF_NONE, cursor_->GetLocation(), |
212 PointerDetails(GetToolType(stylus_), | 206 PointerDetails(EventPointerType::POINTER_TYPE_PEN, |
213 /* radius_x */ 0.0f, /* radius_y */ 0.0f, pressure_, | 207 /* radius_x */ 0.0f, /* radius_y */ 0.0f, pressure_, |
214 tilt_x_, tilt_y_), | 208 tilt_x_, tilt_y_), |
215 TimeTicksFromInputEvent(input))); | 209 TimeTicksFromInputEvent(input))); |
216 | 210 |
217 abs_value_dirty_ = false; | 211 abs_value_dirty_ = false; |
218 } | 212 } |
219 | 213 |
220 } // namespace ui | 214 } // namespace ui |
OLD | NEW |