summaryrefslogtreecommitdiffstats
path: root/chrome/views
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
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')
-rw-r--r--chrome/views/dialog_delegate.cc25
-rw-r--r--chrome/views/dialog_delegate.h8
-rw-r--r--chrome/views/message_box_view.cc12
-rw-r--r--chrome/views/message_box_view.h4
4 files changed, 26 insertions, 23 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;
}
diff --git a/chrome/views/dialog_delegate.h b/chrome/views/dialog_delegate.h
index 99b22ec..c578790 100644
--- a/chrome/views/dialog_delegate.h
+++ b/chrome/views/dialog_delegate.h
@@ -63,10 +63,10 @@ class DialogDelegate : public WindowDelegate {
// Returns the default dialog button. This should not be a mask as only one
// button should ever be the default button. Return DIALOGBUTTON_NONE if
- // there is no default.
- virtual int GetDefaultDialogButton() const {
- return DIALOGBUTTON_OK;
- }
+ // there is no default. Default behavior is to return DIALOGBUTTON_OK or
+ // DIALOGBUTTON_CANCEL (in that order) if they are present, DIALOGBUTTON_NONE
+ // otherwise.
+ virtual int GetDefaultDialogButton() const;
// Returns whether the specified dialog button is enabled.
virtual bool IsDialogButtonEnabled(DialogButton button) const {
diff --git a/chrome/views/message_box_view.cc b/chrome/views/message_box_view.cc
index beeb708..fc0b23f 100644
--- a/chrome/views/message_box_view.cc
+++ b/chrome/views/message_box_view.cc
@@ -80,24 +80,12 @@ void MessageBoxView::ViewHierarchyChanged(bool is_add,
if (child == this && is_add) {
if (prompt_field_)
prompt_field_->SelectAll();
- MessageLoop::current()->PostTask(FROM_HERE,
- focus_grabber_factory_.NewRunnableMethod(
- &MessageBoxView::FocusFirstFocusableControl));
}
}
///////////////////////////////////////////////////////////////////////////////
// MessageBoxView, private:
-void MessageBoxView::FocusFirstFocusableControl() {
- if (prompt_field_)
- prompt_field_->RequestFocus();
- else if (check_box_)
- check_box_->RequestFocus();
- else
- RequestFocus();
-}
-
void MessageBoxView::Init(int dialog_flags,
const std::wstring& default_prompt) {
message_label_->SetMultiLine(true);
diff --git a/chrome/views/message_box_view.h b/chrome/views/message_box_view.h
index a15fa89..6ca5932 100644
--- a/chrome/views/message_box_view.h
+++ b/chrome/views/message_box_view.h
@@ -66,10 +66,6 @@ class MessageBoxView : public views::View {
views::View* child);
private:
- // Called after ViewHierarchyChanged's call stack unwinds and returns to the
- // message loop to focus the first focusable element in the dialog box.
- void FocusFirstFocusableControl();
-
// Sets up the layout manager and initializes the prompt field. This should
// only be called once, from the constructor.
void Init(int dialog_flags, const std::wstring& default_prompt);