OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_FORMS_FORM_FIELD_H_ | 5 #ifndef CHROME_COMMON_FORM_FIELD_DATA_H_ |
6 #define WEBKIT_FORMS_FORM_FIELD_H_ | 6 #define CHROME_COMMON_FORM_FIELD_DATA_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/string16.h" | 10 #include "base/string16.h" |
11 #include "webkit/forms/webkit_forms_export.h" | |
12 | |
13 namespace webkit { | |
14 namespace forms { | |
15 | 11 |
16 // Stores information about a field in a form. | 12 // Stores information about a field in a form. |
17 struct WEBKIT_FORMS_EXPORT FormField { | 13 struct FormFieldData { |
18 FormField(); | 14 FormFieldData(); |
19 virtual ~FormField(); | 15 virtual ~FormFieldData(); |
20 | 16 |
21 // Equality tests for identity which does not include |value| or | 17 // Equality tests for identity which does not include |value| or |
22 // |is_autofilled|. | 18 // |is_autofilled|. |
23 // TODO(dhollowa): These operators need to be revised when we implement field | 19 // TODO(dhollowa): These operators need to be revised when we implement field |
24 // ids. | 20 // ids. |
25 bool operator==(const FormField& field) const; | 21 bool operator==(const FormFieldData& field) const; |
26 bool operator!=(const FormField& field) const; | 22 bool operator!=(const FormFieldData& field) const; |
27 // Comparsion operator exposed for STL map. Uses label, then name to sort. | 23 // Comparsion operator exposed for STL map. Uses label, then name to sort. |
28 bool operator<(const FormField& field) const; | 24 bool operator<(const FormFieldData& field) const; |
29 | 25 |
30 string16 label; | 26 string16 label; |
31 string16 name; | 27 string16 name; |
32 string16 value; | 28 string16 value; |
33 string16 form_control_type; | 29 string16 form_control_type; |
34 string16 autocomplete_type; | 30 string16 autocomplete_type; |
35 size_t max_length; | 31 size_t max_length; |
36 bool is_autofilled; | 32 bool is_autofilled; |
37 bool is_focusable; | 33 bool is_focusable; |
38 bool should_autocomplete; | 34 bool should_autocomplete; |
39 | 35 |
40 // For the HTML snippet |<option value="US">United States</option>|, the | 36 // For the HTML snippet |<option value="US">United States</option>|, the |
41 // value is "US" and the contents are "United States". | 37 // value is "US" and the contents are "United States". |
42 std::vector<string16> option_values; | 38 std::vector<string16> option_values; |
43 std::vector<string16> option_contents; | 39 std::vector<string16> option_contents; |
44 }; | 40 }; |
45 | 41 |
46 // So we can compare FormFields with EXPECT_EQ(). | 42 // So we can compare FormFieldDatas with EXPECT_EQ(). |
47 WEBKIT_FORMS_EXPORT std::ostream& operator<<(std::ostream& os, | 43 std::ostream& operator<<(std::ostream& os, const FormFieldData& field); |
48 const FormField& field); | |
49 | 44 |
50 } // namespace forms | 45 // Prefer to use this macro in place of |EXPECT_EQ()| for comparing |
51 } // namespace webkit | 46 // |FormFieldData|s in test code. |
52 | 47 #define EXPECT_FORM_FIELD_DATA_EQUALS(expected, actual) \ |
53 // Prefer to use this macro in place of |EXPECT_EQ()| for comparing |FormField|s | |
54 // in test code. | |
55 #define EXPECT_FORM_FIELD_EQUALS(expected, actual) \ | |
56 do { \ | 48 do { \ |
57 EXPECT_EQ(expected.label, actual.label); \ | 49 EXPECT_EQ(expected.label, actual.label); \ |
58 EXPECT_EQ(expected.name, actual.name); \ | 50 EXPECT_EQ(expected.name, actual.name); \ |
59 EXPECT_EQ(expected.value, actual.value); \ | 51 EXPECT_EQ(expected.value, actual.value); \ |
60 EXPECT_EQ(expected.form_control_type, actual.form_control_type); \ | 52 EXPECT_EQ(expected.form_control_type, actual.form_control_type); \ |
61 EXPECT_EQ(expected.autocomplete_type, actual.autocomplete_type); \ | 53 EXPECT_EQ(expected.autocomplete_type, actual.autocomplete_type); \ |
62 EXPECT_EQ(expected.max_length, actual.max_length); \ | 54 EXPECT_EQ(expected.max_length, actual.max_length); \ |
63 EXPECT_EQ(expected.is_autofilled, actual.is_autofilled); \ | 55 EXPECT_EQ(expected.is_autofilled, actual.is_autofilled); \ |
64 } while (0) | 56 } while (0) |
65 | 57 |
66 #endif // WEBKIT_FORMS_FORM_FIELD_H_ | 58 #endif // CHROME_COMMON_FORM_FIELD_DATA_H_ |
OLD | NEW |