Roll src/third_party/skia de7665a:76033be
[chromium-blink-merge.git] / components / autofill / core / common / form_field_data.h
blobef96b73a469473f268526d5f31566f7f938b5da1
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_AUTOFILL_CORE_COMMON_FORM_FIELD_DATA_H_
6 #define COMPONENTS_AUTOFILL_CORE_COMMON_FORM_FIELD_DATA_H_
8 #include <vector>
10 #include "base/i18n/rtl.h"
11 #include "base/strings/string16.h"
13 class Pickle;
14 class PickleIterator;
16 namespace autofill {
18 // Stores information about a field in a form.
19 struct FormFieldData {
20 enum RoleAttribute {
21 // "presentation"
22 ROLE_ATTRIBUTE_PRESENTATION,
23 // Anything else.
24 ROLE_ATTRIBUTE_OTHER,
27 FormFieldData();
28 ~FormFieldData();
30 // Returns true if two form fields are the same, not counting the value.
31 bool SameFieldAs(const FormFieldData& field) const;
33 // Comparison operator exposed for STL map. Uses label, then name to sort.
34 bool operator<(const FormFieldData& field) const;
36 // If you add more, be sure to update the comparison operator, SameFieldAs,
37 // serializing functions (in the .cc file) and the constructor.
38 base::string16 label;
39 base::string16 name;
40 base::string16 value;
41 std::string form_control_type;
42 std::string autocomplete_attribute;
43 size_t max_length;
44 bool is_autofilled;
45 bool is_checked;
46 bool is_checkable;
47 bool is_focusable;
48 bool should_autocomplete;
49 RoleAttribute role;
50 base::i18n::TextDirection text_direction;
52 // For the HTML snippet |<option value="US">United States</option>|, the
53 // value is "US" and the contents are "United States".
54 std::vector<base::string16> option_values;
55 std::vector<base::string16> option_contents;
58 // Serialize and deserialize FormFieldData. These are used when FormData objects
59 // are serialized and deserialized.
60 void SerializeFormFieldData(const FormFieldData& form_field_data,
61 Pickle* serialized);
62 bool DeserializeFormFieldData(PickleIterator* pickle_iterator,
63 FormFieldData* form_field_data);
65 // So we can compare FormFieldDatas with EXPECT_EQ().
66 std::ostream& operator<<(std::ostream& os, const FormFieldData& field);
68 // Prefer to use this macro in place of |EXPECT_EQ()| for comparing
69 // |FormFieldData|s in test code.
70 #define EXPECT_FORM_FIELD_DATA_EQUALS(expected, actual) \
71 do { \
72 EXPECT_EQ(expected.label, actual.label); \
73 EXPECT_EQ(expected.name, actual.name); \
74 EXPECT_EQ(expected.value, actual.value); \
75 EXPECT_EQ(expected.form_control_type, actual.form_control_type); \
76 EXPECT_EQ(expected.autocomplete_attribute, actual.autocomplete_attribute); \
77 EXPECT_EQ(expected.max_length, actual.max_length); \
78 EXPECT_EQ(expected.is_autofilled, actual.is_autofilled); \
79 EXPECT_EQ(expected.is_checked, actual.is_checked); \
80 EXPECT_EQ(expected.is_checkable, actual.is_checkable); \
81 } while (0)
83 } // namespace autofill
85 #endif // COMPONENTS_AUTOFILL_CORE_COMMON_FORM_FIELD_DATA_H_