Bug 1523166 - Explicitly wait for the localized buttons before sizing the window to content. r=mconley
authorJared Wein <jwein@mozilla.com>
Fri, 01 Feb 2019 20:53:47 +0000
changeset 456497 41293fa5d3efbfb7615bc3a1d86a4f47224f4d51
parent 456496 3f938555c3635ec9d75162a6456369c786b31e58
child 456498 52f541c1147efcba8febe1c26a51181bb0901233
push id111656
push userdvarga@mozilla.com
push dateSat, 02 Feb 2019 09:51:54 +0000
treeherdermozilla-inbound@d8cebb3b46cf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley
bugs1523166
milestone67.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 1523166 - Explicitly wait for the localized buttons before sizing the window to content. r=mconley 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