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" |
(...skipping 16 matching lines...) Expand all Loading... |
27 #undef USB_KEYMAP | 27 #undef USB_KEYMAP |
28 #undef USB_KEYMAP_DECLARATION | 28 #undef USB_KEYMAP_DECLARATION |
29 | 29 |
30 namespace { | 30 namespace { |
31 | 31 |
32 const int kRepeatDelayMs = 500; | 32 const int kRepeatDelayMs = 500; |
33 const int kRepeatIntervalMs = 50; | 33 const int kRepeatIntervalMs = 50; |
34 | 34 |
35 int EventFlagToEvdevModifier(int flag) { | 35 int EventFlagToEvdevModifier(int flag) { |
36 switch (flag) { | 36 switch (flag) { |
37 case EF_CAPS_LOCK_DOWN: | |
38 return EVDEV_MODIFIER_CAPS_LOCK; | |
39 case EF_SHIFT_DOWN: | 37 case EF_SHIFT_DOWN: |
40 return EVDEV_MODIFIER_SHIFT; | 38 return EVDEV_MODIFIER_SHIFT; |
41 case EF_CONTROL_DOWN: | 39 case EF_CONTROL_DOWN: |
42 return EVDEV_MODIFIER_CONTROL; | 40 return EVDEV_MODIFIER_CONTROL; |
43 case EF_ALT_DOWN: | 41 case EF_ALT_DOWN: |
44 return EVDEV_MODIFIER_ALT; | 42 return EVDEV_MODIFIER_ALT; |
| 43 case EF_COMMAND_DOWN: |
| 44 return EVDEV_MODIFIER_COMMAND; |
45 case EF_ALTGR_DOWN: | 45 case EF_ALTGR_DOWN: |
46 return EVDEV_MODIFIER_ALTGR; | 46 return EVDEV_MODIFIER_ALTGR; |
47 case EF_MOD3_DOWN: | 47 case EF_MOD3_DOWN: |
48 return EVDEV_MODIFIER_MOD3; | 48 return EVDEV_MODIFIER_MOD3; |
| 49 case EF_CAPS_LOCK_ON: |
| 50 return EVDEV_MODIFIER_CAPS_LOCK; |
49 case EF_LEFT_MOUSE_BUTTON: | 51 case EF_LEFT_MOUSE_BUTTON: |
50 return EVDEV_MODIFIER_LEFT_MOUSE_BUTTON; | 52 return EVDEV_MODIFIER_LEFT_MOUSE_BUTTON; |
51 case EF_MIDDLE_MOUSE_BUTTON: | 53 case EF_MIDDLE_MOUSE_BUTTON: |
52 return EVDEV_MODIFIER_MIDDLE_MOUSE_BUTTON; | 54 return EVDEV_MODIFIER_MIDDLE_MOUSE_BUTTON; |
53 case EF_RIGHT_MOUSE_BUTTON: | 55 case EF_RIGHT_MOUSE_BUTTON: |
54 return EVDEV_MODIFIER_RIGHT_MOUSE_BUTTON; | 56 return EVDEV_MODIFIER_RIGHT_MOUSE_BUTTON; |
55 case EF_BACK_MOUSE_BUTTON: | 57 case EF_BACK_MOUSE_BUTTON: |
56 return EVDEV_MODIFIER_BACK_MOUSE_BUTTON; | 58 return EVDEV_MODIFIER_BACK_MOUSE_BUTTON; |
57 case EF_FORWARD_MOUSE_BUTTON: | 59 case EF_FORWARD_MOUSE_BUTTON: |
58 return EVDEV_MODIFIER_FORWARD_MOUSE_BUTTON; | 60 return EVDEV_MODIFIER_FORWARD_MOUSE_BUTTON; |
59 case EF_COMMAND_DOWN: | |
60 return EVDEV_MODIFIER_COMMAND; | |
61 default: | 61 default: |
62 return EVDEV_MODIFIER_NONE; | 62 return EVDEV_MODIFIER_NONE; |
63 } | 63 } |
64 } | 64 } |
65 | 65 |
66 } // namespace | 66 } // namespace |
67 | 67 |
68 KeyboardEvdev::KeyboardEvdev(EventModifiersEvdev* modifiers, | 68 KeyboardEvdev::KeyboardEvdev(EventModifiersEvdev* modifiers, |
69 KeyboardLayoutEngine* keyboard_layout_engine, | 69 KeyboardLayoutEngine* keyboard_layout_engine, |
70 const EventDispatchCallback& callback) | 70 const EventDispatchCallback& callback) |
(...skipping 24 matching lines...) Expand all Loading... |
95 key_state_.set(key, down); | 95 key_state_.set(key, down); |
96 UpdateKeyRepeat(key, down, suppress_auto_repeat, device_id); | 96 UpdateKeyRepeat(key, down, suppress_auto_repeat, device_id); |
97 DispatchKey(key, down, is_repeat, timestamp, device_id); | 97 DispatchKey(key, down, is_repeat, timestamp, device_id); |
98 } | 98 } |
99 | 99 |
100 void KeyboardEvdev::SetCapsLockEnabled(bool enabled) { | 100 void KeyboardEvdev::SetCapsLockEnabled(bool enabled) { |
101 modifiers_->SetModifierLock(EVDEV_MODIFIER_CAPS_LOCK, enabled); | 101 modifiers_->SetModifierLock(EVDEV_MODIFIER_CAPS_LOCK, enabled); |
102 } | 102 } |
103 | 103 |
104 bool KeyboardEvdev::IsCapsLockEnabled() { | 104 bool KeyboardEvdev::IsCapsLockEnabled() { |
105 return (modifiers_->GetModifierFlags() & EF_CAPS_LOCK_DOWN) != 0; | 105 return (modifiers_->GetModifierFlags() & EF_CAPS_LOCK_ON) != 0; |
106 } | 106 } |
107 | 107 |
108 bool KeyboardEvdev::IsAutoRepeatEnabled() { | 108 bool KeyboardEvdev::IsAutoRepeatEnabled() { |
109 return auto_repeat_enabled_; | 109 return auto_repeat_enabled_; |
110 } | 110 } |
111 | 111 |
112 void KeyboardEvdev::SetAutoRepeatEnabled(bool enabled) { | 112 void KeyboardEvdev::SetAutoRepeatEnabled(bool enabled) { |
113 auto_repeat_enabled_ = enabled; | 113 auto_repeat_enabled_ = enabled; |
114 } | 114 } |
115 | 115 |
(...skipping 18 matching lines...) Expand all Loading... |
134 void KeyboardEvdev::UpdateModifier(int modifier_flag, bool down) { | 134 void KeyboardEvdev::UpdateModifier(int modifier_flag, bool down) { |
135 if (modifier_flag == EF_NONE) | 135 if (modifier_flag == EF_NONE) |
136 return; | 136 return; |
137 | 137 |
138 int modifier = EventFlagToEvdevModifier(modifier_flag); | 138 int modifier = EventFlagToEvdevModifier(modifier_flag); |
139 if (modifier == EVDEV_MODIFIER_NONE) | 139 if (modifier == EVDEV_MODIFIER_NONE) |
140 return; | 140 return; |
141 | 141 |
142 // TODO post-X11: Revise remapping to not use EF_MOD3_DOWN. | 142 // TODO post-X11: Revise remapping to not use EF_MOD3_DOWN. |
143 // Currently EF_MOD3_DOWN means that the CapsLock key is currently down, | 143 // Currently EF_MOD3_DOWN means that the CapsLock key is currently down, |
144 // and EF_CAPS_LOCK_DOWN means the caps lock state is enabled (and the | 144 // and EF_CAPS_LOCK_ON means the caps lock state is enabled (and the |
145 // key may or may not be down, but usually isn't). There does need to | 145 // key may or may not be down, but usually isn't). There does need to |
146 // to be two different flags, since the physical CapsLock key is subject | 146 // to be two different flags, since the physical CapsLock key is subject |
147 // to remapping, but the caps lock state (which can be triggered in a | 147 // to remapping, but the caps lock state (which can be triggered in a |
148 // variety of ways) is not. | 148 // variety of ways) is not. |
149 if (modifier == EVDEV_MODIFIER_CAPS_LOCK) | 149 if (modifier == EVDEV_MODIFIER_CAPS_LOCK) |
150 modifiers_->UpdateModifier(EVDEV_MODIFIER_MOD3, down); | 150 modifiers_->UpdateModifier(EVDEV_MODIFIER_MOD3, down); |
151 else | 151 else |
152 modifiers_->UpdateModifier(modifier, down); | 152 modifiers_->UpdateModifier(modifier, down); |
153 } | 153 } |
154 | 154 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 UpdateModifier(flag, down); | 247 UpdateModifier(flag, down); |
248 } | 248 } |
249 | 249 |
250 KeyEvent event(down ? ET_KEY_PRESSED : ET_KEY_RELEASED, key_code, dom_code, | 250 KeyEvent event(down ? ET_KEY_PRESSED : ET_KEY_RELEASED, key_code, dom_code, |
251 modifiers_->GetModifierFlags(), dom_key, timestamp); | 251 modifiers_->GetModifierFlags(), dom_key, timestamp); |
252 event.set_source_device_id(device_id); | 252 event.set_source_device_id(device_id); |
253 callback_.Run(&event); | 253 callback_.Run(&event); |
254 } | 254 } |
255 | 255 |
256 } // namespace ui | 256 } // namespace ui |
OLD | NEW |