Bug 1217129: Part 4a - Allow creating CustomizableUI widgets without tooltips. r=gijs
authorKris Maglione <maglione.k@gmail.com>
Fri, 15 Jan 2016 15:03:20 -0800
changeset 280533 5979b6fe12500500c00985819e10d545abb76584
parent 280532 e2fcc19b6f27308451610a59b15bf919c1372c06
child 280534 77ae13dc32ae43283188e287693b36cb00c599b4
push id29918
push usercbook@mozilla.com
push dateWed, 20 Jan 2016 14:30:40 +0000
treeherdermozilla-central@b39b15928984 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgijs
bugs1217129
milestone46.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1217129: Part 4a - Allow creating CustomizableUI widgets without tooltips. r=gijs
browser/components/customizableui/CustomizableUI.jsm
--- a/browser/components/customizableui/CustomizableUI.jsm
+++ b/browser/components/customizableui/CustomizableUI.jsm
@@ -1337,17 +1337,19 @@ var CustomizableUIInternal = {
           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);
+      if (tooltip) {
+        node.setAttribute("tooltiptext", tooltip);
+      }
       node.setAttribute("class", "toolbarbutton-1 chromeclass-toolbar-additional");
 
       let commandHandler = this.handleWidgetCommand.bind(this, aWidget, node);
       node.addEventListener("command", commandHandler, false);
       let clickHandler = this.handleWidgetClick.bind(this, aWidget, node);
       node.addEventListener("click", clickHandler, false);
 
       // If the widget has a view, and has view showing / hiding listeners,
@@ -1380,44 +1382,48 @@ var CustomizableUIInternal = {
       }
     }
 
     aWidget.instances.set(aDocument, node);
     return node;
   },
 
   getLocalizedProperty: function(aWidget, aProp, aFormatArgs, aDef) {
+    const kReqStringProps = ["label"];
+
     if (typeof aWidget == "string") {
       aWidget = gPalette.get(aWidget);
     }
     if (!aWidget) {
       throw new Error("getLocalizedProperty was passed a non-widget to work with.");
     }
     let def, name;
     // Let widgets pass their own string identifiers or strings, so that
     // we can use strings which aren't the default (in case string ids change)
     // and so that non-builtin-widgets can also provide labels, tooltips, etc.
-    if (aWidget[aProp]) {
+    if (aWidget[aProp] != null) {
       name = aWidget[aProp];
       // By using this as the default, if a widget provides a full string rather
       // than a string ID for localization, we will fall back to that string
       // and return that.
       def = aDef || name;
     } else {
       name = aWidget.id + "." + aProp;
       def = aDef || "";
     }
     try {
       if (Array.isArray(aFormatArgs) && aFormatArgs.length) {
         return gWidgetsBundle.formatStringFromName(name, aFormatArgs,
           aFormatArgs.length) || def;
       }
       return gWidgetsBundle.GetStringFromName(name) || def;
     } catch(ex) {
-      if (!def) {
+      // If an empty string was explicitly passed, treat it as an actual
+      // value rather than a missing property.
+      if (!def && (name != "" || kReqStringProps.includes(aProp))) {
         ERROR("Could not localize property '" + name + "'.");
       }
     }
     return def;
   },
 
   addShortcut: function(aShortcutNode, aTargetNode) {
     if (!aTargetNode)