1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 this.EXPORTED_SYMBOLS = ["ShortcutUtils"];
9 const Cu = Components.utils;
10 Cu.import("resource://gre/modules/Services.jsm");
11 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
13 XPCOMUtils.defineLazyGetter(this, "PlatformKeys", function() {
14 return Services.strings.createBundle(
15 "chrome://global-platform/locale/platformKeys.properties");
18 XPCOMUtils.defineLazyGetter(this, "Keys", function() {
19 return Services.strings.createBundle(
20 "chrome://global/locale/keys.properties");
25 * Prettifies the modifier keys for an element.
27 * @param Node aElemKey
28 * The key element to get the modifiers from.
29 * @param boolean aNoCloverLeaf
30 * Pass true to use a descriptive string instead of the cloverleaf symbol. (OS X only)
32 * A prettified and properly separated modifier keys string.
34 prettifyShortcut: function(aElemKey, aNoCloverLeaf) {
36 let elemMod = aElemKey.getAttribute("modifiers");
38 if (elemMod.match("accel")) {
39 if (Services.appinfo.OS == "Darwin") {
40 // XXX bug 779642 Use "Cmd-" literal vs. cloverleaf meta-key until
41 // Orion adds variable height lines.
45 elemString += PlatformKeys.GetStringFromName("VK_META") +
46 PlatformKeys.GetStringFromName("MODIFIER_SEPARATOR");
49 elemString += PlatformKeys.GetStringFromName("VK_CONTROL") +
50 PlatformKeys.GetStringFromName("MODIFIER_SEPARATOR");
53 if (elemMod.match("access")) {
54 if (Services.appinfo.OS == "Darwin") {
55 elemString += PlatformKeys.GetStringFromName("VK_CONTROL") +
56 PlatformKeys.GetStringFromName("MODIFIER_SEPARATOR");
58 elemString += PlatformKeys.GetStringFromName("VK_ALT") +
59 PlatformKeys.GetStringFromName("MODIFIER_SEPARATOR");
62 if (elemMod.match("os")) {
63 elemString += PlatformKeys.GetStringFromName("VK_WIN") +
64 PlatformKeys.GetStringFromName("MODIFIER_SEPARATOR");
66 if (elemMod.match("shift")) {
67 elemString += PlatformKeys.GetStringFromName("VK_SHIFT") +
68 PlatformKeys.GetStringFromName("MODIFIER_SEPARATOR");
70 if (elemMod.match("alt")) {
71 elemString += PlatformKeys.GetStringFromName("VK_ALT") +
72 PlatformKeys.GetStringFromName("MODIFIER_SEPARATOR");
74 if (elemMod.match("ctrl") || elemMod.match("control")) {
75 elemString += PlatformKeys.GetStringFromName("VK_CONTROL") +
76 PlatformKeys.GetStringFromName("MODIFIER_SEPARATOR");
78 if (elemMod.match("meta")) {
79 elemString += PlatformKeys.GetStringFromName("VK_META") +
80 PlatformKeys.GetStringFromName("MODIFIER_SEPARATOR");
84 let keyCode = aElemKey.getAttribute("keycode");
87 // Some keys might not exist in the locale file, which will throw:
88 key = Keys.GetStringFromName(keyCode.toUpperCase());
90 Cu.reportError("Error finding " + keyCode + ": " + ex);
91 key = keyCode.replace(/^VK_/, '');
94 key = aElemKey.getAttribute("key");
96 return elemString + key;
100 Object.freeze(ShortcutUtils);