OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/base/accelerators/accelerator.h" | 5 #include "ui/base/accelerators/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(TOOLKIT_GTK) | 9 #elif defined(TOOLKIT_GTK) |
10 #include <gdk/gdk.h> | 10 #include <gdk/gdk.h> |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 } | 75 } |
76 | 76 |
77 bool Accelerator::IsCtrlDown() const { | 77 bool Accelerator::IsCtrlDown() const { |
78 return (modifiers_ & EF_CONTROL_DOWN) == EF_CONTROL_DOWN; | 78 return (modifiers_ & EF_CONTROL_DOWN) == EF_CONTROL_DOWN; |
79 } | 79 } |
80 | 80 |
81 bool Accelerator::IsAltDown() const { | 81 bool Accelerator::IsAltDown() const { |
82 return (modifiers_ & EF_ALT_DOWN) == EF_ALT_DOWN; | 82 return (modifiers_ & EF_ALT_DOWN) == EF_ALT_DOWN; |
83 } | 83 } |
84 | 84 |
85 bool Accelerator::IsCmdDown() const { | |
86 return (modifiers_ & EF_COMMAND_DOWN) == EF_COMMAND_DOWN; | |
Nico
2012/08/22 14:30:49
nit: if you say `!= 0` instead of `== EF_COMMAND_D
| |
87 } | |
88 | |
85 string16 Accelerator::GetShortcutText() const { | 89 string16 Accelerator::GetShortcutText() const { |
86 int string_id = 0; | 90 int string_id = 0; |
87 switch(key_code_) { | 91 switch(key_code_) { |
88 case ui::VKEY_TAB: | 92 case ui::VKEY_TAB: |
89 string_id = IDS_APP_TAB_KEY; | 93 string_id = IDS_APP_TAB_KEY; |
90 break; | 94 break; |
91 case ui::VKEY_RETURN: | 95 case ui::VKEY_RETURN: |
92 string_id = IDS_APP_ENTER_KEY; | 96 string_id = IDS_APP_ENTER_KEY; |
93 break; | 97 break; |
94 case ui::VKEY_ESCAPE: | 98 case ui::VKEY_ESCAPE: |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 shortcut = l10n_util::GetStringFUTF16(IDS_APP_SHIFT_MODIFIER, shortcut); | 191 shortcut = l10n_util::GetStringFUTF16(IDS_APP_SHIFT_MODIFIER, shortcut); |
188 | 192 |
189 // Note that we use 'else-if' in order to avoid using Ctrl+Alt as a shortcut. | 193 // Note that we use 'else-if' in order to avoid using Ctrl+Alt as a shortcut. |
190 // See http://blogs.msdn.com/oldnewthing/archive/2004/03/29/101121.aspx for | 194 // See http://blogs.msdn.com/oldnewthing/archive/2004/03/29/101121.aspx for |
191 // more information. | 195 // more information. |
192 if (IsCtrlDown()) | 196 if (IsCtrlDown()) |
193 shortcut = l10n_util::GetStringFUTF16(IDS_APP_CONTROL_MODIFIER, shortcut); | 197 shortcut = l10n_util::GetStringFUTF16(IDS_APP_CONTROL_MODIFIER, shortcut); |
194 else if (IsAltDown()) | 198 else if (IsAltDown()) |
195 shortcut = l10n_util::GetStringFUTF16(IDS_APP_ALT_MODIFIER, shortcut); | 199 shortcut = l10n_util::GetStringFUTF16(IDS_APP_ALT_MODIFIER, shortcut); |
196 | 200 |
201 if (IsCmdDown()) | |
202 shortcut = l10n_util::GetStringFUTF16(IDS_APP_COMMAND_MODIFIER, shortcut); | |
203 | |
197 // For some reason, menus in Windows ignore standard Unicode directionality | 204 // For some reason, menus in Windows ignore standard Unicode directionality |
198 // marks (such as LRE, PDF, etc.). On RTL locales, we use RTL menus and | 205 // marks (such as LRE, PDF, etc.). On RTL locales, we use RTL menus and |
199 // therefore any text we draw for the menu items is drawn in an RTL context. | 206 // therefore any text we draw for the menu items is drawn in an RTL context. |
200 // Thus, the text "Ctrl++" (which we currently use for the Zoom In option) | 207 // Thus, the text "Ctrl++" (which we currently use for the Zoom In option) |
201 // appears as "++Ctrl" in RTL because the Unicode BiDi algorithm puts | 208 // appears as "++Ctrl" in RTL because the Unicode BiDi algorithm puts |
202 // punctuations on the left when the context is right-to-left. Shortcuts that | 209 // punctuations on the left when the context is right-to-left. Shortcuts that |
203 // do not end with a punctuation mark (such as "Ctrl+H" do not have this | 210 // do not end with a punctuation mark (such as "Ctrl+H" do not have this |
204 // problem). | 211 // problem). |
205 // | 212 // |
206 // The only way to solve this problem is to adjust the string if the locale | 213 // The only way to solve this problem is to adjust the string if the locale |
(...skipping 14 matching lines...) Expand all Loading... | |
221 | 228 |
222 // Subtracting the size of the shortcut key and 1 for the '+' sign. | 229 // Subtracting the size of the shortcut key and 1 for the '+' sign. |
223 shortcut_rtl.append(shortcut, 0, shortcut.length() - key_length - 1); | 230 shortcut_rtl.append(shortcut, 0, shortcut.length() - key_length - 1); |
224 shortcut.swap(shortcut_rtl); | 231 shortcut.swap(shortcut_rtl); |
225 } | 232 } |
226 | 233 |
227 return shortcut; | 234 return shortcut; |
228 } | 235 } |
229 | 236 |
230 } // namespace ui | 237 } // namespace ui |
OLD | NEW |