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

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

Issue 492043003: Fill on account select in the password manager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase on ToT Created 6 years, 1 month 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/autofill_popup_controller_impl.h" 5 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 base::Bind(&AutofillPopupControllerImpl::HandleKeyPressEvent, 111 base::Bind(&AutofillPopupControllerImpl::HandleKeyPressEvent,
112 base::Unretained(this))); 112 base::Unretained(this)));
113 #if !defined(OS_ANDROID) 113 #if !defined(OS_ANDROID)
114 subtext_font_list_ = name_font_list_.DeriveWithSizeDelta(kLabelFontSizeDelta); 114 subtext_font_list_ = name_font_list_.DeriveWithSizeDelta(kLabelFontSizeDelta);
115 #if defined(OS_MACOSX) 115 #if defined(OS_MACOSX)
116 // There is no italic version of the system font. 116 // There is no italic version of the system font.
117 warning_font_list_ = name_font_list_; 117 warning_font_list_ = name_font_list_;
118 #else 118 #else
119 warning_font_list_ = name_font_list_.DeriveWithStyle(gfx::Font::ITALIC); 119 warning_font_list_ = name_font_list_.DeriveWithStyle(gfx::Font::ITALIC);
120 #endif 120 #endif
121 title_font_list_ = name_font_list_.DeriveWithStyle(gfx::Font::BOLD);
121 #endif 122 #endif
122 } 123 }
123 124
124 AutofillPopupControllerImpl::~AutofillPopupControllerImpl() {} 125 AutofillPopupControllerImpl::~AutofillPopupControllerImpl() {}
125 126
126 void AutofillPopupControllerImpl::Show( 127 void AutofillPopupControllerImpl::Show(
127 const std::vector<base::string16>& names, 128 const std::vector<base::string16>& names,
128 const std::vector<base::string16>& subtexts, 129 const std::vector<base::string16>& subtexts,
129 const std::vector<base::string16>& icons, 130 const std::vector<base::string16>& icons,
130 const std::vector<int>& identifiers) { 131 const std::vector<int>& identifiers,
131 SetValues(names, subtexts, icons, identifiers); 132 const base::string16& title) {
Garrett Casto 2014/11/04 23:35:30 Given the way that this works for other labels, it
jww 2014/11/06 21:28:56 Done.
133 SetValues(names, subtexts, icons, identifiers, title);
132 134
133 #if !defined(OS_ANDROID) 135 #if !defined(OS_ANDROID)
134 // Android displays the long text with ellipsis using the view attributes. 136 // Android displays the long text with ellipsis using the view attributes.
135 137
136 UpdatePopupBounds(); 138 UpdatePopupBounds();
137 int popup_width = popup_bounds().width(); 139 int popup_width = popup_bounds().width();
138 140
139 // Elide the name and subtext strings so that the popup fits in the available 141 // Elide the name and subtext strings so that the popup fits in the available
140 // space. 142 // space.
141 for (size_t i = 0; i < names_.size(); ++i) { 143 for (size_t i = 0; i < names_.size(); ++i) {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 bool AutofillPopupControllerImpl::HandleKeyPressEvent( 255 bool AutofillPopupControllerImpl::HandleKeyPressEvent(
254 const content::NativeWebKeyboardEvent& event) { 256 const content::NativeWebKeyboardEvent& event) {
255 switch (event.windowsKeyCode) { 257 switch (event.windowsKeyCode) {
256 case ui::VKEY_UP: 258 case ui::VKEY_UP:
257 SelectPreviousLine(); 259 SelectPreviousLine();
258 return true; 260 return true;
259 case ui::VKEY_DOWN: 261 case ui::VKEY_DOWN:
260 SelectNextLine(); 262 SelectNextLine();
261 return true; 263 return true;
262 case ui::VKEY_PRIOR: // Page up. 264 case ui::VKEY_PRIOR: // Page up.
263 SetSelectedLine(0); 265 SetSelectedLine(GetFirstSelectableLine());
264 return true; 266 return true;
265 case ui::VKEY_NEXT: // Page down. 267 case ui::VKEY_NEXT: // Page down.
266 SetSelectedLine(names().size() - 1); 268 SetSelectedLine(names().size() - 1);
267 return true; 269 return true;
268 case ui::VKEY_ESCAPE: 270 case ui::VKEY_ESCAPE:
269 Hide(); 271 Hide();
270 return true; 272 return true;
271 case ui::VKEY_DELETE: 273 case ui::VKEY_DELETE:
272 return (event.modifiers & content::NativeWebKeyboardEvent::ShiftKey) && 274 return (event.modifiers & content::NativeWebKeyboardEvent::ShiftKey) &&
273 RemoveSelectedLine(); 275 RemoveSelectedLine();
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 const std::vector<int>& AutofillPopupControllerImpl::identifiers() const { 400 const std::vector<int>& AutofillPopupControllerImpl::identifiers() const {
399 return identifiers_; 401 return identifiers_;
400 } 402 }
401 403
402 #if !defined(OS_ANDROID) 404 #if !defined(OS_ANDROID)
403 const gfx::FontList& AutofillPopupControllerImpl::GetNameFontListForRow( 405 const gfx::FontList& AutofillPopupControllerImpl::GetNameFontListForRow(
404 size_t index) const { 406 size_t index) const {
405 if (identifiers_[index] == POPUP_ITEM_ID_WARNING_MESSAGE) 407 if (identifiers_[index] == POPUP_ITEM_ID_WARNING_MESSAGE)
406 return warning_font_list_; 408 return warning_font_list_;
407 409
410 if (identifiers_[index] == POPUP_ITEM_ID_TITLE)
411 return title_font_list_;
412
408 return name_font_list_; 413 return name_font_list_;
409 } 414 }
410 415
411 const gfx::FontList& AutofillPopupControllerImpl::subtext_font_list() const { 416 const gfx::FontList& AutofillPopupControllerImpl::subtext_font_list() const {
412 return subtext_font_list_; 417 return subtext_font_list_;
413 } 418 }
414 #endif 419 #endif
415 420
416 int AutofillPopupControllerImpl::selected_line() const { 421 int AutofillPopupControllerImpl::selected_line() const {
417 return selected_line_; 422 return selected_line_;
418 } 423 }
419 424
420 void AutofillPopupControllerImpl::SetSelectedLine(int selected_line) { 425 void AutofillPopupControllerImpl::SetSelectedLine(int selected_line) {
421 if (selected_line_ == selected_line) 426 if (selected_line_ == selected_line)
422 return; 427 return;
423 428
429 if (selected_line != kNoSelection && identifiers_.size() > 0 &&
430 identifiers_[selected_line] == POPUP_ITEM_ID_TITLE)
431 return;
432
424 if (selected_line_ != kNoSelection && 433 if (selected_line_ != kNoSelection &&
425 static_cast<size_t>(selected_line_) < identifiers_.size()) 434 static_cast<size_t>(selected_line_) < identifiers_.size())
426 InvalidateRow(selected_line_); 435 InvalidateRow(selected_line_);
427 436
428 if (selected_line != kNoSelection) 437 if (selected_line != kNoSelection)
429 InvalidateRow(selected_line); 438 InvalidateRow(selected_line);
430 439
431 selected_line_ = selected_line; 440 selected_line_ = selected_line;
432 441
433 if (selected_line_ != kNoSelection) { 442 if (selected_line_ != kNoSelection) {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 } 524 }
516 525
517 int AutofillPopupControllerImpl::GetRowHeightFromId(int identifier) const { 526 int AutofillPopupControllerImpl::GetRowHeightFromId(int identifier) const {
518 if (identifier == POPUP_ITEM_ID_SEPARATOR) 527 if (identifier == POPUP_ITEM_ID_SEPARATOR)
519 return kSeparatorHeight; 528 return kSeparatorHeight;
520 529
521 return kRowHeight; 530 return kRowHeight;
522 } 531 }
523 532
524 bool AutofillPopupControllerImpl::CanAccept(int id) { 533 bool AutofillPopupControllerImpl::CanAccept(int id) {
525 return id != POPUP_ITEM_ID_SEPARATOR && id != POPUP_ITEM_ID_WARNING_MESSAGE; 534 return id != POPUP_ITEM_ID_SEPARATOR && id != POPUP_ITEM_ID_WARNING_MESSAGE &&
535 id != POPUP_ITEM_ID_TITLE;
526 } 536 }
527 537
528 bool AutofillPopupControllerImpl::HasSuggestions() { 538 bool AutofillPopupControllerImpl::HasSuggestions() {
529 return identifiers_.size() != 0 && 539 return identifiers_.size() != 0 &&
530 (identifiers_[0] > 0 || 540 (identifiers_[0] > 0 ||
531 identifiers_[0] == POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY || 541 identifiers_[0] == POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY ||
532 identifiers_[0] == POPUP_ITEM_ID_PASSWORD_ENTRY || 542 identifiers_[0] == POPUP_ITEM_ID_PASSWORD_ENTRY ||
533 identifiers_[0] == POPUP_ITEM_ID_DATALIST_ENTRY || 543 identifiers_[0] == POPUP_ITEM_ID_DATALIST_ENTRY ||
534 identifiers_[0] == POPUP_ITEM_ID_MAC_ACCESS_CONTACTS); 544 identifiers_[0] == POPUP_ITEM_ID_MAC_ACCESS_CONTACTS);
535 } 545 }
536 546
537 void AutofillPopupControllerImpl::SetValues( 547 void AutofillPopupControllerImpl::SetValues(
538 const std::vector<base::string16>& names, 548 const std::vector<base::string16>& names,
539 const std::vector<base::string16>& subtexts, 549 const std::vector<base::string16>& subtexts,
540 const std::vector<base::string16>& icons, 550 const std::vector<base::string16>& icons,
541 const std::vector<int>& identifiers) { 551 const std::vector<int>& identifiers,
552 const base::string16& title) {
542 names_ = names; 553 names_ = names;
543 full_names_ = names; 554 full_names_ = names;
544 subtexts_ = subtexts; 555 subtexts_ = subtexts;
545 icons_ = icons; 556 icons_ = icons;
546 identifiers_ = identifiers; 557 identifiers_ = identifiers;
558
559 if (!title.empty()) {
560 names_.insert(names_.begin(), title);
561 full_names_.insert(full_names_.begin(), title);
562 subtexts_.insert(subtexts_.begin(), base::string16());
563 icons_.insert(icons_.begin(), base::string16());
564 identifiers_.insert(identifiers_.begin(), POPUP_ITEM_ID_TITLE);
565 }
547 } 566 }
548 567
549 void AutofillPopupControllerImpl::ShowView() { 568 void AutofillPopupControllerImpl::ShowView() {
550 view_->Show(); 569 view_->Show();
551 } 570 }
552 571
553 void AutofillPopupControllerImpl::InvalidateRow(size_t row) { 572 void AutofillPopupControllerImpl::InvalidateRow(size_t row) {
554 DCHECK(0 <= row); 573 DCHECK(0 <= row);
555 DCHECK(row < identifiers_.size()); 574 DCHECK(row < identifiers_.size());
556 view_->InvalidateRow(row); 575 view_->InvalidateRow(row);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 644
626 names_.clear(); 645 names_.clear();
627 subtexts_.clear(); 646 subtexts_.clear();
628 icons_.clear(); 647 icons_.clear();
629 identifiers_.clear(); 648 identifiers_.clear();
630 full_names_.clear(); 649 full_names_.clear();
631 650
632 selected_line_ = kNoSelection; 651 selected_line_ = kNoSelection;
633 } 652 }
634 653
654 int AutofillPopupControllerImpl::GetFirstSelectableLine() {
655 if (identifiers().size() < 1 || identifiers()[0] != POPUP_ITEM_ID_TITLE)
656 return 0;
657
658 return 1;
659 }
660
635 } // namespace autofill 661 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698