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

Unified Diff: chrome/renderer/autofill/form_autofill_util.cc

Issue 11348273: [autofill] Fill in values on a successful run of interactive autocomplete. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: estade@ review Created 8 years, 1 month 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/renderer/autofill/form_autofill_util.cc
diff --git a/chrome/renderer/autofill/form_autofill_util.cc b/chrome/renderer/autofill/form_autofill_util.cc
index 3da2f9869cd77763a64524f4d7aa7753684c9432..2fa0ae3d3545df8093b6322cf23b6dd66acbd550 100644
--- a/chrome/renderer/autofill/form_autofill_util.cc
+++ b/chrome/renderer/autofill/form_autofill_util.cc
@@ -413,9 +413,9 @@ void GetOptionStringsFromElement(const WebSelectElement& select_element,
}
// The callback type used by |ForEachMatchingFormField()|.
-typedef void (*Callback)(WebKit::WebFormControlElement*,
- const FormFieldData*,
- bool);
+typedef void (*Callback)(const FormFieldData&,
+ bool,
+ WebKit::WebFormControlElement*);
// For each autofillable field in |data| that matches a field in the |form|,
// the |callback| is invoked with the corresponding |form| field data.
@@ -469,49 +469,17 @@ void ForEachMatchingFormField(const WebFormElement& form_element,
!element->isFocusable())
continue;
- callback(element, &data.fields[i], is_initiating_element);
- }
-}
-
-// Sets the |field|'s value to the value in |data|.
-// Also sets the "autofilled" attribute, causing the background to be yellow.
-void FillFormField(WebKit::WebFormControlElement* field,
- const FormFieldData* data,
- bool is_initiating_node) {
- // Nothing to fill.
- if (data->value.empty())
- return;
-
- WebInputElement* input_element = toWebInputElement(field);
- if (IsTextInput(input_element)) {
- // If the maxlength attribute contains a negative value, maxLength()
- // returns the default maxlength value.
- input_element->setValue(
- data->value.substr(0, input_element->maxLength()), true);
- input_element->setAutofilled(true);
- if (is_initiating_node) {
- int length = input_element->value().length();
- input_element->setSelectionRange(length, length);
- // Clear the current IME composition (the underline), if there is one.
- input_element->document().frame()->unmarkText();
- }
- } else {
- DCHECK(IsSelectElement(*field));
- WebSelectElement select_element = field->to<WebSelectElement>();
- if (select_element.value() != data->value) {
- select_element.setValue(data->value);
- select_element.dispatchFormControlChangeEvent();
- }
+ callback(data.fields[i], is_initiating_element, element);
}
}
// Sets the |field|'s "suggested" (non JS visible) value to the value in |data|.
// Also sets the "autofilled" attribute, causing the background to be yellow.
-void PreviewFormField(WebKit::WebFormControlElement* field,
- const FormFieldData* data,
- bool is_initiating_node) {
+void PreviewFormField(const FormFieldData& data,
+ bool is_initiating_node,
+ WebKit::WebFormControlElement* field) {
// Nothing to preview.
- if (data->value.empty())
+ if (data.value.empty())
return;
// Only preview input fields.
@@ -522,7 +490,7 @@ void PreviewFormField(WebKit::WebFormControlElement* field,
// If the maxlength attribute contains a negative value, maxLength()
// returns the default maxlength value.
input_element->setSuggestedValue(
- data->value.substr(0, input_element->maxLength()));
+ data.value.substr(0, input_element->maxLength()));
input_element->setAutofilled(true);
if (is_initiating_node) {
// Select the part of the text that the user didn't type.
@@ -823,6 +791,38 @@ void FillForm(const FormData& form, const WebInputElement& element) {
&FillFormField);
}
+// Sets the |field|'s value to the value in |data|.
+// Also sets the "autofilled" attribute, causing the background to be yellow.
+void FillFormField(const FormFieldData& data,
+ bool is_initiating_node,
+ WebKit::WebFormControlElement* field) {
+ // Nothing to fill.
+ if (data.value.empty())
+ return;
+
+ WebInputElement* input_element = toWebInputElement(field);
+ if (IsTextInput(input_element)) {
+ // If the maxlength attribute contains a negative value, maxLength()
+ // returns the default maxlength value.
+ input_element->setValue(
+ data.value.substr(0, input_element->maxLength()), true);
+ input_element->setAutofilled(true);
+ if (is_initiating_node) {
+ int length = input_element->value().length();
+ input_element->setSelectionRange(length, length);
+ // Clear the current IME composition (the underline), if there is one.
+ input_element->document().frame()->unmarkText();
+ }
+ } else {
+ DCHECK(IsSelectElement(*field));
+ WebSelectElement select_element = field->to<WebSelectElement>();
+ if (select_element.value() != data.value) {
+ select_element.setValue(data.value);
+ select_element.dispatchFormControlChangeEvent();
+ }
+ }
+}
+
void PreviewForm(const FormData& form, const WebInputElement& element) {
WebFormElement form_element = element.form();
if (form_element.isNull())
« chrome/renderer/autofill/autofill_agent.cc ('K') | « chrome/renderer/autofill/form_autofill_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698