Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 1421 → Rev 1422

/mozilla/nomodal/branch/001_own_dialogs/src/components/Prompt.js
0,0 → 1,227
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 
// =====================================================================================================================
// FIXME
// - focus if parent tab is selected
// - 'prompt' and 'auth' dialogs
// - only for unsecure-js windows
// - customize standard/modalless dialogs via prefs
function NoModal_Prompt()
{
Components.utils.import("resource://nomodal_modules/DialogParams.jsm");
}
NoModal_Prompt.prototype = {
classDescription: "NoModal_Prompt",
classID: Components.ID("{21fa8349-62d3-406b-b042-4016469d6fe0}"),
contractID: "@mozilla.org/embedcomp/prompt-service;1",
QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIPromptService, Components.interfaces.nsIPromptService2]),
 
// -----------------------------------------------------------------------------------------------------------------
showDialog: function(aParent, params)
{
var requestor = aParent.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
var docShell = requestor.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShell);
var parentInt = requestor.getInterface(Components.interfaces.nsIDOMWindowInternal);
 
// disable all dynamics in the window
var jsAllowed = docShell.allowJavascript;
docShell.allowJavascript = false;
docShell.suspendRefreshURIs();
 
var win;
var refocus = function(aEvent) { dump("refocus\n"); if(win) win.focus(); };
var unload = function(aEvent) { dump("unload\n"); if(win) win.close(); };
aParent.addEventListener('click', refocus, true);
aParent.addEventListener('unload', unload, true);
 
var args = Components.classes["@mozilla.org/embedcomp/dialogparam;1"]
.createInstance(Components.interfaces.nsIDialogParamBlock);
args.SetString(0, params.text);
args.SetString(2, params.iconClass);
args.SetString(6, params.editfield1Value);
args.SetString(12, params.dialogTitle);
args.SetString(13, params.openingSound);
args.SetInt (2, params.numberButtons);
args.SetInt (3, params.numberEditfields);
args.SetInt (7, params.soundEventId);
 
var windowWatcher = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
.getService(Components.interfaces.nsIWindowWatcher);
win = windowWatcher.openWindow(aParent, "chrome://global/content/commonDialog.xul",
"_blank", "centerscreen,chrome,titlebar", args);
 
 
 
var winInt = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindowInternal);
 
var threadManager = Components.classes["@mozilla.org/thread-manager;1"]
.getService(Components.interfaces.nsIThreadManager);
 
while(!winInt.closed && threadManager.currentThread.processNextEvent(true));
 
if(!parentInt.closed) {
// restore
aParent.removeEventListener('click', refocus, true);
aParent.removeEventListener('unload', unload, true);
docShell.resumeRefreshURIs();
docShell.allowJavascript = jsAllowed;
 
//NoModal_DialogParams.decode(paramsRaw, params);
params.result = args.GetInt(0);
params.editfield1Value = args.GetString(6);
 
return true;
}
else {
return false;
}
},
 
// -----------------------------------------------------------------------------------------------------------------
// interface nsIPromptService
alert: function(aParent, aDialogTitle, aText)
{
var params = {
dialogTitleKey: "Alert",
dialogTitle: aDialogTitle,
text: aText,
numberButtons: 1,
numberEditfields: 0,
iconClass: "alert-icon",
openingSound: "_moz_alertdialog",
soundEventId: 1,
url: "chrome://global/content/commonDialog.xul",
};
 
this.showDialog(aParent, params);
//return NoModal_Prompt.origin.alert(aParent, aDialogTitle, aText);
},
 
// -----------------------------------------------------------------------------------------------------------------
// interface nsIPromptService
alertCheck: function(aParent, aDialogTitle, aText, aCheckMsg, aCheckState)
{
return NoModal_Prompt.origin.alertCheck(aParent, aDialogTitle, aText, aCheckMsg, aCheckState);
},
 
// -----------------------------------------------------------------------------------------------------------------
// interface nsIPromptService
confirm: function(aParent, aDialogTitle, aText)
{
var params = {
dialogTitleKey: "Confirm",
dialogTitle: aDialogTitle,
text: aText,
numberButtons: 2,
numberEditfields: 0,
iconClass: "question-icon",
openingSound: "_moz_confirmdialog",
soundEventId: 2,
url: "chrome://global/content/commonDialog.xul",
};
 
this.showDialog(aParent, params);
 
return (params.result == 0);
//return NoModal_Prompt.origin.confirm(aParent, aDialogTitle, aText);
},
 
