Index: chrome/renderer/form_manager.cc |
diff --git a/chrome/renderer/form_manager.cc b/chrome/renderer/form_manager.cc |
index b94a1a049eb3c0e3f9123963230be5aa98d6241f..5e5a888d23ea66d852fc59b8fdc1ced7bd769eff 100644 |
--- a/chrome/renderer/form_manager.cc |
+++ b/chrome/renderer/form_manager.cc |
@@ -273,6 +273,15 @@ void GetOptionStringsFromElement(WebFormControlElement element, |
} |
} |
+// In HTML5, all text fields except password are text input fields to |
+// autocomplete. |
+static bool IsTextInput(const WebInputElement* element) { |
+ if (!element) |
+ return false; |
+ |
+ return element->isTextField() && !element->isPasswordField(); |
+} |
+ |
} // namespace |
struct FormManager::FormElement { |
@@ -308,10 +317,11 @@ void FormManager::WebFormControlElementToFormField( |
field->set_option_strings(option_strings); |
} |
- if (element.formControlType() == WebString::fromUTF8("text")) { |
- const WebInputElement& input_element = element.toConst<WebInputElement>(); |
- field->set_max_length(input_element.maxLength()); |
- field->set_autofilled(input_element.isAutofilled()); |
+ const WebInputElement* input_element = |
+ WebInputElement::toWebInputElement(&element); |
+ if (IsTextInput(input_element)) { |
+ field->set_max_length(input_element->maxLength()); |
+ field->set_autofilled(input_element->isAutofilled()); |
} |
if (!(extract_mask & EXTRACT_VALUE)) |
@@ -320,11 +330,9 @@ void FormManager::WebFormControlElementToFormField( |
// TODO(jhawkins): In WebKit, move value() and setValue() to |
// WebFormControlElement. |
string16 value; |
- if (element.formControlType() == WebString::fromUTF8("text") || |
+ if (IsTextInput(input_element) || |
element.formControlType() == WebString::fromUTF8("hidden")) { |
- const WebInputElement& input_element = |
- element.toConst<WebInputElement>(); |
- value = input_element.value(); |
+ value = input_element->value(); |
} else if (element.formControlType() == WebString::fromUTF8("select-one")) { |
// TODO(jhawkins): This is ugly. WebSelectElement::value() is a non-const |
// method. Look into fixing this on the WebKit side. |
@@ -417,11 +425,11 @@ bool FormManager::WebFormElementToFormData(const WebFormElement& element, |
for (size_t i = 0; i < control_elements.size(); ++i) { |
const WebFormControlElement& control_element = control_elements[i]; |
+ const WebInputElement* input_element = |
+ WebInputElement::toWebInputElement(&control_element); |
if (requirements & REQUIRE_AUTOCOMPLETE && |
- control_element.formControlType() == WebString::fromUTF8("text")) { |
- const WebInputElement& input_element = |
- control_element.toConst<WebInputElement>(); |
- if (!input_element.autoComplete()) |
+ IsTextInput(input_element)) { |
+ if (!input_element->autoComplete()) |
Ilya Sherman
2011/01/25 06:21:30
nit: No need for nested if-stmts here; you can com
honten.org
2011/01/25 06:38:28
Done.
|
continue; |
} |
@@ -631,22 +639,22 @@ 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")) { |
- |
- WebInputElement input_element = element.to<WebInputElement>(); |
+ WebInputElement* input_element = |
+ WebInputElement::toWebInputElement(&element); |
+ if (IsTextInput(input_element)) { |
// We don't modify the value of disabled fields. |
- if (!input_element.isEnabled()) |
+ if (!input_element->isEnabled()) |
continue; |
- input_element.setValue(string16()); |
- input_element.setAutofilled(false); |
+ input_element->setValue(string16()); |
+ input_element->setAutofilled(false); |
// Clearing the value in the focused node (above) can cause selection |
// to be lost. We force selection range to restore the text cursor. |
- if (node == input_element) { |
- int length = input_element.value().length(); |
- input_element.setSelectionRange(length, length); |
+ if (node == *input_element) { |
+ int length = input_element->value().length(); |
+ input_element->setSelectionRange(length, length); |
} |
} else if (element.formControlType() == WebString::fromUTF8("select-one")) { |
WebSelectElement select_element = element.to<WebSelectElement>(); |
@@ -664,44 +672,43 @@ bool FormManager::ClearPreviewedFormWithNode(const WebNode& node, |
return false; |
for (size_t i = 0; i < form_element->control_elements.size(); ++i) { |
- WebFormControlElement* element = &form_element->control_elements[i]; |
- |
+ WebInputElement* input_element = |
+ WebInputElement::toWebInputElement(&form_element->control_elements[i]); |
// Only input elements can be previewed. |
- if (element->formControlType() != WebString::fromUTF8("text")) |
+ if (!IsTextInput(input_element)) |
continue; |
// If the input element has not been auto-filled, FormManager has not |
// previewed this field, so we have nothing to reset. |
- WebInputElement input_element = element->to<WebInputElement>(); |
- if (!input_element.isAutofilled()) |
+ 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()) |
+ if (input_element->suggestedValue().isEmpty()) |
continue; |
// Clear the suggested value. For the initiating node, also restore the |
// original value. |
- input_element.setSuggestedValue(WebString()); |
- bool is_initiating_node = (node == input_element); |
+ input_element->setSuggestedValue(WebString()); |
+ bool is_initiating_node = (node == *input_element); |
if (is_initiating_node) { |
// Call |setValue()| to force the renderer to update the field's displayed |
// value. |
- input_element.setValue(input_element.value()); |
- input_element.setAutofilled(was_autofilled); |
+ input_element->setValue(input_element->value()); |
+ input_element->setAutofilled(was_autofilled); |
} else { |
- input_element.setAutofilled(false); |
+ 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); |
+ int length = input_element->value().length(); |
+ input_element->setSelectionRange(length, length); |
} |
} |
@@ -730,12 +737,12 @@ bool FormManager::FormWithNodeIsAutoFilled(const WebNode& node) { |
return false; |
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")) |
+ WebInputElement* input_element = |
+ WebInputElement::toWebInputElement(&form_element->control_elements[i]); |
+ if (!IsTextInput(input_element)) |
continue; |
- const WebInputElement& input_element = element.to<WebInputElement>(); |
- if (input_element.isAutofilled()) |
+ if (input_element->isAutofilled()) |
return true; |
} |
@@ -844,22 +851,22 @@ 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")) { |
- const WebInputElement& input_element = |
- element->toConst<WebInputElement>(); |
+ const WebInputElement* input_element = |
+ WebInputElement::toWebInputElement(element); |
+ if (IsTextInput(input_element)) { |
// TODO(jhawkins): WebKit currently doesn't handle the autocomplete |
// attribute for select control elements, but it probably should. |
- if (requirements & REQUIRE_AUTOCOMPLETE && !input_element.autoComplete()) |
+ if (requirements & REQUIRE_AUTOCOMPLETE && !input_element->autoComplete()) |
continue; |
- is_initiating_node = (input_element == node); |
+ is_initiating_node = (*input_element == node); |
// Don't require the node that initiated the auto-fill process to be |
// empty. The user is typing in this field and we should complete the |
// value when the user selects a value to fill out. |
if (requirements & REQUIRE_EMPTY && |
!is_initiating_node && |
- !input_element.value().isEmpty()) |
+ !input_element->value().isEmpty()) |
continue; |
} |
@@ -882,16 +889,17 @@ void FormManager::FillFormField(WebFormControlElement* field, |
if (data->value().empty()) |
return; |
- if (field->formControlType() == WebString::fromUTF8("text")) { |
- WebInputElement input_element = field->to<WebInputElement>(); |
+ WebInputElement* input_element = WebInputElement::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())); |
- input_element.setAutofilled(true); |
+ input_element->setValue( |
+ data->value().substr(0, input_element->maxLength())); |
+ input_element->setAutofilled(true); |
if (is_initiating_node) { |
- int length = input_element.value().length(); |
- input_element.setSelectionRange(length, length); |
+ int length = input_element->value().length(); |
+ input_element->setSelectionRange(length, length); |
} |
} else if (field->formControlType() == WebString::fromUTF8("select-one")) { |
WebSelectElement select_element = field->to<WebSelectElement>(); |
@@ -907,16 +915,16 @@ void FormManager::PreviewFormField(WebFormControlElement* field, |
return; |
// Only preview input fields. |
- if (field->formControlType() != WebString::fromUTF8("text")) |
+ WebInputElement* input_element = WebInputElement::toWebInputElement(field); |
+ if (!IsTextInput(input_element)) |
return; |
- WebInputElement input_element = field->to<WebInputElement>(); |
- |
// 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); |
+ input_element->setSuggestedValue( |
+ data->value().substr(0, input_element->maxLength())); |
+ input_element->setAutofilled(true); |
if (is_initiating_node) |
- input_element.setSelectionRange(0, input_element.suggestedValue().length()); |
+ input_element->setSelectionRange(0, |
+ input_element->suggestedValue().length()); |
Ilya Sherman
2011/01/25 06:21:30
nit: Please indent this line so that the leading "
honten.org
2011/01/25 06:38:28
Done.
|
} |