Bug 558202 - enter/escape keys don't work correctly in confirmEx in Fennec [r=mfinkle]
authorMatt Brubeck <mbrubeck@mozilla.com>
Fri, 09 Apr 2010 00:59:23 -0400
changeset 66120 e8a1785de0703ec369dc45856c2eef6b94983c53
parent 66119 ef3ee6fef78fc7918cbfb75e93bab6777d78365a
child 66121 576a6bcdb62bfb85999ef3cd963a93ba6a370d72
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)
reviewersmfinkle
bugs558202
Bug 558202 - enter/escape keys don't work correctly in confirmEx in Fennec [r=mfinkle]
mobile/chrome/content/prompt/prompt.js
mobile/components/PromptService.js
--- a/mobile/chrome/content/prompt/prompt.js
+++ b/mobile/chrome/content/prompt/prompt.js
@@ -30,17 +30,21 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 var PromptHelper = {
     
     closeDialog : function(confirm, id) {
       let dialog = document.getElementById(id);
-      dialog.arguments.result = confirm;
+      if (typeof confirm == "boolean" && dialog.arguments && "defaultButton" in dialog.arguments)
+        // confirmEx always returns 1 when dismissed with "escape" (bug 345067).
+        dialog.arguments.result = confirm ? dialog.arguments.defaultButton : 1;
+      else
+        dialog.arguments.result = confirm;
       dialog.close();
     },
     
     //
     // alert dialog
     //
     onCloseAlert: function(dialog) {
         if (dialog.arguments) {
--- a/mobile/components/PromptService.js
+++ b/mobile/components/PromptService.js
@@ -226,20 +226,28 @@ promptService.prototype = {
     let doc = this.getDocument();
     if (!doc) {
       return this._getFallbackService().confirmEx(aParent, aTitle, aText, aButtonFlags, aButton0,
             aButton1, aButton2, aCheckMsg, aCheckState);
     }
 
     let numButtons = 0;
     let titles = [aButton0, aButton1, aButton2];
+
+    let defaultButton = 0;
+    if (aButtonFlags & Ci.nsIPromptService.BUTTON_POS_1_DEFAULT)
+      defaultButton = 1;
+    if (aButtonFlags & Ci.nsIPromptService.BUTTON_POS_2_DEFAULT)
+      defaultButton = 2;
     
-    var params = new Object();
-    params.result = false;
-    params.checkbox = aCheckState;
+    var params = {
+      result: false,
+      checkbox: aCheckState,
+      defaultButton: defaultButton
+    }
 
     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);
     this.sizeScrollableMsg("prompt-confirm-message", 25);
 
     doc.getElementById("prompt-confirm-checkbox").checked = aCheckState.value;