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

Side by Side Diff: chrome/browser/ui/views/passwords/credentials_selection_view.cc

Issue 1151373006: Update Confirmation UI for saved password change (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Browser test fixed Created 5 years, 4 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/views/passwords/credentials_selection_view.h"
6
7 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
8 #include "ui/base/models/simple_combobox_model.h"
9 #include "ui/base/resource/resource_bundle.h"
10 #include "ui/views/controls/button/button.h"
11 #include "ui/views/controls/combobox/combobox.h"
12 #include "ui/views/controls/label.h"
13 #include "ui/views/layout/fill_layout.h"
14 #include "ui/views/layout/grid_layout.h"
15 #include "ui/views/layout/layout_constants.h"
16
17 namespace {
18
19 views::Label* GeneratePasswordLabel(const autofill::PasswordForm& form) {
20 views::Label* label = new views::Label(form.password_value);
21 label->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList(
22 ui::ResourceBundle::SmallFont));
23 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
24 label->SetObscured(true);
25 return label;
26 }
27
28 views::Combobox* GenerateUsernameCombobox(
29 const std::vector<const autofill::PasswordForm*>& forms,
30 const base::string16& best_matched_username) {
31 std::vector<base::string16> usernames;
32 int best_matched_username_index = -1;
vabr (Chromium) 2015/07/31 12:48:13 To avoid issues with int type conversion, use size
dvadym 2015/08/03 15:44:07 Done.
33 for (size_t index = 0; index < forms.size(); ++index) {
34 usernames.push_back(forms[index]->username_value);
35 if (forms[index]->username_value == best_matched_username) {
36 best_matched_username_index = index;
37 }
38 }
39
40 views::Combobox* combobox =
41 new views::Combobox(new ui::SimpleComboboxModel(usernames));
42
43 if (best_matched_username_index >= 0) {
44 combobox->SetSelectedIndex(best_matched_username_index);
45 }
46 return combobox;
47 }
48
49 } // namespace
50
51 CredentialsSelectionView::CredentialsSelectionView(
52 ManagePasswordsBubbleModel* manage_passwords_bubble_model,
53 const std::vector<const autofill::PasswordForm*>& password_forms,
54 const base::string16& best_matched_username)
55 : password_forms_(password_forms) {
56 DCHECK(!password_forms.empty());
57
58 // Layout.
59 views::GridLayout* layout = new views::GridLayout(this);
60 SetLayoutManager(layout);
61
62 // ColumnSet.
63 int column_set_id = 0;
64 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id);
65 column_set->AddPaddingColumn(0, views::kItemLabelSpacing);
66 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
67 views::GridLayout::USE_PREF, 0, 0);
68 column_set->AddPaddingColumn(0,
69 views::kUnrelatedControlLargeHorizontalSpacing);
70 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
71 views::GridLayout::USE_PREF, 0, 0);
72 column_set->AddPaddingColumn(0, views::kItemLabelSpacing);
73
74 // The username combobox and password label.
75 layout->StartRowWithPadding(0, column_set_id, 0,
76 views::kRelatedControlVerticalSpacing);
77 combobox_ = GenerateUsernameCombobox(
78 manage_passwords_bubble_model->local_credentials().get(),
79 best_matched_username);
80 combobox_->set_listener(this);
81 layout->AddView(combobox_);
82 label_ = GeneratePasswordLabel(*GetSelectedCredentials());
83 layout->AddView(label_);
84
85 GetLayoutManager()->Layout(this);
86 }
87
88 const autofill::PasswordForm*
89 CredentialsSelectionView::GetSelectedCredentials() {
90 DCHECK_EQ(password_forms_.size(),
91 static_cast<size_t>(combobox_->model()->GetItemCount()));
92 return password_forms_[combobox_->selected_index()];
93 }
94
95 void CredentialsSelectionView::OnPerformAction(views::Combobox* source) {
96 label_->SetText(GetSelectedCredentials()->password_value);
97 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698