Index: chrome/browser/ui/views/passwords/credentials_selection_view.cc |
diff --git a/chrome/browser/ui/views/passwords/credentials_selection_view.cc b/chrome/browser/ui/views/passwords/credentials_selection_view.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2beba0f6d62210f30b7049b6001e920ccf196fec |
--- /dev/null |
+++ b/chrome/browser/ui/views/passwords/credentials_selection_view.cc |
@@ -0,0 +1,84 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/ui/views/passwords/credentials_selection_view.h" |
+ |
+#include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" |
+#include "ui/base/models/simple_combobox_model.h" |
+#include "ui/base/resource/resource_bundle.h" |
+#include "ui/views/controls/button/button.h" |
+#include "ui/views/controls/combobox/combobox.h" |
+#include "ui/views/controls/label.h" |
+#include "ui/views/layout/fill_layout.h" |
+#include "ui/views/layout/grid_layout.h" |
+#include "ui/views/layout/layout_constants.h" |
+ |
+namespace { |
+ |
+views::Label* GeneratePasswordLabel(const autofill::PasswordForm& form) { |
+ views::Label* label = new views::Label(form.password_value); |
+ label->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( |
+ ui::ResourceBundle::SmallFont)); |
+ label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
+ label->SetObscured(true); |
+ return label; |
+} |
+ |
+views::Combobox* GenerateUsernameCombobox( |
+ const std::vector<const autofill::PasswordForm*>& forms) { |
+ std::vector<base::string16> usernames; |
+ for (const auto& form : forms) |
vabr (Chromium)
2015/07/24 08:24:29
const auto& -> const auto*
The elements of |forms|
dvadym
2015/07/24 16:42:39
Thanks
|
+ usernames.push_back(form->username_value); |
+ |
+ views::Combobox* combobox = |
+ new views::Combobox(new ui::SimpleComboboxModel(usernames)); |
+ return combobox; |
+} |
+ |
+} // namespace |
+ |
+CredentialsSelectionView::CredentialsSelectionView( |
+ ManagePasswordsBubbleModel* manage_passwords_bubble_model, |
+ const std::vector<const autofill::PasswordForm*>& password_forms) |
+ : password_forms_(password_forms) { |
+ DCHECK(!password_forms.empty()); |
+ |
+ // Layout. |
+ views::GridLayout* layout = new views::GridLayout(this); |
+ SetLayoutManager(layout); |
+ |
+ // ColumnSet. |
+ int column_set_id = 0; |
+ views::ColumnSet* column_set = layout->AddColumnSet(column_set_id); |
+ column_set->AddPaddingColumn(0, views::kItemLabelSpacing); |
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 2, |
+ views::GridLayout::USE_PREF, 0, 0); |
+ column_set->AddPaddingColumn(0, |
+ views::kUnrelatedControlLargeHorizontalSpacing); |
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, |
+ views::GridLayout::USE_PREF, 0, 0); |
+ column_set->AddPaddingColumn(0, views::kItemLabelSpacing); |
+ |
+ // The username combobox and password label. |
+ layout->StartRowWithPadding(0, column_set_id, 0, |
+ views::kRelatedControlVerticalSpacing); |
+ combobox_ = GenerateUsernameCombobox( |
+ manage_passwords_bubble_model->local_credentials().get()); |
+ combobox_->set_listener(this); |
+ layout->AddView(combobox_); |
+ label_ = GeneratePasswordLabel(*password_forms[0]); |
+ layout->AddView(label_); |
+ |
+ GetLayoutManager()->Layout(this); |
+} |
+ |
+const autofill::PasswordForm* |
+CredentialsSelectionView::GetSelectedCredentials() { |
+ DCHECK_EQ((int)password_forms_.size(), combobox_->model()->GetItemCount()); |
vabr (Chromium)
2015/07/24 08:24:29
First, no C-style casting, please. Do use static_c
dvadym
2015/07/24 16:42:39
Done.
|
+ return password_forms_[combobox_->selected_index()]; |
+} |
+ |
+void CredentialsSelectionView::OnPerformAction(views::Combobox* source) { |
+ label_->SetText(GetSelectedCredentials()->password_value); |
+} |