Bug 1523166 - Explicitly wait for the localized buttons before sizing the window to content. r=mconley a=lizzard
authorJared Wein <jwein@mozilla.com>
Fri, 01 Feb 2019 20:53:47 +0000
changeset 515841 546e05b0e3d22b9957fff74c7c5a0f0c8617494f
parent 515840 59b0981f244c1d330541d4593fcafa2635c3ac6b
child 515842 bfdf856d1c9a2d717f33bddf1dabad8776167805
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley, lizzard
bugs1523166
milestone66.0
Bug 1523166 - Explicitly wait for the localized buttons before sizing the window to content. r=mconley a=lizzard Differential Revision: https://phabricator.services.mozilla.com/D17777
toolkit/content/widgets/dialog.xml
--- a/toolkit/content/widgets/dialog.xml
+++ b/toolkit/content/widgets/dialog.xml
@@ -55,20 +55,20 @@
 
     <implementation>
       <field name="_mStrBundle">null</field>
       <field name="_closeHandler">(function(event) {
         if (!document.documentElement.cancelDialog())
           event.preventDefault();
       })</field>
 
-      <!-- Gets set to true if document.l10n.setAttributes is
-           used to localize the dialog buttons. Needed to properly
-           size the dialog after the asynchronous translation. -->
-      <field name="_l10nButtons">false</field>
+      <!-- Gets populated by elements that are passed to document.l10n.setAttributes
+           to localize the dialog buttons. Needed to properly size the dialog after
+           the asynchronous translation. -->
+      <field name="_l10nButtons">[]</field>
 
       <property name="buttons"
                 onget="return this.getAttribute('buttons');"
                 onset="this._configureButtons(val); return val;"/>
 
       <property name="defaultButton">
         <getter>
         <![CDATA[
@@ -233,18 +233,18 @@
               if (defaultButton)
                 window.notifyDefaultButtonLoaded(defaultButton);
             } catch (e) { }
           }
 
           // Give focus after onload completes, see bug 103197.
           setTimeout(focusInit, 0);
 
-          if (this._l10nButtons) {
-            requestAnimationFrame(() => {
+          if (this._l10nButtons.length) {
+            document.l10n.translateElements(this._l10nButtons).then(() => {
               window.sizeToContent();
             });
           }
         ]]>
         </body>
       </method>
 
       <method name="openHelp">
@@ -308,17 +308,17 @@
             if (!button.hasAttribute("label")) {
               // dialog attributes override the default labels in dialog.properties
               if (this.hasAttribute("buttonlabel" + dlgtype)) {
                 button.setAttribute("label", this.getAttribute("buttonlabel" + dlgtype));
                 if (this.hasAttribute("buttonaccesskey" + dlgtype))
                   button.setAttribute("accesskey", this.getAttribute("buttonaccesskey" + dlgtype));
               } else if (this.hasAttribute("buttonid" + dlgtype)) {
                 document.l10n.setAttributes(button, this.getAttribute("buttonid" + dlgtype));
-                this._l10nButtons = true;
+                this._l10nButtons.push(button);
               } else if (dlgtype != "extra1" && dlgtype != "extra2") {
                 button.setAttribute("label", this.mStrBundle.GetStringFromName("button-" + dlgtype));
                 var accessKey = this.mStrBundle.GetStringFromName("accesskey-" + dlgtype);
                 if (accessKey)
                   button.setAttribute("accesskey", accessKey);
               }
             }
             // allow specifying alternate icons in the dialog header