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 #endif | 9 #endif |
10 | 10 |
11 #include "app/l10n_util.h" | 11 #include "app/l10n_util.h" |
| 12 #include "base/i18n/rtl.h" |
12 #include "base/logging.h" | 13 #include "base/logging.h" |
13 #include "base/string_util.h" | 14 #include "base/string_util.h" |
14 #include "grit/app_strings.h" | 15 #include "grit/app_strings.h" |
15 | 16 |
16 namespace views { | 17 namespace views { |
17 | 18 |
18 std::wstring Accelerator::GetShortcutText() const { | 19 std::wstring Accelerator::GetShortcutText() const { |
19 int string_id = 0; | 20 int string_id = 0; |
20 switch(key_code_) { | 21 switch(key_code_) { |
21 case base::VKEY_TAB: | 22 case base::VKEY_TAB: |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 } else { | 86 } else { |
86 shortcut = l10n_util::GetString(string_id); | 87 shortcut = l10n_util::GetString(string_id); |
87 } | 88 } |
88 | 89 |
89 // Checking whether the character used for the accelerator is alphanumeric. | 90 // Checking whether the character used for the accelerator is alphanumeric. |
90 // If it is not, then we need to adjust the string later on if the locale is | 91 // If it is not, then we need to adjust the string later on if the locale is |
91 // right-to-left. See below for more information of why such adjustment is | 92 // right-to-left. See below for more information of why such adjustment is |
92 // required. | 93 // required. |
93 std::wstring shortcut_rtl; | 94 std::wstring shortcut_rtl; |
94 bool adjust_shortcut_for_rtl = false; | 95 bool adjust_shortcut_for_rtl = false; |
95 if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT && | 96 if (base::i18n::IsRTL() && shortcut.length() == 1 && |
96 shortcut.length() == 1 && | 97 !IsAsciiAlpha(shortcut.at(0)) && !IsAsciiDigit(shortcut.at(0))) { |
97 !IsAsciiAlpha(shortcut.at(0)) && | |
98 !IsAsciiDigit(shortcut.at(0))) { | |
99 adjust_shortcut_for_rtl = true; | 98 adjust_shortcut_for_rtl = true; |
100 shortcut_rtl.assign(shortcut); | 99 shortcut_rtl.assign(shortcut); |
101 } | 100 } |
102 | 101 |
103 if (IsShiftDown()) | 102 if (IsShiftDown()) |
104 shortcut = l10n_util::GetStringF(IDS_APP_SHIFT_MODIFIER, shortcut); | 103 shortcut = l10n_util::GetStringF(IDS_APP_SHIFT_MODIFIER, shortcut); |
105 | 104 |
106 // Note that we use 'else-if' in order to avoid using Ctrl+Alt as a shortcut. | 105 // Note that we use 'else-if' in order to avoid using Ctrl+Alt as a shortcut. |
107 // See http://blogs.msdn.com/oldnewthing/archive/2004/03/29/101121.aspx for | 106 // See http://blogs.msdn.com/oldnewthing/archive/2004/03/29/101121.aspx for |
108 // more information. | 107 // more information. |
(...skipping 29 matching lines...) Expand all Loading... |
138 | 137 |
139 // Subtracting the size of the shortcut key and 1 for the '+' sign. | 138 // Subtracting the size of the shortcut key and 1 for the '+' sign. |
140 shortcut_rtl.append(shortcut, 0, shortcut.length() - key_length - 1); | 139 shortcut_rtl.append(shortcut, 0, shortcut.length() - key_length - 1); |
141 shortcut.swap(shortcut_rtl); | 140 shortcut.swap(shortcut_rtl); |
142 } | 141 } |
143 | 142 |
144 return shortcut; | 143 return shortcut; |
145 } | 144 } |
146 | 145 |
147 } // namespace views | 146 } // namespace views |
OLD | NEW |