| 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 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 int AutofillPopupControllerImpl::GetIconResourceID( | 349 int AutofillPopupControllerImpl::GetIconResourceID( |
| 350 const base::string16& resource_name) const { | 350 const base::string16& resource_name) const { |
| 351 for (size_t i = 0; i < arraysize(kDataResources); ++i) { | 351 for (size_t i = 0; i < arraysize(kDataResources); ++i) { |
| 352 if (resource_name == base::ASCIIToUTF16(kDataResources[i].name)) | 352 if (resource_name == base::ASCIIToUTF16(kDataResources[i].name)) |
| 353 return kDataResources[i].id; | 353 return kDataResources[i].id; |
| 354 } | 354 } |
| 355 | 355 |
| 356 return -1; | 356 return -1; |
| 357 } | 357 } |
| 358 | 358 |
| 359 bool AutofillPopupControllerImpl::CanDelete(size_t index) const { | |
| 360 // TODO(isherman): Native AddressBook suggestions on Mac and Android should | |
| 361 // not be considered to be deleteable. | |
| 362 int id = suggestions_[index].frontend_id; | |
| 363 return id > 0 || id == POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY || | |
| 364 id == POPUP_ITEM_ID_PASSWORD_ENTRY; | |
| 365 } | |
| 366 | |
| 367 bool AutofillPopupControllerImpl::IsWarning(size_t index) const { | 359 bool AutofillPopupControllerImpl::IsWarning(size_t index) const { |
| 368 return suggestions_[index].frontend_id == POPUP_ITEM_ID_WARNING_MESSAGE; | 360 return suggestions_[index].frontend_id == POPUP_ITEM_ID_WARNING_MESSAGE; |
| 369 } | 361 } |
| 370 | 362 |
| 371 gfx::Rect AutofillPopupControllerImpl::GetRowBounds(size_t index) { | 363 gfx::Rect AutofillPopupControllerImpl::GetRowBounds(size_t index) { |
| 372 int top = kPopupBorderThickness; | 364 int top = kPopupBorderThickness; |
| 373 for (size_t i = 0; i < index; ++i) { | 365 for (size_t i = 0; i < index; ++i) { |
| 374 top += GetRowHeightFromId(suggestions_[i].frontend_id); | 366 top += GetRowHeightFromId(suggestions_[i].frontend_id); |
| 375 } | 367 } |
| 376 | 368 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 SetSelectedLine(new_selected_line); | 493 SetSelectedLine(new_selected_line); |
| 502 } | 494 } |
| 503 | 495 |
| 504 bool AutofillPopupControllerImpl::RemoveSelectedLine() { | 496 bool AutofillPopupControllerImpl::RemoveSelectedLine() { |
| 505 if (selected_line_ == kNoSelection) | 497 if (selected_line_ == kNoSelection) |
| 506 return false; | 498 return false; |
| 507 | 499 |
| 508 DCHECK_GE(selected_line_, 0); | 500 DCHECK_GE(selected_line_, 0); |
| 509 DCHECK_LT(selected_line_, static_cast<int>(GetLineCount())); | 501 DCHECK_LT(selected_line_, static_cast<int>(GetLineCount())); |
| 510 | 502 |
| 511 if (!CanDelete(selected_line_)) | 503 if (!delegate_->RemoveSuggestion(suggestions_[selected_line_].value, |
| 504 suggestions_[selected_line_].frontend_id)) { |
| 512 return false; | 505 return false; |
| 513 | 506 } |
| 514 delegate_->RemoveSuggestion(suggestions_[selected_line_].value, | |
| 515 suggestions_[selected_line_].frontend_id); | |
| 516 | 507 |
| 517 // Remove the deleted element. | 508 // Remove the deleted element. |
| 518 suggestions_.erase(suggestions_.begin() + selected_line_); | 509 suggestions_.erase(suggestions_.begin() + selected_line_); |
| 519 elided_values_.erase(elided_values_.begin() + selected_line_); | 510 elided_values_.erase(elided_values_.begin() + selected_line_); |
| 520 elided_labels_.erase(elided_labels_.begin() + selected_line_); | 511 elided_labels_.erase(elided_labels_.begin() + selected_line_); |
| 521 | 512 |
| 522 SetSelectedLine(kNoSelection); | 513 SetSelectedLine(kNoSelection); |
| 523 | 514 |
| 524 if (HasSuggestions()) { | 515 if (HasSuggestions()) { |
| 525 delegate_->ClearPreviewedForm(); | 516 delegate_->ClearPreviewedForm(); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 popup_bounds_ = gfx::Rect(); | 648 popup_bounds_ = gfx::Rect(); |
| 658 | 649 |
| 659 suggestions_.clear(); | 650 suggestions_.clear(); |
| 660 elided_values_.clear(); | 651 elided_values_.clear(); |
| 661 elided_labels_.clear(); | 652 elided_labels_.clear(); |
| 662 | 653 |
| 663 selected_line_ = kNoSelection; | 654 selected_line_ = kNoSelection; |
| 664 } | 655 } |
| 665 | 656 |
| 666 } // namespace autofill | 657 } // namespace autofill |
| OLD | NEW |