Commit bef7f927 authored by keishi@chromium.org's avatar keishi@chromium.org

DataList UI (Chromium part)

WebKit part is here
http://codereview.chromium.org/10037002/

Example page for <datalist>
https://tinker.io/22681/191

BUG=
TEST=


Review URL: http://codereview.chromium.org/10024059

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132561 0039d316-1c4b-4281-b951-d872f2087c98
parent c27e71f9
...@@ -12,19 +12,11 @@ ...@@ -12,19 +12,11 @@
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "grit/chromium_strings.h" #include "grit/chromium_strings.h"
#include "grit/generated_resources.h" #include "grit/generated_resources.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
using content::RenderViewHost; using content::RenderViewHost;
using WebKit::WebAutofillClient;
namespace {
// The value to give as the unique id for all warnings.
const int kWarningId = -1;
// The value to give as the unique id for all password entries.
const int kPasswordEntryId = -2;
} // namespace
AutofillExternalDelegate::~AutofillExternalDelegate() { AutofillExternalDelegate::~AutofillExternalDelegate() {
} }
...@@ -51,7 +43,7 @@ void AutofillExternalDelegate::SelectAutofillSuggestionAtIndex(int unique_id, ...@@ -51,7 +43,7 @@ void AutofillExternalDelegate::SelectAutofillSuggestionAtIndex(int unique_id,
if (list_index == suggestions_options_index_ || if (list_index == suggestions_options_index_ ||
list_index == suggestions_clear_index_ || list_index == suggestions_clear_index_ ||
unique_id == kWarningId) unique_id == WebAutofillClient::MenuItemIDWarningMessage)
return; return;
FillAutofillFormData(unique_id, true); FillAutofillFormData(unique_id, true);
...@@ -97,7 +89,7 @@ void AutofillExternalDelegate::OnSuggestionsReturned( ...@@ -97,7 +89,7 @@ void AutofillExternalDelegate::OnSuggestionsReturned(
v.assign(1, l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED)); v.assign(1, l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED));
l.assign(1, string16()); l.assign(1, string16());
i.assign(1, string16()); i.assign(1, string16());
ids.assign(1, kWarningId); ids.assign(1, WebAutofillClient::MenuItemIDWarningMessage);
} else if (ids[0] < 0 && ids.size() > 1) { } else if (ids[0] < 0 && ids.size() > 1) {
// If we received a warning instead of suggestions from autofill but regular // If we received a warning instead of suggestions from autofill but regular
// suggestions from autocomplete, don't show the autofill warning. // suggestions from autocomplete, don't show the autofill warning.
...@@ -166,7 +158,8 @@ void AutofillExternalDelegate::OnShowPasswordSuggestions( ...@@ -166,7 +158,8 @@ void AutofillExternalDelegate::OnShowPasswordSuggestions(
SetBounds(bounds); SetBounds(bounds);
std::vector<string16> empty(suggestions.size()); std::vector<string16> empty(suggestions.size());
std::vector<int> password_ids(suggestions.size(), kPasswordEntryId); std::vector<int> password_ids(suggestions.size(),
WebAutofillClient::MenuItemIDPasswordEntry);
ApplyAutofillSuggestions(suggestions, empty, empty, password_ids, -1); ApplyAutofillSuggestions(suggestions, empty, empty, password_ids, -1);
} }
...@@ -179,7 +172,7 @@ bool AutofillExternalDelegate::DidAcceptAutofillSuggestions( ...@@ -179,7 +172,7 @@ bool AutofillExternalDelegate::DidAcceptAutofillSuggestions(
int unique_id, int unique_id,
unsigned index) { unsigned index) {
// If the selected element is a warning we don't want to do anything. // If the selected element is a warning we don't want to do anything.
if (unique_id == kWarningId) if (unique_id == WebAutofillClient::MenuItemIDWarningMessage)
return false; return false;
if (suggestions_options_index_ != -1 && if (suggestions_options_index_ != -1 &&
......
...@@ -62,6 +62,7 @@ ...@@ -62,6 +62,7 @@
#include "webkit/forms/form_data_predictions.h" #include "webkit/forms/form_data_predictions.h"
#include "webkit/forms/form_field.h" #include "webkit/forms/form_field.h"
#include "webkit/forms/password_form_dom_manager.h" #include "webkit/forms/password_form_dom_manager.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h"
using base::TimeTicks; using base::TimeTicks;
using content::BrowserThread; using content::BrowserThread;
...@@ -480,7 +481,8 @@ void AutofillManager::OnQueryFormFieldAutofill(int query_id, ...@@ -480,7 +481,8 @@ void AutofillManager::OnQueryFormFieldAutofill(int query_id,
values.assign(1, l10n_util::GetStringUTF16(warning)); values.assign(1, l10n_util::GetStringUTF16(warning));
labels.assign(1, string16()); labels.assign(1, string16());
icons.assign(1, string16()); icons.assign(1, string16());
unique_ids.assign(1, -1); unique_ids.assign(1,
WebKit::WebAutofillClient::MenuItemIDWarningMessage);
} else { } else {
bool section_is_autofilled = bool section_is_autofilled =
SectionIsAutofilled(*form_structure, form, SectionIsAutofilled(*form_structure, form,
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include "ui/gfx/rect.h" #include "ui/gfx/rect.h"
#include "webkit/forms/form_data.h" #include "webkit/forms/form_data.h"
#include "webkit/forms/form_field.h" #include "webkit/forms/form_field.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h"
using content::BrowserThread; using content::BrowserThread;
using content::WebContents; using content::WebContents;
...@@ -911,7 +912,8 @@ TEST_F(AutofillManagerTest, GetProfileSuggestionsMethodGet) { ...@@ -911,7 +912,8 @@ TEST_F(AutofillManagerTest, GetProfileSuggestionsMethodGet) {
}; };
string16 expected_labels[] = {string16()}; string16 expected_labels[] = {string16()};
string16 expected_icons[] = {string16()}; string16 expected_icons[] = {string16()};
int expected_unique_ids[] = {-1}; int expected_unique_ids[] =
{WebKit::WebAutofillClient::MenuItemIDWarningMessage};
ExpectSuggestions(page_id, values, labels, icons, unique_ids, ExpectSuggestions(page_id, values, labels, icons, unique_ids,
kDefaultPageID, arraysize(expected_values), expected_values, kDefaultPageID, arraysize(expected_values), expected_values,
expected_labels, expected_icons, expected_unique_ids); expected_labels, expected_icons, expected_unique_ids);
......
This diff is collapsed.
...@@ -76,12 +76,12 @@ class AutofillAgent : public content::RenderViewObserver, ...@@ -76,12 +76,12 @@ class AutofillAgent : public content::RenderViewObserver,
virtual void didAcceptAutofillSuggestion(const WebKit::WebNode& node, virtual void didAcceptAutofillSuggestion(const WebKit::WebNode& node,
const WebKit::WebString& value, const WebKit::WebString& value,
const WebKit::WebString& label, const WebKit::WebString& label,
int unique_id, int item_id,
unsigned index) OVERRIDE; unsigned index) OVERRIDE;
virtual void didSelectAutofillSuggestion(const WebKit::WebNode& node, virtual void didSelectAutofillSuggestion(const WebKit::WebNode& node,
const WebKit::WebString& value, const WebKit::WebString& value,
const WebKit::WebString& label, const WebKit::WebString& label,
int unique_id) OVERRIDE; int item_id) OVERRIDE;
virtual void didClearAutofillSelection(const WebKit::WebNode& node) OVERRIDE; virtual void didClearAutofillSelection(const WebKit::WebNode& node) OVERRIDE;
virtual void removeAutocompleteSuggestion( virtual void removeAutocompleteSuggestion(
const WebKit::WebString& name, const WebKit::WebString& name,
...@@ -137,6 +137,13 @@ class AutofillAgent : public content::RenderViewObserver, ...@@ -137,6 +137,13 @@ class AutofillAgent : public content::RenderViewObserver,
void QueryAutofillSuggestions(const WebKit::WebInputElement& element, void QueryAutofillSuggestions(const WebKit::WebInputElement& element,
bool display_warning_if_disabled); bool display_warning_if_disabled);
void CombineDataListEntriesAndShow(const WebKit::WebInputElement& element,
const std::vector<string16>& values,
const std::vector<string16>& labels,
const std::vector<string16>& icons,
const std::vector<int>& item_ids,
bool has_autofill_item);
// Queries the AutofillManager for form data for the form containing |node|. // Queries the AutofillManager for form data for the form containing |node|.
// |value| is the current text in the field, and |unique_id| is the selected // |value| is the current text in the field, and |unique_id| is the selected
// profile's unique ID. |action| specifies whether to Fill or Preview the // profile's unique ID. |action| specifies whether to Fill or Preview the
...@@ -164,7 +171,7 @@ class AutofillAgent : public content::RenderViewObserver, ...@@ -164,7 +171,7 @@ class AutofillAgent : public content::RenderViewObserver,
int autofill_query_id_; int autofill_query_id_;
// The element corresponding to the last request sent for form field Autofill. // The element corresponding to the last request sent for form field Autofill.
WebKit::WebInputElement autofill_query_element_; WebKit::WebInputElement element_;
// The action to take when receiving Autofill data from the AutofillManager. // The action to take when receiving Autofill data from the AutofillManager.
AutofillAction autofill_action_; AutofillAction autofill_action_;
...@@ -175,12 +182,6 @@ class AutofillAgent : public content::RenderViewObserver, ...@@ -175,12 +182,6 @@ class AutofillAgent : public content::RenderViewObserver,
// Was the query node autofilled prior to previewing the form? // Was the query node autofilled prior to previewing the form?
bool was_query_node_autofilled_; bool was_query_node_autofilled_;
// The menu index of the "Clear" menu item.
int suggestions_clear_index_;
// The menu index of the "Autofill options..." menu item.
int suggestions_options_index_;
// Have we already shown Autofill suggestions for the field the user is // Have we already shown Autofill suggestions for the field the user is
// currently editing? Used to keep track of state for metrics logging. // currently editing? Used to keep track of state for metrics logging.
bool has_shown_autofill_popup_for_current_edit_; bool has_shown_autofill_popup_for_current_edit_;
......
...@@ -84,6 +84,7 @@ TEST_F(ChromeRenderViewTest, SendForms) { ...@@ -84,6 +84,7 @@ TEST_F(ChromeRenderViewTest, SendForms) {
document.getElementById("firstname").to<WebInputElement>(); document.getElementById("firstname").to<WebInputElement>();
// Make sure to query for Autofill suggestions before selecting one. // Make sure to query for Autofill suggestions before selecting one.
autofill_agent_->element_ = firstname;
autofill_agent_->QueryAutofillSuggestions(firstname, false); autofill_agent_->QueryAutofillSuggestions(firstname, false);
// Accept suggestion that contains a label. Labeled items indicate Autofill // Accept suggestion that contains a label. Labeled items indicate Autofill
...@@ -153,6 +154,7 @@ TEST_F(ChromeRenderViewTest, FillFormElement) { ...@@ -153,6 +154,7 @@ TEST_F(ChromeRenderViewTest, FillFormElement) {
middlename.setAutofilled(true); middlename.setAutofilled(true);
// Make sure to query for Autofill suggestions before selecting one. // Make sure to query for Autofill suggestions before selecting one.
autofill_agent_->element_ = firstname;
autofill_agent_->QueryAutofillSuggestions(firstname, false); autofill_agent_->QueryAutofillSuggestions(firstname, false);
// Accept a suggestion in a form that has been auto-filled. This triggers // Accept a suggestion in a form that has been auto-filled. This triggers
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "chrome/common/autofill_messages.h" #include "chrome/common/autofill_messages.h"
#include "chrome/renderer/autofill/form_autofill_util.h" #include "chrome/renderer/autofill/form_autofill_util.h"
#include "content/public/renderer/render_view.h" #include "content/public/renderer/render_view.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h"
...@@ -534,9 +535,10 @@ bool PasswordAutofillManager::ShowSuggestionPopup( ...@@ -534,9 +535,10 @@ bool PasswordAutofillManager::ShowSuggestionPopup(
std::vector<string16> labels(suggestions.size()); std::vector<string16> labels(suggestions.size());
std::vector<string16> icons(suggestions.size()); std::vector<string16> icons(suggestions.size());
std::vector<int> ids(suggestions.size(), 0); std::vector<int> ids(suggestions.size(),
WebKit::WebAutofillClient::MenuItemIDPasswordEntry);
webview->applyAutofillSuggestions( webview->applyAutofillSuggestions(
user_input, suggestions, labels, icons, ids, -1); user_input, suggestions, labels, icons, ids);
return true; return true;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment