diff options
Diffstat (limited to 'chromium/ui/views/bubble/bubble_dialog_model_host.cc')
-rw-r--r-- | chromium/ui/views/bubble/bubble_dialog_model_host.cc | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/chromium/ui/views/bubble/bubble_dialog_model_host.cc b/chromium/ui/views/bubble/bubble_dialog_model_host.cc index 3f2df684cd8..cee4c6b6ac6 100644 --- a/chromium/ui/views/bubble/bubble_dialog_model_host.cc +++ b/chromium/ui/views/bubble/bubble_dialog_model_host.cc @@ -21,6 +21,7 @@ #include "ui/views/layout/box_layout_view.h" #include "ui/views/layout/fill_layout.h" #include "ui/views/layout/layout_provider.h" +#include "ui/views/metadata/metadata_header_macros.h" #include "ui/views/metadata/metadata_impl_macros.h" #include "ui/views/view_class_properties.h" @@ -50,6 +51,7 @@ DialogContentType FieldTypeToContentType(ui::DialogModelField::Type type) { // StyledLabel. class CheckboxControl : public Checkbox { public: + METADATA_HEADER(CheckboxControl); CheckboxControl(std::unique_ptr<View> label, int label_line_height) : label_line_height_(label_line_height) { auto* layout = SetLayoutManager(std::make_unique<BoxLayout>()); @@ -90,10 +92,14 @@ class CheckboxControl : public Checkbox { const int label_line_height_; }; +BEGIN_METADATA(CheckboxControl, Checkbox) +END_METADATA + } // namespace class BubbleDialogModelHost::LayoutConsensusView : public View { public: + METADATA_HEADER(LayoutConsensusView); LayoutConsensusView(LayoutConsensusGroup* group, std::unique_ptr<View> view) : group_(group) { group->AddView(this); @@ -126,6 +132,9 @@ class BubbleDialogModelHost::LayoutConsensusView : public View { LayoutConsensusGroup* const group_; }; +BEGIN_METADATA(BubbleDialogModelHost, LayoutConsensusView, View) +END_METADATA + BubbleDialogModelHost::LayoutConsensusGroup::LayoutConsensusGroup() = default; BubbleDialogModelHost::LayoutConsensusGroup::~LayoutConsensusGroup() { DCHECK(children_.empty()); @@ -321,15 +330,6 @@ void BubbleDialogModelHost::Close() { model_.reset(); } -void BubbleDialogModelHost::SelectAllText(int unique_id) { - const DialogModelHostField& field_view_info = - FindDialogModelHostField(model_->GetFieldByUniqueId(unique_id)); - - DCHECK(field_view_info.focusable_view); - static_cast<views::Textfield*>(field_view_info.focusable_view) - ->SelectAll(false); -} - void BubbleDialogModelHost::OnFieldAdded(ui::DialogModelField* field) { switch (field->type(GetPassKey())) { case ui::DialogModelField::kButton: @@ -439,10 +439,11 @@ void BubbleDialogModelHost::AddOrUpdateCheckbox( const int line_height = label->GetLineHeight(); checkbox = std::make_unique<CheckboxControl>(std::move(label), line_height); } + checkbox->SetChecked(model_field->is_checked()); checkbox->SetCallback(base::BindRepeating( [](ui::DialogModelCheckbox* model_field, - util::PassKey<DialogModelHost> pass_key, Checkbox* checkbox, + base::PassKey<DialogModelHost> pass_key, Checkbox* checkbox, const ui::Event& event) { model_field->OnChecked(pass_key, checkbox->GetChecked()); }, @@ -462,7 +463,7 @@ void BubbleDialogModelHost::AddOrUpdateCombobox( : model_field->accessible_name(GetPassKey())); combobox->SetCallback(base::BindRepeating( [](ui::DialogModelCombobox* model_field, - util::PassKey<DialogModelHost> pass_key, Combobox* combobox) { + base::PassKey<DialogModelHost> pass_key, Combobox* combobox) { // TODO(pbos): This should be a subscription through the Combobox // directly, but Combobox right now doesn't support listening to // selected-index changes. @@ -490,10 +491,19 @@ void BubbleDialogModelHost::AddOrUpdateTextfield( : model_field->accessible_name(GetPassKey())); textfield->SetText(model_field->text()); + // If this textfield is initially focused the text should be initially + // selected as well. + base::Optional<int> initially_focused_field_id = + model_->initially_focused_field(GetPassKey()); + if (initially_focused_field_id && + model_field->unique_id(GetPassKey()) == initially_focused_field_id) { + textfield->SelectAll(true); + } + property_changed_subscriptions_.push_back( textfield->AddTextChangedCallback(base::BindRepeating( [](ui::DialogModelTextfield* model_field, - util::PassKey<DialogModelHost> pass_key, Textfield* textfield) { + base::PassKey<DialogModelHost> pass_key, Textfield* textfield) { model_field->OnTextChanged(pass_key, textfield->GetText()); }, model_field, GetPassKey(), textfield.get()))); |