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 "views/accelerator.h" | 5 #include "views/accelerator.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
| 9 #elif defined(OS_LINUX) |
| 10 #include <gdk/gdk.h> |
9 #endif | 11 #endif |
10 | 12 |
11 #include "app/l10n_util.h" | 13 #include "app/l10n_util.h" |
12 #include "base/i18n/rtl.h" | 14 #include "base/i18n/rtl.h" |
13 #include "base/logging.h" | 15 #include "base/logging.h" |
14 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 17 #include "base/utf_string_conversions.h" |
15 #include "grit/app_strings.h" | 18 #include "grit/app_strings.h" |
16 | 19 |
17 namespace views { | 20 namespace views { |
18 | 21 |
19 std::wstring Accelerator::GetShortcutText() const { | 22 std::wstring Accelerator::GetShortcutText() const { |
20 int string_id = 0; | 23 int string_id = 0; |
21 switch(key_code_) { | 24 switch(key_code_) { |
22 case base::VKEY_TAB: | 25 case base::VKEY_TAB: |
23 string_id = IDS_APP_TAB_KEY; | 26 string_id = IDS_APP_TAB_KEY; |
24 break; | 27 break; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 // an unshifted mode (e.g. French AZERY layout has 'a with grave | 77 // an unshifted mode (e.g. French AZERY layout has 'a with grave |
75 // accent' for '0'). For display in the menu (e.g. Ctrl-0 for the | 78 // accent' for '0'). For display in the menu (e.g. Ctrl-0 for the |
76 // default zoom level), we leave VK_[0-9] alone without translation. | 79 // default zoom level), we leave VK_[0-9] alone without translation. |
77 wchar_t key; | 80 wchar_t key; |
78 if (key_code_ >= '0' && key_code_ <= '9') | 81 if (key_code_ >= '0' && key_code_ <= '9') |
79 key = key_code_; | 82 key = key_code_; |
80 else | 83 else |
81 key = LOWORD(::MapVirtualKeyW(key_code_, MAPVK_VK_TO_CHAR)); | 84 key = LOWORD(::MapVirtualKeyW(key_code_, MAPVK_VK_TO_CHAR)); |
82 shortcut += key; | 85 shortcut += key; |
83 #elif defined(OS_LINUX) | 86 #elif defined(OS_LINUX) |
84 NOTIMPLEMENTED(); | 87 gchar* name = gdk_keyval_name(gdk_keyval_to_lower(key_code_)); |
| 88 if (name) { |
| 89 if (name[0] != 0 && name[1] == 0) |
| 90 shortcut += static_cast<wchar_t>(g_ascii_toupper(name[0])); |
| 91 else |
| 92 shortcut += UTF8ToWide(name); |
| 93 } |
85 #endif | 94 #endif |
86 } else { | 95 } else { |
87 shortcut = l10n_util::GetString(string_id); | 96 shortcut = l10n_util::GetString(string_id); |
88 } | 97 } |
89 | 98 |
90 // Checking whether the character used for the accelerator is alphanumeric. | 99 // Checking whether the character used for the accelerator is alphanumeric. |
91 // If it is not, then we need to adjust the string later on if the locale is | 100 // If it is not, then we need to adjust the string later on if the locale is |
92 // right-to-left. See below for more information of why such adjustment is | 101 // right-to-left. See below for more information of why such adjustment is |
93 // required. | 102 // required. |
94 std::wstring shortcut_rtl; | 103 std::wstring shortcut_rtl; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 | 146 |
138 // Subtracting the size of the shortcut key and 1 for the '+' sign. | 147 // Subtracting the size of the shortcut key and 1 for the '+' sign. |
139 shortcut_rtl.append(shortcut, 0, shortcut.length() - key_length - 1); | 148 shortcut_rtl.append(shortcut, 0, shortcut.length() - key_length - 1); |
140 shortcut.swap(shortcut_rtl); | 149 shortcut.swap(shortcut_rtl); |
141 } | 150 } |
142 | 151 |
143 return shortcut; | 152 return shortcut; |
144 } | 153 } |
145 | 154 |
146 } // namespace views | 155 } // namespace views |
OLD | NEW |