// -----------------------------------------------------------------------------------------------------------------
// interface nsIPromptService
confirmCheck: function(aParent, aDialogTitle, aText, aCheckMsg, aCheckState)
{
return NoModal_Prompt.origin.confirmCheck(aParent, aDialogTitle, aText, aCheckMsg, aCheckState);
},
 
// -----------------------------------------------------------------------------------------------------------------
// interface nsIPromptService
confirmEx: function(aParent, aDialogTitle, aText, aButtonFlags, aButton0Title, aButton1Title, aButton2Title,
aCheckMsg, aCheckState)
{
return NoModal_Prompt.origin.confirmEx(aParent, aDialogTitle, aText, aButtonFlags, aButton0Title,
aButton1Title, aButton2Title, aCheckMsg, aCheckState);
},
 
// -----------------------------------------------------------------------------------------------------------------
// interface nsIPromptService
prompt: function(aParent, aDialogTitle, aText, aValue, aCheckMsg, aCheckState)
{
dump("prompt p1\n");
// note: no check msg/state
var params = {
dialogTitleKey: "Prompt",
dialogTitle: aDialogTitle,
text: aText,
numberButtons: 2,
numberEditfields: 1,
iconClass: "question-icon",
openingSound: "_moz_promptdialog",
soundEventId: 3,
url: "chrome://global/content/commonDialog.xul",
editfield1Value: aValue.value,
};
 
dump("prompt p2\n");
this.showDialog(aParent, params);
 
dump("prompt p3\n");
var res = (params.result == 0);
if(res) {
aValue.value = params.editfield1Value;
}
 
dump("prompt p4\n");
return res;
//return NoModal_Prompt.origin.prompt(aParent, aDialogTitle, aText, aValue, aCheckMsg, aCheckState);
},
 
// -----------------------------------------------------------------------------------------------------------------
// interface nsIPromptService
promptUsernameAndPassword: function(aParent, aDialogTitle, aText, aUsername, aPassword, aCheckMsg, aCheckState)
{
return NoModal_Prompt.origin.promptUsernameAndPassword(aParent, aDialogTitle, aText, aUsername, aPassword,
aCheckMsg, aCheckState);
},
 
// -----------------------------------------------------------------------------------------------------------------
// interface nsIPromptService
promptPassword: function(aParent, aDialogTitle, aText, aPassword, aCheckMsg, aCheckState)
{
return NoModal_Prompt.origin.promptPassword(aParent, aDialogTitle, aText, aPassword, aCheckMsg, aCheckState);
},
 
// -----------------------------------------------------------------------------------------------------------------
// interface nsIPromptService
select: function(aParent, aDialogTitle, aText, aCount, aSelectList, aOutSelection)
{
return NoModal_Prompt.origin.select(aParent, aDialogTitle, aText, aCount, aSelectList, aOutSelection);
},
 
// -----------------------------------------------------------------------------------------------------------------
// interface nsIPromptService2
promptAuth: function(aParent, aChannel, level, authInfo, checkboxLabel, checkValue)
{
return NoModal_Prompt.origin.promptAuth(aParent, aChannel, level, authInfo, checkboxLabel, checkValue);
},
 
// -----------------------------------------------------------------------------------------------------------------
// interface nsIPromptService2
asyncPromptAuth: function(aParent, aChannel, aCallback, aContext, level, authInfo, checkboxLabel, checkValue)
{
return NoModal_Prompt.origin.asyncPromptAuth(aParent, aChannel, level, authInfo, checkboxLabel, checkValue);
},
};
 
// =====================================================================================================================
function NSGetModule(compMgr, fileSpec)
{
dump("Prompt.js p3\n");
 
NoModal_Prompt.origin = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
 
return XPCOMUtils.generateModule([NoModal_Prompt]);
}
dump("Prompt.js p2\n");
/mozilla/nomodal/branch/001_own_dialogs/src/modules/DialogParams.jsm
0,0 → 1,42
var EXPORTED_SYMBOLS = ["NoModal_DialogParams"];
 
