Chromium Code Reviews| Index: chrome/browser/ui/views/autofill/password_generation_popup_view_views.cc |
| diff --git a/chrome/browser/ui/views/autofill/password_generation_popup_view_views.cc b/chrome/browser/ui/views/autofill/password_generation_popup_view_views.cc |
| index 4fbf85b2eb4c9ee3e04048fe0f00e0bc2612d47a..5ed6d8eacf8a7bb1c9a718e817cf5e6210e0d367 100644 |
| --- a/chrome/browser/ui/views/autofill/password_generation_popup_view_views.cc |
| +++ b/chrome/browser/ui/views/autofill/password_generation_popup_view_views.cc |
| @@ -4,8 +4,10 @@ |
| #include "chrome/browser/ui/views/autofill/password_generation_popup_view_views.h" |
| +#include "base/debug/stack_trace.h" |
| #include "base/strings/string16.h" |
| #include "chrome/browser/ui/autofill/password_generation_popup_controller.h" |
| +#include "ui/base/resource/resource_bundle.h" |
| #include "ui/gfx/canvas.h" |
| #include "ui/views/background.h" |
| #include "ui/views/border.h" |
| @@ -18,8 +20,8 @@ namespace autofill { |
| namespace { |
| const SkColor kExplanatoryTextBackground = SkColorSetRGB(0xF5, 0xF5, 0xF5); |
| -const SkColor kExplanatoryTextColor = SkColorSetRGB(0x93, 0x93, 0x93); |
| -const SkColor kDividerColor = SkColorSetRGB(0xE7, 0xE7, 0xE7); |
| +const SkColor kExplanatoryTextColor = SkColorSetRGB(0x7F, 0x7F, 0x7F); |
| +const SkColor kDividerColor = SkColorSetRGB(0xE9, 0xE9, 0xE9); |
| // This is the amount of vertical whitespace that is left above and below the |
| // password when it is highlighted. |
| @@ -29,48 +31,95 @@ const int kPasswordVerticalInset = 7; |
| // to get the proper spacing in the help section. |
| const int kHelpVerticalOffset = 3; |
| +// Class that shows the password and the suggestion side-by-side. |
| +class PasswordLabel : public views::View { |
| + public: |
| + PasswordLabel(const base::string16& password, |
| + const base::string16& suggestion, |
| + const gfx::Rect& bounds, |
| + const gfx::FontList& font_list, |
| + int horizontal_border) { |
| + views::Label* password_label = new views::Label(password, font_list); |
| + password_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| + password_label->SetBoundsRect(bounds); |
| + password_label->SetBorder( |
| + views::Border::CreateEmptyBorder(0, horizontal_border, 0, 0)); |
| + AddChildView(password_label); |
| + |
| + views::Label* suggestion_label = new views::Label(suggestion, font_list); |
| + suggestion_label->SetHorizontalAlignment(gfx::ALIGN_RIGHT); |
| + suggestion_label->SetBoundsRect(bounds); |
|
Evan Stade
2014/02/03 18:49:15
set child bounds in the layout() function, either
Garrett Casto
2014/02/04 17:54:57
Done.
|
| + suggestion_label->SetBorder( |
| + views::Border::CreateEmptyBorder(0, 0, 0, horizontal_border)); |
| + suggestion_label->SetEnabledColor(kExplanatoryTextColor); |
| + AddChildView(suggestion_label); |
| + |
| + SetBoundsRect(bounds); |
|
Evan Stade
2014/02/03 18:49:15
same applies here, only the parent view is respons
Garrett Casto
2014/02/04 17:54:57
Done.
|
| + } |
| + virtual ~PasswordLabel() {} |
| + |
| + virtual views::View* GetEventHandlerForRect(const gfx::Rect& rect) OVERRIDE { |
| + // Event handling is done by AutofillPopupBaseView. |
| + return parent(); |
|
Evan Stade
2014/02/03 18:49:15
I think the normal way of doing this is
virtual b
Garrett Casto
2014/02/04 17:54:57
Done.
|
| + } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(PasswordLabel); |
| +}; |
| + |
| } // namespace |
| PasswordGenerationPopupViewViews::PasswordGenerationPopupViewViews( |
| PasswordGenerationPopupController* controller, |
| views::Widget* observing_widget) |
| : AutofillPopupBaseView(controller, observing_widget), |
| + password_view_(NULL), |
| controller_(controller) { |
| - password_label_ = new views::Label(controller->password()); |
| - password_label_->SetBoundsRect(controller->password_bounds()); |
| - password_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| - password_label_->set_clip_insets(gfx::Insets( |
| - kPasswordVerticalInset, 0, kPasswordVerticalInset, 0)); |
| - password_label_->SetBorder(views::Border::CreateEmptyBorder( |
| - 0, controller_->kHorizontalPadding, 0, controller_->kHorizontalPadding)); |
| - AddChildView(password_label_); |
| - |
| - base::string16 help_text = controller->HelpText(); |
| - base::string16 learn_more_link_text = controller->LearnMoreLink(); |
| - views::StyledLabel* help_label = |
| - new views::StyledLabel(help_text + learn_more_link_text, this); |
| + if (controller_->display_password()) |
| + CreatePasswordView(); |
| + |
| + base::string16 help_text = controller_->HelpText(); |
| + base::string16 saved_passwords_link_text = controller_->SavedPasswordsLink(); |
| + help_label_ = |
| + new views::StyledLabel(help_text + saved_passwords_link_text, this); |
| + help_label_->SetFontList(controller_->font_list()); |
| views::StyledLabel::RangeStyleInfo default_style; |
| default_style.color = kExplanatoryTextColor; |
| - help_label->SetDefaultStyle(default_style); |
| - help_label->AddStyleRange( |
| + help_label_->SetDefaultStyle(default_style); |
| + |
| + views::StyledLabel::RangeStyleInfo link_style = |
| + views::StyledLabel::RangeStyleInfo::CreateForLink(); |
| + help_label_->AddStyleRange( |
| gfx::Range(help_text.size(), |
| - help_text.size() + learn_more_link_text.size()), |
| + help_text.size() + saved_passwords_link_text.size()), |
| views::StyledLabel::RangeStyleInfo::CreateForLink()); |
| - help_label->SetBoundsRect(controller->help_bounds()); |
| - help_label->set_background( |
| + help_label_->SetBoundsRect(controller_->help_bounds()); |
|
Evan Stade
2014/02/03 18:49:15
ditto
Garrett Casto
2014/02/04 17:54:57
Done.
|
| + help_label_->set_background( |
| views::Background::CreateSolidBackground(kExplanatoryTextBackground)); |
| - help_label->SetBorder(views::Border::CreateEmptyBorder( |
| + help_label_->SetBorder(views::Border::CreateEmptyBorder( |
| controller_->kHelpVerticalPadding - kHelpVerticalOffset, |
| controller_->kHorizontalPadding, |
| 0, |
| controller_->kHorizontalPadding)); |
| - AddChildView(help_label); |
| + AddChildView(help_label_); |
| set_background(views::Background::CreateSolidBackground(kPopupBackground)); |
| } |
| PasswordGenerationPopupViewViews::~PasswordGenerationPopupViewViews() {} |
| +void PasswordGenerationPopupViewViews::CreatePasswordView() { |
| + password_view_ = |
| + new PasswordLabel(controller_->password(), |
| + controller_->SuggestedText(), |
| + controller_->password_bounds(), |
| + controller_->font_list(), |
| + controller_->kHorizontalPadding); |
| + password_view_->set_clip_insets(gfx::Insets( |
| + kPasswordVerticalInset, 0, kPasswordVerticalInset, 0)); |
| + AddChildView(password_view_); |
| +} |
| + |
| void PasswordGenerationPopupViewViews::Show() { |
| DoShow(); |
| } |
| @@ -83,6 +132,13 @@ void PasswordGenerationPopupViewViews::Hide() { |
| } |
| void PasswordGenerationPopupViewViews::UpdateBoundsAndRedrawPopup() { |
| + // Currently the UI can change from not offering a password to offering |
| + // a password (e.g. the user is editing a generated password and deletes it), |
| + // but it can't change the other way around. |
| + if (controller_->display_password()) { |
| + CreatePasswordView(); |
| + help_label_->SetBoundsRect(controller_->help_bounds()); |
| + } |
| DoUpdateBoundsAndRedrawPopup(); |
| } |
| @@ -90,12 +146,14 @@ void PasswordGenerationPopupViewViews::OnPaint(gfx::Canvas* canvas) { |
| if (!controller_) |
| return; |
| - if (controller_->password_selected()) { |
| - password_label_->set_background( |
| - views::Background::CreateSolidBackground(kHoveredBackgroundColor)); |
| - } else { |
| - password_label_->set_background( |
| - views::Background::CreateSolidBackground(kPopupBackground)); |
| + if (password_view_) { |
| + if (controller_->password_selected()) { |
| + password_view_->set_background( |
|
Evan Stade
2014/02/03 18:49:15
i feel like this should happen when the password s
Garrett Casto
2014/02/04 17:54:57
Done.
|
| + views::Background::CreateSolidBackground(kHoveredBackgroundColor)); |
| + } else { |
| + password_view_->set_background( |
| + views::Background::CreateSolidBackground(kPopupBackground)); |
| + } |
| } |
| // Draw border and background. |
| @@ -103,12 +161,13 @@ void PasswordGenerationPopupViewViews::OnPaint(gfx::Canvas* canvas) { |
| // Divider line needs to be drawn after OnPaint() otherwise the background |
| // will overwrite the divider. |
| - canvas->FillRect(controller_->divider_bounds(), kDividerColor); |
| + if (password_view_) |
| + canvas->FillRect(controller_->divider_bounds(), kDividerColor); |
| } |
| void PasswordGenerationPopupViewViews::StyledLabelLinkClicked( |
| const gfx::Range& range, int event_flags) { |
| - controller_->OnHelpLinkClicked(); |
| + controller_->OnSavedPasswordsLinkClicked(); |
| } |
| PasswordGenerationPopupView* PasswordGenerationPopupView::Create( |