Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8105)

Unified Diff: chrome/browser/ui/autofill/password_generation_popup_controller_impl.cc

Issue 342833002: [Password Generation] Update Aura UI (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..b0acb02890a8a896db7ab53508e0796c73ce4295 100644
--- a/chrome/browser/ui/autofill/password_generation_popup_controller_impl.cc
+++ b/chrome/browser/ui/autofill/password_generation_popup_controller_impl.cc
@@ -33,6 +33,13 @@
namespace autofill {
+namespace {
+// The amount of additional space that a link takes up as it has a border if
+// it's focused. TODO(gcasto): Does OSX do this as well?
+const int kLinkBorderSize = 1;
+const int kPasswordSectionHeight = 62;
+}
+
base::WeakPtr<PasswordGenerationPopupControllerImpl>
PasswordGenerationPopupControllerImpl::GetOrCreate(
base::WeakPtr<PasswordGenerationPopupControllerImpl> previous,
@@ -159,7 +166,7 @@ void PasswordGenerationPopupControllerImpl::PasswordAccepted() {
int PasswordGenerationPopupControllerImpl::GetDesiredWidth() {
// Minimum width in pixels.
- const int minimum_required_width = 300;
+ const int minimum_required_width = 350;
// If the width of the field is longer than the minimum, use that instead.
int width = std::max(minimum_required_width,
@@ -177,21 +184,56 @@ int PasswordGenerationPopupControllerImpl::GetDesiredWidth() {
}
int PasswordGenerationPopupControllerImpl::GetDesiredHeight(int width) {
Evan Stade 2014/06/19 00:16:35 size calculations belong in view implementations.
Garrett Casto 2014/06/20 23:47:00 One problem with this is that you need to know the
Evan Stade 2014/06/23 18:20:40 what platform are you using for the study? cros? C
Garrett Casto 2014/06/24 01:15:11 I actually don't know if it's CrOS or Windows. I t
- // 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.
+ // Calculating the height of the help text is complicated by the fact that
+ // we won't add a line break in the middle of a link. Note that this currently
+ // doesn't appropriately wrap at word boundries either, but that is less of
+ // a problem at the moment given the size of the link and it's placement on
+ // the line.
+ // TODO(gcasto): I really wish that there was a better cross platform way of
+ // calculating this, but it's not clear that there is.
+ // gfx::ElideRectangleText() is close, but it doesn't understand embedded
+ // links.
int total_length = gfx::GetStringWidth(HelpText(), font_list_);
- int usable_width = width - 2 * kHorizontalPadding;
+ int before_link_length =
+ gfx::GetStringWidth(HelpText().substr(0, HelpTextLinkRange().start()),
+ font_list_);
+ int after_link_length =
+ gfx::GetStringWidth(HelpText().substr(0, HelpTextLinkRange().end()),
+ font_list_);
+ // Even though the link will only be on one line, this is how the usable width
+ // is calculated on StyledLabel.
+ int usable_width =
+ width - 2 * kHorizontalPadding - 2 * kLinkBorderSize;
+ int num_lines;
+ if (before_link_length / usable_width != after_link_length / usable_width) {
+ // Link would be wrapped, line break before the link starts.
+ int link_and_after_length =
+ gfx::GetStringWidth(HelpText().substr(HelpTextLinkRange().start()),
+ font_list_);
+ num_lines = (before_link_length/usable_width +
+ link_and_after_length/usable_width +
+ 2);
+ } else {
+ // Link shouldn't cross a line break.
+ num_lines = total_length/usable_width + 1;
+ }
+
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;
+ ((num_lines-1) *
Evan Stade 2014/06/19 00:16:35 spaces around binary operators
Garrett Casto 2014/06/20 23:47:00 Done.
+ (font_list_.GetHeight() +
+ PasswordGenerationPopupView::kHelpSectionAdditionalSpacing)) +
+ font_list_.GetBaseline();
+ // The vertical padding on the last line should be from the base of the
+ // characters not the lowest level of a character, so subtract the descent.
+ int font_descent = font_list_.GetHeight() - font_list_.GetBaseline();
+ int help_section_height =
+ text_height + 2 * kHelpVerticalPadding - font_descent;
int password_section_height = 0;
if (display_password_) {
- password_section_height =
- font_list_.GetFontSize() + 2 * kPasswordVerticalPadding;
+ // Minimum width is wide enought that we shouldn't have to do any text
+ // wrapping in this section.
+ password_section_height = kPasswordSectionHeight;
}
return (2 * kPopupBorderThickness +
@@ -213,7 +255,7 @@ void PasswordGenerationPopupControllerImpl::CalculateBounds() {
kPopupBorderThickness,
kPopupBorderThickness,
sub_view_width,
- font_list_.GetFontSize() + 2 * kPasswordVerticalPadding);
+ kPasswordSectionHeight);
divider_bounds_ = gfx::Rect(kPopupBorderThickness,
password_bounds_.bottom(),

Powered by Google App Engine
This is Rietveld 408576698