summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/views/constrained_window_impl.cc9
-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
5 files changed, 33 insertions, 25 deletions
diff --git a/chrome/browser/views/constrained_window_impl.cc b/chrome/browser/views/constrained_window_impl.cc
index c687041..abd10fa 100644
--- a/chrome/browser/views/constrained_window_impl.cc
+++ b/chrome/browser/views/constrained_window_impl.cc
@@ -868,8 +868,13 @@ void ConstrainedWindowImpl::ActivateConstrainedWindow() {
// better find whether the inner window should get focus.
::SetFocus(constrained_contents_->GetContainerHWND());
} else {
- // Give our window the focus so we get keyboard messages.
- ::SetFocus(GetHWND());
+ views::View* view_to_focus = NULL;
+ if (window_delegate())
+ view_to_focus = window_delegate()->GetInitiallyFocusedView();
+ if (view_to_focus)
+ view_to_focus->RequestFocus();
+ else // Give our window the focus so we get keyboard messages.
+ ::SetFocus(GetHWND());
}
}
}
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);