// =====================================================================================================================
var NoModal_DialogParams = {
MAX_VALUES: 8,
 
// -----------------------------------------------------------------------------------------------------------------
create: function()
{
return Components.classes["@mozilla.org/embedcomp/dialogparam;1"]
.createInstance(Components.interfaces.nsIDialogParamBlock);
},
 
// -----------------------------------------------------------------------------------------------------------------
encode: function(obj, params)
{
params.QueryInterface(Components.interfaces.nsIDialogParamBlock);
 
var i = 0;
for(var a in obj) {
params.SetString(i++, a);
params.SetString(i++, obj[a]);
}
 
for(; i < NoModal_DialogParams.MAX_VALUES * 2; ++i) {
params.SetString(i, null);
}
},
 
// -----------------------------------------------------------------------------------------------------------------
decode: function(params, obj)
{
params.QueryInterface(Components.interfaces.nsIDialogParamBlock);
 
for(var i = 0; i < NoModal_DialogParams.MAX_VALUES; ++i) {
var k = params.GetString(i*2);
var v = params.GetString(i*2+1);
 
if(k != "") obj[k] = v;
}
},
}
/mozilla/nomodal/branch/001_own_dialogs/src/chrome/content/dialog.css
0,0 → 1,2
@import url("chrome://communicator/skin/");
@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
/mozilla/nomodal/branch/001_own_dialogs/src/chrome/content/Confirm.js
0,0 → 1,18
// =====================================================================================================================
NoModal.Dialog_Alert = function()
{
NoModal.Dialog.call(this);
}
NoModal.Dialog_Alert.prototype = {
// -----------------------------------------------------------------------------------------------------------------
onLoad: function()
{
NoModal.Dialog.prototype.onLoad.call(this);
 
return true;
},
}
NoModal.inherit(NoModal.Dialog_Alert, NoModal.Dialog);
 
// == REGISTER =========================================================================================================
NoModal.DialogClass = NoModal.Dialog_Alert;
/mozilla/nomodal/branch/001_own_dialogs/src/chrome/content/Dialog.js
0,0 → 1,77
// =====================================================================================================================
NoModal.onDialogLoad = function()
{
var dialogController = new NoModal.DialogClass();
 
dialogController.paramsRaw = window.arguments[0];
dialogController.params = {};
NoModal_DialogParams.decode(dialogController.paramsRaw, dialogController.params);
 
if(!dialogController.onLoad()) {
window.close();
}
 
window.addEventListener('dialogaccept', function(aEvent)
{
if(!dialogController.onDialogAccept()) {
aEvent.preventDefault();
aEvent.stopPropagation();
}
return true;
 
}, false);
window.addEventListener('dialogcancel', function(aEvent)
{
if(!dialogController.onDialogCancel()) {
aEvent.preventDefault();
aEvent.stopPropagation();
}
 
return true;
}, false);
}
 
// =====================================================================================================================
NoModal.Dialog = function()
{
}
NoModal.Dialog.prototype = {
// -----------------------------------------------------------------------------------------------------------------
onLoad: function()
{
// title
var dialogs = document.getElementsByTagName("dialog");
if(dialogs && dialogs.length > 0) {
dialogs[0].setAttribute('title', this.params.title);
}
 
// text
document.getElementById("text").value = this.params.text;
 
return true;
},
 
// -----------------------------------------------------------------------------------------------------------------
onDialogAccept: function()
{
this.setDialogResult(true);
return true;
},
 
// -----------------------------------------------------------------------------------------------------------------
onDialogCancel: function()
{
this.setDialogResult(false);
return true;
},
 
// -----------------------------------------------------------------------------------------------------------------
setDialogResult: function(result)
{
this.params.result = result;
NoModal_DialogParams.encode(this.params, this.paramsRaw);
},
}
 
// == BOOTSTRAP ========================================================================================================
window.addEventListener('load', NoModal.onDialogLoad, false);
/mozilla/nomodal/branch/001_own_dialogs/src/chrome/content/browser.xul
0,0 → 1,13
<?xml version="1.0"?>
 
<overlay id="movelayer"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
<script type="application/x-javascript" src="chrome://nomodal/content/browser.js" />
 
<menupopup id="menu_EditPopup">
<menuseparator/>
<menuitem id="context-nomodal" label="NoModal" oncommand="NoModal.onCommand(this)" />
</menupopup>
 
