Bug 511627: Implement a dialog system for fennec [r=mark.finkle]

This commit is contained in:
Fabrice Desré 2009-09-02 10:15:22 -04:00
parent 90f46ea81a
commit ded6d0f1c3
6 changed files with 106 additions and 0 deletions

View File

@ -0,0 +1,62 @@
<?xml version="1.0"?>
<bindings
xmlns="http://www.mozilla.org/xbl"
xmlns:xbl="http://www.mozilla.org/xbl"
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<binding id="dialog">
<content>
<xul:stack>
<xul:box xbl:inherits="orient" class="dialog-dark" align="center">
<children/>
</xul:box>
<xul:image collapsed="true" top="-10" anonid="close" class="close-button"
onclick="document.getBindingParent(this).close()"/>
</xul:stack>
</content>
<implementation>
<field name="arguments"/>
<constructor><![CDATA[
if (!this.hasAttribute("orient"))
this.setAttribute("orient", "vertical");
if (this.hasAttribute("closebutton") && (this.getAttribute("closebutton") == "true"))
document.getAnonymousElementByAttribute(this, "anonid", "close").removeAttribute("collapsed");
this._closed = false;
if (this.hasAttribute("script")) {
try {
let loader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
loader.loadSubScript(this.getAttribute("script"), this);
} catch(e) {
throw("Dialog : Unable to load script : " + this.getAttribute("script") + "\n");
}
}
]]>
</constructor>
<method name="close">
<body>
if (this.hasAttribute("onclose")) {
var f = new Function(this.getAttribute("onclose"));
f.call(this);
}
this.parentNode.parentNode.removeChild(this.parentNode);
this._closed = true;
</body>
</method>
<method name="waitForClose">
<body>
let thread = Components.classes["@mozilla.org/thread-manager;1"]
.getService(Components.interfaces.nsIThreadManager)
.currentThread;
while (!this._closed)
thread.processNextEvent(true);
</body>
</method>
</implementation>
</binding>
</bindings>

View File

@ -159,3 +159,8 @@ richlistitem[type="warning"] {
richlistitem[type="message"]{
-moz-binding: url("chrome://browser/content/bindings/console.xml#message");
}
dialog {
-moz-binding: url("chrome://browser/content/bindings/dialog.xml#dialog");
font-size: 100%;
}

View File

@ -2007,6 +2007,32 @@ function getNotificationBox(aWindow) {
return Browser.getNotificationBox();
}
function importDialog(src, arguments) {
// load the dialog with a synchronous XHR
let xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance();
xhr.open("GET", src, false);
xhr.overrideMimeType("text/xml");
xhr.send(null);
if (!xhr.responseXML)
return null;
let doc = xhr.responseXML.documentElement;
var dialog = null;
// we need to insert before select-container if we want it to show correctly
let selectContainer = document.getElementById("select-container");
let parent = selectContainer.parentNode;
// create a full-screen semi-opaque box as a background
let back = document.createElement("box");
back.setAttribute("class", "modal-block");
dialog = back.appendChild(document.importNode(doc, true));
parent.insertBefore(back, selectContainer);
dialog.arguments = arguments;
return dialog;
}
function showDownloadsManager(aWindowContext, aID, aReason) {
BrowserUI.show(UIMODE_PANEL);
BrowserUI.switchPane("downloads-container");

View File

@ -13,6 +13,7 @@ chrome.jar:
content/bindings/extensions.xml (content/bindings/extensions.xml)
content/bindings/downloads.xml (content/bindings/downloads.xml)
content/bindings/console.xml (content/bindings/console.xml)
content/bindings/dialog.xml (content/bindings/dialog.xml)
content/browser.css (content/browser.css)
content/cursor.css (content/cursor.css)
content/content.css (content/content.css)

View File

@ -897,3 +897,9 @@ richpref {
#select-list > option[selected="true"] > image {
list-style-image: url("chrome://browser/skin/images/check-30.png");
}
.modal-block {
-moz-box-align: center;
-moz-box-pack: center;
background-color: rgba(128, 128, 128, 0.5);
}

View File

@ -602,3 +602,9 @@ richpref {
#select-list > option > image {
min-width: 30px;
}
.modal-block {
-moz-box-align: center;
-moz-box-pack: center;
background-color: rgba(128, 128, 128, 0.5);
}