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