Bug 518054: nsPromptService needs to fire event when opening modal dialogs [r=mark.finkle]

This commit is contained in:
Fabrice Desré 2009-10-12 15:05:46 -04:00
parent 1245e49797
commit afa0f5a32b
3 changed files with 26 additions and 11 deletions

View File

@ -17,6 +17,7 @@
<implementation implements="nsIDOMEventListener">
<field name="arguments"/>
<field name="parent"/>
<constructor><![CDATA[
if (!this.hasAttribute("orient"))
@ -53,6 +54,12 @@
}
this.parentNode.parentNode.removeChild(this.parentNode);
this._closed = true;
// emit DOMModalDialogClosed event
let event = document.createEvent("Events");
event.initEvent("DOMModalDialogClosed", true, false);
let dispatcher = this.parent || getBrowser();
dispatcher.dispatchEvent(event);
</body>
</method>

View File

@ -2070,7 +2070,7 @@ function getNotificationBox(aWindow) {
return Browser.getNotificationBox();
}
function importDialog(src, arguments) {
function importDialog(parent, src, arguments) {
// load the dialog with a synchronous XHR
let xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance();
xhr.open("GET", src, false);
@ -2078,6 +2078,7 @@ function importDialog(src, arguments) {
xhr.send(null);
if (!xhr.responseXML)
return null;
let doc = xhr.responseXML.documentElement;
var dialog = null;
@ -2086,6 +2087,12 @@ function importDialog(src, arguments) {
let selectContainer = document.getElementById("select-container");
let parent = selectContainer.parentNode;
// emit DOMWillOpenModalDialog event
let event = document.createEvent("Events");
event.initEvent("DOMWillOpenModalDialog", true, false);
let dispatcher = parent || getBrowser();
dispatcher.dispatchEvent(event);
// create a full-screen semi-opaque box as a background
let back = document.createElement("box");
back.setAttribute("class", "modal-block");
@ -2093,6 +2100,7 @@ function importDialog(src, arguments) {
parent.insertBefore(back, selectContainer);
dialog.arguments = arguments;
dialog.parent = parent;
return dialog;
}

View File

@ -75,14 +75,14 @@ promptService.prototype = {
elem.parentNode.style.height = height + "px";
},
openDialog: function(src, params) {
openDialog: function(parent, src, params) {
let wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
let browser = wm.getMostRecentWindow("navigator:browser");
return browser.importDialog(src, params);
return browser.importDialog(parent, src, params);
},
alert: function(aParent, aTitle, aText) {
let dialog = this.openDialog("chrome://browser/content/prompt/alert.xul", null);
let dialog = this.openDialog(aParent, "chrome://browser/content/prompt/alert.xul", null);
let doc = this.getDocument();
doc.getElementById("prompt-alert-title").value = aTitle;
doc.getElementById("prompt-alert-message").appendChild(doc.createTextNode(aText));
@ -93,7 +93,7 @@ promptService.prototype = {
},
alertCheck: function(aParent, aTitle, aText, aCheckMsg, aCheckState) {
let dialog = this.openDialog("chrome://browser/content/prompt/alert.xul", aCheckState);
let dialog = this.openDialog(aParent, "chrome://browser/content/prompt/alert.xul", aCheckState);
let doc = this.getDocument();
doc.getElementById("prompt-alert-title").value = aTitle;
doc.getElementById("prompt-alert-message").appendChild(doc.createTextNode(aText));
@ -112,7 +112,7 @@ promptService.prototype = {
var params = new Object();
params.result = false;
let doc = this.getDocument();
let dialog = this.openDialog("chrome://browser/content/prompt/confirm.xul", params);
let dialog = this.openDialog(aParent, "chrome://browser/content/prompt/confirm.xul", params);
doc.getElementById("prompt-confirm-title").value = aTitle;
doc.getElementById("prompt-confirm-message").appendChild(doc.createTextNode(aText));
this.sizeElement("prompt-confirm-message", 80);
@ -127,7 +127,7 @@ promptService.prototype = {
params.result = false;
params.checkbox = aCheckState;
let doc = this.getDocument();
let dialog = this.openDialog("chrome://browser/content/prompt/confirm.xul", params);
let dialog = this.openDialog(aParent, "chrome://browser/content/prompt/confirm.xul", params);
doc.getElementById("prompt-confirm-title").value = aTitle;
doc.getElementById("prompt-confirm-message").appendChild(doc.createTextNode(aText));
this.sizeElement("prompt-confirm-message", 80);
@ -198,7 +198,7 @@ promptService.prototype = {
params.result = false;
params.checkbox = aCheckState;
let doc = this.getDocument();
let dialog = this.openDialog("chrome://browser/content/prompt/confirm.xul", params);
let dialog = this.openDialog(aParent, "chrome://browser/content/prompt/confirm.xul", params);
doc.getElementById("prompt-confirm-title").value = aTitle;
doc.getElementById("prompt-confirm-message").appendChild(doc.createTextNode(aText));
this.sizeElement("prompt-confirm-message", 80);
@ -266,7 +266,7 @@ promptService.prototype = {
params.result = false;
params.checkbox = aCheckState;
params.value = aValue;
let dialog = this.openDialog("chrome://browser/content/prompt/prompt.xul", params);
let dialog = this.openDialog(aParent, "chrome://browser/content/prompt/prompt.xul", params);
let doc = this.getDocument();
doc.getElementById("prompt-prompt-title").value = aTitle;
doc.getElementById("prompt-prompt-message").appendChild(doc.createTextNode(aText));
@ -302,7 +302,7 @@ promptService.prototype = {
params.checkbox = aCheckState;
params.user = aUsername;
params.password = aPassword;
let dialog = this.openDialog("chrome://browser/content/prompt/promptPassword.xul", params);
let dialog = this.openDialog(aParent, "chrome://browser/content/prompt/promptPassword.xul", params);
let doc = this.getDocument();
doc.getElementById("prompt-password-title").value = aTitle;
doc.getElementById("prompt-password-message").appendChild(doc.createTextNode(aText));
@ -423,7 +423,7 @@ promptService.prototype = {
var params = new Object();
params.result = false;
params.selection = aOutSelection;
let dialog = this.openDialog("chrome://browser/content/prompt/select.xul", params);
let dialog = this.openDialog(aParent, "chrome://browser/content/prompt/select.xul", params);
let doc = this.getDocument();
doc.getElementById("prompt-select-title").value = aTitle;
doc.getElementById("prompt-select-message").appendChild(doc.createTextNode(aText));