Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Unified Diff: ui/views/window/dialog_client_view.cc

Issue 14230018: Handle dialog acclerators explicitly; nix default button switching. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Limit the focused view handling to LabelButton; update tests. Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/window/dialog_client_view.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/window/dialog_client_view.cc
diff --git a/ui/views/window/dialog_client_view.cc b/ui/views/window/dialog_client_view.cc
index a9862927f04cac3102bc9db972e81d6a632b7d1d..37e6e24d67ddf3b1130851c37899e6605e864053 100644
--- a/ui/views/window/dialog_client_view.cc
+++ b/ui/views/window/dialog_client_view.cc
@@ -43,8 +43,6 @@ DialogClientView::DialogClientView(Widget* owner, View* contents_view)
: ClientView(owner, contents_view),
ok_button_(NULL),
cancel_button_(NULL),
- default_button_(NULL),
- focus_manager_(NULL),
extra_view_(NULL),
footnote_view_(NULL),
notified_delegate_(false) {
@@ -55,14 +53,14 @@ DialogClientView::DialogClientView(Widget* owner, View* contents_view)
ui::NativeTheme::kColorId_DialogBackground);
set_background(views::Background::CreateSolidBackground(color));
}
-}
-DialogClientView::~DialogClientView() {
- if (focus_manager_)
- focus_manager_->RemoveFocusChangeListener(this);
- focus_manager_ = NULL;
+ // Add accelerators for the return and escape keys.
+ AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE));
+ AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE));
}
+DialogClientView::~DialogClientView() {}
+
void DialogClientView::AcceptWindow() {
// Only notify the delegate once. See |notified_delegate_|'s comment.
if (!notified_delegate_ && GetDialogDelegate()->Accept(false)) {
@@ -81,13 +79,10 @@ void DialogClientView::CancelWindow() {
void DialogClientView::UpdateDialogButtons() {
DialogDelegate* dialog = GetDialogDelegate();
const int buttons = dialog->GetDialogButtons();
- ui::Accelerator escape(ui::VKEY_ESCAPE, ui::EF_NONE);
if (buttons & ui::DIALOG_BUTTON_OK) {
if (!ok_button_) {
ok_button_ = CreateDialogButton(ui::DIALOG_BUTTON_OK);
- if (buttons & ui::DIALOG_BUTTON_CANCEL)
- ok_button_->AddAccelerator(escape);
AddChildView(ok_button_);
}
@@ -100,7 +95,6 @@ void DialogClientView::UpdateDialogButtons() {
if (buttons & ui::DIALOG_BUTTON_CANCEL) {
if (!cancel_button_) {
cancel_button_ = CreateDialogButton(ui::DIALOG_BUTTON_CANCEL);
- cancel_button_->AddAccelerator(escape);
AddChildView(cancel_button_);
}
@@ -109,12 +103,6 @@ void DialogClientView::UpdateDialogButtons() {
delete cancel_button_;
cancel_button_ = NULL;
}
-
- // Use the escape key to close the window if there are no dialog buttons.
- if (!has_dialog_buttons())
- AddAccelerator(escape);
- else
- ResetAccelerators();
}
///////////////////////////////////////////////////////////////////////////////
@@ -144,36 +132,6 @@ const DialogClientView* DialogClientView::AsDialogClientView() const {
return this;
}
-void DialogClientView::OnWillChangeFocus(View* focused_before,
- View* focused_now) {
- // New style dialogs do not move the default button with the focus.
- // TODO(msw|wittman): Remove this functionality once the new style has landed.
- if (DialogDelegate::UseNewStyle())
- return;
-
- // Make the newly focused button default or restore the dialog's default.
- const int default_button = GetDialogDelegate()->GetDefaultDialogButton();
- LabelButton* new_default_button = NULL;
- if (focused_now &&
- (focused_now->GetClassName() == LabelButton::kViewClassName)) {
- new_default_button = static_cast<LabelButton*>(focused_now);
- } else if (default_button == ui::DIALOG_BUTTON_OK && ok_button_) {
- new_default_button = ok_button_;
- } else if (default_button == ui::DIALOG_BUTTON_CANCEL && cancel_button_) {
- new_default_button = cancel_button_;
- }
-
- if (default_button_ && default_button_ != new_default_button)
- default_button_->SetIsDefault(false);
- default_button_ = new_default_button;
- if (default_button_ && !default_button_->is_default())
- default_button_->SetIsDefault(true);
-}
-
-void DialogClientView::OnDidChangeFocus(View* focused_before,
- View* focused_now) {
-}
-
////////////////////////////////////////////////////////////////////////////////
// DialogClientView, View overrides:
@@ -265,9 +223,27 @@ void DialogClientView::Layout() {
}
bool DialogClientView::AcceleratorPressed(const ui::Accelerator& accelerator) {
- DCHECK_EQ(accelerator.key_code(), ui::VKEY_ESCAPE);
- Close();
- return true;
+ if (accelerator.key_code() == ui::VKEY_ESCAPE) {
+ if (!cancel_button_ || !cancel_button_->AcceleratorPressed(accelerator))
+ CancelWindow();
+ return true;
+ }
+
+ if (accelerator.key_code() == ui::VKEY_RETURN) {
+ View* focused = GetFocusManager()->GetFocusedView();
+ const int default_button_id = GetDialogDelegate()->GetDefaultDialogButton();
+ Button* default_button = ok_button_;
+ if (default_button_id == ui::DIALOG_BUTTON_CANCEL && cancel_button_)
+ default_button = cancel_button_;
+ if (!(focused && focused->GetClassName() == LabelButton::kViewClassName &&
+ focused->AcceleratorPressed(accelerator)) &&
+ !(default_button && default_button->AcceleratorPressed(accelerator)))
+ AcceptWindow();
+ return true;
+ }
+
+ NOTREACHED();
+ return false;
}
void DialogClientView::ViewHierarchyChanged(bool is_add,
@@ -275,10 +251,6 @@ void DialogClientView::ViewHierarchyChanged(bool is_add,
View* child) {
ClientView::ViewHierarchyChanged(is_add, parent, child);
if (is_add && child == this) {
- focus_manager_ = GetFocusManager();
- if (focus_manager_)
- GetFocusManager()->AddFocusChangeListener(this);
-
UpdateDialogButtons();
CreateExtraView();
CreateFootnoteView();
@@ -308,8 +280,6 @@ DialogClientView::DialogClientView(View* contents_view)
: ClientView(NULL, contents_view),
ok_button_(NULL),
cancel_button_(NULL),
- default_button_(NULL),
- focus_manager_(NULL),
extra_view_(NULL),
footnote_view_(NULL),
notified_delegate_(false) {}
@@ -345,14 +315,14 @@ LabelButton* DialogClientView::CreateDialogButton(ui::DialogButton type) {
const string16 title = GetDialogDelegate()->GetDialogButtonLabel(type);
LabelButton* button = new LabelButton(this, title);
button->SetStyle(Button::STYLE_NATIVE_TEXTBUTTON);
- button->set_focusable(true);
const int kDialogMinButtonWidth = 75;
button->set_min_size(gfx::Size(kDialogMinButtonWidth, 0));
button->SetGroup(kButtonGroup);
if (type == GetDialogDelegate()->GetDefaultDialogButton()) {
- default_button_ = button;
+ // Make the button appear default, but handle the return key in this view.
button->SetIsDefault(true);
+ button->RemoveAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE));
}
return button;
}
« no previous file with comments | « ui/views/window/dialog_client_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698