OLD | NEW |
---|---|
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 Loading... | |
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, | |
markusheintz_
2014/04/04 14:56:25
I'm still not convinced that this really makes the
| |
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 column_set->AddPaddingColumn(0, views::kPanelHorizMargin); | |
153 } | |
154 | |
122 int ManagePasswordsBubbleView::GetMaximumFieldWidth(FieldType type) { | 155 int ManagePasswordsBubbleView::GetMaximumFieldWidth(FieldType type) { |
123 int maximum = 0; | 156 int maximum = 0; |
124 if (manage_passwords_bubble_model_->manage_passwords_bubble_state() != | 157 if (manage_passwords_bubble_model_->manage_passwords_bubble_state() != |
125 ManagePasswordsBubbleModel::PASSWORD_TO_BE_SAVED) { | 158 ManagePasswordsBubbleModel::PASSWORD_TO_BE_SAVED) { |
126 // If we are in the PASSWORD_TO_BE_SAVED state we only display the | 159 // 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. | 160 // password that was just submitted and should not take these into account. |
128 for (autofill::PasswordFormMap::const_iterator i( | 161 for (autofill::PasswordFormMap::const_iterator i( |
129 manage_passwords_bubble_model_->best_matches().begin()); | 162 manage_passwords_bubble_model_->best_matches().begin()); |
130 i != manage_passwords_bubble_model_->best_matches().end(); ++i) { | 163 i != manage_passwords_bubble_model_->best_matches().end(); ++i) { |
131 maximum = std::max(maximum, GetFieldWidth((*i->second), type)); | 164 maximum = std::max(maximum, GetFieldWidth((*i->second), type)); |
(...skipping 25 matching lines...) Expand all Loading... | |
157 void ManagePasswordsBubbleView::Close() { | 190 void ManagePasswordsBubbleView::Close() { |
158 GetWidget()->Close(); | 191 GetWidget()->Close(); |
159 } | 192 } |
160 | 193 |
161 void ManagePasswordsBubbleView::Init() { | 194 void ManagePasswordsBubbleView::Init() { |
162 using views::GridLayout; | 195 using views::GridLayout; |
163 | 196 |
164 GridLayout* layout = new GridLayout(this); | 197 GridLayout* layout = new GridLayout(this); |
165 SetFocusable(true); | 198 SetFocusable(true); |
166 SetLayoutManager(layout); | 199 SetLayoutManager(layout); |
200 BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET); | |
201 BuildColumnSet(layout, DOUBLE_VIEW_COLUMN_SET); | |
167 | 202 |
168 // This calculates the necessary widths for credential columns in the bubble. | 203 // This calculates the necessary widths for credential columns in the bubble. |
169 const int first_field_width = std::max( | 204 const int first_field_width = std::max( |
170 GetMaximumFieldWidth(USERNAME_FIELD), | 205 GetMaximumFieldWidth(USERNAME_FIELD), |
171 views::Label(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_DELETED)) | 206 views::Label(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_DELETED)) |
172 .GetPreferredSize() | 207 .GetPreferredSize() |
173 .width()); | 208 .width()); |
174 | 209 |
175 const int second_field_width = std::max( | 210 const int second_field_width = std::max( |
176 GetMaximumFieldWidth(PASSWORD_FIELD), | 211 GetMaximumFieldWidth(PASSWORD_FIELD), |
177 views::Label(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_UNDO)) | 212 views::Label(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_UNDO)) |
178 .GetPreferredSize() | 213 .GetPreferredSize() |
179 .width()); | 214 .width()); |
180 | 215 |
181 const int kSingleColumnSetId = 0; | 216 // 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(); | 217 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
189 views::Label* title_label = | 218 views::Label* title_label = |
190 new views::Label(manage_passwords_bubble_model_->title()); | 219 new views::Label(manage_passwords_bubble_model_->title()); |
191 title_label->SetMultiLine(true); | 220 title_label->SetMultiLine(true); |
192 title_label->SetFontList(rb->GetFontList(ui::ResourceBundle::MediumFont)); | 221 title_label->SetFontList(rb->GetFontList(ui::ResourceBundle::MediumFont)); |
193 | 222 |
194 layout->StartRowWithPadding(0, kSingleColumnSetId, | 223 layout->StartRowWithPadding( |
195 0, views::kRelatedControlSmallVerticalSpacing); | 224 0, SINGLE_VIEW_COLUMN_SET, 0, views::kRelatedControlSmallVerticalSpacing); |
196 layout->AddView(title_label); | 225 layout->AddView(title_label); |
197 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); | 226 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); |
198 | 227 |
199 if (manage_passwords_bubble_model_->manage_passwords_bubble_state() == | 228 if (manage_passwords_bubble_model_->WaitingToSavePassword()) { |
200 ManagePasswordsBubbleModel::PASSWORD_TO_BE_SAVED) { | 229 // If we've got a password that we're deciding whether or not to save, |
201 const int kSingleColumnCredentialsId = 1; | 230 // then we need to display a single-view columnset containing the |
202 views::ColumnSet* single_column = | 231 // ManagePasswordItemView, followed by double-view columnset containing |
203 layout->AddColumnSet(kSingleColumnCredentialsId); | 232 // 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( | 233 ManagePasswordItemView* item = new ManagePasswordItemView( |
211 manage_passwords_bubble_model_, | 234 manage_passwords_bubble_model_, |
212 manage_passwords_bubble_model_->pending_credentials(), | 235 manage_passwords_bubble_model_->pending_credentials(), |
213 first_field_width, second_field_width); | 236 first_field_width, |
214 item->SetBorder(views::Border::CreateSolidSidedBorder( | 237 second_field_width, |
215 1, | 238 ManagePasswordItemView::FIRST_ITEM); |
216 0, | 239 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); |
217 1, | |
218 0, | |
219 GetNativeTheme()->GetSystemColor( | |
220 ui::NativeTheme::kColorId_EnabledMenuButtonBorderColor))); | |
221 layout->AddView(item); | 240 layout->AddView(item); |
222 | 241 |
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( | 242 cancel_button_ = new views::LabelButton( |
235 this, l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_CANCEL_BUTTON)); | 243 this, l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_CANCEL_BUTTON)); |
236 cancel_button_->SetStyle(views::Button::STYLE_BUTTON); | 244 cancel_button_->SetStyle(views::Button::STYLE_BUTTON); |
237 save_button_ = new views::BlueButton( | 245 save_button_ = new views::BlueButton( |
238 this, l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_BUTTON)); | 246 this, l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_BUTTON)); |
239 | 247 |
240 layout->StartRowWithPadding(0, kDoubleColumnSetId, | 248 layout->StartRowWithPadding( |
241 0, views::kRelatedControlVerticalSpacing); | 249 0, DOUBLE_VIEW_COLUMN_SET, 0, views::kRelatedControlVerticalSpacing); |
242 layout->AddView(save_button_); | 250 layout->AddView(save_button_); |
243 layout->AddView(cancel_button_); | 251 layout->AddView(cancel_button_); |
244 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 252 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
245 } else { | 253 } else { |
246 const int kSingleButtonSetId = 3; | 254 // If we have a list of passwords to store for the current site, display |
247 views::ColumnSet* single_column_set = | 255 // them to the user for management. Otherwise, render a "No passwords for |
248 layout->AddColumnSet(kSingleButtonSetId); | 256 // this site" message. |
249 single_column_set->AddPaddingColumn(0, views::kPanelHorizMargin); | 257 // |
250 single_column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 1, | 258 // TODO(mkwst): Do we really want the "No passwords" case? It would probably |
251 GridLayout::USE_PREF, 0, 0); | 259 // be better to only clear the pending password upon navigation, rather than |
252 single_column_set->AddPaddingColumn(0, | 260 // as soon as the bubble closes. |
253 views::kUnrelatedControlHorizontalSpacing); | 261 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()) { | 262 if (!manage_passwords_bubble_model_->best_matches().empty()) { |
267 for (autofill::PasswordFormMap::const_iterator i( | 263 for (autofill::PasswordFormMap::const_iterator i( |
268 manage_passwords_bubble_model_->best_matches().begin()); | 264 manage_passwords_bubble_model_->best_matches().begin()); |
269 i != manage_passwords_bubble_model_->best_matches().end(); ++i) { | 265 i != manage_passwords_bubble_model_->best_matches().end(); ++i) { |
270 layout->StartRow(0, kSingleColumnCredentialsId); | |
271 ManagePasswordItemView* item = new ManagePasswordItemView( | 266 ManagePasswordItemView* item = new ManagePasswordItemView( |
272 manage_passwords_bubble_model_, *i->second, first_field_width, | 267 manage_passwords_bubble_model_, |
273 second_field_width); | 268 *i->second, |
274 if (i == manage_passwords_bubble_model_->best_matches().begin()) { | 269 first_field_width, |
275 item->SetBorder(views::Border::CreateSolidSidedBorder( | 270 second_field_width, |
276 1, | 271 num_items_displayed == 0 ? ManagePasswordItemView::FIRST_ITEM |
277 0, | 272 : ManagePasswordItemView::SUBSEQUENT_ITEM); |
278 1, | 273 |
279 0, | 274 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); | 275 layout->AddView(item); |
276 num_items_displayed++; | |
292 } | 277 } |
293 } else if (!manage_passwords_bubble_model_->password_submitted()) { | 278 } else if (!manage_passwords_bubble_model_->password_submitted()) { |
294 views::Label* empty_label = new views::Label( | 279 views::Label* empty_label = new views::Label( |
295 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_NO_PASSWORDS)); | 280 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_NO_PASSWORDS)); |
296 empty_label->SetMultiLine(true); | 281 empty_label->SetMultiLine(true); |
297 layout->StartRow(0, kSingleColumnSetId); | 282 |
283 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); | |
298 layout->AddView(empty_label); | 284 layout->AddView(empty_label); |
299 } | 285 } |
300 | 286 |
287 // If the user just saved a password, it won't be in the 'best matches' list | |
288 // we just walked through. Display it explicitly. | |
301 if (manage_passwords_bubble_model_->password_submitted()) { | 289 if (manage_passwords_bubble_model_->password_submitted()) { |
302 layout->StartRow(0, kSingleColumnCredentialsId); | |
303 ManagePasswordItemView* item = new ManagePasswordItemView( | 290 ManagePasswordItemView* item = new ManagePasswordItemView( |
304 manage_passwords_bubble_model_, | 291 manage_passwords_bubble_model_, |
305 manage_passwords_bubble_model_->pending_credentials(), | 292 manage_passwords_bubble_model_->pending_credentials(), |
306 first_field_width, second_field_width); | 293 first_field_width, |
307 if (manage_passwords_bubble_model_->best_matches().empty()) { | 294 second_field_width, |
308 item->SetBorder(views::Border::CreateSolidSidedBorder( | 295 num_items_displayed ? ManagePasswordItemView::FIRST_ITEM |
309 1, | 296 : ManagePasswordItemView::SUBSEQUENT_ITEM); |
310 0, | 297 |
311 1, | 298 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); | 299 layout->AddView(item); |
300 num_items_displayed++; | |
325 } | 301 } |
326 | 302 |
303 // Build a "manage" link and "done" button, and throw them both into a new | |
304 // row | |
305 // containing a double-view columnset. | |
327 manage_link_ = | 306 manage_link_ = |
328 new views::Link(manage_passwords_bubble_model_->manage_link()); | 307 new views::Link(manage_passwords_bubble_model_->manage_link()); |
329 manage_link_->SetUnderline(false); | 308 manage_link_->SetUnderline(false); |
330 manage_link_->set_listener(this); | 309 manage_link_->set_listener(this); |
331 layout->StartRowWithPadding(0, kSingleButtonSetId, | |
332 0, views::kRelatedControlVerticalSpacing); | |
333 layout->AddView(manage_link_); | |
334 | 310 |
335 done_button_ = | 311 done_button_ = |
336 new views::LabelButton(this, l10n_util::GetStringUTF16(IDS_DONE)); | 312 new views::LabelButton(this, l10n_util::GetStringUTF16(IDS_DONE)); |
337 done_button_->SetStyle(views::Button::STYLE_BUTTON); | 313 done_button_->SetStyle(views::Button::STYLE_BUTTON); |
314 | |
315 layout->StartRowWithPadding( | |
316 0, DOUBLE_VIEW_COLUMN_SET, 0, views::kRelatedControlVerticalSpacing); | |
317 layout->AddView(manage_link_); | |
338 layout->AddView(done_button_); | 318 layout->AddView(done_button_); |
339 } | 319 } |
340 } | 320 } |
341 | 321 |
342 void ManagePasswordsBubbleView::WindowClosing() { | 322 void ManagePasswordsBubbleView::WindowClosing() { |
343 // Close() closes the window asynchronously, so by the time we reach here, | 323 // Close() closes the window asynchronously, so by the time we reach here, |
344 // |manage_passwords_bubble_| may have already been reset. | 324 // |manage_passwords_bubble_| may have already been reset. |
345 if (manage_passwords_bubble_ == this) | 325 if (manage_passwords_bubble_ == this) |
346 manage_passwords_bubble_ = NULL; | 326 manage_passwords_bubble_ = NULL; |
347 } | 327 } |
(...skipping 10 matching lines...) Expand all Loading... | |
358 manage_passwords_bubble_model_->manage_passwords_bubble_state() == | 338 manage_passwords_bubble_model_->manage_passwords_bubble_state() == |
359 ManagePasswordsBubbleModel::PASSWORD_TO_BE_SAVED); | 339 ManagePasswordsBubbleModel::PASSWORD_TO_BE_SAVED); |
360 Close(); | 340 Close(); |
361 } | 341 } |
362 | 342 |
363 void ManagePasswordsBubbleView::LinkClicked(views::Link* source, | 343 void ManagePasswordsBubbleView::LinkClicked(views::Link* source, |
364 int event_flags) { | 344 int event_flags) { |
365 DCHECK_EQ(source, manage_link_); | 345 DCHECK_EQ(source, manage_link_); |
366 manage_passwords_bubble_model_->OnManageLinkClicked(); | 346 manage_passwords_bubble_model_->OnManageLinkClicked(); |
367 } | 347 } |
OLD | NEW |