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

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

Issue 534543002: Clean up ManagePasswordsBubbleView and ManagePasswordItemView. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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_item_view.h" 5 #include "chrome/browser/ui/views/passwords/manage_password_item_view.h"
6 6
7 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" 7 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
8 #include "chrome/grit/generated_resources.h" 8 #include "chrome/grit/generated_resources.h"
9 #include "components/password_manager/core/common/password_manager_ui.h"
10 #include "ui/base/l10n/l10n_util.h" 9 #include "ui/base/l10n/l10n_util.h"
11 #include "ui/base/resource/resource_bundle.h" 10 #include "ui/base/resource/resource_bundle.h"
12 #include "ui/resources/grit/ui_resources.h" 11 #include "ui/resources/grit/ui_resources.h"
12 #include "ui/views/border.h"
13 #include "ui/views/controls/button/button.h" 13 #include "ui/views/controls/button/button.h"
14 #include "ui/views/controls/button/image_button.h" 14 #include "ui/views/controls/button/image_button.h"
15 #include "ui/views/controls/label.h"
16 #include "ui/views/controls/link.h"
17 #include "ui/views/controls/link_listener.h"
15 #include "ui/views/layout/fill_layout.h" 18 #include "ui/views/layout/fill_layout.h"
16 #include "ui/views/layout/grid_layout.h" 19 #include "ui/views/layout/grid_layout.h"
17 #include "ui/views/layout/layout_constants.h" 20 #include "ui/views/layout/layout_constants.h"
18 21
19 namespace { 22 namespace {
20 23
21 int FirstFieldWidth() { 24 int FirstFieldWidth() {
22 return std::max( 25 return std::max(
23 ManagePasswordsBubbleModel::UsernameFieldWidth(), 26 ManagePasswordsBubbleModel::UsernameFieldWidth(),
24 views::Label(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_DELETED)) 27 views::Label(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_DELETED))
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 views::Label* label = new views::Label(form.password_value); 85 views::Label* label = new views::Label(form.password_value);
83 label->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( 86 label->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList(
84 ui::ResourceBundle::SmallFont)); 87 ui::ResourceBundle::SmallFont));
85 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 88 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
86 label->SetObscured(true); 89 label->SetObscured(true);
87 return label; 90 return label;
88 } 91 }
89 92
90 } // namespace 93 } // namespace
91 94
92 // Pending View 95 // Render credentials in two columns: username and password.
96 class ManagePasswordItemView::PendingView : public views::View {
97 public:
98 explicit PendingView(ManagePasswordItemView* parent);
99
100 private:
101 virtual ~PendingView() {}
vabr (Chromium) 2014/09/02 13:29:28 Please do not inline the destructors in the classe
vasilii 2014/09/02 15:33:33 Done.
102 };
103
93 ManagePasswordItemView::PendingView::PendingView( 104 ManagePasswordItemView::PendingView::PendingView(
94 ManagePasswordItemView* parent) { 105 ManagePasswordItemView* parent) {
95 views::GridLayout* layout = new views::GridLayout(this); 106 views::GridLayout* layout = new views::GridLayout(this);
96 SetLayoutManager(layout); 107 SetLayoutManager(layout);
97 108
98 BuildColumnSet(layout, TWO_COLUMN_SET); 109 BuildColumnSet(layout, TWO_COLUMN_SET);
99 layout->StartRowWithPadding( 110 layout->StartRowWithPadding(
100 0, TWO_COLUMN_SET, 0, views::kRelatedControlVerticalSpacing); 111 0, TWO_COLUMN_SET, 0, views::kRelatedControlVerticalSpacing);
101 layout->AddView(GenerateUsernameLabel(parent->password_form_)); 112 layout->AddView(GenerateUsernameLabel(parent->password_form_));
102 layout->AddView(GeneratePasswordLabel(parent->password_form_)); 113 layout->AddView(GeneratePasswordLabel(parent->password_form_));
103 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 114 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
104 } 115 }
105 116
106 ManagePasswordItemView::PendingView::~PendingView() { 117 // Render credentials in three columns: username, password, and delete.
107 } 118 class ManagePasswordItemView::ManageView : public views::View,
119 public views::ButtonListener {
120 public:
121 explicit ManageView(ManagePasswordItemView* parent);
108 122
109 // Manage View 123 private:
124 virtual ~ManageView() {}
125
126 // views::ButtonListener:
127 virtual void ButtonPressed(views::Button* sender,
128 const ui::Event& event) OVERRIDE;
129
130 views::ImageButton* delete_button_;
131 ManagePasswordItemView* parent_;
132 };
133
110 ManagePasswordItemView::ManageView::ManageView(ManagePasswordItemView* parent) 134 ManagePasswordItemView::ManageView::ManageView(ManagePasswordItemView* parent)
111 : parent_(parent) { 135 : parent_(parent) {
112 views::GridLayout* layout = new views::GridLayout(this); 136 views::GridLayout* layout = new views::GridLayout(this);
113 SetLayoutManager(layout); 137 SetLayoutManager(layout);
114 138
115 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 139 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
116 delete_button_ = new views::ImageButton(this); 140 delete_button_ = new views::ImageButton(this);
117 delete_button_->SetImage(views::ImageButton::STATE_NORMAL, 141 delete_button_->SetImage(views::ImageButton::STATE_NORMAL,
118 rb->GetImageNamed(IDR_CLOSE_2).ToImageSkia()); 142 rb->GetImageNamed(IDR_CLOSE_2).ToImageSkia());
119 delete_button_->SetImage(views::ImageButton::STATE_HOVERED, 143 delete_button_->SetImage(views::ImageButton::STATE_HOVERED,
120 rb->GetImageNamed(IDR_CLOSE_2_H).ToImageSkia()); 144 rb->GetImageNamed(IDR_CLOSE_2_H).ToImageSkia());
121 delete_button_->SetImage(views::ImageButton::STATE_PRESSED, 145 delete_button_->SetImage(views::ImageButton::STATE_PRESSED,
122 rb->GetImageNamed(IDR_CLOSE_2_P).ToImageSkia()); 146 rb->GetImageNamed(IDR_CLOSE_2_P).ToImageSkia());
123 147
124 BuildColumnSet(layout, THREE_COLUMN_SET); 148 BuildColumnSet(layout, THREE_COLUMN_SET);
125 layout->StartRowWithPadding( 149 layout->StartRowWithPadding(
126 0, THREE_COLUMN_SET, 0, views::kRelatedControlVerticalSpacing); 150 0, THREE_COLUMN_SET, 0, views::kRelatedControlVerticalSpacing);
127 layout->AddView(GenerateUsernameLabel(parent->password_form_)); 151 layout->AddView(GenerateUsernameLabel(parent->password_form_));
128 layout->AddView(GeneratePasswordLabel(parent->password_form_)); 152 layout->AddView(GeneratePasswordLabel(parent->password_form_));
129 layout->AddView(delete_button_); 153 layout->AddView(delete_button_);
130 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 154 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
131 } 155 }
132 156
133 void ManagePasswordItemView::ManageView::ButtonPressed(views::Button* sender, 157 void ManagePasswordItemView::ManageView::ButtonPressed(views::Button* sender,
134 const ui::Event& event) { 158 const ui::Event& event) {
135 DCHECK_EQ(delete_button_, sender); 159 DCHECK_EQ(delete_button_, sender);
136 parent_->NotifyClickedDelete(); 160 parent_->NotifyClickedDelete();
137 } 161 }
138 162
139 ManagePasswordItemView::ManageView::~ManageView() { 163 // Render a notification to the user that a password has been removed, and
140 } 164 // offer an undo link.
165 class ManagePasswordItemView::UndoView : public views::View,
166 public views::LinkListener {
167 public:
168 explicit UndoView(ManagePasswordItemView* parent);
141 169
142 // Undo View 170 private:
171 virtual ~UndoView() {}
172
173 // views::LinkListener:
174 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
175
176 views::Link* undo_link_;
177 ManagePasswordItemView* parent_;
178 };
179
143 ManagePasswordItemView::UndoView::UndoView(ManagePasswordItemView* parent) 180 ManagePasswordItemView::UndoView::UndoView(ManagePasswordItemView* parent)
144 : parent_(parent) { 181 : parent_(parent) {
145 views::GridLayout* layout = new views::GridLayout(this); 182 views::GridLayout* layout = new views::GridLayout(this);
146 SetLayoutManager(layout); 183 SetLayoutManager(layout);
147 184
148 views::Label* text = 185 views::Label* text =
149 new views::Label(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_DELETED)); 186 new views::Label(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_DELETED));
150 text->SetHorizontalAlignment(gfx::ALIGN_LEFT); 187 text->SetHorizontalAlignment(gfx::ALIGN_LEFT);
151 text->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( 188 text->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList(
152 ui::ResourceBundle::SmallFont)); 189 ui::ResourceBundle::SmallFont));
(...skipping 13 matching lines...) Expand all
166 layout->AddView(undo_link_); 203 layout->AddView(undo_link_);
167 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 204 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
168 } 205 }
169 206
170 void ManagePasswordItemView::UndoView::LinkClicked(views::Link* sender, 207 void ManagePasswordItemView::UndoView::LinkClicked(views::Link* sender,
171 int event_flags) { 208 int event_flags) {
172 DCHECK_EQ(undo_link_, sender); 209 DCHECK_EQ(undo_link_, sender);
173 parent_->NotifyClickedUndo(); 210 parent_->NotifyClickedUndo();
174 } 211 }
175 212
176 ManagePasswordItemView::UndoView::~UndoView() {
177 }
178
179 // ManagePasswordItemView 213 // ManagePasswordItemView
180 ManagePasswordItemView::ManagePasswordItemView( 214 ManagePasswordItemView::ManagePasswordItemView(
181 ManagePasswordsBubbleModel* manage_passwords_bubble_model, 215 ManagePasswordsBubbleModel* manage_passwords_bubble_model,
182 autofill::PasswordForm password_form, 216 autofill::PasswordForm password_form,
183 password_manager::ui::PasswordItemPosition position) 217 password_manager::ui::PasswordItemPosition position)
184 : model_(manage_passwords_bubble_model), 218 : model_(manage_passwords_bubble_model),
185 password_form_(password_form), 219 password_form_(password_form),
186 delete_password_(false) { 220 delete_password_(false) {
187 views::FillLayout* layout = new views::FillLayout(); 221 views::FillLayout* layout = new views::FillLayout();
188 SetLayoutManager(layout); 222 SetLayoutManager(layout);
(...skipping 13 matching lines...) Expand all
202 AddChildView(new PendingView(this)); 236 AddChildView(new PendingView(this));
203 } else { 237 } else {
204 AddChildView(new ManageView(this)); 238 AddChildView(new ManageView(this));
205 } 239 }
206 GetLayoutManager()->Layout(this); 240 GetLayoutManager()->Layout(this);
207 } 241 }
208 242
209 ManagePasswordItemView::~ManagePasswordItemView() { 243 ManagePasswordItemView::~ManagePasswordItemView() {
210 } 244 }
211 245
246 void ManagePasswordItemView::NotifyClickedDelete() {
247 delete_password_ = true;
248 Refresh();
249 }
250
251 void ManagePasswordItemView::NotifyClickedUndo() {
252 delete_password_ = false;
253 Refresh();
254 }
255
212 void ManagePasswordItemView::Refresh() { 256 void ManagePasswordItemView::Refresh() {
213 DCHECK(!password_manager::ui::IsPendingState(model_->state())); 257 DCHECK(!password_manager::ui::IsPendingState(model_->state()));
214 258
215 RemoveAllChildViews(true); 259 RemoveAllChildViews(true);
216 if (delete_password_) 260 if (delete_password_)
217 AddChildView(new UndoView(this)); 261 AddChildView(new UndoView(this));
218 else 262 else
219 AddChildView(new ManageView(this)); 263 AddChildView(new ManageView(this));
220 GetLayoutManager()->Layout(this); 264 GetLayoutManager()->Layout(this);
221 265
222 // After the view is consistent, notify the model that the password needs to 266 // After the view is consistent, notify the model that the password needs to
223 // be updated (either removed or put back into the store, as appropriate. 267 // be updated (either removed or put back into the store, as appropriate.
224 model_->OnPasswordAction(password_form_, 268 model_->OnPasswordAction(password_form_,
225 delete_password_ 269 delete_password_
226 ? ManagePasswordsBubbleModel::REMOVE_PASSWORD 270 ? ManagePasswordsBubbleModel::REMOVE_PASSWORD
227 : ManagePasswordsBubbleModel::ADD_PASSWORD); 271 : ManagePasswordsBubbleModel::ADD_PASSWORD);
228 } 272 }
229
230 void ManagePasswordItemView::NotifyClickedDelete() {
231 delete_password_ = true;
232 Refresh();
233 }
234
235 void ManagePasswordItemView::NotifyClickedUndo() {
236 delete_password_ = false;
237 Refresh();
238 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698