Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(468)

Unified Diff: chrome/browser/autofill/autofill_external_delegate.cc

Issue 10443084: Add Datalist Support to New Autofill UI (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix order of adding datalist items to keep warning code Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/autofill/autofill_external_delegate.cc
diff --git a/chrome/browser/autofill/autofill_external_delegate.cc b/chrome/browser/autofill/autofill_external_delegate.cc
index 1a7d2e56c42dcd5a72c4140fe6b34194719a982c..086bdbeaca6609759918c6e1dbb67e8c0a00ece9 100644
--- a/chrome/browser/autofill/autofill_external_delegate.cc
+++ b/chrome/browser/autofill/autofill_external_delegate.cc
@@ -30,7 +30,8 @@ AutofillExternalDelegate::AutofillExternalDelegate(
tab_contents_wrapper ? tab_contents_wrapper->web_contents() : NULL),
autofill_query_id_(0),
display_warning_if_disabled_(false),
- has_shown_autofill_popup_for_current_edit_(false) {
+ has_shown_autofill_popup_for_current_edit_(false),
+ popup_visible_(false) {
}
void AutofillExternalDelegate::SelectAutofillSuggestionAtIndex(int unique_id) {
@@ -45,7 +46,9 @@ void AutofillExternalDelegate::SelectAutofillSuggestionAtIndex(int unique_id) {
if (unique_id == WebAutofillClient::MenuItemIDPasswordEntry)
return;
- FillAutofillFormData(unique_id, true);
+ // Only preview the data if it is a profile.
+ if (unique_id > 0)
+ FillAutofillFormData(unique_id, true);
}
void AutofillExternalDelegate::OnQuery(int query_id,
@@ -70,12 +73,7 @@ void AutofillExternalDelegate::OnSuggestionsReturned(
if (query_id != autofill_query_id_)
return;
- if (values.empty()) {
- // No suggestions, any popup currently showing is obsolete.
- HideAutofillPopup();
- return;
- }
-
+ // List any data list values at the start.
Ilya Sherman 2012/06/01 06:28:16 nit: Remove this comment?
csharp 2012/06/04 15:02:03 Done.
std::vector<string16> v(values);
std::vector<string16> l(labels);
std::vector<string16> i(icons);
@@ -94,7 +92,8 @@ void AutofillExternalDelegate::OnSuggestionsReturned(
l.assign(1, string16());
i.assign(1, string16());
ids.assign(1, WebAutofillClient::MenuItemIDWarningMessage);
- } else if (ids[0] < 0 && ids.size() > 1) {
+ } else if (ids[0] == WebAutofillClient::MenuItemIDWarningMessage &&
+ ids.size() > 1) {
// If we received a warning instead of suggestions from autofill but regular
// suggestions from autocomplete, don't show the autofill warning.
v.erase(v.begin());
@@ -104,8 +103,13 @@ void AutofillExternalDelegate::OnSuggestionsReturned(
}
// If we were about to show a warning and we shouldn't, don't.
- if (ids[0] < 0 && !display_warning_if_disabled_)
- return;
+ if (ids[0] == WebAutofillClient::MenuItemIDWarningMessage &&
+ !display_warning_if_disabled_) {
+ v.clear();
+ l.clear();
+ i.clear();
+ ids.clear();
+ }
// Only include "Autofill Options" special menu item if we have Autofill
// items, identified by |unique_ids| having at least one valid value.
@@ -142,9 +146,34 @@ void AutofillExternalDelegate::OnSuggestionsReturned(
ids.pop_back();
}
+ // Insert the datalist elements, if any, at the start of the list.
+ if (!data_list_values_.empty()) {
+ // Insert the separator between the datalist and Autofill values.
Ilya Sherman 2012/06/01 06:28:16 Only if there are non-datalist items?
csharp 2012/06/04 15:02:03 Done.
+ v.insert(v.begin(), string16());
+ l.insert(l.begin(), string16());
+ i.insert(i.begin(), string16());
+ ids.insert(ids.begin(), WebAutofillClient::MenuItemIDSeparator);
+
+ // Insert the datalist elements.
+ v.insert(v.begin(), data_list_values_.begin(), data_list_values_.end());
+ l.insert(l.begin(), data_list_labels_.begin(), data_list_labels_.end());
+ i.insert(i.begin(), data_list_icons_.begin(), data_list_icons_.end());
+ ids.insert(ids.begin(),
+ data_list_unique_ids_.begin(),
+ data_list_unique_ids_.end());
+ }
+
+ if (v.empty()) {
+ // No suggestions, any popup currently showing is obsolete.
+ HideAutofillPopup();
+ return;
+ }
+
// Send to display.
- if (!v.empty() && autofill_query_field_.is_focusable)
+ if (!v.empty() && autofill_query_field_.is_focusable) {
+ popup_visible_ = true;
ApplyAutofillSuggestions(v, l, i, ids);
+ }
tab_contents_wrapper_->autofill_manager()->OnDidShowAutofillSuggestions(
has_autofill_item && !has_shown_autofill_popup_for_current_edit_);
@@ -170,6 +199,19 @@ void AutofillExternalDelegate::OnShowPasswordSuggestions(
ApplyAutofillSuggestions(suggestions, empty, empty, password_ids);
}
+void AutofillExternalDelegate::SetCurrentDataListValues(
+ const std::vector<string16>& data_list_values,
+ const std::vector<string16>& data_list_labels,
+ const std::vector<string16>& data_list_icons,
+ const std::vector<int>& data_list_unique_ids) {
+ DCHECK(!popup_visible_);
+
+ data_list_values_ = data_list_values;
+ data_list_labels_ = data_list_labels;
+ data_list_icons_ = data_list_icons;
+ data_list_unique_ids_ = data_list_unique_ids;
+}
+
void AutofillExternalDelegate::RemoveAutocompleteEntry(const string16& value) {
if (tab_contents_wrapper_) {
tab_contents_wrapper_->autocomplete_history_manager()->
@@ -197,23 +239,25 @@ bool AutofillExternalDelegate::DidAcceptAutofillSuggestions(
if (unique_id == WebAutofillClient::MenuItemIDWarningMessage)
return false;
+ RenderViewHost* host =
+ tab_contents_wrapper_->web_contents()->GetRenderViewHost();
+
if (unique_id == WebAutofillClient::MenuItemIDAutofillOptions) {
// User selected 'Autofill Options'.
autofill_manager_->OnShowAutofillDialog();
} else if (unique_id == WebAutofillClient::MenuItemIDClearForm) {
// User selected 'Clear form'.
- RenderViewHost* host =
- tab_contents_wrapper_->web_contents()->GetRenderViewHost();
host->Send(new AutofillMsg_ClearForm(host->GetRoutingID()));
} else if (unique_id == WebAutofillClient::MenuItemIDPasswordEntry &&
password_autofill_manager_.DidAcceptAutofillSuggestion(
autofill_query_field_, value)) {
// DidAcceptAutofillSuggestion has already handled the work to fill in
// the page as required.
+ } else if (unique_id == WebAutofillClient::MenuItemIDDataListEntry) {
+ host->Send(new AutofillMsg_AcceptDataListSuggestion(host->GetRoutingID(),
+ value));
} else if (unique_id == WebAutofillClient::MenuItemIDAutocompleteEntry) {
// User selected an Autocomplete, so we fill directly.
- RenderViewHost* host =
- tab_contents_wrapper_->web_contents()->GetRenderViewHost();
host->Send(new AutofillMsg_SetNodeText(
host->GetRoutingID(),
value));
@@ -233,6 +277,8 @@ void AutofillExternalDelegate::ClearPreviewedForm() {
}
void AutofillExternalDelegate::HideAutofillPopup() {
+ popup_visible_ = false;
+
HideAutofillPopupInternal();
}
« no previous file with comments | « chrome/browser/autofill/autofill_external_delegate.h ('k') | chrome/browser/autofill/autofill_external_delegate_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698