| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/views/accelerator.h" | 5 #include "chrome/views/accelerator.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "chrome/common/l10n_util.h" | 9 #include "chrome/common/l10n_util.h" |
| 10 #include "grit/generated_resources.h" | 10 #include "grit/generated_resources.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 string_id = IDS_F1_KEY; | 45 string_id = IDS_F1_KEY; |
| 46 break; | 46 break; |
| 47 case VK_F11: | 47 case VK_F11: |
| 48 string_id = IDS_F11_KEY; | 48 string_id = IDS_F11_KEY; |
| 49 break; | 49 break; |
| 50 } | 50 } |
| 51 | 51 |
| 52 std::wstring shortcut; | 52 std::wstring shortcut; |
| 53 if (!string_id) { | 53 if (!string_id) { |
| 54 // Our fallback is to try translate the key code to a regular char. | 54 // Our fallback is to try translate the key code to a regular char. |
| 55 wchar_t key = LOWORD(::MapVirtualKeyW(key_code_, MAPVK_VK_TO_CHAR)); | 55 wchar_t key; |
| 56 // Special-case digits. Some keyboard layouts (e.g. French) |
| 57 // have characters other than digits assigned in an unshifted mode. |
| 58 // For display in the menu (e.g. Ctrl-0 for the default zoom level), we |
| 59 // still want to show digits. |
| 60 if (key_code_ >= '0' && key_code_ <= '9') |
| 61 key = key_code_; |
| 62 else |
| 63 key = LOWORD(::MapVirtualKeyW(key_code_, MAPVK_VK_TO_CHAR)); |
| 56 shortcut += key; | 64 shortcut += key; |
| 57 } else { | 65 } else { |
| 58 shortcut = l10n_util::GetString(string_id); | 66 shortcut = l10n_util::GetString(string_id); |
| 59 } | 67 } |
| 60 | 68 |
| 61 // Checking whether the character used for the accelerator is alphanumeric. | 69 // Checking whether the character used for the accelerator is alphanumeric. |
| 62 // If it is not, then we need to adjust the string later on if the locale is | 70 // If it is not, then we need to adjust the string later on if the locale is |
| 63 // right-to-left. See below for more information of why such adjustment is | 71 // right-to-left. See below for more information of why such adjustment is |
| 64 // required. | 72 // required. |
| 65 std::wstring shortcut_rtl; | 73 std::wstring shortcut_rtl; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 // Subtracting the size of the shortcut key and 1 for the '+' sign. | 119 // Subtracting the size of the shortcut key and 1 for the '+' sign. |
| 112 shortcut_rtl.append(shortcut, 0, shortcut.length() - key_length - 1); | 120 shortcut_rtl.append(shortcut, 0, shortcut.length() - key_length - 1); |
| 113 shortcut.swap(shortcut_rtl); | 121 shortcut.swap(shortcut_rtl); |
| 114 } | 122 } |
| 115 | 123 |
| 116 return shortcut; | 124 return shortcut; |
| 117 } | 125 } |
| 118 | 126 |
| 119 } // namespace views | 127 } // namespace views |
| 120 | 128 |
| OLD | NEW |