From 96cb3976d7aa8fbc2ff47d5ddda57862c6c3ab91 Mon Sep 17 00:00:00 2001 From: Justin Dolske Date: Wed, 24 Nov 2010 19:30:00 -0800 Subject: [PATCH] Bug 613760 - Tab-modal prompt dialog has no default button on os x. r=gavin, a=blocking --- .../components/prompts/content/tabprompts.xml | 27 +++++++++++---- .../components/prompts/src/CommonDialog.jsm | 33 +++++++++---------- 2 files changed, 36 insertions(+), 24 deletions(-) diff --git a/toolkit/components/prompts/content/tabprompts.xml b/toolkit/components/prompts/content/tabprompts.xml index c3d31ad8dca1..da6eef1b91c6 100644 --- a/toolkit/components/prompts/content/tabprompts.xml +++ b/toolkit/components/prompts/content/tabprompts.xml @@ -206,8 +206,6 @@ if (action == "default") { let bnum = this.args.defaultButtonNum || 0; let button = this.ui["button" + bnum]; - if (!button.hasAttribute("default")) - return; this.onButtonClick(bnum); } else { // action == "cancel" this.onButtonClick(1); // Cancel button @@ -225,14 +223,31 @@ group="system" action="this.onKeyAction('default', event);"/> -#ifndef XP_MACOSX - // Focus shift clears the default button. + let bnum = this.args.defaultButtonNum || 0; + let defaultButton = this.ui["button" + bnum]; + +#ifdef XP_MACOSX + // On OS X, the default button always stays marked as such (until + // the entire prompt blurs). + defaultButton.setAttribute("default", true); +#else + // On other platforms, the default button is only marked as such + // when no other button has focus. XUL buttons on not-OSX will + // react to pressing enter as a command, so you can't trigger the + // default without tabbing to it or something that isn't a button. + let focusedDefault = (event.originalTarget == defaultButton); + let someButtonFocused = event.originalTarget instanceof Ci.nsIDOMXULButtonElement; + defaultButton.setAttribute("default", focusedDefault || !someButtonFocused); +#endif + + + // If focus shifted to somewhere else in the browser, don't make + // the default button look active. let bnum = this.args.defaultButtonNum || 0; let button = this.ui["button" + bnum]; - button.setAttribute("default", event.originalTarget == button); + button.setAttribute("default", false); -#endif diff --git a/toolkit/components/prompts/src/CommonDialog.jsm b/toolkit/components/prompts/src/CommonDialog.jsm index 8dfebdb15f85..83a045bcd337 100644 --- a/toolkit/components/prompts/src/CommonDialog.jsm +++ b/toolkit/components/prompts/src/CommonDialog.jsm @@ -179,25 +179,22 @@ CommonDialog.prototype = { this.args.buttonNumClicked = 1; - // If there are no input fields on the dialog, select the default button. - // Otherwise, select the appropriate input field. - // XXX shouldn't we set an unfocused default even when a textbox is focused? - if (!this.hasInputField) { - // Set the default button (and focus it on non-OS X systems) - let b = 0; - if (this.args.defaultButtonNum) - b = this.args.defaultButtonNum; - let button = this.ui["button" + b]; - if (xulDialog) { - xulDialog.defaultButton = ['accept', 'cancel', 'extra1', 'extra2'][b]; - let isOSX = ("nsILocalFileMac" in Components.interfaces); - if (!isOSX) - button.focus(); - } else { - button.setAttribute("default", "true"); - button.focus(); - } + // Set the default button + let b = (this.args.defaultButtonNum || 0) + let button = this.ui["button" + b]; + if (xulDialog) + xulDialog.defaultButton = ['accept', 'cancel', 'extra1', 'extra2'][b]; + else + button.setAttribute("default", "true"); + + // Set default focus / selection. + if (!this.hasInputField) { + let isOSX = ("nsILocalFileMac" in Components.interfaces); + if (isOSX) + this.ui.infoBody.focus(); + else + button.focus(); } else { if (this.args.promptType == "promptPassword") this.ui.password1Textbox.select();