Bug 927605 - UX-only: use the ShortcutUtils module in CustomizableUI, r=mikedeboer
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Tue, 22 Oct 2013 14:03:44 +0200
changeset 152408 0745d47f1cbb0895a9d66bd5bd6a3e4d5c29a6c0
parent 152407 4ebc28e74ceabbd069b41ac7a654a35d47cd1632
child 152486 83d17494e03c4d1249c74a16aef8e0b2560ff259
push id549
push usergijskruitbosch@gmail.com
push dateTue, 22 Oct 2013 22:40:04 +0000
treeherderux@0745d47f1cbb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikedeboer
bugs927605
milestone27.0a1
Bug 927605 - UX-only: use the ShortcutUtils module in CustomizableUI, r=mikedeboer
browser/components/customizableui/src/CustomizableUI.jsm
--- a/browser/components/customizableui/src/CustomizableUI.jsm
+++ b/browser/components/customizableui/src/CustomizableUI.jsm
@@ -17,20 +17,18 @@ XPCOMUtils.defineLazyModuleGetter(this, 
 XPCOMUtils.defineLazyModuleGetter(this, "DeferredTask",
   "resource://gre/modules/DeferredTask.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
   "resource://gre/modules/PrivateBrowsingUtils.jsm");
 XPCOMUtils.defineLazyGetter(this, "gWidgetsBundle", function() {
   const kUrl = "chrome://browser/locale/customizableui/customizableWidgets.properties";
   return Services.strings.createBundle(kUrl);
 });
-XPCOMUtils.defineLazyGetter(this, "gPlatformKeys", function() {
-  const kUrl = "chrome://global-platform/locale/platformKeys.properties";
-  return Services.strings.createBundle(kUrl);
-});
+XPCOMUtils.defineLazyModuleGetter(this, "ShortcutUtils",
+  "resource://gre/modules/ShortcutUtils.jsm");
 XPCOMUtils.defineLazyServiceGetter(this, "gELS",
   "@mozilla.org/eventlistenerservice;1", "nsIEventListenerService");
 
 const kNSXUL = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
 
 const kSpecialWidgetPfx = "customizableui-special-";
 
 const kCustomizationContextMenu = "customizationContextMenu";
@@ -926,17 +924,17 @@ let CustomizableUIInternal = {
       }
       node.setAttribute("removable", aWidget.removable);
       node.setAttribute("overflows", aWidget.overflows);
       node.setAttribute("label", this.getLocalizedProperty(aWidget, "label"));
       let additionalTooltipArguments = [];
       if (aWidget.shortcutId) {
         let keyEl = aDocument.getElementById(aWidget.shortcutId);
         if (keyEl) {
-          additionalTooltipArguments.push(this.createShortcutString(keyEl));
+          additionalTooltipArguments.push(ShortcutUtils.prettifyShortcut(keyEl));
         } else {
           ERROR("Key element with id '" + aWidget.shortcutId + "' for widget '" + aWidget.id +
                 "' not found!");
         }
       }
       let tooltip = this.getLocalizedProperty(aWidget, "tooltiptext", additionalTooltipArguments);
       node.setAttribute("tooltiptext", tooltip);
       node.setAttribute("class", "toolbarbutton-1 chromeclass-toolbar-additional");
@@ -1011,61 +1009,16 @@ let CustomizableUIInternal = {
     } catch(ex) {
       if (!def) {
         ERROR("Could not localize property '" + name + "'.");
       }
     }
     return def;
   },
 
-  // From devtools/shared/helpers.js:
-  createShortcutString: function(aElemKey) {
-    let elemString = "";
-    let elemMod = aElemKey.getAttribute("modifiers");
-
-    if (elemMod.match("accel")) {
-      if (Services.appinfo.OS == "Darwin") {
-        elemString += gPlatformKeys.GetStringFromName("VK_META") +
-          gPlatformKeys.GetStringFromName("MODIFIER_SEPARATOR");
-      } else {
-        elemString += gPlatformKeys.GetStringFromName("VK_CONTROL") +
-          gPlatformKeys.GetStringFromName("MODIFIER_SEPARATOR");
-      }
-    }
-    if (elemMod.match("access")) {
-      if (Services.appinfo.OS == "Darwin") {
-        elemString += gPlatformKeys.GetStringFromName("VK_CONTROL") +
-          gPlatformKeys.GetStringFromName("MODIFIER_SEPARATOR");
-      } else {
-        elemString += gPlatformKeys.GetStringFromName("VK_ALT") +
-          gPlatformKeys.GetStringFromName("MODIFIER_SEPARATOR");
-      }
-    }
-    if (elemMod.match("shift")) {
-      elemString += gPlatformKeys.GetStringFromName("VK_SHIFT") +
-        gPlatformKeys.GetStringFromName("MODIFIER_SEPARATOR");
-    }
-    if (elemMod.match("alt")) {
-      elemString += gPlatformKeys.GetStringFromName("VK_ALT") +
-        gPlatformKeys.GetStringFromName("MODIFIER_SEPARATOR");
-    }
-    if (elemMod.match("ctrl") || elemMod.match("control")) {
-      elemString += gPlatformKeys.GetStringFromName("VK_CONTROL") +
-        gPlatformKeys.GetStringFromName("MODIFIER_SEPARATOR");
-    }
-    if (elemMod.match("meta")) {
-      elemString += gPlatformKeys.GetStringFromName("VK_META") +
-        gPlatformKeys.GetStringFromName("MODIFIER_SEPARATOR");
-    }
-
-    return elemString +
-      (aElemKey.getAttribute("keycode").replace(/^.*VK_/, "") ||
-       aElemKey.getAttribute("key")).toUpperCase();
-  },
-
   handleWidgetCommand: function(aWidget, aNode, aEvent) {
     LOG("handleWidgetCommand");
 
     if (aWidget.type == "button") {
       this.maybeAutoHidePanel(aEvent);
 
       if (aWidget.onCommand) {
         try {