fune/toolkit/components/prompts/content/commonDialog.js
Emilio Cobos Álvarez 71031bc0b1 Bug 1605724 - Call sizeToContent() again when the icon loads if it hasn't loaded yet. r=dao
https://hg.mozilla.org/mozilla-central/rev/234701139a2a61d1262e609c9d8ac42384ecafda

Removed the following CSS rule:

  #iconContainer {
    -moz-box-pack: center;
    min-height: 55px; /* maximum icon height + icon margin */
    min-width: 58px; /* maximum icon width + icon margin */
  }

Which enforced the size of the icon row.

The icon loads asynchronously, so by the first time we fire DOMContentLoaded it
may not have loaded yet. This means that sizeToContent() will size the window to
an smaller size and stuff will wrap around when it loads.

<image> doesn't block onload so even delaying this wouldn't work.

Instead, call sizeToContent() again when it loads so that we size the window
right again.

Alternatively / on top of this, we could add a wrapper around the <image>
again and fix its width, may be better too...

Differential Revision: https://phabricator.services.mozilla.com/D58704

--HG--
extra : moz-landing-system : lando
2020-01-07 15:13:27 +00:00

75 lines
2.4 KiB
JavaScript

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const { CommonDialog } = ChromeUtils.import(
"resource://gre/modules/CommonDialog.jsm"
);
var propBag, args, Dialog;
function commonDialogOnLoad() {
propBag = window.arguments[0]
.QueryInterface(Ci.nsIWritablePropertyBag2)
.QueryInterface(Ci.nsIWritablePropertyBag);
// Convert to a JS object
args = {};
for (let prop of propBag.enumerator) {
args[prop.name] = prop.value;
}
let dialog = document.getElementById("commonDialog");
let ui = {
prompt: window,
loginContainer: document.getElementById("loginContainer"),
loginTextbox: document.getElementById("loginTextbox"),
loginLabel: document.getElementById("loginLabel"),
password1Container: document.getElementById("password1Container"),
password1Textbox: document.getElementById("password1Textbox"),
password1Label: document.getElementById("password1Label"),
infoBody: document.getElementById("infoBody"),
infoTitle: document.getElementById("infoTitle"),
infoIcon: document.getElementById("infoIcon"),
checkbox: document.getElementById("checkbox"),
checkboxContainer: document.getElementById("checkboxContainer"),
button3: dialog.getButton("extra2"),
button2: dialog.getButton("extra1"),
button1: dialog.getButton("cancel"),
button0: dialog.getButton("accept"),
focusTarget: window,
};
Dialog = new CommonDialog(args, ui);
document.addEventListener("dialogaccept", function() {
Dialog.onButton0();
});
document.addEventListener("dialogcancel", function() {
Dialog.onButton1();
});
document.addEventListener("dialogextra1", function() {
Dialog.onButton2();
window.close();
});
document.addEventListener("dialogextra2", function() {
Dialog.onButton3();
window.close();
});
Dialog.onLoad(dialog);
// resize the window to the content
window.sizeToContent();
// If the icon hasn't loaded yet, size the window to the content again when
// it does, as its layout can change.
ui.infoIcon.addEventListener("load", () => window.sizeToContent());
window.getAttention();
}
function commonDialogOnUnload() {
// Convert args back into property bag
for (let propName in args) {
propBag.setProperty(propName, args[propName]);
}
}