Index: chrome/renderer/form_manager.cc |
diff --git a/chrome/renderer/form_manager.cc b/chrome/renderer/form_manager.cc |
index f9dd7820d22f2d632f7dc4b8be96b02938f44a9b..21469e1178108d7c096fedb62c214a75bd7f5e37 100644 |
--- a/chrome/renderer/form_manager.cc |
+++ b/chrome/renderer/form_manager.cc |
@@ -273,6 +273,16 @@ void GetOptionStringsFromElement(WebFormControlElement element, |
} |
} |
+// In HTML5, email,month and tel are text input field to autocomplete. |
James Hawkins
2011/01/03 19:50:00
space after comma
|
+static bool IsTextInput(const WebFormControlElement& element) { |
+ const static char* type_names[] = {"text", "email", "tel", "month"}; |
+ for (size_t i = 0; i < sizeof(type_names)/sizeof(const char*); ++i) { |
+ if (element.formControlType() == WebString::fromUTF8(type_names[i])) |
+ return true; |
+ } |
+ return false; |
+} |
+ |
} // namespace |
struct FormManager::FormElement { |
@@ -308,7 +318,7 @@ void FormManager::WebFormControlElementToFormField( |
field->set_option_strings(option_strings); |
} |
- if (element.formControlType() == WebString::fromUTF8("text")) { |
+ if (IsTextInput(element)) { |
const WebInputElement& input_element = element.toConst<WebInputElement>(); |
field->set_max_length(input_element.maxLength()); |
field->set_autofilled(input_element.isAutofilled()); |
@@ -320,7 +330,7 @@ void FormManager::WebFormControlElementToFormField( |
// TODO(jhawkins): In WebKit, move value() and setValue() to |
// WebFormControlElement. |
string16 value; |
- if (element.formControlType() == WebString::fromUTF8("text") || |
+ if (IsTextInput(element) || |
element.formControlType() == WebString::fromUTF8("hidden")) { |
const WebInputElement& input_element = |
element.toConst<WebInputElement>(); |
@@ -417,8 +427,7 @@ bool FormManager::WebFormElementToFormData(const WebFormElement& element, |
for (size_t i = 0; i < control_elements.size(); ++i) { |
const WebFormControlElement& control_element = control_elements[i]; |
- if (requirements & REQUIRE_AUTOCOMPLETE && |
- control_element.formControlType() == WebString::fromUTF8("text")) { |
+ if (requirements & REQUIRE_AUTOCOMPLETE && IsTextInput(control_element)) { |
const WebInputElement& input_element = |
control_element.toConst<WebInputElement>(); |
if (!input_element.autoComplete()) |
@@ -631,7 +640,7 @@ bool FormManager::ClearFormWithNode(const WebNode& node) { |
for (size_t i = 0; i < form_element->control_elements.size(); ++i) { |
WebFormControlElement element = form_element->control_elements[i]; |
- if (element.formControlType() == WebString::fromUTF8("text")) { |
+ if (IsTextInput(element)) { |
WebInputElement input_element = element.to<WebInputElement>(); |
@@ -667,7 +676,7 @@ bool FormManager::ClearPreviewedFormWithNode(const WebNode& node, |
WebFormControlElement* element = &form_element->control_elements[i]; |
// Only input elements can be previewed. |
- if (element->formControlType() != WebString::fromUTF8("text")) |
+ if (!IsTextInput(*element)) |
continue; |
// If the input element has not been auto-filled, FormManager has not |
@@ -731,7 +740,7 @@ bool FormManager::FormWithNodeIsAutoFilled(const WebNode& node) { |
for (size_t i = 0; i < form_element->control_elements.size(); ++i) { |
WebFormControlElement element = form_element->control_elements[i]; |
- if (element.formControlType() != WebString::fromUTF8("text")) |
+ if (!IsTextInput(element)) |
continue; |
const WebInputElement& input_element = element.to<WebInputElement>(); |
@@ -844,7 +853,7 @@ void FormManager::ForEachMatchingFormField(FormElement* form, |
// More than likely |requirements| will contain REQUIRE_AUTOCOMPLETE and/or |
// REQUIRE_EMPTY, which both require text form control elements, so special- |
// case this type of element. |
- if (element->formControlType() == WebString::fromUTF8("text")) { |
+ if (IsTextInput(*element)) { |
const WebInputElement& input_element = |
element->toConst<WebInputElement>(); |
@@ -882,7 +891,7 @@ void FormManager::FillFormField(WebFormControlElement* field, |
if (data->value().empty()) |
return; |
- if (field->formControlType() == WebString::fromUTF8("text")) { |
+ if (IsTextInput(*field)) { |
WebInputElement input_element = field->to<WebInputElement>(); |
// If the maxlength attribute contains a negative value, maxLength() |
@@ -907,7 +916,7 @@ void FormManager::PreviewFormField(WebFormControlElement* field, |
return; |
// Only preview input fields. |
- if (field->formControlType() != WebString::fromUTF8("text")) |
+ if (!IsTextInput(*field)) |
return; |
WebInputElement input_element = field->to<WebInputElement>(); |