Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/glue/form_field.h" | 5 #include "webkit/glue/form_field.h" |
| 6 | 6 |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" | 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebOptionElement.h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebOptionElement.h" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSelectElement.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSelectElement.h" |
| 12 | 12 |
| 13 using WebKit::WebFormControlElement; | 13 using WebKit::WebFormControlElement; |
| 14 using WebKit::WebElement; | 14 using WebKit::WebElement; |
| 15 using WebKit::WebInputElement; | 15 using WebKit::WebInputElement; |
| 16 using WebKit::WebOptionElement; | 16 using WebKit::WebOptionElement; |
| 17 using WebKit::WebSelectElement; | 17 using WebKit::WebSelectElement; |
| 18 using WebKit::WebVector; | 18 using WebKit::WebVector; |
| 19 | 19 |
| 20 namespace webkit_glue { | 20 namespace webkit_glue { |
| 21 | 21 |
| 22 FormField::FormField() | 22 FormField::FormField() |
| 23 : max_length(0), | 23 : max_length(0), |
| 24 is_autofilled(false) { | 24 is_autofilled(false), |
| 25 is_text_input(false) { | |
| 25 } | 26 } |
| 26 | 27 |
| 27 // TODO(jhawkins): This constructor should probably be deprecated and the | 28 // TODO(jhawkins): This constructor should probably be deprecated and the |
| 28 // functionality moved to FormManager. | 29 // functionality moved to FormManager. |
| 29 FormField::FormField(WebFormControlElement element) | 30 FormField::FormField(WebFormControlElement element) |
| 30 : max_length(0), | 31 : max_length(0), |
| 31 is_autofilled(false) { | 32 is_autofilled(false) { |
| 32 name = element.nameForAutofill(); | 33 name = element.nameForAutofill(); |
| 33 | 34 |
| 34 // TODO(jhawkins): Extract the field label. For now we just use the field | 35 // TODO(jhawkins): Extract the field label. For now we just use the field |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 62 const string16& value, | 63 const string16& value, |
| 63 const string16& form_control_type, | 64 const string16& form_control_type, |
| 64 int max_length, | 65 int max_length, |
| 65 bool is_autofilled) | 66 bool is_autofilled) |
| 66 : label(label), | 67 : label(label), |
| 67 name(name), | 68 name(name), |
| 68 value(value), | 69 value(value), |
| 69 form_control_type(form_control_type), | 70 form_control_type(form_control_type), |
| 70 max_length(max_length), | 71 max_length(max_length), |
| 71 is_autofilled(is_autofilled) { | 72 is_autofilled(is_autofilled) { |
| 73 const char* text_types[] = {"text", "email", "search", "tel", "url", | |
| 74 "number", "date", "datetime", "datetime-local", "month", "week", | |
| 75 "time", "range"}; | |
| 76 for(size_t i = 0; i < sizeof(text_types)/sizeof(const char*); ++i) | |
| 77 is_text_input |= form_control_type == ASCIIToUTF16(text_types[i]); | |
| 72 } | 78 } |
|
honten.org
2011/05/17 04:41:18
It's not clean ;-(
But lots of unit tests use thi
dhollowa
2011/05/17 16:47:20
We should simply have a helper function that does
honten.org
2011/05/17 18:45:22
Actually, I wanted to find the function in |form_f
| |
| 73 | 79 |
| 74 FormField::~FormField() { | 80 FormField::~FormField() { |
| 75 } | 81 } |
| 76 | 82 |
| 77 bool FormField::operator==(const FormField& field) const { | 83 bool FormField::operator==(const FormField& field) const { |
| 78 // A FormField stores a value, but the value is not part of the identity of | 84 // A FormField stores a value, but the value is not part of the identity of |
| 79 // the field, so we don't want to compare the values. | 85 // the field, so we don't want to compare the values. |
| 80 return (label == field.label && | 86 return (label == field.label && |
| 81 name == field.name && | 87 name == field.name && |
| 82 form_control_type == field.form_control_type && | 88 form_control_type == field.form_control_type && |
| 83 max_length == field.max_length); | 89 max_length == field.max_length && |
| 90 is_text_input == field.is_text_input); | |
| 84 } | 91 } |
| 85 | 92 |
| 86 bool FormField::operator!=(const FormField& field) const { | 93 bool FormField::operator!=(const FormField& field) const { |
| 87 return !operator==(field); | 94 return !operator==(field); |
| 88 } | 95 } |
| 89 | 96 |
| 90 bool FormField::StrictlyEqualsHack(const FormField& field) const { | 97 bool FormField::StrictlyEqualsHack(const FormField& field) const { |
| 91 return (label == field.label && | 98 return (label == field.label && |
| 92 name == field.name && | 99 name == field.name && |
| 93 value == field.value && | 100 value == field.value && |
| 94 form_control_type == field.form_control_type && | 101 form_control_type == field.form_control_type && |
| 95 max_length == field.max_length); | 102 max_length == field.max_length && |
| 103 is_text_input == field.is_text_input); | |
| 96 } | 104 } |
| 97 | 105 |
| 98 std::ostream& operator<<(std::ostream& os, const FormField& field) { | 106 std::ostream& operator<<(std::ostream& os, const FormField& field) { |
| 99 return os | 107 return os |
| 100 << UTF16ToUTF8(field.label) | 108 << UTF16ToUTF8(field.label) |
| 101 << " " | 109 << " " |
| 102 << UTF16ToUTF8(field.name) | 110 << UTF16ToUTF8(field.name) |
| 103 << " " | 111 << " " |
| 104 << UTF16ToUTF8(field.value) | 112 << UTF16ToUTF8(field.value) |
| 105 << " " | 113 << " " |
| 106 << UTF16ToUTF8(field.form_control_type) | 114 << UTF16ToUTF8(field.form_control_type) |
| 107 << " " | 115 << " " |
| 108 << field.max_length; | 116 << field.max_length; |
| 109 } | 117 } |
| 110 | 118 |
| 111 } // namespace webkit_glue | 119 } // namespace webkit_glue |
| OLD | NEW |