From fc3dbd9016cfa343a1b03eb0c78e98da6e6968eb Mon Sep 17 00:00:00 2001 From: "jcivelli@chromium.org" Date: Sun, 18 Jul 2010 08:05:37 +0000 Subject: The autocomplete popup is now closed when no suggestions are available. BUG=49012 TEST=See bug. Original review: http://codereview.chromium.org/2819051 Review URL: http://codereview.chromium.org/3040007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52844 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/renderer/render_view.cc | 76 ++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 36 deletions(-) (limited to 'chrome/renderer') diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index f737994..ffba7e6 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -1515,44 +1515,48 @@ void RenderView::OnAutoFillSuggestionsReturned( const std::vector& values, const std::vector& labels, const std::vector& unique_ids) { - if (webview() && query_id == autofill_query_id_) { - std::vector v(values); - std::vector l(labels); - std::vector ids(unique_ids); - int separator_index = -1; - - // The form has been auto-filled, so give the user the chance to clear the - // form. Append the 'Clear form' menu item. - if (form_manager_.FormWithNodeIsAutoFilled(autofill_query_node_)) { - v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_CLEAR_FORM_MENU_ITEM)); - l.push_back(string16()); - ids.push_back(0); - suggestions_clear_index_ = v.size() - 1; - separator_index = values.size(); - } - - size_t labeled_item_count = 0; - for (size_t i = 0; i < l.size(); ++i) { - if (!l[i].empty()) - labeled_item_count++; - } + if (!webview() || query_id != autofill_query_id_) + return; - // Only include "AutoFill Options" special menu item if we have labeled - // items. - if (labeled_item_count > 0) { - // Append the 'AutoFill Options...' menu item. - v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_OPTIONS)); - l.push_back(string16()); - ids.push_back(0); - suggestions_options_index_ = v.size() - 1; - separator_index = values.size(); - } + // Any popup currently showing is now obsolete. + webview()->hidePopups(); - // Send to WebKit for display. - if (!v.empty()) - webview()->applyAutoFillSuggestions( - autofill_query_node_, v, l, ids, separator_index); - } + std::vector v(values); + std::vector l(labels); + std::vector ids(unique_ids); + int separator_index = -1; + + // The form has been auto-filled, so give the user the chance to clear the + // form. Append the 'Clear form' menu item. + if (form_manager_.FormWithNodeIsAutoFilled(autofill_query_node_)) { + v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_CLEAR_FORM_MENU_ITEM)); + l.push_back(string16()); + ids.push_back(0); + suggestions_clear_index_ = v.size() - 1; + separator_index = values.size(); + } + + size_t labeled_item_count = 0; + for (size_t i = 0; i < l.size(); ++i) { + if (!l[i].empty()) + labeled_item_count++; + } + + // Only include "AutoFill Options" special menu item if we have labeled + // items. + if (labeled_item_count > 0) { + // Append the 'AutoFill Options...' menu item. + v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_OPTIONS)); + l.push_back(string16()); + ids.push_back(0); + suggestions_options_index_ = v.size() - 1; + separator_index = values.size(); + } + + // Send to WebKit for display. + if (!v.empty()) + webview()->applyAutoFillSuggestions( + autofill_query_node_, v, l, ids, separator_index); } void RenderView::OnAutoFillFormDataFilled(int query_id, -- cgit v1.1