Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | "use strict"; |
michael@0 | 6 | |
michael@0 | 7 | this.EXPORTED_SYMBOLS = ["ShortcutUtils"]; |
michael@0 | 8 | |
michael@0 | 9 | const Cu = Components.utils; |
michael@0 | 10 | Cu.import("resource://gre/modules/Services.jsm"); |
michael@0 | 11 | Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 12 | |
michael@0 | 13 | XPCOMUtils.defineLazyGetter(this, "PlatformKeys", function() { |
michael@0 | 14 | return Services.strings.createBundle( |
michael@0 | 15 | "chrome://global-platform/locale/platformKeys.properties"); |
michael@0 | 16 | }); |
michael@0 | 17 | |
michael@0 | 18 | XPCOMUtils.defineLazyGetter(this, "Keys", function() { |
michael@0 | 19 | return Services.strings.createBundle( |
michael@0 | 20 | "chrome://global/locale/keys.properties"); |
michael@0 | 21 | }); |
michael@0 | 22 | |
michael@0 | 23 | let ShortcutUtils = { |
michael@0 | 24 | /** |
michael@0 | 25 | * Prettifies the modifier keys for an element. |
michael@0 | 26 | * |
michael@0 | 27 | * @param Node aElemKey |
michael@0 | 28 | * The key element to get the modifiers from. |
michael@0 | 29 | * @param boolean aNoCloverLeaf |
michael@0 | 30 | * Pass true to use a descriptive string instead of the cloverleaf symbol. (OS X only) |
michael@0 | 31 | * @return string |
michael@0 | 32 | * A prettified and properly separated modifier keys string. |
michael@0 | 33 | */ |
michael@0 | 34 | prettifyShortcut: function(aElemKey, aNoCloverLeaf) { |
michael@0 | 35 | let elemString = ""; |
michael@0 | 36 | let elemMod = aElemKey.getAttribute("modifiers"); |
michael@0 | 37 | let haveCloverLeaf = false; |
michael@0 | 38 | |
michael@0 | 39 | if (elemMod.match("accel")) { |
michael@0 | 40 | if (Services.appinfo.OS == "Darwin") { |
michael@0 | 41 | // XXX bug 779642 Use "Cmd-" literal vs. cloverleaf meta-key until |
michael@0 | 42 | // Orion adds variable height lines. |
michael@0 | 43 | if (aNoCloverLeaf) { |
michael@0 | 44 | elemString += "Cmd-"; |
michael@0 | 45 | } else { |
michael@0 | 46 | haveCloverLeaf = true; |
michael@0 | 47 | } |
michael@0 | 48 | } else { |
michael@0 | 49 | elemString += PlatformKeys.GetStringFromName("VK_CONTROL") + |
michael@0 | 50 | PlatformKeys.GetStringFromName("MODIFIER_SEPARATOR"); |
michael@0 | 51 | } |
michael@0 | 52 | } |
michael@0 | 53 | if (elemMod.match("access")) { |
michael@0 | 54 | if (Services.appinfo.OS == "Darwin") { |
michael@0 | 55 | elemString += PlatformKeys.GetStringFromName("VK_CONTROL") + |
michael@0 | 56 | PlatformKeys.GetStringFromName("MODIFIER_SEPARATOR"); |
michael@0 | 57 | } else { |
michael@0 | 58 | elemString += PlatformKeys.GetStringFromName("VK_ALT") + |
michael@0 | 59 | PlatformKeys.GetStringFromName("MODIFIER_SEPARATOR"); |
michael@0 | 60 | } |
michael@0 | 61 | } |
michael@0 | 62 | if (elemMod.match("os")) { |
michael@0 | 63 | elemString += PlatformKeys.GetStringFromName("VK_WIN") + |
michael@0 | 64 | PlatformKeys.GetStringFromName("MODIFIER_SEPARATOR"); |
michael@0 | 65 | } |
michael@0 | 66 | if (elemMod.match("shift")) { |
michael@0 | 67 | elemString += PlatformKeys.GetStringFromName("VK_SHIFT") + |
michael@0 | 68 | PlatformKeys.GetStringFromName("MODIFIER_SEPARATOR"); |
michael@0 | 69 | } |
michael@0 | 70 | if (elemMod.match("alt")) { |
michael@0 | 71 | elemString += PlatformKeys.GetStringFromName("VK_ALT") + |
michael@0 | 72 | PlatformKeys.GetStringFromName("MODIFIER_SEPARATOR"); |
michael@0 | 73 | } |
michael@0 | 74 | if (elemMod.match("ctrl") || elemMod.match("control")) { |
michael@0 | 75 | elemString += PlatformKeys.GetStringFromName("VK_CONTROL") + |
michael@0 | 76 | PlatformKeys.GetStringFromName("MODIFIER_SEPARATOR"); |
michael@0 | 77 | } |
michael@0 | 78 | if (elemMod.match("meta")) { |
michael@0 | 79 | elemString += PlatformKeys.GetStringFromName("VK_META") + |
michael@0 | 80 | PlatformKeys.GetStringFromName("MODIFIER_SEPARATOR"); |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | if (haveCloverLeaf) { |
michael@0 | 84 | elemString += PlatformKeys.GetStringFromName("VK_META") + |
michael@0 | 85 | PlatformKeys.GetStringFromName("MODIFIER_SEPARATOR"); |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | let key; |
michael@0 | 89 | let keyCode = aElemKey.getAttribute("keycode"); |
michael@0 | 90 | if (keyCode) { |
michael@0 | 91 | try { |
michael@0 | 92 | // Some keys might not exist in the locale file, which will throw: |
michael@0 | 93 | key = Keys.GetStringFromName(keyCode.toUpperCase()); |
michael@0 | 94 | } catch (ex) { |
michael@0 | 95 | Cu.reportError("Error finding " + keyCode + ": " + ex); |
michael@0 | 96 | key = keyCode.replace(/^VK_/, ''); |
michael@0 | 97 | } |
michael@0 | 98 | } else { |
michael@0 | 99 | key = aElemKey.getAttribute("key"); |
michael@0 | 100 | key = key.toUpperCase(); |
michael@0 | 101 | } |
michael@0 | 102 | return elemString + key; |
michael@0 | 103 | } |
michael@0 | 104 | }; |
michael@0 | 105 | |
michael@0 | 106 | Object.freeze(ShortcutUtils); |