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 | 9 |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "ui/events/event.h" | 11 #include "ui/events/event.h" |
12 | 12 |
13 namespace ui { | 13 namespace ui { |
14 | 14 |
15 TabletEventConverterEvdev::TabletEventConverterEvdev( | 15 TabletEventConverterEvdev::TabletEventConverterEvdev( |
16 int fd, | 16 int fd, |
17 base::FilePath path, | 17 base::FilePath path, |
18 int id, | 18 int id, |
19 InputDeviceType type, | 19 InputDeviceType type, |
20 EventModifiersEvdev* modifiers, | |
21 CursorDelegateEvdev* cursor, | 20 CursorDelegateEvdev* cursor, |
22 const EventDeviceInfo& info, | 21 const EventDeviceInfo& info, |
23 const EventDispatchCallback& callback) | 22 const MouseMoveEventDispatchCallback& mouse_move_callback, |
| 23 const MouseButtonEventDispatchCallback& mouse_button_callback) |
24 : EventConverterEvdev(fd, path, id, type), | 24 : EventConverterEvdev(fd, path, id, type), |
25 cursor_(cursor), | 25 cursor_(cursor), |
26 modifiers_(modifiers), | 26 mouse_move_callback_(mouse_move_callback), |
27 callback_(callback), | 27 mouse_button_callback_(mouse_button_callback), |
28 stylus_(0), | 28 stylus_(0), |
29 abs_value_dirty_(false) { | 29 abs_value_dirty_(false) { |
30 x_abs_min_ = info.GetAbsMinimum(ABS_X); | 30 x_abs_min_ = info.GetAbsMinimum(ABS_X); |
31 x_abs_range_ = info.GetAbsMaximum(ABS_X) - x_abs_min_ + 1; | 31 x_abs_range_ = info.GetAbsMaximum(ABS_X) - x_abs_min_ + 1; |
32 y_abs_min_ = info.GetAbsMinimum(ABS_Y); | 32 y_abs_min_ = info.GetAbsMinimum(ABS_Y); |
33 y_abs_range_ = info.GetAbsMaximum(ABS_Y) - y_abs_min_ + 1; | 33 y_abs_range_ = info.GetAbsMaximum(ABS_Y) - y_abs_min_ + 1; |
34 } | 34 } |
35 | 35 |
36 TabletEventConverterEvdev::~TabletEventConverterEvdev() { | 36 TabletEventConverterEvdev::~TabletEventConverterEvdev() { |
37 Stop(); | 37 Stop(); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 x += display_bounds.x(); | 120 x += display_bounds.x(); |
121 y += display_bounds.y(); | 121 y += display_bounds.y(); |
122 | 122 |
123 cursor_->MoveCursorTo(gfx::PointF(x, y)); | 123 cursor_->MoveCursorTo(gfx::PointF(x, y)); |
124 } | 124 } |
125 | 125 |
126 void TabletEventConverterEvdev::DispatchMouseButton(const input_event& input) { | 126 void TabletEventConverterEvdev::DispatchMouseButton(const input_event& input) { |
127 if (!cursor_) | 127 if (!cursor_) |
128 return; | 128 return; |
129 | 129 |
130 unsigned int modifier; | 130 unsigned int button; |
131 // These are the same as X11 behaviour | 131 // These are the same as X11 behaviour |
132 if (input.code == BTN_TOUCH) | 132 if (input.code == BTN_TOUCH) |
133 modifier = EVDEV_MODIFIER_LEFT_MOUSE_BUTTON; | 133 button = BTN_LEFT; |
134 else if (input.code == BTN_STYLUS2) | 134 else if (input.code == BTN_STYLUS2) |
135 modifier = EVDEV_MODIFIER_RIGHT_MOUSE_BUTTON; | 135 button = BTN_RIGHT; |
136 else if (input.code == BTN_STYLUS) | 136 else if (input.code == BTN_STYLUS) |
137 modifier = EVDEV_MODIFIER_MIDDLE_MOUSE_BUTTON; | 137 button = BTN_MIDDLE; |
138 else | 138 else |
139 return; | 139 return; |
140 | 140 |
141 if (abs_value_dirty_) { | 141 if (abs_value_dirty_) { |
142 UpdateCursor(); | 142 UpdateCursor(); |
143 abs_value_dirty_ = false; | 143 abs_value_dirty_ = false; |
144 } | 144 } |
145 | 145 |
146 int flag = modifiers_->GetEventFlagFromModifier(modifier); | 146 bool down = input.value; |
147 modifiers_->UpdateModifier(modifier, input.value); | 147 |
148 callback_.Run(make_scoped_ptr( | 148 mouse_button_callback_.Run(MouseButtonEventParams( |
149 new MouseEvent(input.value ? ET_MOUSE_PRESSED : ET_MOUSE_RELEASED, | 149 id_, cursor_->GetLocation(), button, down, false /* allow_remap */)); |
150 cursor_->GetLocation(), cursor_->GetLocation(), | |
151 modifiers_->GetModifierFlags() | flag, flag))); | |
152 } | 150 } |
153 | 151 |
154 void TabletEventConverterEvdev::FlushEvents() { | 152 void TabletEventConverterEvdev::FlushEvents() { |
155 if (!cursor_) | 153 if (!cursor_) |
156 return; | 154 return; |
157 | 155 |
158 // Prevent propagation of invalid data on stylus lift off | 156 // Prevent propagation of invalid data on stylus lift off |
159 if (stylus_ == 0) { | 157 if (stylus_ == 0) { |
160 abs_value_dirty_ = false; | 158 abs_value_dirty_ = false; |
161 return; | 159 return; |
162 } | 160 } |
163 | 161 |
164 if (!abs_value_dirty_) | 162 if (!abs_value_dirty_) |
165 return; | 163 return; |
166 | 164 |
167 UpdateCursor(); | 165 UpdateCursor(); |
168 | 166 |
169 callback_.Run(make_scoped_ptr( | 167 mouse_move_callback_.Run(MouseMoveEventParams(id_, cursor_->GetLocation())); |
170 new MouseEvent(ui::ET_MOUSE_MOVED, cursor_->GetLocation(), | |
171 cursor_->GetLocation(), modifiers_->GetModifierFlags(), | |
172 /* changed_button_flags */ 0))); | |
173 | 168 |
174 abs_value_dirty_ = false; | 169 abs_value_dirty_ = false; |
175 } | 170 } |
176 | 171 |
177 } // namespace ui | 172 } // namespace ui |
OLD | NEW |