Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(368)

Side by Side Diff: components/autofill/core/browser/form_field.cc

Issue 1028633004: Autofill: Improve heuristics for city/state/zip fields. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/browser/form_field.h" 5 #include "components/autofill/core/browser/form_field.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 99
100 const AutofillField* field = scanner->Cursor(); 100 const AutofillField* field = scanner->Cursor();
101 101
102 if (!MatchesFormControlType(field->form_control_type, match_type)) 102 if (!MatchesFormControlType(field->form_control_type, match_type))
103 return false; 103 return false;
104 104
105 return MatchAndAdvance(scanner, pattern, match_type, match); 105 return MatchAndAdvance(scanner, pattern, match_type, match);
106 } 106 }
107 107
108 // static 108 // static
109 FormField::ParseNameLabelResult FormField::ParseNameAndLabelSeparately(
Evan Stade 2015/03/24 00:04:32 do you anticipate using this for any other form fi
Lei Zhang 2015/03/25 00:42:28 Not 100% sure, but I feel this may come in handy l
110 AutofillScanner* scanner,
111 const base::string16& pattern,
112 int match_type,
113 AutofillField** match) {
114 if (scanner->IsEnd())
115 return RESULT_MATCH_NONE;
116
117 AutofillField* cur_match = nullptr;
118 size_t saved_cursor = scanner->SaveCursor();
119 bool parsed_name = ParseFieldSpecifics(scanner,
120 pattern,
121 MatchTypeWithoutLabel(match_type),
122 &cur_match);
123 scanner->RewindTo(saved_cursor);
124 bool parsed_label = ParseFieldSpecifics(scanner,
125 pattern,
126 MatchTypeWithoutName(match_type),
127 &cur_match);
128 if (parsed_name && parsed_label) {
129 if (match)
130 *match = cur_match;
131 return RESULT_MATCH_NAME_LABEL;
132 }
133
134 scanner->RewindTo(saved_cursor);
135 if (parsed_name)
136 return RESULT_MATCH_NAME;
137 if (parsed_label)
138 return RESULT_MATCH_LABEL;
139 return RESULT_MATCH_NONE;
140 }
141
142 // static
109 bool FormField::ParseEmptyLabel(AutofillScanner* scanner, 143 bool FormField::ParseEmptyLabel(AutofillScanner* scanner,
110 AutofillField** match) { 144 AutofillField** match) {
111 return ParseFieldSpecifics(scanner, 145 return ParseFieldSpecifics(scanner,
112 base::ASCIIToUTF16("^$"), 146 base::ASCIIToUTF16("^$"),
113 MATCH_LABEL | MATCH_ALL_INPUTS, 147 MATCH_LABEL | MATCH_ALL_INPUTS,
114 match); 148 match);
115 } 149 }
116 150
117 // static 151 // static
118 bool FormField::AddClassification(const AutofillField* field, 152 bool FormField::AddClassification(const AutofillField* field,
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 235
202 if ((match_type & MATCH_PASSWORD) && type == "password") 236 if ((match_type & MATCH_PASSWORD) && type == "password")
203 return true; 237 return true;
204 238
205 if ((match_type & MATCH_NUMBER) && type == "number") 239 if ((match_type & MATCH_NUMBER) && type == "number")
206 return true; 240 return true;
207 241
208 return false; 242 return false;
209 } 243 }
210 244
245 // static
246 int FormField::MatchTypeWithoutLabel(int match_type) {
247 return match_type & ~MATCH_LABEL;
Evan Stade 2015/03/24 00:04:32 just inline these two functions imo
Lei Zhang 2015/03/25 00:42:28 Done.
248 }
249
250 // static
251 int FormField::MatchTypeWithoutName(int match_type) {
252 return match_type & ~MATCH_NAME;
253 }
254
211 } // namespace autofill 255 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698