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

Side by Side Diff: chrome/browser/ui/autofill/password_generation_popup_controller_impl.cc

Issue 152343006: Clean-up: Replaces obsolete Font/FontList methods. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Synced. Created 6 years, 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/autofill/password_generation_popup_controller_impl.h " 5 #include "chrome/browser/ui/autofill/password_generation_popup_controller_impl.h "
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include "base/strings/utf_string_conversion_utils.h" 9 #include "base/strings/utf_string_conversion_utils.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/password_manager/password_manager.h" 11 #include "chrome/browser/password_manager/password_manager.h"
12 #include "chrome/browser/ui/autofill/password_generation_popup_observer.h" 12 #include "chrome/browser/ui/autofill/password_generation_popup_observer.h"
13 #include "chrome/browser/ui/autofill/password_generation_popup_view.h" 13 #include "chrome/browser/ui/autofill/password_generation_popup_view.h"
14 #include "chrome/browser/ui/autofill/popup_constants.h" 14 #include "chrome/browser/ui/autofill/popup_constants.h"
15 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_finder.h" 16 #include "chrome/browser/ui/browser_finder.h"
17 #include "chrome/common/url_constants.h" 17 #include "chrome/common/url_constants.h"
18 #include "components/autofill/content/common/autofill_messages.h" 18 #include "components/autofill/content/common/autofill_messages.h"
19 #include "components/autofill/core/browser/password_generator.h" 19 #include "components/autofill/core/browser/password_generator.h"
20 #include "content/public/browser/native_web_keyboard_event.h" 20 #include "content/public/browser/native_web_keyboard_event.h"
21 #include "content/public/browser/render_view_host.h" 21 #include "content/public/browser/render_view_host.h"
22 #include "content/public/browser/web_contents.h" 22 #include "content/public/browser/web_contents.h"
23 #include "grit/generated_resources.h" 23 #include "grit/generated_resources.h"
24 #include "ui/base/l10n/l10n_util.h" 24 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/events/keycodes/keyboard_codes.h" 25 #include "ui/events/keycodes/keyboard_codes.h"
26 #include "ui/gfx/rect_conversions.h" 26 #include "ui/gfx/rect_conversions.h"
27 #include "ui/gfx/text_utils.h"
27 28
28 namespace autofill { 29 namespace autofill {
29 30
30 const int kMinimumWidth = 60; 31 const int kMinimumWidth = 60;
31 const int kDividerHeight = 1; 32 const int kDividerHeight = 1;
32 33
33 base::WeakPtr<PasswordGenerationPopupControllerImpl> 34 base::WeakPtr<PasswordGenerationPopupControllerImpl>
34 PasswordGenerationPopupControllerImpl::GetOrCreate( 35 PasswordGenerationPopupControllerImpl::GetOrCreate(
35 base::WeakPtr<PasswordGenerationPopupControllerImpl> previous, 36 base::WeakPtr<PasswordGenerationPopupControllerImpl> previous,
36 const gfx::RectF& bounds, 37 const gfx::RectF& bounds,
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 web_contents()->GetRenderViewHost()->Send( 132 web_contents()->GetRenderViewHost()->Send(
132 new AutofillMsg_GeneratedPasswordAccepted( 133 new AutofillMsg_GeneratedPasswordAccepted(
133 web_contents()->GetRenderViewHost()->GetRoutingID(), 134 web_contents()->GetRenderViewHost()->GetRoutingID(),
134 current_password_)); 135 current_password_));
135 password_manager_->SetFormHasGeneratedPassword(form_); 136 password_manager_->SetFormHasGeneratedPassword(form_);
136 Hide(); 137 Hide();
137 } 138 }
138 139
139 int PasswordGenerationPopupControllerImpl::GetDesiredWidth() { 140 int PasswordGenerationPopupControllerImpl::GetDesiredWidth() {
140 // Minimum width we want to display the password. 141 // Minimum width we want to display the password.
141 int minimum_length_for_text = 2 * kHorizontalPadding + 142 int minimum_length_for_text =
142 font_.GetExpectedTextWidth(kMinimumWidth) + 143 2 * kHorizontalPadding +
144 font_list_.GetExpectedTextWidth(kMinimumWidth) +
143 2 * kPopupBorderThickness; 145 2 * kPopupBorderThickness;
144 146
145 // If the width of the field is longer than the minimum, use that instead. 147 // If the width of the field is longer than the minimum, use that instead.
146 return std::max(minimum_length_for_text, 148 return std::max(minimum_length_for_text,
147 controller_common_.RoundedElementBounds().width()); 149 controller_common_.RoundedElementBounds().width());
148 } 150 }
149 151
150 int PasswordGenerationPopupControllerImpl::GetDesiredHeight(int width) { 152 int PasswordGenerationPopupControllerImpl::GetDesiredHeight(int width) {
151 // Note that this wrapping isn't exactly what the popup will do. It shouldn't 153 // Note that this wrapping isn't exactly what the popup will do. It shouldn't
152 // line break in the middle of the link, but as long as the link isn't longer 154 // line break in the middle of the link, but as long as the link isn't longer
153 // than given width this shouldn't affect the height calculated here. The 155 // than given width this shouldn't affect the height calculated here. The
154 // default width should be wide enough to prevent this from being an issue. 156 // default width should be wide enough to prevent this from being an issue.
155 int total_length = font_.GetStringWidth(HelpText() + LearnMoreLink()); 157 int total_length = gfx::GetStringWidth(HelpText() + LearnMoreLink(),
158 font_list_);
156 int usable_width = width - 2 * kHorizontalPadding; 159 int usable_width = width - 2 * kHorizontalPadding;
157 int text_height = 160 int text_height =
158 static_cast<int>(ceil(static_cast<double>(total_length)/usable_width)) * 161 static_cast<int>(ceil(static_cast<double>(total_length)/usable_width)) *
159 font_.GetHeight(); 162 font_list_.GetHeight();
160 int help_section_height = text_height + 2 * kHelpVerticalPadding; 163 int help_section_height = text_height + 2 * kHelpVerticalPadding;
161 164
162 int password_section_height = 165 int password_section_height =
163 font_.GetHeight() + 2 * kPasswordVerticalPadding; 166 font_list_.GetHeight() + 2 * kPasswordVerticalPadding;
164 167
165 return (2 * kPopupBorderThickness + 168 return (2 * kPopupBorderThickness +
166 help_section_height + 169 help_section_height +
167 password_section_height); 170 password_section_height);
168 } 171 }
169 172
170 void PasswordGenerationPopupControllerImpl::CalculateBounds() { 173 void PasswordGenerationPopupControllerImpl::CalculateBounds() {
171 int popup_width = GetDesiredWidth(); 174 int popup_width = GetDesiredWidth();
172 int popup_height = GetDesiredHeight(popup_width); 175 int popup_height = GetDesiredHeight(popup_width);
173 176
174 popup_bounds_ = controller_common_.GetPopupBounds(popup_height, popup_width); 177 popup_bounds_ = controller_common_.GetPopupBounds(popup_height, popup_width);
175 178
176 // Calculate the bounds for the rest of the elements given the bounds of 179 // Calculate the bounds for the rest of the elements given the bounds of
177 // the popup. 180 // the popup.
178 password_bounds_ = gfx::Rect( 181 password_bounds_ = gfx::Rect(
179 kPopupBorderThickness, 182 kPopupBorderThickness,
180 kPopupBorderThickness, 183 kPopupBorderThickness,
181 popup_bounds_.width() - 2 * kPopupBorderThickness, 184 popup_bounds_.width() - 2 * kPopupBorderThickness,
182 font_.GetHeight() + 2 * kPasswordVerticalPadding); 185 font_list_.GetHeight() + 2 * kPasswordVerticalPadding);
183 186
184 divider_bounds_ = gfx::Rect(kPopupBorderThickness, 187 divider_bounds_ = gfx::Rect(kPopupBorderThickness,
185 password_bounds_.bottom(), 188 password_bounds_.bottom(),
186 password_bounds_.width(), 189 password_bounds_.width(),
187 kDividerHeight); 190 kDividerHeight);
188 191
189 int help_height = 192 int help_height =
190 popup_bounds_.height() - divider_bounds_.bottom() - kPopupBorderThickness; 193 popup_bounds_.height() - divider_bounds_.bottom() - kPopupBorderThickness;
191 help_bounds_ = gfx::Rect( 194 help_bounds_ = gfx::Rect(
192 kPopupBorderThickness, 195 kPopupBorderThickness,
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 301
299 base::string16 PasswordGenerationPopupControllerImpl::HelpText() { 302 base::string16 PasswordGenerationPopupControllerImpl::HelpText() {
300 return l10n_util::GetStringUTF16(IDS_PASSWORD_GENERATION_PROMPT); 303 return l10n_util::GetStringUTF16(IDS_PASSWORD_GENERATION_PROMPT);
301 } 304 }
302 305
303 base::string16 PasswordGenerationPopupControllerImpl::LearnMoreLink() { 306 base::string16 PasswordGenerationPopupControllerImpl::LearnMoreLink() {
304 return l10n_util::GetStringUTF16(IDS_PASSWORD_GENERATION_LEARN_MORE_LINK); 307 return l10n_util::GetStringUTF16(IDS_PASSWORD_GENERATION_LEARN_MORE_LINK);
305 } 308 }
306 309
307 } // namespace autofill 310 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698