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

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

Issue 323023002: aura: Supports text input on non UTF-8 environments. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Synced. Created 6 years, 6 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 | « no previous file | no next file » | 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 #define XK_3270 // for XK_3270_BackTab 7 #define XK_3270 // for XK_3270_BackTab
8 #include <X11/keysym.h> 8 #include <X11/keysym.h>
9 #include <X11/Xlib.h> 9 #include <X11/Xlib.h>
10 #include <X11/Xutil.h> 10 #include <X11/Xutil.h>
11 #include <X11/XF86keysym.h> 11 #include <X11/XF86keysym.h>
12 12
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "base/strings/sys_string_conversions.h"
16 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
17 #include "ui/events/keycodes/dom4/keycode_converter.h" 18 #include "ui/events/keycodes/dom4/keycode_converter.h"
18 19
19 namespace ui { 20 namespace ui {
20 21
21 // Get an ui::KeyboardCode from an X keyevent 22 // Get an ui::KeyboardCode from an X keyevent
22 KeyboardCode KeyboardCodeFromXKeyEvent(XEvent* xev) { 23 KeyboardCode KeyboardCodeFromXKeyEvent(XEvent* xev) {
23 // XLookupKeysym does not take into consideration the state of the lock/shift 24 // XLookupKeysym does not take into consideration the state of the lock/shift
24 // etc. keys. So it is necessary to use XLookupString instead. 25 // etc. keys. So it is necessary to use XLookupString instead.
25 KeySym keysym; 26 KeySym keysym;
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 const char* CodeFromXEvent(XEvent* xev) { 430 const char* CodeFromXEvent(XEvent* xev) {
430 return KeycodeConverter::GetInstance()->NativeKeycodeToCode( 431 return KeycodeConverter::GetInstance()->NativeKeycodeToCode(
431 xev->xkey.keycode); 432 xev->xkey.keycode);
432 } 433 }
433 434
434 uint16 GetCharacterFromXEvent(XEvent* xev) { 435 uint16 GetCharacterFromXEvent(XEvent* xev) {
435 char buf[6]; 436 char buf[6];
436 int bytes_written = XLookupString(&xev->xkey, buf, 6, NULL, NULL); 437 int bytes_written = XLookupString(&xev->xkey, buf, 6, NULL, NULL);
437 DCHECK_LE(bytes_written, 6); 438 DCHECK_LE(bytes_written, 6);
438 439
439 base::string16 result; 440 if (bytes_written <= 0)
440 return (bytes_written > 0 && base::UTF8ToUTF16(buf, bytes_written, &result) && 441 return 0;
441 result.length() == 1) ? result[0] : 0; 442 const base::string16& result = base::WideToUTF16(
443 base::SysNativeMBToWide(base::StringPiece(buf, bytes_written)));
444 return result.length() == 1 ? result[0] : 0;
442 } 445 }
443 446
444 unsigned int DefaultXKeysymFromHardwareKeycode(unsigned int hardware_code) { 447 unsigned int DefaultXKeysymFromHardwareKeycode(unsigned int hardware_code) {
445 // This function assumes that X11 is using evdev-based keycodes. 448 // This function assumes that X11 is using evdev-based keycodes.
446 static const unsigned int kHardwareKeycodeMap[] = { 449 static const unsigned int kHardwareKeycodeMap[] = {
447 // This table covers the core 105-key keyboard. 450 // This table covers the core 105-key keyboard.
448 0, // 0x00: 451 0, // 0x00:
449 0, // 0x01: 452 0, // 0x01:
450 0, // 0x02: 453 0, // 0x02:
451 0, // 0x03: 454 0, // 0x03:
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 case VKEY_KBD_BRIGHTNESS_UP: 870 case VKEY_KBD_BRIGHTNESS_UP:
868 return XF86XK_KbdBrightnessUp; 871 return XF86XK_KbdBrightnessUp;
869 872
870 default: 873 default:
871 LOG(WARNING) << "Unknown keycode:" << keycode; 874 LOG(WARNING) << "Unknown keycode:" << keycode;
872 return 0; 875 return 0;
873 } 876 }
874 } 877 }
875 878
876 } // namespace ui 879 } // namespace ui
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698