Commit 1c9581af authored by Peter Boström's avatar Peter Boström Committed by Commit Bot

Fix default accelerators in BubbleDialogModelHost

This removes UpdateAccelerators() as calls to View::ResetAccelerators()
remove dialog buttons' VKEY_RETURN default handlers as well. Removing
UpdateAccelerators() works as DialogModelField accelerators are const on
construction so they never need to be updated.

Bug: 1106422
Change-Id: I1d39cc3d72c6ab043381f8a5c858b1b2ed828558
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2355290
Commit-Queue: Peter Boström <pbos@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798183}
parent 79d81c4c
...@@ -70,12 +70,14 @@ BubbleDialogModelHost::BubbleDialogModelHost( ...@@ -70,12 +70,14 @@ BubbleDialogModelHost::BubbleDialogModelHost(
SetButtonLabel(ui::DIALOG_BUTTON_CANCEL, cancel_button->label()); SetButtonLabel(ui::DIALOG_BUTTON_CANCEL, cancel_button->label());
} }
// TODO(pbos): Consider refactoring ::SetExtraView() so it can be called after
// the Widget is created and still be picked up. Moving this to
// OnDialogInitialized() will not work until then.
auto* extra_button = model_->extra_button(GetPassKey()); auto* extra_button = model_->extra_button(GetPassKey());
if (extra_button) { if (extra_button) {
auto extra_view = OnViewCreatedForField(SetExtraView(std::make_unique<views::MdTextButton>(
std::make_unique<views::MdTextButton>(this, extra_button->label()); this, extra_button->label())),
view_to_field_[extra_view.get()] = extra_button; extra_button);
SetExtraView(std::move(extra_view));
} }
SetButtons(button_mask); SetButtons(button_mask);
...@@ -103,15 +105,13 @@ View* BubbleDialogModelHost::GetInitiallyFocusedView() { ...@@ -103,15 +105,13 @@ View* BubbleDialogModelHost::GetInitiallyFocusedView() {
void BubbleDialogModelHost::OnDialogInitialized() { void BubbleDialogModelHost::OnDialogInitialized() {
// Dialog buttons are added on dialog initialization. // Dialog buttons are added on dialog initialization.
auto* ok_button = model_->ok_button(GetPassKey()); if (GetOkButton())
if (ok_button) OnViewCreatedForField(GetOkButton(), model_->ok_button(GetPassKey()));
view_to_field_[GetOkButton()] = ok_button;
auto* cancel_button = model_->cancel_button(GetPassKey());
if (cancel_button)
view_to_field_[GetCancelButton()] = cancel_button;
UpdateAccelerators(); if (GetCancelButton()) {
OnViewCreatedForField(GetCancelButton(),
model_->cancel_button(GetPassKey()));
}
} }
void BubbleDialogModelHost::Close() { void BubbleDialogModelHost::Close() {
...@@ -166,7 +166,7 @@ void BubbleDialogModelHost::AddInitialFields() { ...@@ -166,7 +166,7 @@ void BubbleDialogModelHost::AddInitialFields() {
break; break;
} }
DCHECK(last_view); DCHECK(last_view);
view_to_field_[last_view] = field.get(); OnViewCreatedForField(last_view, field.get());
last_field_content_type = FieldTypeToContentType(field->type(GetPassKey())); last_field_content_type = FieldTypeToContentType(field->type(GetPassKey()));
// TODO(pbos): Update logic here when mixing types. // TODO(pbos): Update logic here when mixing types.
...@@ -278,18 +278,18 @@ void BubbleDialogModelHost::OnPerformAction(Combobox* combobox) { ...@@ -278,18 +278,18 @@ void BubbleDialogModelHost::OnPerformAction(Combobox* combobox) {
FieldAsCombobox(view_to_field_[combobox])); FieldAsCombobox(view_to_field_[combobox]));
} }
void BubbleDialogModelHost::UpdateAccelerators() { void BubbleDialogModelHost::OnViewCreatedForField(View* view,
// Dialog buttons can't be accessed before the widget is created. Delay until ui::DialogModelField* field) {
// ::OnDialogInitialized(). #if DCHECK_IS_ON()
if (!GetWidget()) // Make sure neither view nor field has been previously used.
return; for (const auto& kv : view_to_field_) {
DCHECK_NE(kv.first, view);
for (auto& kv : view_to_field_) { DCHECK_NE(kv.second, field);
View* const view = kv.first;
view->ResetAccelerators();
for (const auto& accelerator : kv.second->accelerators(GetPassKey()))
view->AddAccelerator(accelerator);
} }
#endif // DCHECK_IS_ON()
view_to_field_[view] = field;
for (const auto& accelerator : field->accelerators(GetPassKey()))
view->AddAccelerator(accelerator);
} }
View* BubbleDialogModelHost::FieldToView(ui::DialogModelField* field) { View* BubbleDialogModelHost::FieldToView(ui::DialogModelField* field) {
......
...@@ -68,7 +68,7 @@ class VIEWS_EXPORT BubbleDialogModelHost : public BubbleDialogDelegateView, ...@@ -68,7 +68,7 @@ class VIEWS_EXPORT BubbleDialogModelHost : public BubbleDialogDelegateView,
std::unique_ptr<views::View> field, std::unique_ptr<views::View> field,
const gfx::FontList& field_font); const gfx::FontList& field_font);
void UpdateAccelerators(); void OnViewCreatedForField(View* view, ui::DialogModelField* field);
void NotifyTextfieldTextChanged(views::Textfield* textfield); void NotifyTextfieldTextChanged(views::Textfield* textfield);
void NotifyComboboxSelectedIndexChanged(views::Combobox* combobox); void NotifyComboboxSelectedIndexChanged(views::Combobox* combobox);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment