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/event_converter_evdev_impl.h" | 5 #include "ui/events/ozone/evdev/event_converter_evdev_impl.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 "ui/events/event.h" | 10 #include "ui/events/event.h" |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 } | 102 } |
103 } | 103 } |
104 | 104 |
105 void EventConverterEvdevImpl::AllowAllKeys() { | 105 void EventConverterEvdevImpl::AllowAllKeys() { |
106 DCHECK(HasKeyboard()); | 106 DCHECK(HasKeyboard()); |
107 blocked_keys_.reset(); | 107 blocked_keys_.reset(); |
108 } | 108 } |
109 | 109 |
110 void EventConverterEvdevImpl::OnStopped() { | 110 void EventConverterEvdevImpl::OnStopped() { |
111 ReleaseKeys(); | 111 ReleaseKeys(); |
| 112 ReleaseMouseButtons(); |
112 } | 113 } |
113 | 114 |
114 void EventConverterEvdevImpl::ProcessEvents(const input_event* inputs, | 115 void EventConverterEvdevImpl::ProcessEvents(const input_event* inputs, |
115 int count) { | 116 int count) { |
116 for (int i = 0; i < count; ++i) { | 117 for (int i = 0; i < count; ++i) { |
117 const input_event& input = inputs[i]; | 118 const input_event& input = inputs[i]; |
118 switch (input.type) { | 119 switch (input.type) { |
119 case EV_KEY: | 120 case EV_KEY: |
120 ConvertKeyEvent(input); | 121 ConvertKeyEvent(input); |
121 break; | 122 break; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 return; | 169 return; |
169 | 170 |
170 if (down == key_state_.test(key)) | 171 if (down == key_state_.test(key)) |
171 return; | 172 return; |
172 | 173 |
173 // Apply key filter (releases for previously pressed keys are excepted). | 174 // Apply key filter (releases for previously pressed keys are excepted). |
174 if (down && blocked_keys_.test(key)) | 175 if (down && blocked_keys_.test(key)) |
175 return; | 176 return; |
176 | 177 |
177 // State transition: !(down) -> (down) | 178 // State transition: !(down) -> (down) |
178 if (down) | 179 key_state_.set(key, down); |
179 key_state_.set(key); | |
180 else | |
181 key_state_.reset(key); | |
182 | 180 |
183 dispatcher_->DispatchKeyEvent(KeyEventParams(id_, key, down, timestamp)); | 181 dispatcher_->DispatchKeyEvent(KeyEventParams(id_, key, down, timestamp)); |
184 } | 182 } |
185 | 183 |
186 void EventConverterEvdevImpl::ReleaseKeys() { | 184 void EventConverterEvdevImpl::ReleaseKeys() { |
187 base::TimeDelta timestamp = ui::EventTimeForNow(); | 185 base::TimeDelta timestamp = ui::EventTimeForNow(); |
188 for (int key = 0; key < KEY_CNT; ++key) | 186 for (int key = 0; key < KEY_CNT; ++key) |
189 OnKeyChange(key, false /* down */, timestamp); | 187 OnKeyChange(key, false /* down */, timestamp); |
190 } | 188 } |
191 | 189 |
| 190 void EventConverterEvdevImpl::ReleaseMouseButtons() { |
| 191 base::TimeDelta timestamp = ui::EventTimeForNow(); |
| 192 for (int code = BTN_MOUSE; code < BTN_JOYSTICK; ++code) |
| 193 OnButtonChange(code, false /* down */, timestamp); |
| 194 } |
| 195 |
192 void EventConverterEvdevImpl::OnLostSync() { | 196 void EventConverterEvdevImpl::OnLostSync() { |
193 LOG(WARNING) << "kernel dropped input events"; | 197 LOG(WARNING) << "kernel dropped input events"; |
194 | 198 |
195 // We may have missed key releases. Release everything. | 199 // We may have missed key releases. Release everything. |
196 // TODO(spang): Use EVIOCGKEY to avoid releasing keys that are still held. | 200 // TODO(spang): Use EVIOCGKEY to avoid releasing keys that are still held. |
197 ReleaseKeys(); | 201 ReleaseKeys(); |
| 202 ReleaseMouseButtons(); |
198 } | 203 } |
199 | 204 |
200 void EventConverterEvdevImpl::DispatchMouseButton(const input_event& input) { | 205 void EventConverterEvdevImpl::DispatchMouseButton(const input_event& input) { |
201 if (!cursor_) | 206 if (!cursor_) |
202 return; | 207 return; |
203 | 208 |
204 dispatcher_->DispatchMouseButtonEvent(MouseButtonEventParams( | 209 OnButtonChange(input.code, input.value, TimeDeltaFromInputEvent(input)); |
205 id_, cursor_->GetLocation(), input.code, input.value, | 210 } |
206 /* allow_remap */ true, TimeDeltaFromInputEvent(input))); | 211 |
| 212 void EventConverterEvdevImpl::OnButtonChange(int code, |
| 213 bool down, |
| 214 const base::TimeDelta& timestamp) { |
| 215 if (code == BTN_SIDE) |
| 216 code = BTN_BACK; |
| 217 else if (code == BTN_EXTRA) |
| 218 code = BTN_FORWARD; |
| 219 |
| 220 int button_offset = code - BTN_MOUSE; |
| 221 if (mouse_button_state_.test(button_offset) == down) |
| 222 return; |
| 223 |
| 224 mouse_button_state_.set(button_offset, down); |
| 225 |
| 226 dispatcher_->DispatchMouseButtonEvent( |
| 227 MouseButtonEventParams(id_, cursor_->GetLocation(), code, down, |
| 228 /* allow_remap */ true, timestamp)); |
207 } | 229 } |
208 | 230 |
209 void EventConverterEvdevImpl::FlushEvents(const input_event& input) { | 231 void EventConverterEvdevImpl::FlushEvents(const input_event& input) { |
210 if (!cursor_ || (x_offset_ == 0 && y_offset_ == 0)) | 232 if (!cursor_ || (x_offset_ == 0 && y_offset_ == 0)) |
211 return; | 233 return; |
212 | 234 |
213 cursor_->MoveCursor(gfx::Vector2dF(x_offset_, y_offset_)); | 235 cursor_->MoveCursor(gfx::Vector2dF(x_offset_, y_offset_)); |
214 | 236 |
215 dispatcher_->DispatchMouseMoveEvent(MouseMoveEventParams( | 237 dispatcher_->DispatchMouseMoveEvent(MouseMoveEventParams( |
216 id_, cursor_->GetLocation(), TimeDeltaFromInputEvent(input))); | 238 id_, cursor_->GetLocation(), TimeDeltaFromInputEvent(input))); |
217 | 239 |
218 x_offset_ = 0; | 240 x_offset_ = 0; |
219 y_offset_ = 0; | 241 y_offset_ = 0; |
220 } | 242 } |
221 | 243 |
222 } // namespace ui | 244 } // namespace ui |
OLD | NEW |