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

Unified Diff: chrome/renderer/form_manager.cc

Issue 6033010: Support autocompletion for HTMl5 tags:"email", "month" and "tel". (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Fix format errors and other naming issues. Created 9 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
Index: chrome/renderer/form_manager.cc
diff --git a/chrome/renderer/form_manager.cc b/chrome/renderer/form_manager.cc
index f9dd7820d22f2d632f7dc4b8be96b02938f44a9b..6d7cc2349b23070954b72da31f11aedddb2660ba 100644
--- a/chrome/renderer/form_manager.cc
+++ b/chrome/renderer/form_manager.cc
@@ -273,6 +273,12 @@ void GetOptionStringsFromElement(WebFormControlElement element,
}
}
+// In HTML5, email, all text fields except password are text input fields to
Ilya Sherman 2011/01/10 20:08:48 nit: I think the fragment "email, " in this senten
honten.org 2011/01/25 05:19:24 Done.
+// autocomplete.
+static bool IsTextInput(const WebInputElement& element) {
+ return element.isTextField() && !element.isPasswordField();
+}
+
} // namespace
struct FormManager::FormElement {
@@ -308,8 +314,8 @@ void FormManager::WebFormControlElementToFormField(
field->set_option_strings(option_strings);
}
- if (element.formControlType() == WebString::fromUTF8("text")) {
- const WebInputElement& input_element = element.toConst<WebInputElement>();
+ const WebInputElement& input_element = element.toConst<WebInputElement>();
Ilya Sherman 2011/01/10 20:08:48 I might be mistaken, but I think this conversion w
Ilya Sherman 2011/01/10 21:08:37 Yep, this conversion is just a static_cast, which
honten.org 2011/01/10 22:50:35 Ok, I'll ask him. On 2011/01/10 21:08:37, Ilya Sh
honten.org 2011/01/10 22:57:13 Darin, Could you tell me if there is a method Ily
dhollowa 2011/01/19 18:49:45 The test: element.hasTagName("input") should be su
darin (slow to review) 2011/01/19 22:04:18 I think you can use WebElement::hasTagName("input"
honten.org 2011/01/25 05:19:24 Now I changed to use toWebInputElement(). On 2011
+ if (IsTextInput(input_element)) {
field->set_max_length(input_element.maxLength());
field->set_autofilled(input_element.isAutofilled());
}
@@ -320,7 +326,7 @@ 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>();
@@ -417,8 +423,10 @@ 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& controll_input_element =
+ control_element.toConst<WebInputElement>();
Ilya Sherman 2011/01/10 20:08:48 nit: If this conversion is legal (see above), you
if (requirements & REQUIRE_AUTOCOMPLETE &&
- control_element.formControlType() == WebString::fromUTF8("text")) {
+ IsTextInput(controll_input_element)) {
const WebInputElement& input_element =
control_element.toConst<WebInputElement>();
if (!input_element.autoComplete())
@@ -631,9 +639,8 @@ 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 = element.to<WebInputElement>();
+ if (IsTextInput(input_element)) {
// We don't modify the value of disabled fields.
if (!input_element.isEnabled())
@@ -665,14 +672,13 @@ bool FormManager::ClearPreviewedFormWithNode(const WebNode& node,
for (size_t i = 0; i < form_element->control_elements.size(); ++i) {
WebFormControlElement* element = &form_element->control_elements[i];
-
+ WebInputElement input_element = element->to<WebInputElement>();
// 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())
continue;
@@ -731,10 +737,10 @@ 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"))
+ WebInputElement input_element = element.to<WebInputElement>();
+ if (!IsTextInput(input_element))
continue;
- const WebInputElement& input_element = element.to<WebInputElement>();
if (input_element.isAutofilled())
return true;
}
@@ -844,9 +850,9 @@ 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 =
+ element->toConst<WebInputElement>();
+ if (IsTextInput(input_element)) {
// TODO(jhawkins): WebKit currently doesn't handle the autocomplete
// attribute for select control elements, but it probably should.
@@ -882,8 +888,8 @@ 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 = field->to<WebInputElement>();
+ if (IsTextInput(input_element)) {
// If the maxlength attribute contains a negative value, maxLength()
// returns the default maxlength value.
@@ -907,10 +913,9 @@ void FormManager::PreviewFormField(WebFormControlElement* field,
return;
// Only preview input fields.
- if (field->formControlType() != WebString::fromUTF8("text"))
- return;
-
WebInputElement input_element = field->to<WebInputElement>();
+ if (!IsTextInput(input_element))
+ return;
// If the maxlength attribute contains a negative value, maxLength()
// returns the default maxlength value.

Powered by Google App Engine
This is Rietveld 408576698