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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 // Used for buttons at the bottom of the bubble which should occupy | 50 // Used for buttons at the bottom of the bubble which should occupy |
51 // the corners. | 51 // the corners. |
52 LINK_BUTTON_COLUMN_SET = 2, | 52 LINK_BUTTON_COLUMN_SET = 2, |
53 }; | 53 }; |
54 | 54 |
55 // Construct an appropriate ColumnSet for the given |type|, and add it | 55 // Construct an appropriate ColumnSet for the given |type|, and add it |
56 // to |layout|. | 56 // to |layout|. |
57 void BuildColumnSet(views::GridLayout* layout, ColumnSetType type) { | 57 void BuildColumnSet(views::GridLayout* layout, ColumnSetType type) { |
58 views::ColumnSet* column_set = layout->AddColumnSet(type); | 58 views::ColumnSet* column_set = layout->AddColumnSet(type); |
59 column_set->AddPaddingColumn(0, views::kPanelHorizMargin); | 59 column_set->AddPaddingColumn(0, views::kPanelHorizMargin); |
| 60 int full_width = kDesiredBubbleWidth - (2 * views::kPanelHorizMargin); |
60 switch (type) { | 61 switch (type) { |
61 case SINGLE_VIEW_COLUMN_SET: | 62 case SINGLE_VIEW_COLUMN_SET: |
62 column_set->AddColumn(views::GridLayout::FILL, | 63 column_set->AddColumn(views::GridLayout::FILL, |
63 views::GridLayout::FILL, | 64 views::GridLayout::FILL, |
64 0, | 65 0, |
65 views::GridLayout::USE_PREF, | 66 views::GridLayout::FIXED, |
66 0, | 67 full_width, |
67 0); | 68 0); |
68 break; | 69 break; |
69 | 70 |
70 case DOUBLE_BUTTON_COLUMN_SET: | 71 case DOUBLE_BUTTON_COLUMN_SET: |
71 column_set->AddColumn(views::GridLayout::TRAILING, | 72 column_set->AddColumn(views::GridLayout::TRAILING, |
72 views::GridLayout::CENTER, | 73 views::GridLayout::CENTER, |
73 1, | 74 1, |
74 views::GridLayout::USE_PREF, | 75 views::GridLayout::USE_PREF, |
75 0, | 76 0, |
76 0); | 77 0); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 parent_->model()->OnSaveClicked(); | 193 parent_->model()->OnSaveClicked(); |
193 parent_->Close(); | 194 parent_->Close(); |
194 } | 195 } |
195 | 196 |
196 void ManagePasswordsBubbleView::PendingView::OnPerformAction( | 197 void ManagePasswordsBubbleView::PendingView::OnPerformAction( |
197 views::Combobox* source) { | 198 views::Combobox* source) { |
198 DCHECK_EQ(source, refuse_combobox_); | 199 DCHECK_EQ(source, refuse_combobox_); |
199 switch (refuse_combobox_->selected_index()) { | 200 switch (refuse_combobox_->selected_index()) { |
200 case SavePasswordRefusalComboboxModel::INDEX_NOPE: | 201 case SavePasswordRefusalComboboxModel::INDEX_NOPE: |
201 parent_->model()->OnNopeClicked(); | 202 parent_->model()->OnNopeClicked(); |
| 203 parent_->Close(); |
202 break; | 204 break; |
203 case SavePasswordRefusalComboboxModel::INDEX_NEVER_FOR_THIS_SITE: | 205 case SavePasswordRefusalComboboxModel::INDEX_NEVER_FOR_THIS_SITE: |
204 parent_->model()->OnNeverForThisSiteClicked(); | 206 parent_->NotifyNeverForThisSiteClicked(); |
205 break; | 207 break; |
206 } | 208 } |
207 parent_->Close(); | 209 } |
| 210 |
| 211 // ManagePasswordsBubbleView::ConfirmNeverView --------------------------------- |
| 212 |
| 213 ManagePasswordsBubbleView::ConfirmNeverView::ConfirmNeverView( |
| 214 ManagePasswordsBubbleView* parent) |
| 215 : parent_(parent) { |
| 216 views::GridLayout* layout = new views::GridLayout(this); |
| 217 layout->set_minimum_size(gfx::Size(kDesiredBubbleWidth, 0)); |
| 218 SetLayoutManager(layout); |
| 219 |
| 220 // Title row. |
| 221 BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET); |
| 222 views::Label* title_label = new views::Label(l10n_util::GetStringUTF16( |
| 223 IDS_MANAGE_PASSWORDS_BLACKLIST_CONFIRMATION_TITLE)); |
| 224 title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 225 title_label->SetMultiLine(true); |
| 226 title_label->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( |
| 227 ui::ResourceBundle::MediumFont)); |
| 228 layout->StartRowWithPadding( |
| 229 0, SINGLE_VIEW_COLUMN_SET, 0, views::kRelatedControlSmallVerticalSpacing); |
| 230 layout->AddView(title_label); |
| 231 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); |
| 232 |
| 233 // Confirmation text. |
| 234 views::Label* confirmation = new views::Label(l10n_util::GetStringUTF16( |
| 235 IDS_MANAGE_PASSWORDS_BLACKLIST_CONFIRMATION_TEXT)); |
| 236 confirmation->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 237 confirmation->SetMultiLine(true); |
| 238 confirmation->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( |
| 239 ui::ResourceBundle::SmallFont)); |
| 240 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); |
| 241 layout->AddView(confirmation); |
| 242 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); |
| 243 |
| 244 // Confirm and undo buttons. |
| 245 BuildColumnSet(layout, DOUBLE_BUTTON_COLUMN_SET); |
| 246 layout->StartRowWithPadding( |
| 247 0, DOUBLE_BUTTON_COLUMN_SET, 0, views::kRelatedControlVerticalSpacing); |
| 248 |
| 249 confirm_button_ = new views::LabelButton( |
| 250 this, |
| 251 l10n_util::GetStringUTF16( |
| 252 IDS_MANAGE_PASSWORDS_BLACKLIST_CONFIRMATION_BUTTON)); |
| 253 confirm_button_->SetStyle(views::Button::STYLE_BUTTON); |
| 254 confirm_button_->SetFontList( |
| 255 ui::ResourceBundle::GetSharedInstance().GetFontList( |
| 256 ui::ResourceBundle::SmallFont)); |
| 257 layout->AddView(confirm_button_); |
| 258 |
| 259 undo_button_ = |
| 260 new views::LabelButton(this, l10n_util::GetStringUTF16(IDS_CANCEL)); |
| 261 undo_button_->SetStyle(views::Button::STYLE_BUTTON); |
| 262 undo_button_->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( |
| 263 ui::ResourceBundle::SmallFont)); |
| 264 layout->AddView(undo_button_); |
| 265 |
| 266 // Extra padding for visual awesomeness. |
| 267 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 268 } |
| 269 |
| 270 ManagePasswordsBubbleView::ConfirmNeverView::~ConfirmNeverView() { |
| 271 } |
| 272 |
| 273 void ManagePasswordsBubbleView::ConfirmNeverView::ButtonPressed( |
| 274 views::Button* sender, |
| 275 const ui::Event& event) { |
| 276 DCHECK(sender == confirm_button_ || sender == undo_button_); |
| 277 if (sender == confirm_button_) |
| 278 parent_->NotifyConfirmedNeverForThisSite(); |
| 279 else |
| 280 parent_->NotifyUndoNeverForThisSite(); |
208 } | 281 } |
209 | 282 |
210 // ManagePasswordsBubbleView::ManageView -------------------------------------- | 283 // ManagePasswordsBubbleView::ManageView -------------------------------------- |
211 | 284 |
212 ManagePasswordsBubbleView::ManageView::ManageView( | 285 ManagePasswordsBubbleView::ManageView::ManageView( |
213 ManagePasswordsBubbleView* parent) | 286 ManagePasswordsBubbleView* parent) |
214 : parent_(parent) { | 287 : parent_(parent) { |
215 views::GridLayout* layout = new views::GridLayout(this); | 288 views::GridLayout* layout = new views::GridLayout(this); |
216 layout->set_minimum_size(gfx::Size(kDesiredBubbleWidth, 0)); | 289 layout->set_minimum_size(gfx::Size(kDesiredBubbleWidth, 0)); |
217 SetLayoutManager(layout); | 290 SetLayoutManager(layout); |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 } | 483 } |
411 | 484 |
412 ManagePasswordsBubbleView::ManagePasswordsBubbleView( | 485 ManagePasswordsBubbleView::ManagePasswordsBubbleView( |
413 content::WebContents* web_contents, | 486 content::WebContents* web_contents, |
414 ManagePasswordsIconView* anchor_view, | 487 ManagePasswordsIconView* anchor_view, |
415 DisplayReason reason) | 488 DisplayReason reason) |
416 : ManagePasswordsBubble(web_contents, reason), | 489 : ManagePasswordsBubble(web_contents, reason), |
417 BubbleDelegateView(anchor_view, | 490 BubbleDelegateView(anchor_view, |
418 anchor_view ? views::BubbleBorder::TOP_RIGHT | 491 anchor_view ? views::BubbleBorder::TOP_RIGHT |
419 : views::BubbleBorder::NONE), | 492 : views::BubbleBorder::NONE), |
420 anchor_view_(anchor_view) { | 493 anchor_view_(anchor_view), |
| 494 never_save_passwords_(false) { |
421 // Compensate for built-in vertical padding in the anchor view's image. | 495 // Compensate for built-in vertical padding in the anchor view's image. |
422 set_anchor_view_insets(gfx::Insets(2, 0, 2, 0)); | 496 set_anchor_view_insets(gfx::Insets(2, 0, 2, 0)); |
423 set_notify_enter_exit_on_child(true); | 497 set_notify_enter_exit_on_child(true); |
424 if (anchor_view) | 498 if (anchor_view) |
425 anchor_view->SetActive(true); | 499 anchor_view->SetActive(true); |
426 } | 500 } |
427 | 501 |
428 ManagePasswordsBubbleView::~ManagePasswordsBubbleView() { | 502 ManagePasswordsBubbleView::~ManagePasswordsBubbleView() { |
429 if (anchor_view_) | 503 if (anchor_view_) |
430 anchor_view_->SetActive(false); | 504 anchor_view_->SetActive(false); |
(...skipping 15 matching lines...) Expand all Loading... |
446 | 520 |
447 void ManagePasswordsBubbleView::Close() { | 521 void ManagePasswordsBubbleView::Close() { |
448 GetWidget()->Close(); | 522 GetWidget()->Close(); |
449 } | 523 } |
450 | 524 |
451 void ManagePasswordsBubbleView::Init() { | 525 void ManagePasswordsBubbleView::Init() { |
452 views::FillLayout* layout = new views::FillLayout(); | 526 views::FillLayout* layout = new views::FillLayout(); |
453 SetLayoutManager(layout); | 527 SetLayoutManager(layout); |
454 SetFocusable(true); | 528 SetFocusable(true); |
455 | 529 |
456 if (password_manager::ui::IsPendingState(model()->state())) | 530 Refresh(); |
457 AddChildView(new PendingView(this)); | |
458 else if (model()->state() == password_manager::ui::BLACKLIST_STATE) | |
459 AddChildView(new BlacklistedView(this)); | |
460 else | |
461 AddChildView(new ManageView(this)); | |
462 } | 531 } |
463 | 532 |
464 void ManagePasswordsBubbleView::WindowClosing() { | 533 void ManagePasswordsBubbleView::WindowClosing() { |
465 // Close() closes the window asynchronously, so by the time we reach here, | 534 // Close() closes the window asynchronously, so by the time we reach here, |
466 // |manage_passwords_bubble_| may have already been reset. | 535 // |manage_passwords_bubble_| may have already been reset. |
467 if (manage_passwords_bubble_ == this) | 536 if (manage_passwords_bubble_ == this) |
468 manage_passwords_bubble_ = NULL; | 537 manage_passwords_bubble_ = NULL; |
469 } | 538 } |
| 539 |
| 540 void ManagePasswordsBubbleView::Refresh() { |
| 541 RemoveAllChildViews(true); |
| 542 if (password_manager::ui::IsPendingState(model()->state())) { |
| 543 if (never_save_passwords_) |
| 544 AddChildView(new ConfirmNeverView(this)); |
| 545 else |
| 546 AddChildView(new PendingView(this)); |
| 547 } else if (model()->state() == password_manager::ui::BLACKLIST_STATE) { |
| 548 AddChildView(new BlacklistedView(this)); |
| 549 } else { |
| 550 AddChildView(new ManageView(this)); |
| 551 } |
| 552 GetLayoutManager()->Layout(this); |
| 553 } |
| 554 |
| 555 void ManagePasswordsBubbleView::NotifyNeverForThisSiteClicked() { |
| 556 if (model()->best_matches().empty()) { |
| 557 // Skip confirmation if there are no existing passwords for this site. |
| 558 NotifyConfirmedNeverForThisSite(); |
| 559 } else { |
| 560 never_save_passwords_ = true; |
| 561 Refresh(); |
| 562 } |
| 563 } |
| 564 |
| 565 void ManagePasswordsBubbleView::NotifyConfirmedNeverForThisSite() { |
| 566 model()->OnNeverForThisSiteClicked(); |
| 567 Close(); |
| 568 } |
| 569 |
| 570 void ManagePasswordsBubbleView::NotifyUndoNeverForThisSite() { |
| 571 never_save_passwords_ = false; |
| 572 Refresh(); |
| 573 } |
OLD | NEW |