Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(396)

Side by Side Diff: ui/events/ozone/evdev/keyboard_evdev.cc

Issue 1560293002: Rename KEY_ constants to avoid conflict with <linux/input.h> (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments (Wez) Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/dom_code.h"
12 #include "ui/events/keycodes/dom/keycode_converter.h" 13 #include "ui/events/keycodes/dom/keycode_converter.h"
13 #include "ui/events/ozone/evdev/event_modifiers_evdev.h" 14 #include "ui/events/ozone/evdev/event_modifiers_evdev.h"
14 #include "ui/events/ozone/evdev/keyboard_util_evdev.h" 15 #include "ui/events/ozone/evdev/keyboard_util_evdev.h"
15 #include "ui/events/ozone/layout/keyboard_layout_engine.h" 16 #include "ui/events/ozone/layout/keyboard_layout_engine.h"
16 #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" 17 #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h"
17 #include "ui/events/ozone/layout/layout_util.h" 18 #include "ui/events/ozone/layout/layout_util.h"
18 19
19 namespace ui { 20 namespace ui {
20 21
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, evdev, 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
30 namespace { 22 namespace {
31 23
32 const int kRepeatDelayMs = 500; 24 const int kRepeatDelayMs = 500;
33 const int kRepeatIntervalMs = 50; 25 const int kRepeatIntervalMs = 50;
34 26
35 int EventFlagToEvdevModifier(int flag) { 27 int EventFlagToEvdevModifier(int flag) {
36 switch (flag) { 28 switch (flag) {
37 case EF_CAPS_LOCK_DOWN: 29 case EF_CAPS_LOCK_DOWN:
38 return EVDEV_MODIFIER_CAPS_LOCK; 30 return EVDEV_MODIFIER_CAPS_LOCK;
39 case EF_SHIFT_DOWN: 31 case EF_SHIFT_DOWN:
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 146
155 void KeyboardEvdev::RefreshModifiers() { 147 void KeyboardEvdev::RefreshModifiers() {
156 // Release all keyboard modifiers. 148 // Release all keyboard modifiers.
157 modifiers_->ResetKeyboardModifiers(); 149 modifiers_->ResetKeyboardModifiers();
158 // Press modifiers for currently held keys. 150 // Press modifiers for currently held keys.
159 for (int key = 0; key < KEY_CNT; ++key) { 151 for (int key = 0; key < KEY_CNT; ++key) {
160 if (!key_state_.test(key)) 152 if (!key_state_.test(key))
161 continue; 153 continue;
162 DomCode dom_code = 154 DomCode dom_code =
163 KeycodeConverter::NativeKeycodeToDomCode(EvdevCodeToNativeCode(key)); 155 KeycodeConverter::NativeKeycodeToDomCode(EvdevCodeToNativeCode(key));
164 if (dom_code == DomCode::DOM_CODE_NONE) 156 if (dom_code == DomCode::NONE)
165 continue; 157 continue;
166 DomKey dom_key; 158 DomKey dom_key;
167 KeyboardCode keycode; 159 KeyboardCode keycode;
168 if (!keyboard_layout_engine_->Lookup(dom_code, EF_NONE, &dom_key, &keycode)) 160 if (!keyboard_layout_engine_->Lookup(dom_code, EF_NONE, &dom_key, &keycode))
169 continue; 161 continue;
170 int flag = ModifierDomKeyToEventFlag(dom_key); 162 int flag = ModifierDomKeyToEventFlag(dom_key);
171 if (flag == EF_NONE) 163 if (flag == EF_NONE)
172 continue; 164 continue;
173 UpdateModifier(flag, true); 165 UpdateModifier(flag, true);
174 } 166 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 ScheduleKeyRepeat(repeat_interval_); 220 ScheduleKeyRepeat(repeat_interval_);
229 } 221 }
230 222
231 void KeyboardEvdev::DispatchKey(unsigned int key, 223 void KeyboardEvdev::DispatchKey(unsigned int key,
232 bool down, 224 bool down,
233 bool repeat, 225 bool repeat,
234 base::TimeDelta timestamp, 226 base::TimeDelta timestamp,
235 int device_id) { 227 int device_id) {
236 DomCode dom_code = 228 DomCode dom_code =
237 KeycodeConverter::NativeKeycodeToDomCode(EvdevCodeToNativeCode(key)); 229 KeycodeConverter::NativeKeycodeToDomCode(EvdevCodeToNativeCode(key));
238 if (dom_code == DomCode::DOM_CODE_NONE) 230 if (dom_code == DomCode::NONE)
239 return; 231 return;
240 int flags = modifiers_->GetModifierFlags(); 232 int flags = modifiers_->GetModifierFlags();
241 DomKey dom_key; 233 DomKey dom_key;
242 KeyboardCode key_code; 234 KeyboardCode key_code;
243 if (!keyboard_layout_engine_->Lookup(dom_code, flags, &dom_key, &key_code)) 235 if (!keyboard_layout_engine_->Lookup(dom_code, flags, &dom_key, &key_code))
244 return; 236 return;
245 if (!repeat) { 237 if (!repeat) {
246 int flag = ModifierDomKeyToEventFlag(dom_key); 238 int flag = ModifierDomKeyToEventFlag(dom_key);
247 UpdateModifier(flag, down); 239 UpdateModifier(flag, down);
248 } 240 }
249 241
250 KeyEvent event(down ? ET_KEY_PRESSED : ET_KEY_RELEASED, key_code, dom_code, 242 KeyEvent event(down ? ET_KEY_PRESSED : ET_KEY_RELEASED, key_code, dom_code,
251 modifiers_->GetModifierFlags(), dom_key, timestamp); 243 modifiers_->GetModifierFlags(), dom_key, timestamp);
252 event.set_source_device_id(device_id); 244 event.set_source_device_id(device_id);
253 callback_.Run(&event); 245 callback_.Run(&event);
254 } 246 }
255 247
256 } // namespace ui 248 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698