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