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 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 const base::string16& AutofillPopupControllerImpl::GetElidedValueAt( | 410 const base::string16& AutofillPopupControllerImpl::GetElidedValueAt( |
411 size_t row) const { | 411 size_t row) const { |
412 return elided_values_[row]; | 412 return elided_values_[row]; |
413 } | 413 } |
414 | 414 |
415 const base::string16& AutofillPopupControllerImpl::GetElidedLabelAt( | 415 const base::string16& AutofillPopupControllerImpl::GetElidedLabelAt( |
416 size_t row) const { | 416 size_t row) const { |
417 return elided_labels_[row]; | 417 return elided_labels_[row]; |
418 } | 418 } |
419 | 419 |
| 420 bool AutofillPopupControllerImpl::GetRemovalConfirmationText( |
| 421 int list_index, |
| 422 base::string16* title, |
| 423 base::string16* body) { |
| 424 return delegate_->GetDeletionConfirmationText( |
| 425 suggestions_[list_index].value, suggestions_[list_index].frontend_id, |
| 426 title, body); |
| 427 } |
| 428 |
| 429 bool AutofillPopupControllerImpl::RemoveSuggestion(int list_index) { |
| 430 if (!delegate_->RemoveSuggestion(suggestions_[list_index].value, |
| 431 suggestions_[list_index].frontend_id)) { |
| 432 return false; |
| 433 } |
| 434 |
| 435 // Remove the deleted element. |
| 436 suggestions_.erase(suggestions_.begin() + list_index); |
| 437 elided_values_.erase(elided_values_.begin() + list_index); |
| 438 elided_labels_.erase(elided_labels_.begin() + list_index); |
| 439 |
| 440 SetSelectedLine(kNoSelection); |
| 441 |
| 442 if (HasSuggestions()) { |
| 443 delegate_->ClearPreviewedForm(); |
| 444 UpdateBoundsAndRedrawPopup(); |
| 445 } else { |
| 446 Hide(); |
| 447 } |
| 448 |
| 449 return true; |
| 450 } |
| 451 |
420 #if !defined(OS_ANDROID) | 452 #if !defined(OS_ANDROID) |
421 const gfx::FontList& AutofillPopupControllerImpl::GetValueFontListForRow( | 453 const gfx::FontList& AutofillPopupControllerImpl::GetValueFontListForRow( |
422 size_t index) const { | 454 size_t index) const { |
423 if (suggestions_[index].frontend_id == POPUP_ITEM_ID_WARNING_MESSAGE) | 455 if (suggestions_[index].frontend_id == POPUP_ITEM_ID_WARNING_MESSAGE) |
424 return warning_font_list_; | 456 return warning_font_list_; |
425 | 457 |
426 if (suggestions_[index].frontend_id == POPUP_ITEM_ID_TITLE) | 458 if (suggestions_[index].frontend_id == POPUP_ITEM_ID_TITLE) |
427 return title_font_list_; | 459 return title_font_list_; |
428 | 460 |
429 return value_font_list_; | 461 return value_font_list_; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 | 524 |
493 SetSelectedLine(new_selected_line); | 525 SetSelectedLine(new_selected_line); |
494 } | 526 } |
495 | 527 |
496 bool AutofillPopupControllerImpl::RemoveSelectedLine() { | 528 bool AutofillPopupControllerImpl::RemoveSelectedLine() { |
497 if (selected_line_ == kNoSelection) | 529 if (selected_line_ == kNoSelection) |
498 return false; | 530 return false; |
499 | 531 |
500 DCHECK_GE(selected_line_, 0); | 532 DCHECK_GE(selected_line_, 0); |
501 DCHECK_LT(selected_line_, static_cast<int>(GetLineCount())); | 533 DCHECK_LT(selected_line_, static_cast<int>(GetLineCount())); |
502 | 534 return RemoveSuggestion(selected_line_); |
503 if (!delegate_->RemoveSuggestion(suggestions_[selected_line_].value, | |
504 suggestions_[selected_line_].frontend_id)) { | |
505 return false; | |
506 } | |
507 | |
508 // Remove the deleted element. | |
509 suggestions_.erase(suggestions_.begin() + selected_line_); | |
510 elided_values_.erase(elided_values_.begin() + selected_line_); | |
511 elided_labels_.erase(elided_labels_.begin() + selected_line_); | |
512 | |
513 SetSelectedLine(kNoSelection); | |
514 | |
515 if (HasSuggestions()) { | |
516 delegate_->ClearPreviewedForm(); | |
517 UpdateBoundsAndRedrawPopup(); | |
518 } else { | |
519 Hide(); | |
520 } | |
521 | |
522 return true; | |
523 } | 535 } |
524 | 536 |
525 int AutofillPopupControllerImpl::LineFromY(int y) { | 537 int AutofillPopupControllerImpl::LineFromY(int y) { |
526 int current_height = kPopupBorderThickness; | 538 int current_height = kPopupBorderThickness; |
527 | 539 |
528 for (size_t i = 0; i < suggestions_.size(); ++i) { | 540 for (size_t i = 0; i < suggestions_.size(); ++i) { |
529 current_height += GetRowHeightFromId(suggestions_[i].frontend_id); | 541 current_height += GetRowHeightFromId(suggestions_[i].frontend_id); |
530 | 542 |
531 if (y <= current_height) | 543 if (y <= current_height) |
532 return i; | 544 return i; |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 popup_bounds_ = gfx::Rect(); | 660 popup_bounds_ = gfx::Rect(); |
649 | 661 |
650 suggestions_.clear(); | 662 suggestions_.clear(); |
651 elided_values_.clear(); | 663 elided_values_.clear(); |
652 elided_labels_.clear(); | 664 elided_labels_.clear(); |
653 | 665 |
654 selected_line_ = kNoSelection; | 666 selected_line_ = kNoSelection; |
655 } | 667 } |
656 | 668 |
657 } // namespace autofill | 669 } // namespace autofill |
OLD | NEW |