Chromium Code Reviews| Index: chrome/browser/ui/views/passwords/manage_passwords_bubble_view.cc |
| diff --git a/chrome/browser/ui/views/passwords/manage_passwords_bubble_view.cc b/chrome/browser/ui/views/passwords/manage_passwords_bubble_view.cc |
| index 81c6d33ecde7658db0f7d6185f01eaf19b59583b..4546d8f804241b2a5c75bad0b08bfee12e63d3bf 100644 |
| --- a/chrome/browser/ui/views/passwords/manage_passwords_bubble_view.cc |
| +++ b/chrome/browser/ui/views/passwords/manage_passwords_bubble_view.cc |
| @@ -25,6 +25,7 @@ |
| #include "ui/views/controls/button/blue_button.h" |
| #include "ui/views/controls/button/label_button.h" |
| #include "ui/views/controls/combobox/combobox.h" |
| +#include "ui/views/layout/fill_layout.h" |
| #include "ui/views/layout/grid_layout.h" |
| #include "ui/views/layout/layout_constants.h" |
| @@ -33,20 +34,6 @@ |
| namespace { |
| -enum FieldType { USERNAME_FIELD, PASSWORD_FIELD }; |
| - |
| -// Upper limit on the size of the username and password fields. |
| -const int kUsernameFieldSize = 30; |
| -const int kPasswordFieldSize = 22; |
| - |
| -// Returns the width of |type| field. |
| -int GetFieldWidth(FieldType type) { |
| - return ui::ResourceBundle::GetSharedInstance() |
| - .GetFontList(ui::ResourceBundle::SmallFont) |
| - .GetExpectedTextWidth(type == USERNAME_FIELD ? kUsernameFieldSize |
| - : kPasswordFieldSize); |
| -} |
| - |
| class SavePasswordRefusalComboboxModel : public ui::ComboboxModel { |
| public: |
| enum { INDEX_NOPE = 0, INDEX_NEVER_FOR_THIS_SITE = 1, }; |
| @@ -92,6 +79,147 @@ void ShowManagePasswordsBubble(content::WebContents* web_contents) { |
| } // namespace chrome |
| +// ManagePasswordsBubbleView::PendingView ------------------------------------- |
| + |
| +ManagePasswordsBubbleView::PendingView::PendingView( |
| + ManagePasswordsBubbleView* parent) |
| + : parent_(parent) { |
| + views::GridLayout* layout = new views::GridLayout(this); |
| + SetLayoutManager(layout); |
| + |
| + // Create the pending credential item, save button and refusal combobox. |
| + ManagePasswordItemView* item = |
| + new ManagePasswordItemView(parent->model(), |
| + parent->model()->pending_credentials(), |
| + ManagePasswordItemView::FIRST_ITEM); |
| + save_button_ = new views::BlueButton( |
| + this, l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_BUTTON)); |
| + refuse_combobox_ = |
| + new views::Combobox(new SavePasswordRefusalComboboxModel()); |
| + refuse_combobox_->set_listener(this); |
| + refuse_combobox_->SetStyle(views::Combobox::STYLE_ACTION); |
| + |
| + // Title row. |
| + parent->BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET); |
|
markusheintz_
2014/04/29 07:51:38
It seems like this method is not used on the paren
|
| + parent->AddTitleRow(layout); |
|
markusheintz_
2014/04/29 07:51:38
The same as above seems to hold for this one.
|
| + |
| + // Credential row. |
| + layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); |
| + layout->AddView(item); |
| + |
| + // Button row. |
| + parent->BuildColumnSet(layout, DOUBLE_BUTTON_COLUMN_SET); |
| + layout->StartRowWithPadding( |
| + 0, DOUBLE_BUTTON_COLUMN_SET, 0, views::kRelatedControlVerticalSpacing); |
| + layout->AddView(save_button_); |
| + layout->AddView(refuse_combobox_); |
| + |
| + // Extra padding for visual awesomeness. |
| + layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| +} |
| + |
| +ManagePasswordsBubbleView::PendingView::~PendingView() { |
| +} |
| + |
| +void ManagePasswordsBubbleView::PendingView::ButtonPressed( |
| + views::Button* sender, |
| + const ui::Event& event) { |
| + DCHECK(sender == save_button_); |
| + parent_->model()->OnSaveClicked(); |
| + parent_->Close(); |
| +} |
| + |
| +void ManagePasswordsBubbleView::PendingView::OnPerformAction( |
| + views::Combobox* source) { |
| + DCHECK_EQ(source, refuse_combobox_); |
| + switch (refuse_combobox_->selected_index()) { |
| + case SavePasswordRefusalComboboxModel::INDEX_NOPE: |
| + parent_->model()->OnNopeClicked(); |
| + break; |
| + case SavePasswordRefusalComboboxModel::INDEX_NEVER_FOR_THIS_SITE: |
| + parent_->model()->OnNeverForThisSiteClicked(); |
| + break; |
| + } |
| + parent_->Close(); |
| +} |
| + |
| +// ManagePasswordsBubbleView::ManageView -------------------------------------- |
| + |
| +ManagePasswordsBubbleView::ManageView::ManageView( |
| + ManagePasswordsBubbleView* parent) |
| + : parent_(parent) { |
| + views::GridLayout* layout = new views::GridLayout(this); |
| + SetLayoutManager(layout); |
| + |
| + // Add the title. |
| + parent->BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET); |
| + parent->AddTitleRow(layout); |
| + |
| + // If we have a list of passwords to store for the current site, display |
| + // them to the user for management. Otherwise, render a "No passwords for |
| + // this site" message. |
| + if (!parent_->model()->best_matches().empty()) { |
| + for (autofill::PasswordFormMap::const_iterator i( |
| + parent_->model()->best_matches().begin()); |
| + i != parent_->model()->best_matches().end(); |
| + ++i) { |
| + ManagePasswordItemView* item = new ManagePasswordItemView( |
| + parent_->model(), |
| + *i->second, |
| + i == parent_->model()->best_matches().begin() |
| + ? ManagePasswordItemView::FIRST_ITEM |
| + : ManagePasswordItemView::SUBSEQUENT_ITEM); |
| + |
| + layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); |
| + layout->AddView(item); |
| + } |
| + } else { |
| + views::Label* empty_label = new views::Label( |
| + l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_NO_PASSWORDS)); |
| + empty_label->SetMultiLine(true); |
| + |
| + layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); |
| + layout->AddView(empty_label); |
| + } |
| + |
| + // Then add the "manage passwords" link and "Done" button. |
| + manage_link_ = new views::Link(parent_->model()->manage_link()); |
| + manage_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| + manage_link_->SetUnderline(false); |
| + manage_link_->set_listener(this); |
| + |
| + done_button_ = |
| + new views::LabelButton(this, l10n_util::GetStringUTF16(IDS_DONE)); |
| + done_button_->SetStyle(views::Button::STYLE_BUTTON); |
| + |
| + parent->BuildColumnSet(layout, LINK_BUTTON_COLUMN_SET); |
| + layout->StartRowWithPadding( |
| + 0, LINK_BUTTON_COLUMN_SET, 0, views::kRelatedControlVerticalSpacing); |
| + layout->AddView(manage_link_); |
| + layout->AddView(done_button_); |
| + |
| + // Extra padding for visual awesomeness. |
| + layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| +} |
| + |
| +ManagePasswordsBubbleView::ManageView::~ManageView() { |
| +} |
| + |
| +void ManagePasswordsBubbleView::ManageView::ButtonPressed( |
| + views::Button* sender, |
| + const ui::Event& event) { |
| + DCHECK(sender == done_button_); |
| + parent_->model()->OnDoneClicked(); |
| + parent_->Close(); |
| +} |
| + |
| +void ManagePasswordsBubbleView::ManageView::LinkClicked(views::Link* source, |
| + int event_flags) { |
| + DCHECK_EQ(source, manage_link_); |
| + parent_->model()->OnManageLinkClicked(); |
| + parent_->Close(); |
| +} |
| + |
| // ManagePasswordsBubbleView -------------------------------------------------- |
| // static |
| @@ -208,6 +336,22 @@ void ManagePasswordsBubbleView::BuildColumnSet(views::GridLayout* layout, |
| column_set->AddPaddingColumn(0, views::kPanelHorizMargin); |
| } |
| +void ManagePasswordsBubbleView::AddTitleRow(views::GridLayout* layout) const { |
| + // Build the title label, and populate it with whatever title our model feels |
| + // is appropriate for the bubble's state. |
| + views::Label* title_label = new views::Label(model()->title()); |
| + title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| + title_label->SetMultiLine(true); |
| + title_label->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( |
| + ui::ResourceBundle::MediumFont)); |
| + |
| + // Add the title to the layout with appropriate padding. |
| + layout->StartRowWithPadding( |
| + 0, SINGLE_VIEW_COLUMN_SET, 0, views::kRelatedControlSmallVerticalSpacing); |
| + layout->AddView(title_label); |
| + layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); |
| +} |
| + |
| void ManagePasswordsBubbleView::AdjustForFullscreen( |
| const gfx::Rect& screen_bounds) { |
| if (GetAnchorView()) |
| @@ -232,118 +376,14 @@ void ManagePasswordsBubbleView::CloseWithoutLogging() { |
| } |
| void ManagePasswordsBubbleView::Init() { |
| - using views::GridLayout; |
| - |
| - GridLayout* layout = new GridLayout(this); |
| - SetFocusable(true); |
| + views::FillLayout* layout = new views::FillLayout(); |
| SetLayoutManager(layout); |
| - BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET); |
| - BuildColumnSet(layout, DOUBLE_BUTTON_COLUMN_SET); |
| - BuildColumnSet(layout, LINK_BUTTON_COLUMN_SET); |
| - |
| - // This calculates the necessary widths for credential columns in the bubble. |
| - const int first_field_width = std::max( |
| - GetFieldWidth(USERNAME_FIELD), |
| - views::Label(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_DELETED)) |
| - .GetPreferredSize() |
| - .width()); |
| - |
| - const int second_field_width = std::max( |
| - GetFieldWidth(PASSWORD_FIELD), |
| - views::Label(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_UNDO)) |
| - .GetPreferredSize() |
| - .width()); |
| - |
| - // Build and populate the header. |
| - views::Label* title_label = new views::Label(model()->title()); |
| - title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| - title_label->SetMultiLine(true); |
| - title_label->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( |
| - ui::ResourceBundle::MediumFont)); |
| - |
| - layout->StartRowWithPadding( |
| - 0, SINGLE_VIEW_COLUMN_SET, 0, views::kRelatedControlSmallVerticalSpacing); |
| - layout->AddView(title_label); |
| - layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); |
| - |
| - if (model()->WaitingToSavePassword()) { |
| - // If we've got a password that we're deciding whether or not to save, |
| - // then we need to display a single-view columnset containing the |
| - // ManagePasswordItemView, followed by double-view columnset containing |
| - // a "Save" and "Reject" button. |
| - ManagePasswordItemView* item = |
| - new ManagePasswordItemView(model(), |
| - model()->pending_credentials(), |
| - first_field_width, |
| - second_field_width, |
| - ManagePasswordItemView::FIRST_ITEM); |
| - layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); |
| - layout->AddView(item); |
| - |
| - refuse_combobox_ = |
| - new views::Combobox(new SavePasswordRefusalComboboxModel()); |
| - refuse_combobox_->set_listener(this); |
| - refuse_combobox_->SetStyle(views::Combobox::STYLE_ACTION); |
| - |
| - save_button_ = new views::BlueButton( |
| - this, l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_BUTTON)); |
| - |
| - layout->StartRowWithPadding( |
| - 0, DOUBLE_BUTTON_COLUMN_SET, 0, views::kRelatedControlVerticalSpacing); |
| - layout->AddView(save_button_); |
| - layout->AddView(refuse_combobox_); |
| - layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| - } else { |
| - // If we have a list of passwords to store for the current site, display |
| - // them to the user for management. Otherwise, render a "No passwords for |
| - // this site" message. |
| - // |
| - // TODO(mkwst): Do we really want the "No passwords" case? It would probably |
| - // be better to only clear the pending password upon navigation, rather than |
| - // as soon as the bubble closes. |
| - if (!model()->best_matches().empty()) { |
| - for (autofill::PasswordFormMap::const_iterator i( |
| - model()->best_matches().begin()); |
| - i != model()->best_matches().end(); |
| - ++i) { |
| - ManagePasswordItemView* item = new ManagePasswordItemView( |
| - model(), |
| - *i->second, |
| - first_field_width, |
| - second_field_width, |
| - i == model()->best_matches().begin() |
| - ? ManagePasswordItemView::FIRST_ITEM |
| - : ManagePasswordItemView::SUBSEQUENT_ITEM); |
| - |
| - layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); |
| - layout->AddView(item); |
| - } |
| - } else { |
| - views::Label* empty_label = new views::Label( |
| - l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_NO_PASSWORDS)); |
| - empty_label->SetMultiLine(true); |
| - |
| - layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); |
| - layout->AddView(empty_label); |
| - } |
| + SetFocusable(true); |
| - // Build a "manage" link and "done" button, and throw them both into a new |
| - // row |
| - // containing a double-view columnset. |
| - manage_link_ = new views::Link(model()->manage_link()); |
| - manage_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| - manage_link_->SetUnderline(false); |
| - manage_link_->set_listener(this); |
| - |
| - done_button_ = |
| - new views::LabelButton(this, l10n_util::GetStringUTF16(IDS_DONE)); |
| - done_button_->SetStyle(views::Button::STYLE_BUTTON); |
| - |
| - layout->StartRowWithPadding( |
| - 0, LINK_BUTTON_COLUMN_SET, 0, views::kRelatedControlVerticalSpacing); |
| - layout->AddView(manage_link_); |
| - layout->AddView(done_button_); |
| - } |
| + if (model()->WaitingToSavePassword()) |
| + AddChildView(new PendingView(this)); |
| + else |
| + AddChildView(new ManageView(this)); |
| } |
| void ManagePasswordsBubbleView::WindowClosing() { |
| @@ -352,37 +392,3 @@ void ManagePasswordsBubbleView::WindowClosing() { |
| if (manage_passwords_bubble_ == this) |
| manage_passwords_bubble_ = NULL; |
| } |
| - |
| -void ManagePasswordsBubbleView::ButtonPressed(views::Button* sender, |
| - const ui::Event& event) { |
| - DCHECK(sender == save_button_ || sender == done_button_); |
| - |
| - if (sender == save_button_) |
| - model()->OnSaveClicked(); |
| - else |
| - model()->OnDoneClicked(); |
| - Close(); |
| -} |
| - |
| -void ManagePasswordsBubbleView::LinkClicked(views::Link* source, |
| - int event_flags) { |
| - DCHECK_EQ(source, manage_link_); |
| - model()->OnManageLinkClicked(); |
| - Close(); |
| -} |
| - |
| -void ManagePasswordsBubbleView::OnPerformAction(views::Combobox* source) { |
| - DCHECK_EQ(source, refuse_combobox_); |
| - switch (refuse_combobox_->selected_index()) { |
| - case SavePasswordRefusalComboboxModel::INDEX_NOPE: |
| - model()->OnNopeClicked(); |
| - break; |
| - case SavePasswordRefusalComboboxModel::INDEX_NEVER_FOR_THIS_SITE: |
| - model()->OnNeverForThisSiteClicked(); |
| - break; |
| - default: |
| - NOTREACHED(); |
| - break; |
| - } |
| - Close(); |
| -} |