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

Side by Side Diff: chrome/test/chromedriver/keycode_text_conversion_win.cc

Issue 12314090: Add utf_string_conversions to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "chrome/test/chromedriver/keycode_text_conversion.h" 5 #include "chrome/test/chromedriver/keycode_text_conversion.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include <cctype> 9 #include <cctype>
10 10
(...skipping 11 matching lines...) Expand all
22 if (modifiers & kAltKeyModifierMask) 22 if (modifiers & kAltKeyModifierMask)
23 keyboard_state[VK_MENU] |= 0x80; 23 keyboard_state[VK_MENU] |= 0x80;
24 wchar_t chars[5]; 24 wchar_t chars[5];
25 int code = ::ToUnicode(key_code, scan_code, keyboard_state, chars, 4, 0); 25 int code = ::ToUnicode(key_code, scan_code, keyboard_state, chars, 4, 0);
26 // |ToUnicode| converts some non-text key codes like F1 to various ASCII 26 // |ToUnicode| converts some non-text key codes like F1 to various ASCII
27 // control chars. Filter those out. 27 // control chars. Filter those out.
28 if (code <= 0 || (code == 1 && std::iscntrl(chars[0]))) { 28 if (code <= 0 || (code == 1 && std::iscntrl(chars[0]))) {
29 return ""; 29 return "";
30 } else { 30 } else {
31 std::string text; 31 std::string text;
32 WideToUTF8(chars, code, &text); 32 base::WideToUTF8(chars, code, &text);
33 return text; 33 return text;
34 } 34 }
35 } 35 }
36 36
37 bool ConvertCharToKeyCode( 37 bool ConvertCharToKeyCode(
38 char16 key, ui::KeyboardCode* key_code, int *necessary_modifiers) { 38 char16 key, ui::KeyboardCode* key_code, int *necessary_modifiers) {
39 short vkey_and_modifiers = ::VkKeyScanW(key); 39 short vkey_and_modifiers = ::VkKeyScanW(key);
40 bool translated = vkey_and_modifiers != -1 && 40 bool translated = vkey_and_modifiers != -1 &&
41 LOBYTE(vkey_and_modifiers) != -1 && 41 LOBYTE(vkey_and_modifiers) != -1 &&
42 HIBYTE(vkey_and_modifiers) != -1; 42 HIBYTE(vkey_and_modifiers) != -1;
43 if (translated) { 43 if (translated) {
44 *key_code = static_cast<ui::KeyboardCode>(LOBYTE(vkey_and_modifiers)); 44 *key_code = static_cast<ui::KeyboardCode>(LOBYTE(vkey_and_modifiers));
45 int win_modifiers = HIBYTE(vkey_and_modifiers); 45 int win_modifiers = HIBYTE(vkey_and_modifiers);
46 int modifiers = 0; 46 int modifiers = 0;
47 if (win_modifiers & 0x01) 47 if (win_modifiers & 0x01)
48 modifiers |= kShiftKeyModifierMask; 48 modifiers |= kShiftKeyModifierMask;
49 if (win_modifiers & 0x02) 49 if (win_modifiers & 0x02)
50 modifiers |= kControlKeyModifierMask; 50 modifiers |= kControlKeyModifierMask;
51 if (win_modifiers & 0x04) 51 if (win_modifiers & 0x04)
52 modifiers |= kAltKeyModifierMask; 52 modifiers |= kAltKeyModifierMask;
53 // Ignore bit 0x08: It is for Hankaku key. 53 // Ignore bit 0x08: It is for Hankaku key.
54 *necessary_modifiers = modifiers; 54 *necessary_modifiers = modifiers;
55 } 55 }
56 return translated; 56 return translated;
57 } 57 }
OLDNEW
« no previous file with comments | « chrome/test/chromedriver/keycode_text_conversion_unittest.cc ('k') | chrome/test/chromedriver/test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698