| OLD | NEW |
| 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 <stdlib.h> | 7 #include <stdlib.h> |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 | 9 |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 // |ToUnicode| converts some non-text key codes like F1 to various | 28 // |ToUnicode| converts some non-text key codes like F1 to various |
| 29 // control chars. Filter those out. | 29 // control chars. Filter those out. |
| 30 if (code <= 0 || (code == 1 && iswcntrl(chars[0]))) | 30 if (code <= 0 || (code == 1 && iswcntrl(chars[0]))) |
| 31 *text = std::string(); | 31 *text = std::string(); |
| 32 else | 32 else |
| 33 base::WideToUTF8(chars, code, text); | 33 base::WideToUTF8(chars, code, text); |
| 34 return true; | 34 return true; |
| 35 } | 35 } |
| 36 | 36 |
| 37 bool ConvertCharToKeyCode( | 37 bool ConvertCharToKeyCode( |
| 38 char16 key, ui::KeyboardCode* key_code, int *necessary_modifiers, | 38 base::char16 key, ui::KeyboardCode* key_code, int *necessary_modifiers, |
| 39 std::string* error_msg) { | 39 std::string* error_msg) { |
| 40 short vkey_and_modifiers = ::VkKeyScanW(key); | 40 short vkey_and_modifiers = ::VkKeyScanW(key); |
| 41 bool translated = vkey_and_modifiers != -1 && | 41 bool translated = vkey_and_modifiers != -1 && |
| 42 LOBYTE(vkey_and_modifiers) != 0xFF && | 42 LOBYTE(vkey_and_modifiers) != 0xFF && |
| 43 HIBYTE(vkey_and_modifiers) != 0xFF; | 43 HIBYTE(vkey_and_modifiers) != 0xFF; |
| 44 *error_msg = std::string(); | 44 *error_msg = std::string(); |
| 45 if (translated) { | 45 if (translated) { |
| 46 *key_code = static_cast<ui::KeyboardCode>(LOBYTE(vkey_and_modifiers)); | 46 *key_code = static_cast<ui::KeyboardCode>(LOBYTE(vkey_and_modifiers)); |
| 47 int win_modifiers = HIBYTE(vkey_and_modifiers); | 47 int win_modifiers = HIBYTE(vkey_and_modifiers); |
| 48 int modifiers = 0; | 48 int modifiers = 0; |
| 49 if (win_modifiers & 0x01) | 49 if (win_modifiers & 0x01) |
| 50 modifiers |= kShiftKeyModifierMask; | 50 modifiers |= kShiftKeyModifierMask; |
| 51 if (win_modifiers & 0x02) | 51 if (win_modifiers & 0x02) |
| 52 modifiers |= kControlKeyModifierMask; | 52 modifiers |= kControlKeyModifierMask; |
| 53 if (win_modifiers & 0x04) | 53 if (win_modifiers & 0x04) |
| 54 modifiers |= kAltKeyModifierMask; | 54 modifiers |= kAltKeyModifierMask; |
| 55 // Ignore bit 0x08: It is for Hankaku key. | 55 // Ignore bit 0x08: It is for Hankaku key. |
| 56 *necessary_modifiers = modifiers; | 56 *necessary_modifiers = modifiers; |
| 57 } | 57 } |
| 58 return translated; | 58 return translated; |
| 59 } | 59 } |
| OLD | NEW |