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

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: Fixed unit test compilation error, updated comments Created 5 years, 5 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 std::vector<base::string16> usernames;
31 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
32 usernames.push_back(form->username_value);
33
34 views::Combobox* combobox =
35 new views::Combobox(new ui::SimpleComboboxModel(usernames));
36 return combobox;
37 }
38
39 } // namespace
40
41 CredentialsSelectionView::CredentialsSelectionView(
42 ManagePasswordsBubbleModel* manage_passwords_bubble_model,
43 const std::vector<const autofill::PasswordForm*>& password_forms)
44 : password_forms_(password_forms) {
45 DCHECK(!password_forms.empty());
46
47 // Layout.
48 views::GridLayout* layout = new views::GridLayout(this);
49 SetLayoutManager(layout);
50
51 // ColumnSet.
52 int column_set_id = 0;
53 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id);
54 column_set->AddPaddingColumn(0, views::kItemLabelSpacing);
55 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 2,
56 views::GridLayout::USE_PREF, 0, 0);
57 column_set->AddPaddingColumn(0,
58 views::kUnrelatedControlLargeHorizontalSpacing);
59 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
60 views::GridLayout::USE_PREF, 0, 0);
61 column_set->AddPaddingColumn(0, views::kItemLabelSpacing);
62
63 // The username combobox and password label.
64 layout->StartRowWithPadding(0, column_set_id, 0,
65 views::kRelatedControlVerticalSpacing);
66 combobox_ = GenerateUsernameCombobox(
67 manage_passwords_bubble_model->local_credentials().get());
68 combobox_->set_listener(this);
69 layout->AddView(combobox_);
70 label_ = GeneratePasswordLabel(*password_forms[0]);
71 layout->AddView(label_);
72
73 GetLayoutManager()->Layout(this);
74 }
75
76 const autofill::PasswordForm*
77 CredentialsSelectionView::GetSelectedCredentials() {
78 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.
79 return password_forms_[combobox_->selected_index()];
80 }
81
82 void CredentialsSelectionView::OnPerformAction(views::Combobox* source) {
83 label_->SetText(GetSelectedCredentials()->password_value);
84 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698