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

Unified Diff: components/autofill/content/renderer/form_autofill_util.cc

Issue 112663005: Add autofill preview support for Textarea (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/autofill/content/renderer/form_autofill_util.cc
diff --git a/components/autofill/content/renderer/form_autofill_util.cc b/components/autofill/content/renderer/form_autofill_util.cc
index df682a28281e151994f5ef81e839264ebb68fcf5..bcb4f6399553df18d52d6445df6f575e66d7fdcf 100644
--- a/components/autofill/content/renderer/form_autofill_util.cc
+++ b/components/autofill/content/renderer/form_autofill_util.cc
@@ -572,21 +572,29 @@ void PreviewFormField(const FormFieldData& data,
if (data.value.empty())
return;
- // Only preview input fields. Excludes checkboxes and radio buttons, as there
- // is no provision for setSuggestedCheckedValue in WebInputElement.
+ // Preview input and textarea fields. For input fields, excludes checkboxes
+ // and radio buttons, as there is no provision for setSuggestedCheckedValue
+ // in WebInputElement.
WebInputElement* input_element = toWebInputElement(field);
- if (!IsTextInput(input_element))
- return;
-
- // If the maxlength attribute contains a negative value, maxLength()
- // returns the default maxlength value.
- input_element->setSuggestedValue(
+ if (IsTextInput(input_element)) {
+ // If the maxlength attribute contains a negative value, maxLength()
+ // returns the default maxlength value.
+ input_element->setSuggestedValue(
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.
- input_element->setSelectionRange(input_element->value().length(),
- input_element->suggestedValue().length());
+ input_element->setAutofilled(true);
+ if (is_initiating_node) {
+ // Select the part of the text that the user didn't type.
+ input_element->setSelectionRange(input_element->value().length(),
+ input_element->suggestedValue().length());
+ }
Ilya Sherman 2013/12/29 03:36:02 Can this be shared across the two branches?
ziran.sun 2014/01/02 15:22:54 Do you mean merge "if(IsTextInput(input_element))"
Ilya Sherman 2014/01/07 01:09:38 It seems like the "if (is_initiating_node)" code o
ziran.sun 2014/01/07 16:40:41 I am not sure if we need to do "setSelectionRange"
+ } else if (IsTextAreaElement(*field)) {
+ WebTextAreaElement textarea = field->to<WebTextAreaElement>();
+ textarea.setSuggestedValue(data.value);
+ field->setAutofilled(true);
+ } else if (IsSelectElement(*field)) {
+ //Handle selectElement here
+ } else {
+ return;
}
Ilya Sherman 2013/12/29 03:36:02 nit: No need for the final "else if" nor for the "
ziran.sun 2014/01/07 16:40:41 Done.
}
@@ -966,7 +974,7 @@ bool WebFormElementToFormData(
bool FindFormAndFieldForInputElement(const WebInputElement& element,
FormData* form,
- FormFieldData* field,
+ FormFieldData* field,
Ilya Sherman 2013/12/29 03:36:02 nit: Spurious diff, please revert.
ziran.sun 2014/01/07 16:40:41 Done.
RequirementsMask requirements) {
if (!IsAutofillableElement(element))
return false;
@@ -1049,38 +1057,51 @@ bool ClearPreviewedFormWithElement(const WebInputElement& element,
ExtractAutofillableElements(form_element, REQUIRE_AUTOCOMPLETE,
&control_elements);
for (size_t i = 0; i < control_elements.size(); ++i) {
- // Only text input elements can be previewed.
+ // text input and textarea elements can be previewed.
Ilya Sherman 2013/12/29 03:36:02 nit: Please keep the word "only"
ziran.sun 2014/01/07 16:40:41 Done.
WebInputElement* input_element = toWebInputElement(&control_elements[i]);
- if (!IsTextInput(input_element))
+ if (!IsTextInput(input_element) && !IsTextAreaElement(control_elements[i]))
continue;
- // If the input element is not auto-filled, we did not preview it, so there
- // is nothing to reset.
- if (!input_element->isAutofilled())
+ // If the control element is not auto-filled, we did not preview it,
Ilya Sherman 2013/12/29 03:36:02 nit: I'd omit "control", i.e. simply "If the eleme
ziran.sun 2014/01/07 16:40:41 Done.
+ // so there is nothing to reset.
+ if(!control_elements[i].isAutofilled())
continue;
// There might be unrelated elements in this form which have already been
// auto-filled. For example, the user might have already filled the address
// part of a form and now be dealing with the credit card section. We only
// want to reset the auto-filled status for fields that were previewed.
- if (input_element->suggestedValue().isEmpty())
+ if ((IsTextInput(input_element) &&
+ input_element->suggestedValue().isEmpty())
+ || (IsTextAreaElement(control_elements[i]) &&
+ control_elements[i].to<WebTextAreaElement>().suggestedValue().isEmpty()))
Ilya Sherman 2013/12/29 03:36:02 nit: The text wrapping here doesn't match the Chro
ziran.sun 2014/01/07 16:40:41 Done.
continue;
// Clear the suggested value. For the initiating node, also restore the
// original value.
- input_element->setSuggestedValue(WebString());
- bool is_initiating_node = (element == *input_element);
- if (is_initiating_node)
- input_element->setAutofilled(was_autofilled);
- else
- input_element->setAutofilled(false);
-
- // Clearing the suggested value in the focused node (above) can cause
- // selection to be lost. We force selection range to restore the text
- // cursor.
- if (is_initiating_node) {
- int length = input_element->value().length();
- input_element->setSelectionRange(length, length);
+ if (IsTextInput(input_element)) {
+ input_element->setSuggestedValue(WebString());
+ bool is_initiating_node = (element == *input_element);
+ if (is_initiating_node)
+ input_element->setAutofilled(was_autofilled);
+ else
+ input_element->setAutofilled(false);
Ilya Sherman 2013/12/29 03:36:02 Can this code be shared between the two branches?
+
+ // Clearing the suggested value in the focused node (above) can cause
+ // selection to be lost. We force selection range to restore the text
+ // cursor.
+ if (is_initiating_node) {
+ int length = input_element->value().length();
+ input_element->setSelectionRange(length, length);
+ }
+ } else if (IsTextAreaElement(control_elements[i])) {
+ WebTextAreaElement txtarea = control_elements[i].to<WebTextAreaElement>();
Ilya Sherman 2013/12/29 03:36:02 nit: Please avoid abbreviations in names. The way
ziran.sun 2014/01/07 16:40:41 Done.
+ txtarea.setSuggestedValue(WebString());
+ bool is_initiating_node = (element == txtarea);
+ if (is_initiating_node)
+ control_elements[i].setAutofilled(was_autofilled);
+ else
+ control_elements[i].setAutofilled(false);
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698