| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/autofill/core/browser/autofill_external_delegate.h" | 5 #include "components/autofill/core/browser/autofill_external_delegate.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "components/autofill/core/browser/autocomplete_history_manager.h" | 8 #include "components/autofill/core/browser/autocomplete_history_manager.h" |
| 9 #include "components/autofill/core/browser/autofill_driver.h" | 9 #include "components/autofill/core/browser/autofill_driver.h" |
| 10 #include "components/autofill/core/browser/autofill_manager.h" | 10 #include "components/autofill/core/browser/autofill_manager.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 ids.pop_back(); | 86 ids.pop_back(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 // If anything else is added to modify the values after inserting the data | 89 // If anything else is added to modify the values after inserting the data |
| 90 // list, AutofillPopupControllerImpl::UpdateDataListValues will need to be | 90 // list, AutofillPopupControllerImpl::UpdateDataListValues will need to be |
| 91 // updated to match. | 91 // updated to match. |
| 92 InsertDataListValues(&values, &labels, &icons, &ids); | 92 InsertDataListValues(&values, &labels, &icons, &ids); |
| 93 | 93 |
| 94 if (values.empty()) { | 94 if (values.empty()) { |
| 95 // No suggestions, any popup currently showing is obsolete. | 95 // No suggestions, any popup currently showing is obsolete. |
| 96 manager_->delegate()->HideAutofillPopup(); | 96 manager_->client()->HideAutofillPopup(); |
| 97 return; | 97 return; |
| 98 } | 98 } |
| 99 | 99 |
| 100 // Send to display. | 100 // Send to display. |
| 101 if (query_field_.is_focusable) { | 101 if (query_field_.is_focusable) { |
| 102 manager_->delegate()->ShowAutofillPopup( | 102 manager_->client()->ShowAutofillPopup(element_bounds_, |
| 103 element_bounds_, | 103 query_field_.text_direction, |
| 104 query_field_.text_direction, | 104 values, |
| 105 values, | 105 labels, |
| 106 labels, | 106 icons, |
| 107 icons, | 107 ids, |
| 108 ids, | 108 GetWeakPtr()); |
| 109 GetWeakPtr()); | |
| 110 } | 109 } |
| 111 } | 110 } |
| 112 | 111 |
| 113 void AutofillExternalDelegate::SetCurrentDataListValues( | 112 void AutofillExternalDelegate::SetCurrentDataListValues( |
| 114 const std::vector<base::string16>& data_list_values, | 113 const std::vector<base::string16>& data_list_values, |
| 115 const std::vector<base::string16>& data_list_labels) { | 114 const std::vector<base::string16>& data_list_labels) { |
| 116 data_list_values_ = data_list_values; | 115 data_list_values_ = data_list_values; |
| 117 data_list_labels_ = data_list_labels; | 116 data_list_labels_ = data_list_labels; |
| 118 | 117 |
| 119 manager_->delegate()->UpdateAutofillPopupDataListValues( | 118 manager_->client()->UpdateAutofillPopupDataListValues(data_list_values, |
| 120 data_list_values, | 119 data_list_labels); |
| 121 data_list_labels); | |
| 122 } | 120 } |
| 123 | 121 |
| 124 void AutofillExternalDelegate::OnPopupShown() { | 122 void AutofillExternalDelegate::OnPopupShown() { |
| 125 manager_->DidShowSuggestions( | 123 manager_->DidShowSuggestions( |
| 126 has_suggestion_ && !has_shown_popup_for_current_edit_); | 124 has_suggestion_ && !has_shown_popup_for_current_edit_); |
| 127 has_shown_popup_for_current_edit_ |= has_suggestion_; | 125 has_shown_popup_for_current_edit_ |= has_suggestion_; |
| 128 } | 126 } |
| 129 | 127 |
| 130 void AutofillExternalDelegate::OnPopupHidden() { | 128 void AutofillExternalDelegate::OnPopupHidden() { |
| 131 } | 129 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 154 NOTREACHED(); // Should be handled elsewhere. | 152 NOTREACHED(); // Should be handled elsewhere. |
| 155 } else if (identifier == POPUP_ITEM_ID_DATALIST_ENTRY) { | 153 } else if (identifier == POPUP_ITEM_ID_DATALIST_ENTRY) { |
| 156 driver_->RendererShouldAcceptDataListSuggestion(value); | 154 driver_->RendererShouldAcceptDataListSuggestion(value); |
| 157 } else if (identifier == POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY) { | 155 } else if (identifier == POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY) { |
| 158 // User selected an Autocomplete, so we fill directly. | 156 // User selected an Autocomplete, so we fill directly. |
| 159 driver_->RendererShouldFillFieldWithValue(value); | 157 driver_->RendererShouldFillFieldWithValue(value); |
| 160 } else { | 158 } else { |
| 161 FillAutofillFormData(identifier, false); | 159 FillAutofillFormData(identifier, false); |
| 162 } | 160 } |
| 163 | 161 |
| 164 manager_->delegate()->HideAutofillPopup(); | 162 manager_->client()->HideAutofillPopup(); |
| 165 } | 163 } |
| 166 | 164 |
| 167 void AutofillExternalDelegate::RemoveSuggestion(const base::string16& value, | 165 void AutofillExternalDelegate::RemoveSuggestion(const base::string16& value, |
| 168 int identifier) { | 166 int identifier) { |
| 169 if (identifier > 0) | 167 if (identifier > 0) |
| 170 manager_->RemoveAutofillProfileOrCreditCard(identifier); | 168 manager_->RemoveAutofillProfileOrCreditCard(identifier); |
| 171 else | 169 else |
| 172 manager_->RemoveAutocompleteEntry(query_field_.name, value); | 170 manager_->RemoveAutocompleteEntry(query_field_.name, value); |
| 173 } | 171 } |
| 174 | 172 |
| 175 void AutofillExternalDelegate::DidEndTextFieldEditing() { | 173 void AutofillExternalDelegate::DidEndTextFieldEditing() { |
| 176 manager_->delegate()->HideAutofillPopup(); | 174 manager_->client()->HideAutofillPopup(); |
| 177 | 175 |
| 178 has_shown_popup_for_current_edit_ = false; | 176 has_shown_popup_for_current_edit_ = false; |
| 179 } | 177 } |
| 180 | 178 |
| 181 void AutofillExternalDelegate::ClearPreviewedForm() { | 179 void AutofillExternalDelegate::ClearPreviewedForm() { |
| 182 driver_->RendererShouldClearPreviewedForm(); | 180 driver_->RendererShouldClearPreviewedForm(); |
| 183 } | 181 } |
| 184 | 182 |
| 185 void AutofillExternalDelegate::Reset() { | 183 void AutofillExternalDelegate::Reset() { |
| 186 manager_->delegate()->HideAutofillPopup(); | 184 manager_->client()->HideAutofillPopup(); |
| 187 } | 185 } |
| 188 | 186 |
| 189 base::WeakPtr<AutofillExternalDelegate> AutofillExternalDelegate::GetWeakPtr() { | 187 base::WeakPtr<AutofillExternalDelegate> AutofillExternalDelegate::GetWeakPtr() { |
| 190 return weak_ptr_factory_.GetWeakPtr(); | 188 return weak_ptr_factory_.GetWeakPtr(); |
| 191 } | 189 } |
| 192 | 190 |
| 193 void AutofillExternalDelegate::FillAutofillFormData(int unique_id, | 191 void AutofillExternalDelegate::FillAutofillFormData(int unique_id, |
| 194 bool is_preview) { | 192 bool is_preview) { |
| 195 // If the selected element is a warning we don't want to do anything. | 193 // If the selected element is a warning we don't want to do anything. |
| 196 if (unique_id == POPUP_ITEM_ID_WARNING_MESSAGE) | 194 if (unique_id == POPUP_ITEM_ID_WARNING_MESSAGE) |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 // Set the values that all datalist elements share. | 300 // Set the values that all datalist elements share. |
| 303 icons->insert(icons->begin(), | 301 icons->insert(icons->begin(), |
| 304 data_list_values_.size(), | 302 data_list_values_.size(), |
| 305 base::string16()); | 303 base::string16()); |
| 306 unique_ids->insert(unique_ids->begin(), | 304 unique_ids->insert(unique_ids->begin(), |
| 307 data_list_values_.size(), | 305 data_list_values_.size(), |
| 308 POPUP_ITEM_ID_DATALIST_ENTRY); | 306 POPUP_ITEM_ID_DATALIST_ENTRY); |
| 309 } | 307 } |
| 310 | 308 |
| 311 } // namespace autofill | 309 } // namespace autofill |
| OLD | NEW |