OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 #include "components/autofill/core/common/form_field_data.h" | 5 #include "components/autofill/core/common/form_field_data.h" |
6 | 6 |
| 7 #include <tuple> |
| 8 |
7 #include "base/pickle.h" | 9 #include "base/pickle.h" |
8 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
10 | 12 |
11 namespace autofill { | 13 namespace autofill { |
12 | 14 |
13 namespace { | 15 namespace { |
14 | 16 |
15 // Increment this anytime pickle format is modified as well as provide | 17 // Increment this anytime pickle format is modified as well as provide |
16 // deserialization routine from previous kPickleVersion format. | 18 // deserialization routine from previous kPickleVersion format. |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 // of a drop-down are currently not considered part of the identity of | 112 // of a drop-down are currently not considered part of the identity of |
111 // a form element. This is debatable, since one might base heuristics | 113 // a form element. This is debatable, since one might base heuristics |
112 // on the types of elements that are available. Alternatively, one | 114 // on the types of elements that are available. Alternatively, one |
113 // could imagine some forms that dynamically change the element | 115 // could imagine some forms that dynamically change the element |
114 // contents (say, insert years starting from the current year) that | 116 // contents (say, insert years starting from the current year) that |
115 // should not be considered changes in the structure of the form. | 117 // should not be considered changes in the structure of the form. |
116 } | 118 } |
117 | 119 |
118 bool FormFieldData::operator<(const FormFieldData& field) const { | 120 bool FormFieldData::operator<(const FormFieldData& field) const { |
119 // Like operator==, this ignores the value. | 121 // Like operator==, this ignores the value. |
120 if (label < field.label) return true; | |
121 if (label > field.label) return false; | |
122 if (name < field.name) return true; | |
123 if (name > field.name) return false; | |
124 if (form_control_type < field.form_control_type) return true; | |
125 if (form_control_type > field.form_control_type) return false; | |
126 if (autocomplete_attribute < field.autocomplete_attribute) return true; | |
127 if (autocomplete_attribute > field.autocomplete_attribute) return false; | |
128 if (max_length < field.max_length) return true; | |
129 if (max_length > field.max_length) return false; | |
130 // Skip |is_checked| and |is_autofilled| as in SameFieldAs. | 122 // Skip |is_checked| and |is_autofilled| as in SameFieldAs. |
131 if (is_checkable < field.is_checkable) return true; | |
132 if (is_checkable > field.is_checkable) return false; | |
133 if (is_focusable < field.is_focusable) return true; | |
134 if (is_focusable > field.is_focusable) return false; | |
135 if (should_autocomplete < field.should_autocomplete) return true; | |
136 if (should_autocomplete > field.should_autocomplete) return false; | |
137 if (role < field.role) return true; | |
138 if (role > field.role) return false; | |
139 if (text_direction < field.text_direction) return true; | |
140 if (text_direction > field.text_direction) return false; | |
141 // See operator== above for why we don't check option_values/contents. | 123 // See operator== above for why we don't check option_values/contents. |
142 return false; | 124 return std::tie(label, name, form_control_type, autocomplete_attribute, |
| 125 max_length, is_checkable, is_focusable, should_autocomplete, |
| 126 role, text_direction) < |
| 127 std::tie(field.label, field.name, field.form_control_type, |
| 128 field.autocomplete_attribute, field.max_length, |
| 129 field.is_checkable, field.is_focusable, |
| 130 field.should_autocomplete, field.role, field.text_direction); |
143 } | 131 } |
144 | 132 |
145 void SerializeFormFieldData(const FormFieldData& field_data, | 133 void SerializeFormFieldData(const FormFieldData& field_data, |
146 base::Pickle* pickle) { | 134 base::Pickle* pickle) { |
147 pickle->WriteInt(kPickleVersion); | 135 pickle->WriteInt(kPickleVersion); |
148 pickle->WriteString16(field_data.label); | 136 pickle->WriteString16(field_data.label); |
149 pickle->WriteString16(field_data.name); | 137 pickle->WriteString16(field_data.name); |
150 pickle->WriteString16(field_data.value); | 138 pickle->WriteString16(field_data.value); |
151 pickle->WriteString(field_data.form_control_type); | 139 pickle->WriteString(field_data.form_control_type); |
152 pickle->WriteString(field_data.autocomplete_attribute); | 140 pickle->WriteString(field_data.autocomplete_attribute); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 << " " << field.autocomplete_attribute << " " << field.max_length | 193 << " " << field.autocomplete_attribute << " " << field.max_length |
206 << " " << (field.is_autofilled ? "true" : "false") << " " | 194 << " " << (field.is_autofilled ? "true" : "false") << " " |
207 << (field.is_checked ? "true" : "false") << " " | 195 << (field.is_checked ? "true" : "false") << " " |
208 << (field.is_checkable ? "true" : "false") << " " | 196 << (field.is_checkable ? "true" : "false") << " " |
209 << (field.is_focusable ? "true" : "false") << " " | 197 << (field.is_focusable ? "true" : "false") << " " |
210 << (field.should_autocomplete ? "true" : "false") << " " | 198 << (field.should_autocomplete ? "true" : "false") << " " |
211 << field.role << " " << field.text_direction; | 199 << field.role << " " << field.text_direction; |
212 } | 200 } |
213 | 201 |
214 } // namespace autofill | 202 } // namespace autofill |
OLD | NEW |