Bug 940038 - Show shortcuts in toolbar buttons in menu panel subviews. r=jaws, ui-r=shorlander, a=sylvestre
authorBlake Winton <bwinton@latte.ca>
Wed, 19 Mar 2014 13:09:32 -0400
changeset 192231 0eb4ef5d034734f2e7deae317a00dcf1157ea790
parent 192230 469c940825b506f5b9231659bf18b11ee2906d7f
child 192232 e7628fbb07b6d5f539576c491f97d55eb8fd7c4f
push id474
push userasasaki@mozilla.com
push dateMon, 02 Jun 2014 21:01:02 +0000
treeherdermozilla-release@967f4cf1b31c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws, shorlander, sylvestre
bugs940038
milestone30.0a2
Bug 940038 - Show shortcuts in toolbar buttons in menu panel subviews. r=jaws, ui-r=shorlander, a=sylvestre
browser/components/customizableui/src/CustomizableWidgets.jsm
browser/themes/shared/customizableui/panelUIOverlay.inc.css
--- a/browser/components/customizableui/src/CustomizableWidgets.jsm
+++ b/browser/components/customizableui/src/CustomizableWidgets.jsm
@@ -76,16 +76,28 @@ function updateCombinedWidgetStyle(aNode
   attrs["cui-areatype"] = aArea ? CustomizableUI.getAreaType(aArea) : null;
   for (let i = 0, l = aNode.childNodes.length; i < l; ++i) {
     if (aNode.childNodes[i].localName == "separator")
       continue;
     setAttributes(aNode.childNodes[i], attrs);
   }
 }
 
+function addShortcut(aNode, aDocument, aItem) {
+  let shortcutId = aNode.getAttribute("key");
+  if (!shortcutId) {
+    return;
+  }
+  let shortcut = aDocument.getElementById(shortcutId);
+  if (!shortcut) {
+    return;
+  }
+  aItem.setAttribute("shortcut", ShortcutUtils.prettifyShortcut(shortcut));
+}
+
 const CustomizableWidgets = [{
     id: "history-panelmenu",
     type: "view",
     viewId: "PanelUI-history",
     shortcutId: "key_gotoHistory",
     tooltiptext: "history-panelmenu.tooltiptext2",
     defaultArea: CustomizableUI.AREA_PANEL,
     onViewShowing: function(aEvent) {
@@ -287,16 +299,17 @@ const CustomizableWidgets = [{
           continue;
 
         let item;
         if (node.localName == "menuseparator") {
           item = doc.createElementNS(kNSXUL, "menuseparator");
         } else if (node.localName == "menuitem") {
           item = doc.createElementNS(kNSXUL, "toolbarbutton");
           item.setAttribute("class", "subviewbutton");
+          addShortcut(node, doc, item);
         } else {
           continue;
         }
         for (let attr of attrs) {
           let attrVal = node.getAttribute(attr);
           if (attrVal)
             item.setAttribute(attr, attrVal);
         }
@@ -362,18 +375,20 @@ const CustomizableWidgets = [{
         } else {
           continue;
         }
         for (let attr of attrs) {
           let attrVal = node.getAttribute(attr);
           if (attrVal)
             item.setAttribute(attr, attrVal);
         }
-        if (node.localName == "menuitem")
+        if (node.localName == "menuitem") {
           item.classList.add("subviewbutton");
+          addShortcut(node, doc, item);
+        }
         fragment.appendChild(item);
       }
 
       items.appendChild(fragment);
     },
     onViewHiding: function(aEvent) {
       let doc = aEvent.target.ownerDocument;
       let items = doc.getElementById("PanelUI-sidebarItems");
@@ -745,16 +760,17 @@ const CustomizableWidgets = [{
 
       for (let item of list) {
         let elem = aDocument.createElementNS(kNSXUL, "toolbarbutton");
         elem.setAttribute("label", item.label);
         elem.setAttribute("type", "checkbox");
         elem.section = aSection;
         elem.value = item.value;
         elem.setAttribute("class", "subviewbutton");
+        addShortcut(item, doc, elem);
         containerElem.appendChild(elem);
       }
     },
     updateCurrentCharset: function(aDocument) {
       let content = aDocument.defaultView.content;
       let currentCharset = content && content.document && content.document.characterSet;
       currentCharset = CharsetMenu.foldCharset(currentCharset);
 
--- a/browser/themes/shared/customizableui/panelUIOverlay.inc.css
+++ b/browser/themes/shared/customizableui/panelUIOverlay.inc.css
@@ -641,16 +641,26 @@ panelview .toolbarbutton-1,
 
 .subviewbutton:not(.panel-subview-footer) > .toolbarbutton-text,
 /* Bookmark items need a more specific selector. */
 .PanelUI-subView .subviewbutton:not(.panel-subview-footer) > .menu-text,
 .PanelUI-subView .subviewbutton:not(.panel-subview-footer) > .menu-iconic-text {
   font: menu;
 }
 
+.PanelUI-subView .subviewbutton[shortcut]::after {
+  content: attr(shortcut);
+  float: right;
+  color: hsl(0,0%,50%);
+}
+
+.PanelUI-subView.cui-widget-panelview .subviewbutton[shortcut]::after {
+  -moz-margin-start: 10px;
+}
+
 /* This is a <label> but it should fit in with the menu font- and colorwise. */
 #PanelUI-characterEncodingView-autodetect-label {
   font: menu;
   color: inherit;
 }
 
 .cui-widget-panelview .subviewbutton:not(.panel-subview-footer) {
   margin-left: 4px;