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

Side by Side 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: UI changes Created 6 years, 5 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/string_split.h" 9 #include "base/strings/string_split.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 web_contents()->GetRenderViewHost()->Send( 152 web_contents()->GetRenderViewHost()->Send(
153 new AutofillMsg_GeneratedPasswordAccepted( 153 new AutofillMsg_GeneratedPasswordAccepted(
154 web_contents()->GetRenderViewHost()->GetRoutingID(), 154 web_contents()->GetRenderViewHost()->GetRoutingID(),
155 current_password_)); 155 current_password_));
156 password_manager_->SetFormHasGeneratedPassword(form_); 156 password_manager_->SetFormHasGeneratedPassword(form_);
157 Hide(); 157 Hide();
158 } 158 }
159 159
160 int PasswordGenerationPopupControllerImpl::GetDesiredWidth() { 160 int PasswordGenerationPopupControllerImpl::GetDesiredWidth() {
161 // Minimum width in pixels. 161 // Minimum width in pixels.
162 const int minimum_required_width = 300; 162 const int minimum_required_width = 350;
Evan Stade 2014/06/24 21:16:58 it's ok to have a minimum width defined in some sh
Garrett Casto 2014/06/24 23:51:30 The first calculation requires information that is
Evan Stade 2014/06/25 00:02:41 You could expose a MinimumWidth() method to the vi
Garrett Casto 2014/06/25 19:38:14 To be clear, you're suggesting that in CalculateBo
Evan Stade 2014/06/25 21:27:29 view_->GetBounds() uses controller_->MinimumWidth(
Garrett Casto 2014/06/25 21:54:55 Done.
163 163
164 // If the width of the field is longer than the minimum, use that instead. 164 // If the width of the field is longer than the minimum, use that instead.
165 int width = std::max(minimum_required_width, 165 int width = std::max(minimum_required_width,
166 controller_common_.RoundedElementBounds().width()); 166 controller_common_.RoundedElementBounds().width());
167 167
168 if (display_password_) { 168 if (display_password_) {
169 // Make sure that the width will always be large enough to display the 169 // Make sure that the width will always be large enough to display the
170 // password and suggestion on one line. 170 // password and suggestion on one line.
171 width = std::max(width, 171 width = std::max(width,
172 gfx::GetStringWidth(current_password_ + SuggestedText(), 172 gfx::GetStringWidth(current_password_ + SuggestedText(),
173 font_list_) + 2 * kHorizontalPadding); 173 font_list_) + 2 * kHorizontalPadding);
174 } 174 }
175 175
176 return width; 176 return width;
177 } 177 }
178 178
179 int PasswordGenerationPopupControllerImpl::GetDesiredHeight(int width) {
180 // Note that this wrapping isn't exactly what the popup will do. It shouldn't
181 // line break in the middle of the link, but as long as the link isn't longer
182 // than given width this shouldn't affect the height calculated here. The
183 // default width should be wide enough to prevent this from being an issue.
184 int total_length = gfx::GetStringWidth(HelpText(), font_list_);
185 int usable_width = width - 2 * kHorizontalPadding;
186 int text_height =
187 static_cast<int>(ceil(static_cast<double>(total_length)/usable_width)) *
188 font_list_.GetFontSize();
189 int help_section_height = text_height + 2 * kHelpVerticalPadding;
190
191 int password_section_height = 0;
192 if (display_password_) {
193 password_section_height =
194 font_list_.GetFontSize() + 2 * kPasswordVerticalPadding;
195 }
196
197 return (2 * kPopupBorderThickness +
198 help_section_height +
199 password_section_height);
200 }
201
202 void PasswordGenerationPopupControllerImpl::CalculateBounds() { 179 void PasswordGenerationPopupControllerImpl::CalculateBounds() {
203 int popup_width = GetDesiredWidth(); 180 int popup_width = GetDesiredWidth();
204 int popup_height = GetDesiredHeight(popup_width); 181 int popup_height = view_->SetBoundsForWidth(popup_width);
Evan Stade 2014/06/24 21:16:58 I think this should be GetHeight(). Just calculate
Garrett Casto 2014/06/24 23:51:30 Done.
205 182
206 popup_bounds_ = controller_common_.GetPopupBounds(popup_height, popup_width); 183 popup_bounds_ = controller_common_.GetPopupBounds(popup_height, popup_width);
Evan Stade 2014/06/25 21:27:29 width should always come before height >:(
Garrett Casto 2014/06/25 21:54:55 Switched.
Evan Stade 2014/06/26 00:06:04 thank you
207 int sub_view_width = popup_bounds_.width() - 2 * kPopupBorderThickness;
208
209 // Calculate the bounds for the rest of the elements given the bounds of
210 // the popup.
211 if (display_password_) {
212 password_bounds_ = gfx::Rect(
213 kPopupBorderThickness,
214 kPopupBorderThickness,
215 sub_view_width,
216 font_list_.GetFontSize() + 2 * kPasswordVerticalPadding);
217
218 divider_bounds_ = gfx::Rect(kPopupBorderThickness,
219 password_bounds_.bottom(),
220 sub_view_width,
221 1 /* divider heigth*/);
222 } else {
223 password_bounds_ = gfx::Rect();
224 divider_bounds_ = gfx::Rect();
225 }
226
227 int help_y = std::max(kPopupBorderThickness, divider_bounds_.bottom());
228 int help_height =
229 popup_bounds_.height() - help_y - kPopupBorderThickness;
230 help_bounds_ = gfx::Rect(
231 kPopupBorderThickness,
232 help_y,
233 sub_view_width,
234 help_height);
235 } 184 }
236 185
237 void PasswordGenerationPopupControllerImpl::Show(bool display_password) { 186 void PasswordGenerationPopupControllerImpl::Show(bool display_password) {
238 display_password_ = display_password; 187 display_password_ = display_password;
239 if (display_password_) 188 if (display_password_)
240 current_password_ = base::ASCIIToUTF16(generator_->Generate()); 189 current_password_ = base::ASCIIToUTF16(generator_->Generate());
241 190
242 CalculateBounds();
243
244 if (!view_) { 191 if (!view_) {
245 view_ = PasswordGenerationPopupView::Create(this); 192 view_ = PasswordGenerationPopupView::Create(this);
193 CalculateBounds();
246 view_->Show(); 194 view_->Show();
247 } else { 195 } else {
196 CalculateBounds();
248 view_->UpdateBoundsAndRedrawPopup(); 197 view_->UpdateBoundsAndRedrawPopup();
249 } 198 }
250 199
251 controller_common_.RegisterKeyPressCallback(); 200 controller_common_.RegisterKeyPressCallback();
252 201
253 if (observer_) 202 if (observer_)
254 observer_->OnPopupShown(display_password_); 203 observer_->OnPopupShown(display_password_);
255 } 204 }
256 205
257 void PasswordGenerationPopupControllerImpl::HideAndDestroy() { 206 void PasswordGenerationPopupControllerImpl::HideAndDestroy() {
(...skipping 24 matching lines...) Expand all
282 Browser* browser = 231 Browser* browser =
283 chrome::FindBrowserWithWebContents(controller_common_.web_contents()); 232 chrome::FindBrowserWithWebContents(controller_common_.web_contents());
284 content::OpenURLParams params( 233 content::OpenURLParams params(
285 GURL(chrome::kAutoPasswordGenerationLearnMoreURL), content::Referrer(), 234 GURL(chrome::kAutoPasswordGenerationLearnMoreURL), content::Referrer(),
286 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, false); 235 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, false);
287 browser->OpenURL(params); 236 browser->OpenURL(params);
288 } 237 }
289 238
290 void PasswordGenerationPopupControllerImpl::SetSelectionAtPoint( 239 void PasswordGenerationPopupControllerImpl::SetSelectionAtPoint(
291 const gfx::Point& point) { 240 const gfx::Point& point) {
292 PasswordSelected(password_bounds_.Contains(point)); 241 PasswordSelected(view_->IsPointInPasswordBounds(point));
293 } 242 }
294 243
295 bool PasswordGenerationPopupControllerImpl::AcceptSelectedLine() { 244 bool PasswordGenerationPopupControllerImpl::AcceptSelectedLine() {
296 if (!password_selected_) 245 if (!password_selected_)
297 return false; 246 return false;
298 247
299 PasswordAccepted(); 248 PasswordAccepted();
300 return true; 249 return true;
301 } 250 }
302 251
303 void PasswordGenerationPopupControllerImpl::SelectionCleared() { 252 void PasswordGenerationPopupControllerImpl::SelectionCleared() {
304 PasswordSelected(false); 253 PasswordSelected(false);
305 } 254 }
306 255
307 gfx::NativeView PasswordGenerationPopupControllerImpl::container_view() { 256 gfx::NativeView PasswordGenerationPopupControllerImpl::container_view() {
308 return controller_common_.container_view(); 257 return controller_common_.container_view();
309 } 258 }
310 259
311 const gfx::FontList& PasswordGenerationPopupControllerImpl::font_list() const { 260 const gfx::FontList& PasswordGenerationPopupControllerImpl::font_list() const {
312 return font_list_; 261 return font_list_;
313 } 262 }
314 263
315 const gfx::Rect& PasswordGenerationPopupControllerImpl::popup_bounds() const { 264 const gfx::Rect& PasswordGenerationPopupControllerImpl::popup_bounds() const {
316 return popup_bounds_; 265 return popup_bounds_;
317 } 266 }
318 267
319 const gfx::Rect& PasswordGenerationPopupControllerImpl::password_bounds()
320 const {
321 return password_bounds_;
322 }
323
324 const gfx::Rect& PasswordGenerationPopupControllerImpl::divider_bounds()
325 const {
326 return divider_bounds_;
327 }
328
329 const gfx::Rect& PasswordGenerationPopupControllerImpl::help_bounds() const {
330 return help_bounds_;
331 }
332
333 bool PasswordGenerationPopupControllerImpl::display_password() const { 268 bool PasswordGenerationPopupControllerImpl::display_password() const {
334 return display_password_; 269 return display_password_;
335 } 270 }
336 271
337 bool PasswordGenerationPopupControllerImpl::password_selected() const { 272 bool PasswordGenerationPopupControllerImpl::password_selected() const {
338 return password_selected_; 273 return password_selected_;
339 } 274 }
340 275
341 base::string16 PasswordGenerationPopupControllerImpl::password() const { 276 base::string16 PasswordGenerationPopupControllerImpl::password() const {
342 return current_password_; 277 return current_password_;
343 } 278 }
344 279
345 base::string16 PasswordGenerationPopupControllerImpl::SuggestedText() { 280 base::string16 PasswordGenerationPopupControllerImpl::SuggestedText() {
346 return l10n_util::GetStringUTF16(IDS_PASSWORD_GENERATION_SUGGESTION); 281 return l10n_util::GetStringUTF16(IDS_PASSWORD_GENERATION_SUGGESTION);
347 } 282 }
348 283
349 const base::string16& PasswordGenerationPopupControllerImpl::HelpText() { 284 const base::string16& PasswordGenerationPopupControllerImpl::HelpText() {
350 return help_text_; 285 return help_text_;
351 } 286 }
352 287
353 const gfx::Range& PasswordGenerationPopupControllerImpl::HelpTextLinkRange() { 288 const gfx::Range& PasswordGenerationPopupControllerImpl::HelpTextLinkRange() {
354 return link_range_; 289 return link_range_;
355 } 290 }
356 291
357 } // namespace autofill 292 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698