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/keyboard_evdev.h" | 5 #include "ui/events/ozone/evdev/keyboard_evdev.h" |
6 | 6 |
7 #include "base/single_thread_task_runner.h" | 7 #include "base/single_thread_task_runner.h" |
8 #include "base/thread_task_runner_handle.h" | 8 #include "base/thread_task_runner_handle.h" |
9 #include "ui/events/event.h" | 9 #include "ui/events/event.h" |
10 #include "ui/events/event_constants.h" | 10 #include "ui/events/event_constants.h" |
11 #include "ui/events/event_utils.h" | 11 #include "ui/events/event_utils.h" |
12 #include "ui/events/keycodes/dom/keycode_converter.h" | 12 #include "ui/events/keycodes/dom/keycode_converter.h" |
13 #include "ui/events/ozone/evdev/event_modifiers_evdev.h" | 13 #include "ui/events/ozone/evdev/event_modifiers_evdev.h" |
14 #include "ui/events/ozone/evdev/keyboard_util_evdev.h" | 14 #include "ui/events/ozone/evdev/keyboard_util_evdev.h" |
15 #include "ui/events/ozone/layout/keyboard_layout_engine.h" | 15 #include "ui/events/ozone/layout/keyboard_layout_engine.h" |
16 #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" | 16 #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" |
17 #include "ui/events/ozone/layout/layout_util.h" | 17 #include "ui/events/ozone/layout/layout_util.h" |
18 | 18 |
19 namespace ui { | 19 namespace ui { |
20 | 20 |
21 // We can't include ui/events/keycodes/dom/dom_code.h here because of | |
22 // conflicts with preprocessor macros in <linux/input.h>, so we use the | |
23 // same underlying data with an additional prefix. | |
24 #define USB_KEYMAP(usb, xkb, win, mac, code, id) DOM_CODE_ ## id = usb | |
25 #define USB_KEYMAP_DECLARATION enum class DomCode | |
26 #include "ui/events/keycodes/dom/keycode_converter_data.inc" | |
27 #undef USB_KEYMAP | |
28 #undef USB_KEYMAP_DECLARATION | |
29 | |
21 namespace { | 30 namespace { |
22 | 31 |
23 const int kRepeatDelayMs = 500; | 32 const int kRepeatDelayMs = 500; |
24 const int kRepeatIntervalMs = 50; | 33 const int kRepeatIntervalMs = 50; |
25 | 34 |
26 int EventFlagToEvdevModifier(int flag) { | 35 int EventFlagToEvdevModifier(int flag) { |
27 switch (flag) { | 36 switch (flag) { |
28 case EF_CAPS_LOCK_DOWN: | 37 case EF_CAPS_LOCK_DOWN: |
29 return EVDEV_MODIFIER_CAPS_LOCK; | 38 return EVDEV_MODIFIER_CAPS_LOCK; |
30 case EF_SHIFT_DOWN: | 39 case EF_SHIFT_DOWN: |
31 return EVDEV_MODIFIER_SHIFT; | 40 return EVDEV_MODIFIER_SHIFT; |
32 case EF_CONTROL_DOWN: | 41 case EF_CONTROL_DOWN: |
33 return EVDEV_MODIFIER_CONTROL; | 42 return EVDEV_MODIFIER_CONTROL; |
34 case EF_ALT_DOWN: | 43 case EF_ALT_DOWN: |
35 return EVDEV_MODIFIER_ALT; | 44 return EVDEV_MODIFIER_ALT; |
36 case EF_ALTGR_DOWN: | 45 case EF_ALTGR_DOWN: |
37 return EVDEV_MODIFIER_ALTGR; | 46 return EVDEV_MODIFIER_ALTGR; |
47 case EF_MOD3_DOWN: | |
48 return EVDEV_MODIFIER_MOD3; | |
38 case EF_LEFT_MOUSE_BUTTON: | 49 case EF_LEFT_MOUSE_BUTTON: |
39 return EVDEV_MODIFIER_LEFT_MOUSE_BUTTON; | 50 return EVDEV_MODIFIER_LEFT_MOUSE_BUTTON; |
40 case EF_MIDDLE_MOUSE_BUTTON: | 51 case EF_MIDDLE_MOUSE_BUTTON: |
41 return EVDEV_MODIFIER_MIDDLE_MOUSE_BUTTON; | 52 return EVDEV_MODIFIER_MIDDLE_MOUSE_BUTTON; |
42 case EF_RIGHT_MOUSE_BUTTON: | 53 case EF_RIGHT_MOUSE_BUTTON: |
43 return EVDEV_MODIFIER_RIGHT_MOUSE_BUTTON; | 54 return EVDEV_MODIFIER_RIGHT_MOUSE_BUTTON; |
44 case EF_BACK_MOUSE_BUTTON: | 55 case EF_BACK_MOUSE_BUTTON: |
45 return EVDEV_MODIFIER_BACK_MOUSE_BUTTON; | 56 return EVDEV_MODIFIER_BACK_MOUSE_BUTTON; |
46 case EF_FORWARD_MOUSE_BUTTON: | 57 case EF_FORWARD_MOUSE_BUTTON: |
47 return EVDEV_MODIFIER_FORWARD_MOUSE_BUTTON; | 58 return EVDEV_MODIFIER_FORWARD_MOUSE_BUTTON; |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
194 ScheduleKeyRepeat(repeat_interval_); | 205 ScheduleKeyRepeat(repeat_interval_); |
195 } | 206 } |
196 | 207 |
197 void KeyboardEvdev::DispatchKey(unsigned int key, | 208 void KeyboardEvdev::DispatchKey(unsigned int key, |
198 bool down, | 209 bool down, |
199 bool repeat, | 210 bool repeat, |
200 base::TimeDelta timestamp, | 211 base::TimeDelta timestamp, |
201 int device_id) { | 212 int device_id) { |
202 DomCode dom_code = | 213 DomCode dom_code = |
203 KeycodeConverter::NativeKeycodeToDomCode(EvdevCodeToNativeCode(key)); | 214 KeycodeConverter::NativeKeycodeToDomCode(EvdevCodeToNativeCode(key)); |
204 // DomCode constants are not included here because of conflicts with | 215 if (dom_code == DomCode::DOM_CODE_NONE) |
205 // evdev preprocessor macros. | |
206 if (!static_cast<int>(dom_code)) | |
207 return; | 216 return; |
208 int flags = modifiers_->GetModifierFlags(); | 217 int flags = modifiers_->GetModifierFlags(); |
209 DomKey dom_key; | 218 DomKey dom_key; |
210 KeyboardCode key_code; | 219 KeyboardCode key_code; |
211 uint16 character; | 220 uint16 character; |
212 uint32 platform_keycode = 0; | 221 uint32 platform_keycode = 0; |
213 if (!keyboard_layout_engine_->Lookup(dom_code, flags, &dom_key, &character, | 222 if (!keyboard_layout_engine_->Lookup(dom_code, flags, &dom_key, &character, |
214 &key_code, &platform_keycode)) { | 223 &key_code, &platform_keycode)) { |
215 return; | 224 return; |
216 } | 225 } |
217 if (!repeat) | 226 if (!repeat) { |
218 UpdateModifier(ModifierDomKeyToEventFlag(dom_key), down); | 227 int flag = ModifierDomKeyToEventFlag(dom_key); |
228 UpdateModifier(flag, down); | |
229 // X11 XKB, using the configuration as modified for ChromeOS, always sets | |
230 // EF_MOD3_DOWN for the physical CapsLock key, even if the layout maps | |
231 // it to something else, so we imitate this to make certain layouts (e.g. | |
232 // German Neo2) work. crbug.com/495277 | |
233 if (dom_code == DomCode::DOM_CODE_CAPS_LOCK) | |
234 UpdateModifier(EF_MOD3_DOWN, down); | |
spang
2015/06/08 22:43:09
Can you now remove the other hack for MOD3 in Upda
kpschoedel
2015/06/09 13:28:50
No, it's still required (in fact, the Neo layout i
| |
235 } | |
219 | 236 |
220 KeyEvent event(down ? ET_KEY_PRESSED : ET_KEY_RELEASED, key_code, dom_code, | 237 KeyEvent event(down ? ET_KEY_PRESSED : ET_KEY_RELEASED, key_code, dom_code, |
221 modifiers_->GetModifierFlags(), dom_key, character, timestamp); | 238 modifiers_->GetModifierFlags(), dom_key, character, timestamp); |
222 event.set_source_device_id(device_id); | 239 event.set_source_device_id(device_id); |
223 if (platform_keycode) | 240 if (platform_keycode) |
224 event.set_platform_keycode(platform_keycode); | 241 event.set_platform_keycode(platform_keycode); |
225 callback_.Run(&event); | 242 callback_.Run(&event); |
226 } | 243 } |
227 | |
228 } // namespace ui | 244 } // namespace ui |
OLD | NEW |