| 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 |
| 49 } // namespace | 53 } // namespace |
| 50 | 54 |
| 51 KeyboardEvdev::KeyboardEvdev(EventModifiersEvdev* modifiers, | 55 KeyboardEvdev::KeyboardEvdev(EventModifiersEvdev* modifiers, |
| 52 KeyboardLayoutEngine* keyboard_layout_engine, | 56 KeyboardLayoutEngine* keyboard_layout_engine, |
| 53 const EventDispatchCallback& callback) | 57 const EventDispatchCallback& callback) |
| 54 : callback_(callback), | 58 : callback_(callback), |
| 55 modifiers_(modifiers), | 59 modifiers_(modifiers), |
| 56 keyboard_layout_engine_(keyboard_layout_engine), | 60 keyboard_layout_engine_(keyboard_layout_engine), |
| 57 repeat_enabled_(true), | 61 repeat_enabled_(true), |
| 58 repeat_key_(KEY_RESERVED) { | 62 repeat_key_(KEY_RESERVED) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 } | 115 } |
| 112 | 116 |
| 113 void KeyboardEvdev::UpdateModifier(int modifier_flag, bool down) { | 117 void KeyboardEvdev::UpdateModifier(int modifier_flag, bool down) { |
| 114 if (modifier_flag == EF_NONE) | 118 if (modifier_flag == EF_NONE) |
| 115 return; | 119 return; |
| 116 | 120 |
| 117 int modifier = EventFlagToEvdevModifier(modifier_flag); | 121 int modifier = EventFlagToEvdevModifier(modifier_flag); |
| 118 if (modifier == EVDEV_MODIFIER_NONE) | 122 if (modifier == EVDEV_MODIFIER_NONE) |
| 119 return; | 123 return; |
| 120 | 124 |
| 121 // TODO post-X11: Revise remapping to not use EF_MOD3_DOWN. | 125 if (IsModifierLock(modifier)) |
| 122 // Currently EF_MOD3_DOWN means that the CapsLock key is currently down, | 126 modifiers_->UpdateModifierLock(modifier, 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); | |
| 130 else | 127 else |
| 131 modifiers_->UpdateModifier(modifier, down); | 128 modifiers_->UpdateModifier(modifier, down); |
| 132 } | 129 } |
| 133 | 130 |
| 134 void KeyboardEvdev::UpdateKeyRepeat(unsigned int key, bool down) { | 131 void KeyboardEvdev::UpdateKeyRepeat(unsigned int key, bool down) { |
| 135 if (!repeat_enabled_) | 132 if (!repeat_enabled_) |
| 136 StopKeyRepeat(); | 133 StopKeyRepeat(); |
| 137 else if (key != repeat_key_ && down) | 134 else if (key != repeat_key_ && down) |
| 138 StartKeyRepeat(key); | 135 StartKeyRepeat(key); |
| 139 else if (key == repeat_key_ && !down) | 136 else if (key == repeat_key_ && !down) |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 UpdateModifier(ModifierDomKeyToEventFlag(dom_key), down); | 189 UpdateModifier(ModifierDomKeyToEventFlag(dom_key), down); |
| 193 | 190 |
| 194 KeyEvent event(down ? ET_KEY_PRESSED : ET_KEY_RELEASED, key_code, dom_code, | 191 KeyEvent event(down ? ET_KEY_PRESSED : ET_KEY_RELEASED, key_code, dom_code, |
| 195 modifiers_->GetModifierFlags(), dom_key, character, timestamp); | 192 modifiers_->GetModifierFlags(), dom_key, character, timestamp); |
| 196 if (platform_keycode) | 193 if (platform_keycode) |
| 197 event.set_platform_keycode(platform_keycode); | 194 event.set_platform_keycode(platform_keycode); |
| 198 callback_.Run(&event); | 195 callback_.Run(&event); |
| 199 } | 196 } |
| 200 | 197 |
| 201 } // namespace ui | 198 } // namespace ui |
| OLD | NEW |