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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jared Wein 2019-01-26 23:23:15 +00:00
Родитель 93752e905d
Коммит e3d4bb863b
2 изменённых файлов: 30 добавлений и 4 удалений

Просмотреть файл

@ -77,6 +77,4 @@ function onLoad() {
document.documentElement.getButton("extra1").hidden = true;
document.getElementById("resetProfileInstead").hidden = true;
}
document.l10n.translateElements(document.querySelectorAll("label, description")).then(
() => window.sizeToContent());
}

Просмотреть файл

@ -60,6 +60,11 @@
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;"/>
@ -159,16 +164,32 @@
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>
@ -216,6 +237,12 @@
// Give focus after onload completes, see bug 103197.
setTimeout(focusInit, 0);
if (this._l10nButtons) {
requestAnimationFrame(() => {
window.sizeToContent();
});
}
]]>
</body>
</method>
@ -286,6 +313,7 @@
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);