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

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

Issue 430463005: linux/cros: Supports XKeyEvent to Unicode conversion independent from user's locale. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed review comments. Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « ui/events/events.gyp ('k') | ui/events/x/keysym_to_unicode.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/x/keysym_to_unicode.h"
22 23
23 #define VKEY_UNSUPPORTED VKEY_UNKNOWN 24 #define VKEY_UNSUPPORTED VKEY_UNKNOWN
24 25
25 namespace ui { 26 namespace ui {
26 27
27 namespace { 28 namespace {
28 29
29 // MAP0 - MAP3: 30 // MAP0 - MAP3:
30 // These are the generated VKEY code maps for all possible Latin keyboard 31 // These are the generated VKEY code maps for all possible Latin keyboard
31 // layouts in Windows. And the maps are only for special letter keys excluding 32 // layouts in Windows. And the maps are only for special letter keys excluding
(...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 836
836 const char* CodeFromXEvent(const XEvent* xev) { 837 const char* CodeFromXEvent(const XEvent* xev) {
837 int keycode = (xev->type == GenericEvent) 838 int keycode = (xev->type == GenericEvent)
838 ? static_cast<XIDeviceEvent*>(xev->xcookie.data)->detail 839 ? static_cast<XIDeviceEvent*>(xev->xcookie.data)->detail
839 : xev->xkey.keycode; 840 : xev->xkey.keycode;
840 return KeycodeConverter::GetInstance()->NativeKeycodeToCode(keycode); 841 return KeycodeConverter::GetInstance()->NativeKeycodeToCode(keycode);
841 } 842 }
842 843
843 uint16 GetCharacterFromXEvent(const XEvent* xev) { 844 uint16 GetCharacterFromXEvent(const XEvent* xev) {
844 XEvent xkeyevent; 845 XEvent xkeyevent;
845 const XKeyEvent* xkey = NULL; 846 const XKeyEvent* xkey;
Wez 2014/08/08 22:56:25 nit: Style guide requires local variables be initi
Yuki 2014/08/11 05:58:52 Done.
846 char buf[6];
847 if (xev->type == GenericEvent) { 847 if (xev->type == GenericEvent) {
848 // Convert the XI2 key event into a core key event so that we can 848 // Convert the XI2 key event into a core key event so that we can
849 // continue to use XLookupString() until crbug.com/367732 is complete. 849 // continue to use XLookupString() until crbug.com/367732 is complete.
850 InitXKeyEventFromXIDeviceEvent(*xev, &xkeyevent); 850 InitXKeyEventFromXIDeviceEvent(*xev, &xkeyevent);
851 xkey = &xkeyevent.xkey; 851 xkey = &xkeyevent.xkey;
852 } else { 852 } else {
853 xkey = &xev->xkey; 853 xkey = &xev->xkey;
854 } 854 }
855 int bytes_written = 855 KeySym keysym = XK_VoidSymbol;
856 XLookupString(const_cast<XKeyEvent*>(xkey), buf, 6, NULL, NULL); 856 XLookupString(const_cast<XKeyEvent*>(xkey), NULL, 0, &keysym, NULL);
857 DCHECK_LE(bytes_written, 6); 857 return GetUnicodeCharacterFromXKeySym(keysym);
858
859 if (bytes_written <= 0)
860 return 0;
861 const base::string16& result = base::WideToUTF16(
862 base::SysNativeMBToWide(base::StringPiece(buf, bytes_written)));
863 return result.length() == 1 ? result[0] : 0;
864 } 858 }
865 859
866 KeyboardCode DefaultKeyboardCodeFromHardwareKeycode( 860 KeyboardCode DefaultKeyboardCodeFromHardwareKeycode(
867 unsigned int hardware_code) { 861 unsigned int hardware_code) {
868 // This function assumes that X11 is using evdev-based keycodes. 862 // This function assumes that X11 is using evdev-based keycodes.
869 static const KeyboardCode kHardwareKeycodeMap[] = { 863 static const KeyboardCode kHardwareKeycodeMap[] = {
870 // Please refer to below links for the table content: 864 // Please refer to below links for the table content:
871 // http://www.w3.org/TR/DOM-Level-3-Events-code/#keyboard-101 865 // http://www.w3.org/TR/DOM-Level-3-Events-code/#keyboard-101
872 // https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent.keyCode 866 // https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent.keyCode
873 // http://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-92 3143f3456c/translate.pdf 867 // 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
1348 // alone does not map to XK_less; XKeysymToKeycode() returns KEY_102ND 1342 // alone does not map to XK_less; XKeysymToKeycode() returns KEY_102ND
1349 // (the '<>' key between Shift and Z on 105-key keyboards) which does. 1343 // (the '<>' key between Shift and Z on 105-key keyboards) which does.
1350 // 1344 //
1351 // crbug.com/386066 and crbug.com/390263 are examples of problems 1345 // crbug.com/386066 and crbug.com/390263 are examples of problems
1352 // associated with this. 1346 // associated with this.
1353 // 1347 //
1354 return XKeysymToKeycode(display, XKeysymForWindowsKeyCode(key_code, false)); 1348 return XKeysymToKeycode(display, XKeysymForWindowsKeyCode(key_code, false));
1355 } 1349 }
1356 1350
1357 } // namespace ui 1351 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/events.gyp ('k') | ui/events/x/keysym_to_unicode.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698