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

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: minor change - use defined variable Created 6 years, 11 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
« no previous file with comments | « chrome/renderer/autofill/form_autofill_browsertest.cc ('k') | 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 42b340e779688bcb7c8022ea201e592fe3ea0672..79dc6a22baea27fc46cec97fe2bf6d2fc9d360d3 100644
--- a/components/autofill/content/renderer/form_autofill_util.cc
+++ b/components/autofill/content/renderer/form_autofill_util.cc
@@ -572,21 +572,26 @@ 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());
+ }
+ } else if (IsTextAreaElement(*field)) {
+ WebTextAreaElement textarea = field->to<WebTextAreaElement>();
+ textarea.setSuggestedValue(data.value);
+ field->setAutofilled(true);
}
}
@@ -1049,38 +1054,53 @@ 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.
- WebInputElement* input_element = toWebInputElement(&control_elements[i]);
- if (!IsTextInput(input_element))
- continue;
-
- // If the input element is not auto-filled, we did not preview it, so there
- // is nothing to reset.
- if (!input_element->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())
+ WebFormControlElement control_element = control_elements[i];
+
+ // Only text input and textarea elements can be previewed.
+ WebInputElement* input_element = toWebInputElement(&control_element);
+ if (!IsTextInput(input_element) && !IsTextAreaElement(control_element))
+ continue;
+
+ // If the element is not auto-filled, we did not preview it,
+ // so there is nothing to reset.
+ if(!control_element.isAutofilled())
+ continue;
+
+ if ((IsTextInput(input_element) &&
+ input_element->suggestedValue().isEmpty()) ||
+ (IsTextAreaElement(control_element) &&
+ control_element.to<WebTextAreaElement>().suggestedValue().isEmpty()))
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);
+
+ // 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_element)) {
+ WebTextAreaElement text_area = control_element.to<WebTextAreaElement>();
+ text_area.setSuggestedValue(WebString());
+ bool is_initiating_node = (element == text_area);
+ if (is_initiating_node)
+ control_element.setAutofilled(was_autofilled);
+ else
+ control_element.setAutofilled(false);
}
}
« no previous file with comments | « chrome/renderer/autofill/form_autofill_browsertest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698