| OLD | NEW |
| 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 Loading... |
| 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) { |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 bool AutofillPopupControllerImpl::HandleKeyPressEvent( | 254 bool AutofillPopupControllerImpl::HandleKeyPressEvent( |
| 254 const content::NativeWebKeyboardEvent& event) { | 255 const content::NativeWebKeyboardEvent& event) { |
| 255 switch (event.windowsKeyCode) { | 256 switch (event.windowsKeyCode) { |
| 256 case ui::VKEY_UP: | 257 case ui::VKEY_UP: |
| 257 SelectPreviousLine(); | 258 SelectPreviousLine(); |
| 258 return true; | 259 return true; |
| 259 case ui::VKEY_DOWN: | 260 case ui::VKEY_DOWN: |
| 260 SelectNextLine(); | 261 SelectNextLine(); |
| 261 return true; | 262 return true; |
| 262 case ui::VKEY_PRIOR: // Page up. | 263 case ui::VKEY_PRIOR: // Page up. |
| 263 SetSelectedLine(0); | 264 // Set no line and then select the next line in case the first line is not |
| 265 // selectable. |
| 266 SetSelectedLine(kNoSelection); |
| 267 SelectNextLine(); |
| 264 return true; | 268 return true; |
| 265 case ui::VKEY_NEXT: // Page down. | 269 case ui::VKEY_NEXT: // Page down. |
| 266 SetSelectedLine(names().size() - 1); | 270 SetSelectedLine(names().size() - 1); |
| 267 return true; | 271 return true; |
| 268 case ui::VKEY_ESCAPE: | 272 case ui::VKEY_ESCAPE: |
| 269 Hide(); | 273 Hide(); |
| 270 return true; | 274 return true; |
| 271 case ui::VKEY_DELETE: | 275 case ui::VKEY_DELETE: |
| 272 return (event.modifiers & content::NativeWebKeyboardEvent::ShiftKey) && | 276 return (event.modifiers & content::NativeWebKeyboardEvent::ShiftKey) && |
| 273 RemoveSelectedLine(); | 277 RemoveSelectedLine(); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 const std::vector<int>& AutofillPopupControllerImpl::identifiers() const { | 402 const std::vector<int>& AutofillPopupControllerImpl::identifiers() const { |
| 399 return identifiers_; | 403 return identifiers_; |
| 400 } | 404 } |
| 401 | 405 |
| 402 #if !defined(OS_ANDROID) | 406 #if !defined(OS_ANDROID) |
| 403 const gfx::FontList& AutofillPopupControllerImpl::GetNameFontListForRow( | 407 const gfx::FontList& AutofillPopupControllerImpl::GetNameFontListForRow( |
| 404 size_t index) const { | 408 size_t index) const { |
| 405 if (identifiers_[index] == POPUP_ITEM_ID_WARNING_MESSAGE) | 409 if (identifiers_[index] == POPUP_ITEM_ID_WARNING_MESSAGE) |
| 406 return warning_font_list_; | 410 return warning_font_list_; |
| 407 | 411 |
| 412 if (identifiers_[index] == POPUP_ITEM_ID_TITLE) |
| 413 return title_font_list_; |
| 414 |
| 408 return name_font_list_; | 415 return name_font_list_; |
| 409 } | 416 } |
| 410 | 417 |
| 411 const gfx::FontList& AutofillPopupControllerImpl::subtext_font_list() const { | 418 const gfx::FontList& AutofillPopupControllerImpl::subtext_font_list() const { |
| 412 return subtext_font_list_; | 419 return subtext_font_list_; |
| 413 } | 420 } |
| 414 #endif | 421 #endif |
| 415 | 422 |
| 416 int AutofillPopupControllerImpl::selected_line() const { | 423 int AutofillPopupControllerImpl::selected_line() const { |
| 417 return selected_line_; | 424 return selected_line_; |
| 418 } | 425 } |
| 419 | 426 |
| 420 void AutofillPopupControllerImpl::SetSelectedLine(int selected_line) { | 427 void AutofillPopupControllerImpl::SetSelectedLine(int selected_line) { |
| 421 if (selected_line_ == selected_line) | 428 if (selected_line_ == selected_line) |
| 422 return; | 429 return; |
| 423 | 430 |
| 431 if (selected_line != kNoSelection && identifiers_.size() > 0 && |
| 432 identifiers_[selected_line] == POPUP_ITEM_ID_TITLE) |
| 433 return; |
| 434 |
| 424 if (selected_line_ != kNoSelection && | 435 if (selected_line_ != kNoSelection && |
| 425 static_cast<size_t>(selected_line_) < identifiers_.size()) | 436 static_cast<size_t>(selected_line_) < identifiers_.size()) |
| 426 InvalidateRow(selected_line_); | 437 InvalidateRow(selected_line_); |
| 427 | 438 |
| 428 if (selected_line != kNoSelection) | 439 if (selected_line != kNoSelection) |
| 429 InvalidateRow(selected_line); | 440 InvalidateRow(selected_line); |
| 430 | 441 |
| 431 selected_line_ = selected_line; | 442 selected_line_ = selected_line; |
| 432 | 443 |
| 433 if (selected_line_ != kNoSelection) { | 444 if (selected_line_ != kNoSelection) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 } | 526 } |
| 516 | 527 |
| 517 int AutofillPopupControllerImpl::GetRowHeightFromId(int identifier) const { | 528 int AutofillPopupControllerImpl::GetRowHeightFromId(int identifier) const { |
| 518 if (identifier == POPUP_ITEM_ID_SEPARATOR) | 529 if (identifier == POPUP_ITEM_ID_SEPARATOR) |
| 519 return kSeparatorHeight; | 530 return kSeparatorHeight; |
| 520 | 531 |
| 521 return kRowHeight; | 532 return kRowHeight; |
| 522 } | 533 } |
| 523 | 534 |
| 524 bool AutofillPopupControllerImpl::CanAccept(int id) { | 535 bool AutofillPopupControllerImpl::CanAccept(int id) { |
| 525 return id != POPUP_ITEM_ID_SEPARATOR && id != POPUP_ITEM_ID_WARNING_MESSAGE; | 536 return id != POPUP_ITEM_ID_SEPARATOR && id != POPUP_ITEM_ID_WARNING_MESSAGE && |
| 537 id != POPUP_ITEM_ID_TITLE; |
| 526 } | 538 } |
| 527 | 539 |
| 528 bool AutofillPopupControllerImpl::HasSuggestions() { | 540 bool AutofillPopupControllerImpl::HasSuggestions() { |
| 529 return identifiers_.size() != 0 && | 541 return identifiers_.size() != 0 && |
| 530 (identifiers_[0] > 0 || | 542 (identifiers_[0] > 0 || |
| 531 identifiers_[0] == POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY || | 543 identifiers_[0] == POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY || |
| 532 identifiers_[0] == POPUP_ITEM_ID_PASSWORD_ENTRY || | 544 identifiers_[0] == POPUP_ITEM_ID_PASSWORD_ENTRY || |
| 533 identifiers_[0] == POPUP_ITEM_ID_DATALIST_ENTRY || | 545 identifiers_[0] == POPUP_ITEM_ID_DATALIST_ENTRY || |
| 534 identifiers_[0] == POPUP_ITEM_ID_MAC_ACCESS_CONTACTS); | 546 identifiers_[0] == POPUP_ITEM_ID_MAC_ACCESS_CONTACTS); |
| 535 } | 547 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 names_.clear(); | 638 names_.clear(); |
| 627 subtexts_.clear(); | 639 subtexts_.clear(); |
| 628 icons_.clear(); | 640 icons_.clear(); |
| 629 identifiers_.clear(); | 641 identifiers_.clear(); |
| 630 full_names_.clear(); | 642 full_names_.clear(); |
| 631 | 643 |
| 632 selected_line_ = kNoSelection; | 644 selected_line_ = kNoSelection; |
| 633 } | 645 } |
| 634 | 646 |
| 635 } // namespace autofill | 647 } // namespace autofill |
| OLD | NEW |