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 "ui/events/event.h" | 7 #include "ui/events/event.h" |
8 #include "ui/events/event_constants.h" | 8 #include "ui/events/event_constants.h" |
9 #include "ui/events/event_utils.h" | 9 #include "ui/events/event_utils.h" |
10 #include "ui/events/keycodes/dom4/keycode_converter.h" | 10 #include "ui/events/keycodes/dom4/keycode_converter.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 return EVDEV_MODIFIER_MIDDLE_MOUSE_BUTTON; | 39 return EVDEV_MODIFIER_MIDDLE_MOUSE_BUTTON; |
40 case EF_RIGHT_MOUSE_BUTTON: | 40 case EF_RIGHT_MOUSE_BUTTON: |
41 return EVDEV_MODIFIER_RIGHT_MOUSE_BUTTON; | 41 return EVDEV_MODIFIER_RIGHT_MOUSE_BUTTON; |
42 case EF_COMMAND_DOWN: | 42 case EF_COMMAND_DOWN: |
43 return EVDEV_MODIFIER_COMMAND; | 43 return EVDEV_MODIFIER_COMMAND; |
44 default: | 44 default: |
45 return EVDEV_MODIFIER_NONE; | 45 return EVDEV_MODIFIER_NONE; |
46 } | 46 } |
47 } | 47 } |
48 | 48 |
49 bool IsModifierLock(int evdev_modifier) { | |
50 return evdev_modifier == EVDEV_MODIFIER_CAPS_LOCK; | |
51 } | |
52 | |
53 } // namespace | 49 } // namespace |
54 | 50 |
55 KeyboardEvdev::KeyboardEvdev(EventModifiersEvdev* modifiers, | 51 KeyboardEvdev::KeyboardEvdev(EventModifiersEvdev* modifiers, |
56 KeyboardLayoutEngine* keyboard_layout_engine, | 52 KeyboardLayoutEngine* keyboard_layout_engine, |
57 const EventDispatchCallback& callback) | 53 const EventDispatchCallback& callback) |
58 : callback_(callback), | 54 : callback_(callback), |
59 modifiers_(modifiers), | 55 modifiers_(modifiers), |
60 keyboard_layout_engine_(keyboard_layout_engine), | 56 keyboard_layout_engine_(keyboard_layout_engine), |
61 repeat_enabled_(true), | 57 repeat_enabled_(true), |
62 repeat_key_(KEY_RESERVED) { | 58 repeat_key_(KEY_RESERVED) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 } | 111 } |
116 | 112 |
117 void KeyboardEvdev::UpdateModifier(int modifier_flag, bool down) { | 113 void KeyboardEvdev::UpdateModifier(int modifier_flag, bool down) { |
118 if (modifier_flag == EF_NONE) | 114 if (modifier_flag == EF_NONE) |
119 return; | 115 return; |
120 | 116 |
121 int modifier = EventFlagToEvdevModifier(modifier_flag); | 117 int modifier = EventFlagToEvdevModifier(modifier_flag); |
122 if (modifier == EVDEV_MODIFIER_NONE) | 118 if (modifier == EVDEV_MODIFIER_NONE) |
123 return; | 119 return; |
124 | 120 |
125 if (IsModifierLock(modifier)) | 121 // TODO post-X11: Revise remapping to not use EF_MOD3_DOWN. |
126 modifiers_->UpdateModifierLock(modifier, down); | 122 // Currently EF_MOD3_DOWN means that the CapsLock key is currently down, |
| 123 // and EF_CAPS_LOCK_DOWN means the caps lock state is enabled (and the |
| 124 // key may or may not be down, but usually isn't). There does need to |
| 125 // to be two different flags, since the physical CapsLock key is subject |
| 126 // to remapping, but the caps lock state (which can be triggered in a |
| 127 // variety of ways) is not. |
| 128 if (modifier == EVDEV_MODIFIER_CAPS_LOCK) |
| 129 modifiers_->UpdateModifier(EVDEV_MODIFIER_MOD3, down); |
127 else | 130 else |
128 modifiers_->UpdateModifier(modifier, down); | 131 modifiers_->UpdateModifier(modifier, down); |
129 } | 132 } |
130 | 133 |
131 void KeyboardEvdev::UpdateKeyRepeat(unsigned int key, bool down) { | 134 void KeyboardEvdev::UpdateKeyRepeat(unsigned int key, bool down) { |
132 if (!repeat_enabled_) | 135 if (!repeat_enabled_) |
133 StopKeyRepeat(); | 136 StopKeyRepeat(); |
134 else if (key != repeat_key_ && down) | 137 else if (key != repeat_key_ && down) |
135 StartKeyRepeat(key); | 138 StartKeyRepeat(key); |
136 else if (key == repeat_key_ && !down) | 139 else if (key == repeat_key_ && !down) |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 UpdateModifier(ModifierDomKeyToEventFlag(dom_key), down); | 192 UpdateModifier(ModifierDomKeyToEventFlag(dom_key), down); |
190 | 193 |
191 KeyEvent event(down ? ET_KEY_PRESSED : ET_KEY_RELEASED, key_code, dom_code, | 194 KeyEvent event(down ? ET_KEY_PRESSED : ET_KEY_RELEASED, key_code, dom_code, |
192 modifiers_->GetModifierFlags(), dom_key, character, timestamp); | 195 modifiers_->GetModifierFlags(), dom_key, character, timestamp); |
193 if (platform_keycode) | 196 if (platform_keycode) |
194 event.set_platform_keycode(platform_keycode); | 197 event.set_platform_keycode(platform_keycode); |
195 callback_.Run(&event); | 198 callback_.Run(&event); |
196 } | 199 } |
197 | 200 |
198 } // namespace ui | 201 } // namespace ui |
OLD | NEW |