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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 view_(NULL), | 104 view_(NULL), |
105 delegate_(delegate), | 105 delegate_(delegate), |
106 text_direction_(text_direction), | 106 text_direction_(text_direction), |
107 weak_ptr_factory_(this) { | 107 weak_ptr_factory_(this) { |
108 ClearState(); | 108 ClearState(); |
109 controller_common_->SetKeyPressCallback( | 109 controller_common_->SetKeyPressCallback( |
110 base::Bind(&AutofillPopupControllerImpl::HandleKeyPressEvent, | 110 base::Bind(&AutofillPopupControllerImpl::HandleKeyPressEvent, |
111 base::Unretained(this))); | 111 base::Unretained(this))); |
112 #if !defined(OS_ANDROID) | 112 #if !defined(OS_ANDROID) |
113 subtext_font_list_ = name_font_list_.DeriveWithSizeDelta(kLabelFontSizeDelta); | 113 subtext_font_list_ = name_font_list_.DeriveWithSizeDelta(kLabelFontSizeDelta); |
| 114 title_font_list_ = name_font_list_.DeriveWithStyle(gfx::Font::BOLD); |
114 #if defined(OS_MACOSX) | 115 #if defined(OS_MACOSX) |
115 // There is no italic version of the system font. | 116 // There is no italic version of the system font. |
116 warning_font_list_ = name_font_list_; | 117 warning_font_list_ = name_font_list_; |
117 #else | 118 #else |
118 warning_font_list_ = name_font_list_.DeriveWithStyle(gfx::Font::ITALIC); | 119 warning_font_list_ = name_font_list_.DeriveWithStyle(gfx::Font::ITALIC); |
119 #endif | 120 #endif |
120 #endif | 121 #endif |
121 } | 122 } |
122 | 123 |
123 AutofillPopupControllerImpl::~AutofillPopupControllerImpl() {} | 124 AutofillPopupControllerImpl::~AutofillPopupControllerImpl() {} |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 bool AutofillPopupControllerImpl::HandleKeyPressEvent( | 253 bool AutofillPopupControllerImpl::HandleKeyPressEvent( |
253 const content::NativeWebKeyboardEvent& event) { | 254 const content::NativeWebKeyboardEvent& event) { |
254 switch (event.windowsKeyCode) { | 255 switch (event.windowsKeyCode) { |
255 case ui::VKEY_UP: | 256 case ui::VKEY_UP: |
256 SelectPreviousLine(); | 257 SelectPreviousLine(); |
257 return true; | 258 return true; |
258 case ui::VKEY_DOWN: | 259 case ui::VKEY_DOWN: |
259 SelectNextLine(); | 260 SelectNextLine(); |
260 return true; | 261 return true; |
261 case ui::VKEY_PRIOR: // Page up. | 262 case ui::VKEY_PRIOR: // Page up. |
262 SetSelectedLine(0); | 263 // Set no line and then select the next line in case the first line is not |
| 264 // selectable. |
| 265 SetSelectedLine(kNoSelection); |
| 266 SelectNextLine(); |
263 return true; | 267 return true; |
264 case ui::VKEY_NEXT: // Page down. | 268 case ui::VKEY_NEXT: // Page down. |
265 SetSelectedLine(names().size() - 1); | 269 SetSelectedLine(names().size() - 1); |
266 return true; | 270 return true; |
267 case ui::VKEY_ESCAPE: | 271 case ui::VKEY_ESCAPE: |
268 Hide(); | 272 Hide(); |
269 return true; | 273 return true; |
270 case ui::VKEY_DELETE: | 274 case ui::VKEY_DELETE: |
271 return (event.modifiers & content::NativeWebKeyboardEvent::ShiftKey) && | 275 return (event.modifiers & content::NativeWebKeyboardEvent::ShiftKey) && |
272 RemoveSelectedLine(); | 276 RemoveSelectedLine(); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 const std::vector<int>& AutofillPopupControllerImpl::identifiers() const { | 401 const std::vector<int>& AutofillPopupControllerImpl::identifiers() const { |
398 return identifiers_; | 402 return identifiers_; |
399 } | 403 } |
400 | 404 |
401 #if !defined(OS_ANDROID) | 405 #if !defined(OS_ANDROID) |
402 const gfx::FontList& AutofillPopupControllerImpl::GetNameFontListForRow( | 406 const gfx::FontList& AutofillPopupControllerImpl::GetNameFontListForRow( |
403 size_t index) const { | 407 size_t index) const { |
404 if (identifiers_[index] == POPUP_ITEM_ID_WARNING_MESSAGE) | 408 if (identifiers_[index] == POPUP_ITEM_ID_WARNING_MESSAGE) |
405 return warning_font_list_; | 409 return warning_font_list_; |
406 | 410 |
| 411 if (identifiers_[index] == POPUP_ITEM_ID_TITLE) |
| 412 return title_font_list_; |
| 413 |
407 return name_font_list_; | 414 return name_font_list_; |
408 } | 415 } |
409 | 416 |
410 const gfx::FontList& AutofillPopupControllerImpl::subtext_font_list() const { | 417 const gfx::FontList& AutofillPopupControllerImpl::subtext_font_list() const { |
411 return subtext_font_list_; | 418 return subtext_font_list_; |
412 } | 419 } |
413 #endif | 420 #endif |
414 | 421 |
415 int AutofillPopupControllerImpl::selected_line() const { | 422 int AutofillPopupControllerImpl::selected_line() const { |
416 return selected_line_; | 423 return selected_line_; |
417 } | 424 } |
418 | 425 |
419 void AutofillPopupControllerImpl::SetSelectedLine(int selected_line) { | 426 void AutofillPopupControllerImpl::SetSelectedLine(int selected_line) { |
420 if (selected_line_ == selected_line) | 427 if (selected_line_ == selected_line) |
421 return; | 428 return; |
422 | 429 |
423 if (selected_line_ != kNoSelection && | 430 if (selected_line_ != kNoSelection && |
424 static_cast<size_t>(selected_line_) < identifiers_.size()) | 431 static_cast<size_t>(selected_line_) < identifiers_.size()) |
425 InvalidateRow(selected_line_); | 432 InvalidateRow(selected_line_); |
426 | 433 |
427 if (selected_line != kNoSelection) | 434 if (selected_line != kNoSelection) { |
428 InvalidateRow(selected_line); | 435 InvalidateRow(selected_line); |
429 | 436 |
| 437 if (!CanAccept(identifiers_[selected_line])) |
| 438 selected_line = kNoSelection; |
| 439 } |
| 440 |
430 selected_line_ = selected_line; | 441 selected_line_ = selected_line; |
431 | 442 |
432 if (selected_line_ != kNoSelection) { | 443 if (selected_line_ != kNoSelection) { |
433 delegate_->DidSelectSuggestion(names_[selected_line_], | 444 delegate_->DidSelectSuggestion(names_[selected_line_], |
434 identifiers_[selected_line_]); | 445 identifiers_[selected_line_]); |
435 } else { | 446 } else { |
436 delegate_->ClearPreviewedForm(); | 447 delegate_->ClearPreviewedForm(); |
437 } | 448 } |
438 } | 449 } |
439 | 450 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 } | 525 } |
515 | 526 |
516 int AutofillPopupControllerImpl::GetRowHeightFromId(int identifier) const { | 527 int AutofillPopupControllerImpl::GetRowHeightFromId(int identifier) const { |
517 if (identifier == POPUP_ITEM_ID_SEPARATOR) | 528 if (identifier == POPUP_ITEM_ID_SEPARATOR) |
518 return kSeparatorHeight; | 529 return kSeparatorHeight; |
519 | 530 |
520 return kRowHeight; | 531 return kRowHeight; |
521 } | 532 } |
522 | 533 |
523 bool AutofillPopupControllerImpl::CanAccept(int id) { | 534 bool AutofillPopupControllerImpl::CanAccept(int id) { |
524 return id != POPUP_ITEM_ID_SEPARATOR && id != POPUP_ITEM_ID_WARNING_MESSAGE; | 535 return id != POPUP_ITEM_ID_SEPARATOR && id != POPUP_ITEM_ID_WARNING_MESSAGE && |
| 536 id != POPUP_ITEM_ID_TITLE; |
525 } | 537 } |
526 | 538 |
527 bool AutofillPopupControllerImpl::HasSuggestions() { | 539 bool AutofillPopupControllerImpl::HasSuggestions() { |
528 return identifiers_.size() != 0 && | 540 return identifiers_.size() != 0 && |
529 (identifiers_[0] > 0 || | 541 (identifiers_[0] > 0 || |
530 identifiers_[0] == POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY || | 542 identifiers_[0] == POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY || |
531 identifiers_[0] == POPUP_ITEM_ID_PASSWORD_ENTRY || | 543 identifiers_[0] == POPUP_ITEM_ID_PASSWORD_ENTRY || |
532 identifiers_[0] == POPUP_ITEM_ID_DATALIST_ENTRY || | 544 identifiers_[0] == POPUP_ITEM_ID_DATALIST_ENTRY || |
533 identifiers_[0] == POPUP_ITEM_ID_MAC_ACCESS_CONTACTS); | 545 identifiers_[0] == POPUP_ITEM_ID_MAC_ACCESS_CONTACTS); |
534 } | 546 } |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 names_.clear(); | 637 names_.clear(); |
626 subtexts_.clear(); | 638 subtexts_.clear(); |
627 icons_.clear(); | 639 icons_.clear(); |
628 identifiers_.clear(); | 640 identifiers_.clear(); |
629 full_names_.clear(); | 641 full_names_.clear(); |
630 | 642 |
631 selected_line_ = kNoSelection; | 643 selected_line_ = kNoSelection; |
632 } | 644 } |
633 | 645 |
634 } // namespace autofill | 646 } // namespace autofill |
OLD | NEW |