summaryrefslogtreecommitdiffstats
path: root/chrome/views/dialog_delegate.cc
diff options
context:
space:
mode:
authorjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-31 22:19:43 +0000
committerjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-31 22:19:43 +0000
commit9c8108d9356604eec57bf3c880f1580eb41fd1c3 (patch)
tree57c45ff318a11d96f6604906c326ba9fe531c6c4 /chrome/views/dialog_delegate.cc
parent2346f78737731d1c4456a950b2e5123ea6f33fbc (diff)
downloadchromium_src-9c8108d9356604eec57bf3c880f1580eb41fd1c3.zip
chromium_src-9c8108d9356604eec57bf3c880f1580eb41fd1c3.tar.gz
chromium_src-9c8108d9356604eec57bf3c880f1580eb41fd1c3.tar.bz2
Some code in MessageBoxView was focusing the first focusable element in the view, overidding the focus set from the DialogDelegate.
We now only rely on the dialog delegate. Also changed dialog delegate so the default button is also the focused button. BUG=98 TEST=Open a javascript alert then confirm dialog. A button should be focused. Open all dialogs in Chrome. A button should be focused by default. Review URL: http://codereview.chromium.org/8786 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4334 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/views/dialog_delegate.cc')
-rw-r--r--chrome/views/dialog_delegate.cc25
1 files changed, 22 insertions, 3 deletions
diff --git a/chrome/views/dialog_delegate.cc b/chrome/views/dialog_delegate.cc
index 6a3ac212..8c63340 100644
--- a/chrome/views/dialog_delegate.cc
+++ b/chrome/views/dialog_delegate.cc
@@ -9,12 +9,31 @@
namespace views {
// Overridden from WindowDelegate:
+
+int DialogDelegate::GetDefaultDialogButton() const {
+ if (GetDialogButtons() & DIALOGBUTTON_OK)
+ return DIALOGBUTTON_OK;
+ if (GetDialogButtons() & DIALOGBUTTON_CANCEL)
+ return DIALOGBUTTON_CANCEL;
+ return DIALOGBUTTON_NONE;
+}
+
View* DialogDelegate::GetInitiallyFocusedView() const {
- // Try to focus the OK then the Cancel button if present.
+ // Focus the default button if any.
DialogClientView* dcv = GetDialogClientView();
- if (GetDialogButtons() & DIALOGBUTTON_OK)
+ int default_button = GetDefaultDialogButton();
+ if (default_button == DIALOGBUTTON_NONE)
+ return NULL;
+
+ if ((default_button & GetDialogButtons()) == 0) {
+ // The default button is a button we don't have.
+ NOTREACHED();
+ return NULL;
+ }
+
+ if (default_button & DIALOGBUTTON_OK)
return dcv->ok_button();
- if (GetDialogButtons() & DIALOGBUTTON_CANCEL)
+ if (default_button & DIALOGBUTTON_CANCEL)
return dcv->cancel_button();
return NULL;
}