| Index: chrome/browser/autofill/autofill_popup_view.cc
|
| diff --git a/chrome/browser/autofill/autofill_popup_view.cc b/chrome/browser/autofill/autofill_popup_view.cc
|
| index 0a146f5308a410a51698bcef04156a7ee899dac2..bf1d0ea6521fe7f79180d2aeaad4c40a40733b8c 100644
|
| --- a/chrome/browser/autofill/autofill_popup_view.cc
|
| +++ b/chrome/browser/autofill/autofill_popup_view.cc
|
| @@ -44,6 +44,7 @@ AutofillPopupView::AutofillPopupView(
|
| content::WebContents* web_contents,
|
| AutofillExternalDelegate* external_delegate)
|
| : external_delegate_(external_delegate),
|
| + row_count_(0),
|
| selected_line_(kNoSelection) {
|
| if (!web_contents)
|
| return;
|
| @@ -75,6 +76,28 @@ void AutofillPopupView::Show(const std::vector<string16>& autofill_values,
|
| autofill_icons_ = autofill_icons;
|
| autofill_unique_ids_ = autofill_unique_ids;
|
|
|
| +
|
| + // Calculate the number of rows visible in the popup.
|
| + row_count_ = 0;
|
| + for (size_t i = 0; i < autofill_unique_ids.size(); ++i) {
|
| + if (autofill_unique_ids[i] != WebAutofillClient::MenuItemIDSeparator)
|
| + ++row_count_;
|
| + }
|
| +
|
| + // Generate the row to index mapping.
|
| + size_t index = 0;
|
| + row_to_index_mapping_.clear();
|
| + for (int row = 0; row < row_count_; ++row, ++index) {
|
| + // The separators aren't valid rows so skip them.
|
| + while (index < autofill_unique_ids.size() &&
|
| + (autofill_unique_ids[index] ==
|
| + WebAutofillClient::MenuItemIDSeparator)) {
|
| + ++index;
|
| + }
|
| +
|
| + row_to_index_mapping_.push_back(index);
|
| + }
|
| +
|
| ShowInternal();
|
| }
|
|
|
| @@ -99,7 +122,7 @@ void AutofillPopupView::SetSelectedLine(int selected_line) {
|
| void AutofillPopupView::SelectNextLine() {
|
| int new_selected_line = selected_line_ + 1;
|
|
|
| - if (new_selected_line == static_cast<int>(autofill_values_.size()))
|
| + if (new_selected_line == static_cast<int>(row_count()))
|
| new_selected_line = 0;
|
|
|
| SetSelectedLine(new_selected_line);
|
| @@ -109,7 +132,7 @@ void AutofillPopupView::SelectPreviousLine() {
|
| int new_selected_line = selected_line_ - 1;
|
|
|
| if (new_selected_line <= kNoSelection)
|
| - new_selected_line = autofill_values_.size() - 1;
|
| + new_selected_line = row_count() - 1;
|
|
|
| SetSelectedLine(new_selected_line);
|
| }
|
| @@ -119,11 +142,11 @@ bool AutofillPopupView::AcceptSelectedLine() {
|
| return false;
|
|
|
| DCHECK_GE(selected_line_, 0);
|
| - DCHECK_LT(selected_line_, static_cast<int>(autofill_values_.size()));
|
| + DCHECK_LT(selected_line_, static_cast<int>(row_count()));
|
|
|
| return external_delegate()->DidAcceptAutofillSuggestions(
|
| - autofill_values_[selected_line_],
|
| - autofill_unique_ids_[selected_line_],
|
| + autofill_values_[RowToIndex(selected_line_)],
|
| + autofill_unique_ids_[RowToIndex(selected_line_)],
|
| selected_line_);
|
| }
|
|
|
| @@ -132,24 +155,26 @@ bool AutofillPopupView::RemoveSelectedLine() {
|
| return false;
|
|
|
| DCHECK_GE(selected_line_, 0);
|
| - DCHECK_LT(selected_line_, static_cast<int>(autofill_values_.size()));
|
| + DCHECK_LT(selected_line_, static_cast<int>(row_count()));
|
| +
|
| + int index = RowToIndex(selected_line_);
|
|
|
| - if (!CanDelete(autofill_unique_ids_[selected_line_]))
|
| + if (!CanDelete(autofill_unique_ids_[index]))
|
| return false;
|
|
|
| - if (autofill_unique_ids_[selected_line_] > 0) {
|
| + if (autofill_unique_ids_[index] > 0) {
|
| external_delegate()->RemoveAutofillProfileOrCreditCard(
|
| - autofill_unique_ids_[selected_line_]);
|
| + autofill_unique_ids_[index]);
|
| } else {
|
| external_delegate()->RemoveAutocompleteEntry(
|
| - autofill_values_[selected_line_]);
|
| + autofill_values_[index]);
|
| }
|
|
|
| // Remove the deleted element.
|
| - autofill_values_.erase(autofill_values_.begin() + selected_line_);
|
| - autofill_labels_.erase(autofill_labels_.begin() + selected_line_);
|
| - autofill_icons_.erase(autofill_icons_.begin() + selected_line_);
|
| - autofill_unique_ids_.erase(autofill_unique_ids_.begin() + selected_line_);
|
| + autofill_values_.erase(autofill_values_.begin() + index);
|
| + autofill_labels_.erase(autofill_labels_.begin() + index);
|
| + autofill_icons_.erase(autofill_icons_.begin() + index);
|
| + autofill_unique_ids_.erase(autofill_unique_ids_.begin() + index);
|
|
|
| // Resize the popup.
|
| ResizePopup();
|
| @@ -162,13 +187,6 @@ bool AutofillPopupView::RemoveSelectedLine() {
|
| return true;
|
| }
|
|
|
| -bool AutofillPopupView::IsSeparatorIndex(int index) {
|
| - // TODO(csharp): Use WebAutofillClient::MenuItemIDSeparator instead.
|
| - // http://crbug.com/125001
|
| - return (index > 0 && autofill_unique_ids_[index - 1] >= 0 &&
|
| - autofill_unique_ids_[index] < 0);
|
| -}
|
| -
|
| int AutofillPopupView::GetIconResourceID(const string16& resource_name) {
|
| for (size_t i = 0; i < arraysize(kDataResources); ++i) {
|
| if (resource_name == ASCIIToUTF16(kDataResources[i].name))
|
| @@ -178,6 +196,13 @@ int AutofillPopupView::GetIconResourceID(const string16& resource_name) {
|
| return -1;
|
| }
|
|
|
| +int AutofillPopupView::RowToIndex(size_t row) {
|
| + if (row_to_index_mapping_.size() > row)
|
| + return row_to_index_mapping_[row];
|
| +
|
| + return -1;
|
| +}
|
| +
|
| bool AutofillPopupView::CanDelete(int id) {
|
| return id > 0 ||
|
| id == WebAutofillClient::MenuItemIDAutocompleteEntry ||
|
|
|