Bug 1523126 - Dialogs that use Fluent for localizing the dialog buttons need to wait for the buttons to be translated before sizing to content. r=mconley
authorJared Wein <jwein@mozilla.com>
Sat, 26 Jan 2019 23:23:15 +0000
changeset 515577 11f88edba10fcab0a5e508b1fba9b58203a51fa4
parent 515576 5ae9eadd86a7eaaaeb0816f27aab4f17c055da44
child 515578 ef038a8b19442250bef744c830b4fecb884ad426
child 515583 2013099b2c13997ffe1362e6e1e9cf09cd4cd4ac
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
bugs1523126
milestone66.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 1523126 - Dialogs that use Fluent for localizing the dialog buttons need to wait for the buttons to be translated before sizing to content. r=mconley Differential Revision: https://phabricator.services.mozilla.com/D17758
browser/base/content/safeMode.js
toolkit/content/widgets/dialog.xml
--- a/browser/base/content/safeMode.js
+++ b/browser/base/content/safeMode.js
@@ -72,11 +72,9 @@ function onLoad() {
       // Hide the reset button is it's not supported.
       document.documentElement.getButton("extra1").hidden = true;
     }
   } else if (!ResetProfile.resetSupported()) {
     // Hide the reset button and text if it's not supported.
     document.documentElement.getButton("extra1").hidden = true;
     document.getElementById("resetProfileInstead").hidden = true;
   }
-  document.l10n.translateElements(document.querySelectorAll("label, description")).then(
-    () => window.sizeToContent());
 }
--- a/toolkit/content/widgets/dialog.xml
+++ b/toolkit/content/widgets/dialog.xml
@@ -55,16 +55,21 @@
 
     <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>
+
       <property name="buttons"
                 onget="return this.getAttribute('buttons');"
                 onset="this._configureButtons(val); return val;"/>
 
       <property name="defaultButton">
         <getter>
         <![CDATA[
           if (this.hasAttribute("defaultButton"))
@@ -154,26 +159,42 @@
         </body>
       </method>
 
       <constructor>
       <![CDATA[
         this._configureButtons(this.buttons);
 
         // listen for when window is closed via native close buttons
-        window.addEventListener("close", this._closeHandler);
+        window.addEventListener("close", this);
 
         // for things that we need to initialize after onload fires
-        window.addEventListener("load", this.postLoadInit);
+        window.addEventListener("load", this);
 
         window.moveToAlertPosition = this.moveToAlertPosition;
         window.centerWindowOnScreen = this.centerWindowOnScreen;
       ]]>
       </constructor>
 
+      <method name="handleEvent">
+        <parameter name="aEvent"/>
+        <body><![CDATA[
+          switch (aEvent.type) {
+            case "close": {
+              this._closeHandler(aEvent);
+              break;
+            }
+            case "load": {
+              this.postLoadInit(aEvent);
+              break;
+            }
+          }
+        ]]></body>
+      </method>
+
       <method name="postLoadInit">
         <parameter name="aEvent"/>
         <body>
         <![CDATA[
           function focusInit() {
             const dialog = document.documentElement;
             const defaultButton = dialog.getButton(dialog.defaultButton);
             // give focus to the first focusable element in the dialog
@@ -211,16 +232,22 @@
             try {
               if (defaultButton)
                 window.notifyDefaultButtonLoaded(defaultButton);
             } catch (e) { }
           }
 
           // Give focus after onload completes, see bug 103197.
           setTimeout(focusInit, 0);
+
+          if (this._l10nButtons) {
+            requestAnimationFrame(() => {
+              window.sizeToContent();
+            });
+          }
         ]]>
         </body>
       </method>
 
       <method name="openHelp">
         <parameter name="event"/>
         <body>
         <![CDATA[
@@ -281,16 +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;
               } 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