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

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

Issue 2960843002: Edit button makes username editable in the password manager bubble. (Closed)
Patch Set: Renamed helper function and did forward declaration for view generator functions. Created 3 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/passwords/manage_password_items_view.h" 5 #include "chrome/browser/ui/views/passwords/manage_password_items_view.h"
6 6
7 #include <numeric> 7 #include <numeric>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" 12 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
13 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" 13 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h"
14 #include "chrome/browser/ui/views/harmony/chrome_layout_provider.h" 14 #include "chrome/browser/ui/views/harmony/chrome_layout_provider.h"
15 #include "chrome/browser/ui/views/harmony/chrome_typography.h" 15 #include "chrome/browser/ui/views/harmony/chrome_typography.h"
16 #include "chrome/grit/generated_resources.h" 16 #include "chrome/grit/generated_resources.h"
17 #include "components/password_manager/core/common/password_manager_ui.h"
17 #include "ui/base/l10n/l10n_util.h" 18 #include "ui/base/l10n/l10n_util.h"
18 #include "ui/base/resource/resource_bundle.h" 19 #include "ui/base/resource/resource_bundle.h"
19 #include "ui/resources/grit/ui_resources.h" 20 #include "ui/resources/grit/ui_resources.h"
20 #include "ui/views/controls/button/button.h" 21 #include "ui/views/controls/button/button.h"
21 #include "ui/views/controls/button/image_button.h" 22 #include "ui/views/controls/button/image_button.h"
22 #include "ui/views/controls/label.h" 23 #include "ui/views/controls/label.h"
23 #include "ui/views/controls/link.h" 24 #include "ui/views/controls/link.h"
24 #include "ui/views/controls/link_listener.h" 25 #include "ui/views/controls/link_listener.h"
26 #include "ui/views/controls/textfield/textfield.h"
25 #include "ui/views/layout/fill_layout.h" 27 #include "ui/views/layout/fill_layout.h"
26 #include "ui/views/layout/grid_layout.h" 28 #include "ui/views/layout/grid_layout.h"
27 29
28 namespace { 30 namespace {
29 31
30 enum ColumnSets { 32 enum ColumnSets {
31 ONE_COLUMN_SET, 33 ONE_COLUMN_SET,
32 TWO_COLUMN_SET, 34 TWO_COLUMN_SET,
33 THREE_COLUMN_SET 35 THREE_COLUMN_SET
34 }; 36 };
(...skipping 28 matching lines...) Expand all
63 column_set->AddPaddingColumn(0, column_divider); 65 column_set->AddPaddingColumn(0, column_divider);
64 column_set->AddColumn(views::GridLayout::TRAILING, 66 column_set->AddColumn(views::GridLayout::TRAILING,
65 views::GridLayout::FILL, 67 views::GridLayout::FILL,
66 0, 68 0,
67 views::GridLayout::USE_PREF, 69 views::GridLayout::USE_PREF,
68 0, 70 0,
69 0); 71 0);
70 } 72 }
71 } 73 }
72 74
73 std::unique_ptr<views::Label> GenerateUsernameLabel(
74 const autofill::PasswordForm& form) {
75 auto label = base::MakeUnique<views::Label>(GetDisplayUsername(form),
76 CONTEXT_DEPRECATED_SMALL);
77 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
78 return label;
79 }
80
81 std::unique_ptr<views::Label> GeneratePasswordLabel(
82 const autofill::PasswordForm& form) {
83 base::string16 text =
84 form.federation_origin.unique()
85 ? form.password_value
86 : l10n_util::GetStringFUTF16(
87 IDS_PASSWORDS_VIA_FEDERATION,
88 base::UTF8ToUTF16(form.federation_origin.host()));
89 auto label = base::MakeUnique<views::Label>(text, CONTEXT_DEPRECATED_SMALL);
90 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
91 if (form.federation_origin.unique())
92 label->SetObscured(true);
93 return label;
94 }
95
96 std::unique_ptr<views::ImageButton> GenerateDeleteButton( 75 std::unique_ptr<views::ImageButton> GenerateDeleteButton(
97 views::ButtonListener* listener) { 76 views::ButtonListener* listener) {
98 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 77 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
99 std::unique_ptr<views::ImageButton> button(new views::ImageButton(listener)); 78 std::unique_ptr<views::ImageButton> button(new views::ImageButton(listener));
100 button->SetImage(views::ImageButton::STATE_NORMAL, 79 button->SetImage(views::ImageButton::STATE_NORMAL,
101 rb->GetImageNamed(IDR_CLOSE_2).ToImageSkia()); 80 rb->GetImageNamed(IDR_CLOSE_2).ToImageSkia());
102 button->SetImage(views::ImageButton::STATE_HOVERED, 81 button->SetImage(views::ImageButton::STATE_HOVERED,
103 rb->GetImageNamed(IDR_CLOSE_2_H).ToImageSkia()); 82 rb->GetImageNamed(IDR_CLOSE_2_H).ToImageSkia());
104 button->SetImage(views::ImageButton::STATE_PRESSED, 83 button->SetImage(views::ImageButton::STATE_PRESSED,
105 rb->GetImageNamed(IDR_CLOSE_2_P).ToImageSkia()); 84 rb->GetImageNamed(IDR_CLOSE_2_P).ToImageSkia());
(...skipping 17 matching lines...) Expand all
123 undo_link->SetHorizontalAlignment(gfx::ALIGN_RIGHT); 102 undo_link->SetHorizontalAlignment(gfx::ALIGN_RIGHT);
124 undo_link->set_listener(listener); 103 undo_link->set_listener(listener);
125 undo_link->SetUnderline(false); 104 undo_link->SetUnderline(false);
126 undo_link->SetFontList(views::style::GetFont(CONTEXT_DEPRECATED_SMALL, 105 undo_link->SetFontList(views::style::GetFont(CONTEXT_DEPRECATED_SMALL,
127 views::style::STYLE_LINK)); 106 views::style::STYLE_LINK));
128 return undo_link; 107 return undo_link;
129 } 108 }
130 109
131 } // namespace 110 } // namespace
132 111
112 std::unique_ptr<views::Label> GenerateUsernameLabel(
113 const autofill::PasswordForm& form) {
114 auto label = base::MakeUnique<views::Label>(GetDisplayUsername(form),
115 CONTEXT_DEPRECATED_SMALL);
116 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
117 return label;
118 }
119
120 std::unique_ptr<views::Textfield> GenerateUsernameEditable(
121 const autofill::PasswordForm& form) {
122 auto editable = base::MakeUnique<views::Textfield>();
123 editable->SetText(form.username_value);
124 return editable;
125 }
126
127 std::unique_ptr<views::Label> GeneratePasswordLabel(
128 const autofill::PasswordForm& form) {
129 base::string16 text =
130 form.federation_origin.unique()
131 ? form.password_value
132 : l10n_util::GetStringFUTF16(
133 IDS_PASSWORDS_VIA_FEDERATION,
134 base::UTF8ToUTF16(form.federation_origin.host()));
135 auto label = base::MakeUnique<views::Label>(text, CONTEXT_DEPRECATED_SMALL);
136 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
137 if (form.federation_origin.unique())
138 label->SetObscured(true);
139 return label;
140 }
141
133 // Manage credentials: stores credentials state and adds proper row to layout 142 // Manage credentials: stores credentials state and adds proper row to layout
134 // based on credential state. 143 // based on credential state.
135 class ManagePasswordItemsView::PasswordFormRow : public views::ButtonListener, 144 class ManagePasswordItemsView::PasswordFormRow : public views::ButtonListener,
136 public views::LinkListener { 145 public views::LinkListener {
137 public: 146 public:
138 PasswordFormRow(ManagePasswordItemsView* host, 147 PasswordFormRow(ManagePasswordItemsView* host,
139 const autofill::PasswordForm* password_form, 148 const autofill::PasswordForm* password_form,
140 int fixed_height); 149 int fixed_height);
141 ~PasswordFormRow() override = default; 150 ~PasswordFormRow() override = default;
142 151
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 deleted 318 deleted
310 ? ManagePasswordsBubbleModel::REMOVE_PASSWORD 319 ? ManagePasswordsBubbleModel::REMOVE_PASSWORD
311 : ManagePasswordsBubbleModel::ADD_PASSWORD); 320 : ManagePasswordsBubbleModel::ADD_PASSWORD);
312 } 321 }
313 322
314 void ManagePasswordItemsView::Refresh() { 323 void ManagePasswordItemsView::Refresh() {
315 DCHECK_NE(password_manager::ui::PENDING_PASSWORD_STATE, model_->state()); 324 DCHECK_NE(password_manager::ui::PENDING_PASSWORD_STATE, model_->state());
316 RemoveAllChildViews(true); 325 RemoveAllChildViews(true);
317 AddRows(); 326 AddRows();
318 } 327 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698