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

Side by Side Diff: ui/events/keycodes/keyboard_code_conversion_x.cc

Issue 954943003: [KeyboardEvent] Use DOM |code| rather than Windows-based key code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added missing VKEY in windows for brightness and power Created 5 years, 10 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/keycodes/keyboard_code_conversion_x.h" 5 #include "ui/events/keycodes/keyboard_code_conversion_x.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #define XK_3270 // for XK_3270_BackTab 9 #define XK_3270 // for XK_3270_BackTab
10 #include <X11/XF86keysym.h> 10 #include <X11/XF86keysym.h>
11 #include <X11/Xlib.h> 11 #include <X11/Xlib.h>
12 #include <X11/Xutil.h> 12 #include <X11/Xutil.h>
13 #include <X11/extensions/XInput2.h> 13 #include <X11/extensions/XInput2.h>
14 #include <X11/keysym.h> 14 #include <X11/keysym.h>
15 15
16 #include "base/basictypes.h" 16 #include "base/basictypes.h"
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
19 #include "base/strings/sys_string_conversions.h" 19 #include "base/strings/sys_string_conversions.h"
20 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
21 #include "ui/events/keycodes/dom4/keycode_converter.h" 21 #include "ui/events/keycodes/dom4/keycode_converter.h"
22 #include "ui/events/keycodes/keyboard_code_conversion_xkb.h"
22 #include "ui/events/x/keysym_to_unicode.h" 23 #include "ui/events/x/keysym_to_unicode.h"
23 24
24 #define VKEY_UNSUPPORTED VKEY_UNKNOWN 25 #define VKEY_UNSUPPORTED VKEY_UNKNOWN
25 26
26 namespace ui { 27 namespace ui {
27 28
28 namespace { 29 namespace {
29 30
30 // MAP0 - MAP3: 31 // MAP0 - MAP3:
31 // These are the generated VKEY code maps for all possible Latin keyboard 32 // These are the generated VKEY code maps for all possible Latin keyboard
(...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 return VKEY_UNKNOWN; 877 return VKEY_UNKNOWN;
877 } 878 }
878 879
879 DomCode CodeFromXEvent(const XEvent* xev) { 880 DomCode CodeFromXEvent(const XEvent* xev) {
880 int keycode = (xev->type == GenericEvent) 881 int keycode = (xev->type == GenericEvent)
881 ? static_cast<XIDeviceEvent*>(xev->xcookie.data)->detail 882 ? static_cast<XIDeviceEvent*>(xev->xcookie.data)->detail
882 : xev->xkey.keycode; 883 : xev->xkey.keycode;
883 return ui::KeycodeConverter::NativeKeycodeToDomCode(keycode); 884 return ui::KeycodeConverter::NativeKeycodeToDomCode(keycode);
884 } 885 }
885 886
886 uint16 GetCharacterFromXEvent(const XEvent* xev) { 887 void GetMeaningFromXEvent(const XEvent* xev, DomKey* key, base::char16* ch) {
887 XEvent xkeyevent = {0}; 888 XEvent xkeyevent = {0};
888 const XKeyEvent* xkey = NULL; 889 const XKeyEvent* xkey = NULL;
889 if (xev->type == GenericEvent) { 890 if (xev->type == GenericEvent) {
890 // Convert the XI2 key event into a core key event so that we can 891 // Convert the XI2 key event into a core key event so that we can
891 // continue to use XLookupString() until crbug.com/367732 is complete. 892 // continue to use XLookupString() until crbug.com/367732 is complete.
892 InitXKeyEventFromXIDeviceEvent(*xev, &xkeyevent); 893 InitXKeyEventFromXIDeviceEvent(*xev, &xkeyevent);
893 xkey = &xkeyevent.xkey; 894 xkey = &xkeyevent.xkey;
894 } else { 895 } else {
895 xkey = &xev->xkey; 896 xkey = &xev->xkey;
896 } 897 }
897 KeySym keysym = XK_VoidSymbol; 898 KeySym keysym = XK_VoidSymbol;
898 XLookupString(const_cast<XKeyEvent*>(xkey), NULL, 0, &keysym, NULL); 899 XLookupString(const_cast<XKeyEvent*>(xkey), NULL, 0, &keysym, NULL);
899 return GetUnicodeCharacterFromXKeySym(keysym); 900 *ch = GetUnicodeCharacterFromXKeySym(keysym);
901 *key = XkbKeySymToDomKey(keysym, *ch);
902 }
903
904 uint16 GetCharacterFromXEvent(const XEvent* xev) {
905 base::char16 ch;
906 DomKey key;
907 GetMeaningFromXEvent(xev, &key, &ch);
908 return ch;
900 } 909 }
901 910
902 KeyboardCode DefaultKeyboardCodeFromHardwareKeycode( 911 KeyboardCode DefaultKeyboardCodeFromHardwareKeycode(
903 unsigned int hardware_code) { 912 unsigned int hardware_code) {
904 // This function assumes that X11 is using evdev-based keycodes. 913 // This function assumes that X11 is using evdev-based keycodes.
905 static const KeyboardCode kHardwareKeycodeMap[] = { 914 static const KeyboardCode kHardwareKeycodeMap[] = {
906 // Please refer to below links for the table content: 915 // Please refer to below links for the table content:
907 // http://www.w3.org/TR/DOM-Level-3-Events-code/#keyboard-101 916 // http://www.w3.org/TR/DOM-Level-3-Events-code/#keyboard-101
908 // https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent.keyCode 917 // https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent.keyCode
909 // http://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-92 3143f3456c/translate.pdf 918 // http://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-92 3143f3456c/translate.pdf
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
1384 // alone does not map to XK_less; XKeysymToKeycode() returns KEY_102ND 1393 // alone does not map to XK_less; XKeysymToKeycode() returns KEY_102ND
1385 // (the '<>' key between Shift and Z on 105-key keyboards) which does. 1394 // (the '<>' key between Shift and Z on 105-key keyboards) which does.
1386 // 1395 //
1387 // crbug.com/386066 and crbug.com/390263 are examples of problems 1396 // crbug.com/386066 and crbug.com/390263 are examples of problems
1388 // associated with this. 1397 // associated with this.
1389 // 1398 //
1390 return XKeysymToKeycode(display, XKeysymForWindowsKeyCode(key_code, false)); 1399 return XKeysymToKeycode(display, XKeysymForWindowsKeyCode(key_code, false));
1391 } 1400 }
1392 1401
1393 } // namespace ui 1402 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/keycodes/keyboard_code_conversion_x.h ('k') | ui/events/keycodes/keyboard_code_conversion_xkb.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698