Index: chrome/browser/ui/autofill/password_generation_popup_controller_impl.cc |
diff --git a/chrome/browser/ui/autofill/password_generation_popup_controller_impl.cc b/chrome/browser/ui/autofill/password_generation_popup_controller_impl.cc |
index d946711d78758bd168cc69f858252c4d2900a8f5..747b9a523b692096f33aec01a012bdada889eebb 100644 |
--- a/chrome/browser/ui/autofill/password_generation_popup_controller_impl.cc |
+++ b/chrome/browser/ui/autofill/password_generation_popup_controller_impl.cc |
@@ -79,8 +79,6 @@ PasswordGenerationPopupControllerImpl::PasswordGenerationPopupControllerImpl( |
generator_(new PasswordGenerator(max_length)), |
controller_common_(bounds, container_view, web_contents), |
view_(NULL), |
- font_list_(ResourceBundle::GetSharedInstance().GetFontList( |
- ResourceBundle::SmallFont)), |
password_selected_(false), |
display_password_(false), |
weak_ptr_factory_(this) { |
@@ -157,81 +155,20 @@ void PasswordGenerationPopupControllerImpl::PasswordAccepted() { |
Hide(); |
} |
-int PasswordGenerationPopupControllerImpl::GetDesiredWidth() { |
+int PasswordGenerationPopupControllerImpl::GetMinimumWidth() { |
// Minimum width in pixels. |
- const int minimum_required_width = 300; |
+ const int minimum_width = 360; |
// If the width of the field is longer than the minimum, use that instead. |
- int width = std::max(minimum_required_width, |
- controller_common_.RoundedElementBounds().width()); |
- |
- if (display_password_) { |
- // Make sure that the width will always be large enough to display the |
- // password and suggestion on one line. |
- width = std::max(width, |
- gfx::GetStringWidth(current_password_ + SuggestedText(), |
- font_list_) + 2 * kHorizontalPadding); |
- } |
- |
- return width; |
-} |
- |
-int PasswordGenerationPopupControllerImpl::GetDesiredHeight(int width) { |
- // Note that this wrapping isn't exactly what the popup will do. It shouldn't |
- // line break in the middle of the link, but as long as the link isn't longer |
- // than given width this shouldn't affect the height calculated here. The |
- // default width should be wide enough to prevent this from being an issue. |
- int total_length = gfx::GetStringWidth(HelpText(), font_list_); |
- int usable_width = width - 2 * kHorizontalPadding; |
- int text_height = |
- static_cast<int>(ceil(static_cast<double>(total_length)/usable_width)) * |
- font_list_.GetFontSize(); |
- int help_section_height = text_height + 2 * kHelpVerticalPadding; |
- |
- int password_section_height = 0; |
- if (display_password_) { |
- password_section_height = |
- font_list_.GetFontSize() + 2 * kPasswordVerticalPadding; |
- } |
- |
- return (2 * kPopupBorderThickness + |
- help_section_height + |
- password_section_height); |
+ return std::max(minimum_width, |
+ controller_common_.RoundedElementBounds().width()); |
} |
void PasswordGenerationPopupControllerImpl::CalculateBounds() { |
- int popup_width = GetDesiredWidth(); |
- int popup_height = GetDesiredHeight(popup_width); |
- |
- popup_bounds_ = controller_common_.GetPopupBounds(popup_height, popup_width); |
- int sub_view_width = popup_bounds_.width() - 2 * kPopupBorderThickness; |
- |
- // Calculate the bounds for the rest of the elements given the bounds of |
- // the popup. |
- if (display_password_) { |
- password_bounds_ = gfx::Rect( |
- kPopupBorderThickness, |
- kPopupBorderThickness, |
- sub_view_width, |
- font_list_.GetFontSize() + 2 * kPasswordVerticalPadding); |
- |
- divider_bounds_ = gfx::Rect(kPopupBorderThickness, |
- password_bounds_.bottom(), |
- sub_view_width, |
- 1 /* divider heigth*/); |
- } else { |
- password_bounds_ = gfx::Rect(); |
- divider_bounds_ = gfx::Rect(); |
- } |
+ gfx::Size bounds = view_->GetPreferredSizeOfPasswordView(); |
- int help_y = std::max(kPopupBorderThickness, divider_bounds_.bottom()); |
- int help_height = |
- popup_bounds_.height() - help_y - kPopupBorderThickness; |
- help_bounds_ = gfx::Rect( |
- kPopupBorderThickness, |
- help_y, |
- sub_view_width, |
- help_height); |
+ popup_bounds_ = controller_common_.GetPopupBounds(bounds.width(), |
+ bounds.height()); |
} |
void PasswordGenerationPopupControllerImpl::Show(bool display_password) { |
@@ -239,12 +176,12 @@ void PasswordGenerationPopupControllerImpl::Show(bool display_password) { |
if (display_password_) |
current_password_ = base::ASCIIToUTF16(generator_->Generate()); |
- CalculateBounds(); |
- |
if (!view_) { |
view_ = PasswordGenerationPopupView::Create(this); |
+ CalculateBounds(); |
view_->Show(); |
} else { |
+ CalculateBounds(); |
view_->UpdateBoundsAndRedrawPopup(); |
} |
@@ -289,7 +226,7 @@ void PasswordGenerationPopupControllerImpl::OnSavedPasswordsLinkClicked() { |
void PasswordGenerationPopupControllerImpl::SetSelectionAtPoint( |
const gfx::Point& point) { |
- PasswordSelected(password_bounds_.Contains(point)); |
+ PasswordSelected(view_->IsPointInPasswordBounds(point)); |
} |
bool PasswordGenerationPopupControllerImpl::AcceptSelectedLine() { |
@@ -308,28 +245,10 @@ gfx::NativeView PasswordGenerationPopupControllerImpl::container_view() { |
return controller_common_.container_view(); |
} |
-const gfx::FontList& PasswordGenerationPopupControllerImpl::font_list() const { |
- return font_list_; |
-} |
- |
const gfx::Rect& PasswordGenerationPopupControllerImpl::popup_bounds() const { |
return popup_bounds_; |
} |
-const gfx::Rect& PasswordGenerationPopupControllerImpl::password_bounds() |
- const { |
- return password_bounds_; |
-} |
- |
-const gfx::Rect& PasswordGenerationPopupControllerImpl::divider_bounds() |
- const { |
- return divider_bounds_; |
-} |
- |
-const gfx::Rect& PasswordGenerationPopupControllerImpl::help_bounds() const { |
- return help_bounds_; |
-} |
- |
bool PasswordGenerationPopupControllerImpl::display_password() const { |
return display_password_; |
} |