summaryrefslogtreecommitdiffstats
path: root/toolkit/modules/ShortcutUtils.jsm
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /toolkit/modules/ShortcutUtils.jsm
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'toolkit/modules/ShortcutUtils.jsm')
-rw-r--r--toolkit/modules/ShortcutUtils.jsm113
1 files changed, 113 insertions, 0 deletions
diff --git a/toolkit/modules/ShortcutUtils.jsm b/toolkit/modules/ShortcutUtils.jsm
new file mode 100644
index 000000000..fed0950b0
--- /dev/null
+++ b/toolkit/modules/ShortcutUtils.jsm
@@ -0,0 +1,113 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+this.EXPORTED_SYMBOLS = ["ShortcutUtils"];
+
+const Cu = Components.utils;
+Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
+XPCOMUtils.defineLazyGetter(this, "PlatformKeys", function() {
+ return Services.strings.createBundle(
+ "chrome://global-platform/locale/platformKeys.properties");
+});
+
+XPCOMUtils.defineLazyGetter(this, "Keys", function() {
+ return Services.strings.createBundle(
+ "chrome://global/locale/keys.properties");
+});
+
+var ShortcutUtils = {
+ /**
+ * Prettifies the modifier keys for an element.
+ *
+ * @param Node aElemKey
+ * The key element to get the modifiers from.
+ * @param boolean aNoCloverLeaf
+ * Pass true to use a descriptive string instead of the cloverleaf symbol. (OS X only)
+ * @return string
+ * A prettified and properly separated modifier keys string.
+ */
+ prettifyShortcut: function(aElemKey, aNoCloverLeaf) {
+ let elemString = "";
+ let elemMod = aElemKey.getAttribute("modifiers");
+ let haveCloverLeaf = false;
+
+ if (elemMod.match("accel")) {
+ if (Services.appinfo.OS == "Darwin") {
+ // XXX bug 779642 Use "Cmd-" literal vs. cloverleaf meta-key until
+ // Orion adds variable height lines.
+ if (aNoCloverLeaf) {
+ elemString += "Cmd-";
+ } else {
+ haveCloverLeaf = true;
+ }
+ } else {
+ elemString += PlatformKeys.GetStringFromName("VK_CONTROL") +
+ PlatformKeys.GetStringFromName("MODIFIER_SEPARATOR");
+ }
+ }
+ if (elemMod.match("access")) {
+ if (Services.appinfo.OS == "Darwin") {
+ elemString += PlatformKeys.GetStringFromName("VK_CONTROL") +
+ PlatformKeys.GetStringFromName("MODIFIER_SEPARATOR");
+ } else {
+ elemString += PlatformKeys.GetStringFromName("VK_ALT") +
+ PlatformKeys.GetStringFromName("MODIFIER_SEPARATOR");
+ }
+ }
+ if (elemMod.match("os")) {
+ elemString += PlatformKeys.GetStringFromName("VK_WIN") +
+ PlatformKeys.GetStringFromName("MODIFIER_SEPARATOR");
+ }
+ if (elemMod.match("shift")) {
+ elemString += PlatformKeys.GetStringFromName("VK_SHIFT") +
+ PlatformKeys.GetStringFromName("MODIFIER_SEPARATOR");
+ }
+ if (elemMod.match("alt")) {
+ elemString += PlatformKeys.GetStringFromName("VK_ALT") +
+ PlatformKeys.GetStringFromName("MODIFIER_SEPARATOR");
+ }
+ if (elemMod.match("ctrl") || elemMod.match("control")) {
+ elemString += PlatformKeys.GetStringFromName("VK_CONTROL") +
+ PlatformKeys.GetStringFromName("MODIFIER_SEPARATOR");
+ }
+ if (elemMod.match("meta")) {
+ elemString += PlatformKeys.GetStringFromName("VK_META") +
+ PlatformKeys.GetStringFromName("MODIFIER_SEPARATOR");
+ }
+
+ if (haveCloverLeaf) {
+ elemString += PlatformKeys.GetStringFromName("VK_META") +
+ PlatformKeys.GetStringFromName("MODIFIER_SEPARATOR");
+ }
+
+ let key;
+ let keyCode = aElemKey.getAttribute("keycode");
+ if (keyCode) {
+ try {
+ // Some keys might not exist in the locale file, which will throw:
+ key = Keys.GetStringFromName(keyCode.toUpperCase());
+ } catch (ex) {
+ Cu.reportError("Error finding " + keyCode + ": " + ex);
+ key = keyCode.replace(/^VK_/, '');
+ }
+ } else {
+ key = aElemKey.getAttribute("key");
+ key = key.toUpperCase();
+ }
+ return elemString + key;
+ },
+
+ findShortcut: function(aElemCommand) {
+ let document = aElemCommand.ownerDocument;
+ return document.querySelector("key[command=\"" + aElemCommand.getAttribute("id") + "\"]");
+ }
+};
+
+Object.freeze(ShortcutUtils);
+
+this.ShortcutUtils = ShortcutUtils;