Bug 511627: Implement a dialog system for fennec [r=mark.finkle]
authorFabrice Desré <fabrice.desre@gmail.com>
Wed, 02 Sep 2009 10:15:22 -0400
changeset 65505 a1d5b8be6963c607e7f5376e57ec098cce964173
parent 65504 c6f107f8996f36e46c59e90caa1093ecc3516623
child 65506 c6d819aa527868cac18f33b7236360703b6b6913
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmark
bugs511627
Bug 511627: Implement a dialog system for fennec [r=mark.finkle]
mobile/chrome/content/bindings/dialog.xml
mobile/chrome/content/browser.css
mobile/chrome/content/browser.js
mobile/chrome/jar.mn
mobile/themes/hildon/browser.css
mobile/themes/wince/browser.css
new file mode 100644
--- /dev/null
+++ b/mobile/chrome/content/bindings/dialog.xml
@@ -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>
--- a/mobile/chrome/content/browser.css
+++ b/mobile/chrome/content/browser.css
@@ -154,8 +154,13 @@ richlistitem[opType="needs-disable"] .hi
 richlistitem[type="error"],
 richlistitem[type="warning"] {
   -moz-binding: url("chrome://browser/content/bindings/console.xml#error");
 }
 
 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%;
+}
--- a/mobile/chrome/content/browser.js
+++ b/mobile/chrome/content/browser.js
@@ -2002,16 +2002,42 @@ var SoftKeyboardObserver = {
   }
 };
 #endif
 
 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");
   // TODO: select the download with aID
 }
 
 var AlertsHelper = {
   _timeoutID: -1,
--- a/mobile/chrome/jar.mn
+++ b/mobile/chrome/jar.mn
@@ -8,16 +8,17 @@ chrome.jar:
   content/commandUtil.js               (content/commandUtil.js)
   content/bindings.xml                 (content/bindings.xml)
   content/tabs.xml                     (content/tabs.xml)
   content/checkbox.xml                 (content/checkbox.xml)
   content/notification.xml             (content/notification.xml)
   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)
   content/checkerboard.png             (content/checkerboard.png)
 % content branding %content/branding/
   content/preferences/richpref.xml     (content/preferences/richpref.xml)
 * content/sanitize.xul                 (content/sanitize.xul)
 * content/sanitize.js                  (content/sanitize.js)
--- a/mobile/themes/hildon/browser.css
+++ b/mobile/themes/hildon/browser.css
@@ -892,8 +892,14 @@ richpref {
 
 #select-list > option > image {
   min-width: 30px;
 }
 
 #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);
+}
--- a/mobile/themes/wince/browser.css
+++ b/mobile/themes/wince/browser.css
@@ -597,8 +597,14 @@ richpref {
 #select-buttons {
   padding: 0.55mm 1.1mm; /* row size & core spacing */
   -moz-box-pack: center;
 }
 
 #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);
+}