</overlay>
/mozilla/nomodal/branch/001_own_dialogs/src/chrome/content/Alert.xul
0,0 → 1,16
<?xml version="1.0"?>
 
<?xml-stylesheet href="chrome://nomodal/content/dialog.css" type="text/css"?>
 
<dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
xmlns:html="http://www.w3.org/1999/xhtml"
title="Alert"
buttons="accept"
>
 
<script type="application/x-javascript" src="chrome://nomodal/content/Common.js" />
<script type="application/x-javascript" src="chrome://nomodal/content/Dialog.js" />
<script type="application/x-javascript" src="chrome://nomodal/content/Alert.js" />
 
<label id="text" />
</dialog>
/mozilla/nomodal/branch/001_own_dialogs/src/chrome/content/browser.js
0,0 → 1,16
// =====================================================================================================================
var NoModal = {
// -----------------------------------------------------------------------------------------------------------------
init: function()
{
},
 
// -----------------------------------------------------------------------------------------------------------------
onCommand: function(menuitem)
{
alert("NoModal.onCommand");
},
};
 
// == BOOTSTRAP ========================================================================================================
window.addEventListener('load', NoModal.init, false);
/mozilla/nomodal/branch/001_own_dialogs/src/chrome/content/Alert.js
0,0 → 1,18
// =====================================================================================================================
NoModal.Dialog_Alert = function()
{
NoModal.Dialog.call(this);
}
NoModal.Dialog_Alert.prototype = {
// -----------------------------------------------------------------------------------------------------------------
onLoad: function()
{
NoModal.Dialog.prototype.onLoad.call(this);
 
return true;
},
}
NoModal.inherit(NoModal.Dialog_Alert, NoModal.Dialog);
 
// == REGISTER =========================================================================================================
NoModal.DialogClass = NoModal.Dialog_Alert;
/mozilla/nomodal/branch/001_own_dialogs/src/chrome/content/Common.js
0,0 → 1,17
// =====================================================================================================================
var NoModal = {
// -----------------------------------------------------------------------------------------------------------------
inherit: function(child, supertype)
{
child.prototype.__proto__ = supertype.prototype;
},
 
// -----------------------------------------------------------------------------------------------------------------
startup: function()
{
Components.utils.import("resource://nomodal_modules/DialogParams.jsm");
},
}
 
// == BOOTSTRAP ========================================================================================================
NoModal.startup();
/mozilla/nomodal/branch/001_own_dialogs/src/chrome/content/Confirm.xul
0,0 → 1,16
<?xml version="1.0"?>
 
<?xml-stylesheet href="chrome://nomodal/content/dialog.css" type="text/css"?>
 
<dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
xmlns:html="http://www.w3.org/1999/xhtml"
title="Confirm"
buttons="accept,cancel"
>
 
<script type="application/x-javascript" src="chrome://nomodal/content/Common.js" />
<script type="application/x-javascript" src="chrome://nomodal/content/Dialog.js" />
<script type="application/x-javascript" src="chrome://nomodal/content/Confirm.js" />
 
<label id="text" />
</dialog>
/mozilla/nomodal/branch/001_own_dialogs/src/install.rdf
0,0 → 1,27
<?xml version="1.0"?>
 
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
 
<Description about="urn:mozilla:install-manifest">
<em:id>{f4b488a5-3c73-4e28-b0c9-e03c9a71af65}</em:id>
<em:version>1.0</em:version>
<em:type>2</em:type>
 
<!-- firefox -->
<em:targetApplication>
<Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minVersion>3.5.0</em:minVersion>
<em:maxVersion>4.0.*</em:maxVersion>
</Description>
</em:targetApplication>
 
<em:name>NoModal</em:name>
<em:description></em:description>
<em:creator>Anatoli Klassen</em:creator>
<em:homepageURL></em:homepageURL>
<em:updateURL></em:updateURL>
<em:updateKey></em:updateKey>
</Description>
</RDF>
/mozilla/nomodal/branch/001_own_dialogs/src/chrome.manifest
0,0 → 1,4
content nomodal chrome/content/
resource nomodal_modules modules/
overlay chrome://browser/content/browser.xul chrome://nomodal/content/browser.xul