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

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

Issue 218993006: Extracting the remaining ManagePasswordsBubbleView::Init code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rewrite. Created 6 years, 8 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 | Annotate | Revision Log
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_passwords_bubble_view.h" 5 #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h"
6 6
7 #include "chrome/browser/chrome_notification_types.h" 7 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/ui/browser.h" 8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/browser_finder.h" 9 #include "chrome/browser/ui/browser_finder.h"
10 #include "chrome/browser/ui/browser_window.h" 10 #include "chrome/browser/ui/browser_window.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 manage_passwords_bubble_model_( 112 manage_passwords_bubble_model_(
113 new ManagePasswordsBubbleModel(web_contents)), 113 new ManagePasswordsBubbleModel(web_contents)),
114 icon_view_(icon_view) { 114 icon_view_(icon_view) {
115 // Compensate for built-in vertical padding in the anchor view's image. 115 // Compensate for built-in vertical padding in the anchor view's image.
116 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); 116 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0));
117 set_notify_enter_exit_on_child(true); 117 set_notify_enter_exit_on_child(true);
118 } 118 }
119 119
120 ManagePasswordsBubbleView::~ManagePasswordsBubbleView() {} 120 ManagePasswordsBubbleView::~ManagePasswordsBubbleView() {}
121 121
122 void ManagePasswordsBubbleView::BuildColumnSet(views::GridLayout* layout,
123 ColumnSetType type) {
124 views::ColumnSet* column_set = layout->AddColumnSet(type);
125 column_set->AddPaddingColumn(0, views::kPanelHorizMargin);
126 switch (type) {
127 case SINGLE_VIEW_COLUMN_SET:
128 column_set->AddColumn(views::GridLayout::FILL,
129 views::GridLayout::FILL,
130 0,
131 views::GridLayout::USE_PREF,
132 0,
133 0);
134 break;
135
136 case DOUBLE_VIEW_COLUMN_SET:
137 column_set->AddColumn(views::GridLayout::TRAILING,
138 views::GridLayout::CENTER,
139 1,
140 views::GridLayout::USE_PREF,
141 0,
142 0);
143 column_set->AddPaddingColumn(0, views::kRelatedButtonHSpacing);
144 column_set->AddColumn(views::GridLayout::TRAILING,
145 views::GridLayout::CENTER,
146 0,
147 views::GridLayout::USE_PREF,
148 0,
149 0);
150 break;
151
152 default:
vabr (Chromium) 2014/04/02 08:38:52 I believe that if you remove the "default:" clause
Mike West 2014/04/02 09:40:35 You're entirely correct. Thanks for the suggestion
153 NOTREACHED();
154 break;
155 }
156 column_set->AddPaddingColumn(0, views::kPanelHorizMargin);
157 }
158
122 int ManagePasswordsBubbleView::GetMaximumFieldWidth(FieldType type) { 159 int ManagePasswordsBubbleView::GetMaximumFieldWidth(FieldType type) {
123 int maximum = 0; 160 int maximum = 0;
124 if (manage_passwords_bubble_model_->manage_passwords_bubble_state() != 161 if (manage_passwords_bubble_model_->manage_passwords_bubble_state() !=
125 ManagePasswordsBubbleModel::PASSWORD_TO_BE_SAVED) { 162 ManagePasswordsBubbleModel::PASSWORD_TO_BE_SAVED) {
126 // If we are in the PASSWORD_TO_BE_SAVED state we only display the 163 // If we are in the PASSWORD_TO_BE_SAVED state we only display the
127 // password that was just submitted and should not take these into account. 164 // password that was just submitted and should not take these into account.
128 for (autofill::PasswordFormMap::const_iterator i( 165 for (autofill::PasswordFormMap::const_iterator i(
129 manage_passwords_bubble_model_->best_matches().begin()); 166 manage_passwords_bubble_model_->best_matches().begin());
130 i != manage_passwords_bubble_model_->best_matches().end(); ++i) { 167 i != manage_passwords_bubble_model_->best_matches().end(); ++i) {
131 maximum = std::max(maximum, GetFieldWidth((*i->second), type)); 168 maximum = std::max(maximum, GetFieldWidth((*i->second), type));
(...skipping 25 matching lines...) Expand all
157 void ManagePasswordsBubbleView::Close() { 194 void ManagePasswordsBubbleView::Close() {
158 GetWidget()->Close(); 195 GetWidget()->Close();
159 } 196 }
160 197
161 void ManagePasswordsBubbleView::Init() { 198 void ManagePasswordsBubbleView::Init() {
162 using views::GridLayout; 199 using views::GridLayout;
163 200
164 GridLayout* layout = new GridLayout(this); 201 GridLayout* layout = new GridLayout(this);
165 SetFocusable(true); 202 SetFocusable(true);
166 SetLayoutManager(layout); 203 SetLayoutManager(layout);
204 BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET);
205 BuildColumnSet(layout, DOUBLE_VIEW_COLUMN_SET);
167 206
168 // This calculates the necessary widths for credential columns in the bubble. 207 // This calculates the necessary widths for credential columns in the bubble.
169 const int first_field_width = std::max( 208 const int first_field_width = std::max(
170 GetMaximumFieldWidth(USERNAME_FIELD), 209 GetMaximumFieldWidth(USERNAME_FIELD),
171 views::Label(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_DELETED)) 210 views::Label(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_DELETED))
172 .GetPreferredSize() 211 .GetPreferredSize()
173 .width()); 212 .width());
174 213
175 const int second_field_width = std::max( 214 const int second_field_width = std::max(
176 GetMaximumFieldWidth(PASSWORD_FIELD), 215 GetMaximumFieldWidth(PASSWORD_FIELD),
177 views::Label(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_UNDO)) 216 views::Label(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_UNDO))
178 .GetPreferredSize() 217 .GetPreferredSize()
179 .width()); 218 .width());
180 219
181 const int kSingleColumnSetId = 0; 220 // Build and populate the header.
182 views::ColumnSet* column_set = layout->AddColumnSet(kSingleColumnSetId);
183 column_set->AddPaddingColumn(0, views::kPanelHorizMargin);
184 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 0,
185 GridLayout::USE_PREF, 0, 0);
186 column_set->AddPaddingColumn(0, views::kPanelHorizMargin);
187
188 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 221 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
189 views::Label* title_label = 222 views::Label* title_label =
190 new views::Label(manage_passwords_bubble_model_->title()); 223 new views::Label(manage_passwords_bubble_model_->title());
191 title_label->SetMultiLine(true); 224 title_label->SetMultiLine(true);
192 title_label->SetFontList(rb->GetFontList(ui::ResourceBundle::MediumFont)); 225 title_label->SetFontList(rb->GetFontList(ui::ResourceBundle::MediumFont));
193 226
194 layout->StartRowWithPadding(0, kSingleColumnSetId, 227 layout->StartRowWithPadding(
195 0, views::kRelatedControlSmallVerticalSpacing); 228 0, SINGLE_VIEW_COLUMN_SET, 0, views::kRelatedControlSmallVerticalSpacing);
196 layout->AddView(title_label); 229 layout->AddView(title_label);
197 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); 230 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing);
198 231
199 if (manage_passwords_bubble_model_->manage_passwords_bubble_state() == 232 if (manage_passwords_bubble_model_->WaitingToSavePassword()) {
200 ManagePasswordsBubbleModel::PASSWORD_TO_BE_SAVED) { 233 // If we've got a password that we're deciding whether or not to save,
201 const int kSingleColumnCredentialsId = 1; 234 // then we need to display a single-view columnset containing the
202 views::ColumnSet* single_column = 235 // ManagePasswordItemView, followed by double-view columnset containing
203 layout->AddColumnSet(kSingleColumnCredentialsId); 236 // a "Save" and "Reject" button.
204 single_column->AddPaddingColumn(0, views::kPanelHorizMargin);
205 single_column->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
206 GridLayout::USE_PREF, 0, 0);
207 single_column->AddPaddingColumn(0, views::kPanelHorizMargin);
208
209 layout->StartRow(0, kSingleColumnCredentialsId);
210 ManagePasswordItemView* item = new ManagePasswordItemView( 237 ManagePasswordItemView* item = new ManagePasswordItemView(
211 manage_passwords_bubble_model_, 238 manage_passwords_bubble_model_,
212 manage_passwords_bubble_model_->pending_credentials(), 239 manage_passwords_bubble_model_->pending_credentials(),
213 first_field_width, second_field_width); 240 first_field_width,
214 item->SetBorder(views::Border::CreateSolidSidedBorder( 241 second_field_width,
215 1, 242 ManagePasswordItemView::FIRST_ITEM);
216 0, 243 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET);
217 1,
218 0,
219 GetNativeTheme()->GetSystemColor(
220 ui::NativeTheme::kColorId_EnabledMenuButtonBorderColor)));
221 layout->AddView(item); 244 layout->AddView(item);
222 245
223 const int kDoubleColumnSetId = 2;
224 views::ColumnSet* double_column_set =
225 layout->AddColumnSet(kDoubleColumnSetId);
226 double_column_set->AddPaddingColumn(0, views::kPanelHorizMargin);
227 double_column_set->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 1,
228 GridLayout::USE_PREF, 0, 0);
229 double_column_set->AddPaddingColumn(0, views::kRelatedButtonHSpacing);
230 double_column_set->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 0,
231 GridLayout::USE_PREF, 0, 0);
232 double_column_set->AddPaddingColumn(0, views::kPanelHorizMargin);
233
234 cancel_button_ = new views::LabelButton( 246 cancel_button_ = new views::LabelButton(
235 this, l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_CANCEL_BUTTON)); 247 this, l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_CANCEL_BUTTON));
236 cancel_button_->SetStyle(views::Button::STYLE_BUTTON); 248 cancel_button_->SetStyle(views::Button::STYLE_BUTTON);
237 save_button_ = new views::BlueButton( 249 save_button_ = new views::BlueButton(
238 this, l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_BUTTON)); 250 this, l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_BUTTON));
239 251
240 layout->StartRowWithPadding(0, kDoubleColumnSetId, 252 layout->StartRowWithPadding(
241 0, views::kRelatedControlVerticalSpacing); 253 0, DOUBLE_VIEW_COLUMN_SET, 0, views::kRelatedControlVerticalSpacing);
242 layout->AddView(save_button_); 254 layout->AddView(save_button_);
243 layout->AddView(cancel_button_); 255 layout->AddView(cancel_button_);
244 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 256 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
245 } else { 257 } else {
246 const int kSingleButtonSetId = 3; 258 // If we have a list of passwords to store for the current site, display
247 views::ColumnSet* single_column_set = 259 // them to the user for management. Otherwise, render a "No passwords for
248 layout->AddColumnSet(kSingleButtonSetId); 260 // this site" message.
249 single_column_set->AddPaddingColumn(0, views::kPanelHorizMargin); 261 //
250 single_column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 1, 262 // TODO(mkwst): Do we really want the "No passwords" case? It would probably
251 GridLayout::USE_PREF, 0, 0); 263 // be better to only clear the pending password upon navigation, rather than
252 single_column_set->AddPaddingColumn(0, 264 // as soon as the bubble closes.
253 views::kUnrelatedControlHorizontalSpacing); 265 int num_items_displayed = 0;
254 single_column_set->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 0,
255 GridLayout::USE_PREF, 0, 0);
256 single_column_set->AddPaddingColumn(0, views::kPanelHorizMargin);
257
258 const int kSingleColumnCredentialsId = 1;
259 views::ColumnSet* single_column =
260 layout->AddColumnSet(kSingleColumnCredentialsId);
261 single_column->AddPaddingColumn(0, views::kPanelHorizMargin);
262 single_column->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
263 GridLayout::USE_PREF, 0, 0);
264 single_column->AddPaddingColumn(0, views::kPanelHorizMargin);
265
266 if (!manage_passwords_bubble_model_->best_matches().empty()) { 266 if (!manage_passwords_bubble_model_->best_matches().empty()) {
267 for (autofill::PasswordFormMap::const_iterator i( 267 for (autofill::PasswordFormMap::const_iterator i(
268 manage_passwords_bubble_model_->best_matches().begin()); 268 manage_passwords_bubble_model_->best_matches().begin());
269 i != manage_passwords_bubble_model_->best_matches().end(); ++i) { 269 i != manage_passwords_bubble_model_->best_matches().end(); ++i) {
270 layout->StartRow(0, kSingleColumnCredentialsId);
271 ManagePasswordItemView* item = new ManagePasswordItemView( 270 ManagePasswordItemView* item = new ManagePasswordItemView(
272 manage_passwords_bubble_model_, *i->second, first_field_width, 271 manage_passwords_bubble_model_,
273 second_field_width); 272 *i->second,
274 if (i == manage_passwords_bubble_model_->best_matches().begin()) { 273 first_field_width,
275 item->SetBorder(views::Border::CreateSolidSidedBorder( 274 second_field_width,
276 1, 275 num_items_displayed == 0 ? ManagePasswordItemView::FIRST_ITEM
277 0, 276 : ManagePasswordItemView::MIDDLE_ITEM);
278 1, 277
279 0, 278 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET);
280 GetNativeTheme()->GetSystemColor(
281 ui::NativeTheme::kColorId_EnabledMenuButtonBorderColor)));
282 } else {
283 item->SetBorder(views::Border::CreateSolidSidedBorder(
284 0,
285 0,
286 1,
287 0,
288 GetNativeTheme()->GetSystemColor(
289 ui::NativeTheme::kColorId_EnabledMenuButtonBorderColor)));
290 }
291 layout->AddView(item); 279 layout->AddView(item);
280 num_items_displayed++;
292 } 281 }
293 } else if (!manage_passwords_bubble_model_->password_submitted()) { 282 } else if (!manage_passwords_bubble_model_->password_submitted()) {
294 views::Label* empty_label = new views::Label( 283 views::Label* empty_label = new views::Label(
295 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_NO_PASSWORDS)); 284 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_NO_PASSWORDS));
296 empty_label->SetMultiLine(true); 285 empty_label->SetMultiLine(true);
297 layout->StartRow(0, kSingleColumnSetId); 286
287 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET);
298 layout->AddView(empty_label); 288 layout->AddView(empty_label);
299 } 289 }
300 290
291 // If the user just saved a password, it won't be in the 'best matches' list
292 // we just walked through. Display it explicitly.
301 if (manage_passwords_bubble_model_->password_submitted()) { 293 if (manage_passwords_bubble_model_->password_submitted()) {
302 layout->StartRow(0, kSingleColumnCredentialsId);
303 ManagePasswordItemView* item = new ManagePasswordItemView( 294 ManagePasswordItemView* item = new ManagePasswordItemView(
304 manage_passwords_bubble_model_, 295 manage_passwords_bubble_model_,
305 manage_passwords_bubble_model_->pending_credentials(), 296 manage_passwords_bubble_model_->pending_credentials(),
306 first_field_width, second_field_width); 297 first_field_width,
307 if (manage_passwords_bubble_model_->best_matches().empty()) { 298 second_field_width,
308 item->SetBorder(views::Border::CreateSolidSidedBorder( 299 num_items_displayed ? ManagePasswordItemView::FIRST_ITEM
309 1, 300 : ManagePasswordItemView::MIDDLE_ITEM);
310 0, 301
311 1, 302 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET);
312 0,
313 GetNativeTheme()->GetSystemColor(
314 ui::NativeTheme::kColorId_EnabledMenuButtonBorderColor)));
315 } else {
316 item->SetBorder(views::Border::CreateSolidSidedBorder(
317 0,
318 0,
319 1,
320 0,
321 GetNativeTheme()->GetSystemColor(
322 ui::NativeTheme::kColorId_EnabledMenuButtonBorderColor)));
323 }
324 layout->AddView(item); 303 layout->AddView(item);
304 num_items_displayed++;
325 } 305 }
326 306
307 // Build a "manage" link and "done" button, and throw them both into a new
308 // row
309 // containing a double-view columnset.
327 manage_link_ = 310 manage_link_ =
328 new views::Link(manage_passwords_bubble_model_->manage_link()); 311 new views::Link(manage_passwords_bubble_model_->manage_link());
329 manage_link_->SetUnderline(false); 312 manage_link_->SetUnderline(false);
330 manage_link_->set_listener(this); 313 manage_link_->set_listener(this);
331 layout->StartRowWithPadding(0, kSingleButtonSetId,
332 0, views::kRelatedControlVerticalSpacing);
333 layout->AddView(manage_link_);
334 314
335 done_button_ = 315 done_button_ =
336 new views::LabelButton(this, l10n_util::GetStringUTF16(IDS_DONE)); 316 new views::LabelButton(this, l10n_util::GetStringUTF16(IDS_DONE));
337 done_button_->SetStyle(views::Button::STYLE_BUTTON); 317 done_button_->SetStyle(views::Button::STYLE_BUTTON);
318
319 layout->StartRowWithPadding(
320 0, DOUBLE_VIEW_COLUMN_SET, 0, views::kRelatedControlVerticalSpacing);
321 layout->AddView(manage_link_);
338 layout->AddView(done_button_); 322 layout->AddView(done_button_);
339 } 323 }
340 } 324 }
341 325
342 void ManagePasswordsBubbleView::WindowClosing() { 326 void ManagePasswordsBubbleView::WindowClosing() {
343 // Close() closes the window asynchronously, so by the time we reach here, 327 // Close() closes the window asynchronously, so by the time we reach here,
344 // |manage_passwords_bubble_| may have already been reset. 328 // |manage_passwords_bubble_| may have already been reset.
345 if (manage_passwords_bubble_ == this) 329 if (manage_passwords_bubble_ == this)
346 manage_passwords_bubble_ = NULL; 330 manage_passwords_bubble_ = NULL;
347 } 331 }
(...skipping 10 matching lines...) Expand all
358 manage_passwords_bubble_model_->manage_passwords_bubble_state() == 342 manage_passwords_bubble_model_->manage_passwords_bubble_state() ==
359 ManagePasswordsBubbleModel::PASSWORD_TO_BE_SAVED); 343 ManagePasswordsBubbleModel::PASSWORD_TO_BE_SAVED);
360 Close(); 344 Close();
361 } 345 }
362 346
363 void ManagePasswordsBubbleView::LinkClicked(views::Link* source, 347 void ManagePasswordsBubbleView::LinkClicked(views::Link* source,
364 int event_flags) { 348 int event_flags) {
365 DCHECK_EQ(source, manage_link_); 349 DCHECK_EQ(source, manage_link_);
366 manage_passwords_bubble_model_->OnManageLinkClicked(); 350 manage_passwords_bubble_model_->OnManageLinkClicked();
367 } 351 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698