| 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 #ifndef WEBKIT_GLUE_FORM_FIELD_H_ | 5 #ifndef WEBKIT_GLUE_FORM_FIELD_H_ |
| 6 #define WEBKIT_GLUE_FORM_FIELD_H_ | 6 #define WEBKIT_GLUE_FORM_FIELD_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/string16.h" | 10 #include "base/string16.h" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement
.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement
.h" |
| 12 | 12 |
| 13 namespace webkit_glue { | 13 namespace webkit_glue { |
| 14 | 14 |
| 15 // Stores information about a field in a form. | 15 // Stores information about a field in a form. |
| 16 class FormField { | 16 struct FormField { |
| 17 public: | |
| 18 FormField(); | 17 FormField(); |
| 19 explicit FormField(WebKit::WebFormControlElement element); | 18 explicit FormField(WebKit::WebFormControlElement element); |
| 20 FormField(const string16& label, | 19 FormField(const string16& label, |
| 21 const string16& name, | 20 const string16& name, |
| 22 const string16& value, | 21 const string16& value, |
| 23 const string16& form_control_type, | 22 const string16& form_control_type, |
| 24 int max_length, | 23 int max_length, |
| 25 bool is_autofilled); | 24 bool is_autofilled); |
| 26 virtual ~FormField(); | 25 virtual ~FormField(); |
| 27 | 26 |
| 28 const string16& label() const { return label_; } | |
| 29 const string16& name() const { return name_; } | |
| 30 const string16& value() const { return value_; } | |
| 31 const string16& form_control_type() const { return form_control_type_; } | |
| 32 int max_length() const { return max_length_; } | |
| 33 bool is_autofilled() const { return is_autofilled_; } | |
| 34 | |
| 35 // Returns option string for elements for which they make sense (select-one, | |
| 36 // for example) for the rest of elements return an empty array. | |
| 37 const std::vector<string16>& option_strings() const { | |
| 38 return option_strings_; | |
| 39 } | |
| 40 | |
| 41 void set_label(const string16& label) { label_ = label; } | |
| 42 void set_name(const string16& name) { name_ = name; } | |
| 43 void set_value(const string16& value) { value_ = value; } | |
| 44 void set_form_control_type(const string16& form_control_type) { | |
| 45 form_control_type_ = form_control_type; | |
| 46 } | |
| 47 void set_max_length(int max_length) { max_length_ = max_length; } | |
| 48 void set_autofilled(bool is_autofilled) { is_autofilled_ = is_autofilled; } | |
| 49 void set_option_strings(const std::vector<string16>& strings) { | |
| 50 option_strings_ = strings; | |
| 51 } | |
| 52 | |
| 53 // Equality tests for identity which does not include |value_| or |size_|. | 27 // Equality tests for identity which does not include |value_| or |size_|. |
| 54 // Use |StrictlyEqualsHack| method to test all members. | 28 // Use |StrictlyEqualsHack| method to test all members. |
| 55 // TODO(dhollowa): These operators need to be revised when we implement field | 29 // TODO(dhollowa): These operators need to be revised when we implement field |
| 56 // ids. | 30 // ids. |
| 57 bool operator==(const FormField& field) const; | 31 bool operator==(const FormField& field) const; |
| 58 bool operator!=(const FormField& field) const; | 32 bool operator!=(const FormField& field) const; |
| 59 | 33 |
| 60 // Test equality of all data members. | 34 // Test equality of all data members. |
| 61 // TODO(dhollowa): This will be removed when we implement field ids. | 35 // TODO(dhollowa): This will be removed when we implement field ids. |
| 62 bool StrictlyEqualsHack(const FormField& field) const; | 36 bool StrictlyEqualsHack(const FormField& field) const; |
| 63 | 37 |
| 64 private: | 38 string16 label; |
| 65 string16 label_; | 39 string16 name; |
| 66 string16 name_; | 40 string16 value; |
| 67 string16 value_; | 41 string16 form_control_type; |
| 68 string16 form_control_type_; | 42 int max_length; |
| 69 int max_length_; | 43 bool is_autofilled; |
| 70 bool is_autofilled_; | 44 std::vector<string16> option_strings; |
| 71 std::vector<string16> option_strings_; | |
| 72 }; | 45 }; |
| 73 | 46 |
| 74 // So we can compare FormFields with EXPECT_EQ(). | 47 // So we can compare FormFields with EXPECT_EQ(). |
| 75 std::ostream& operator<<(std::ostream& os, const FormField& field); | 48 std::ostream& operator<<(std::ostream& os, const FormField& field); |
| 76 | 49 |
| 77 } // namespace webkit_glue | 50 } // namespace webkit_glue |
| 78 | 51 |
| 79 #endif // WEBKIT_GLUE_FORM_FIELD_H_ | 52 #endif // WEBKIT_GLUE_FORM_FIELD_H_ |
| OLD | NEW |