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

Side by Side Diff: chrome/browser/autofill/address.cc

Issue 6484022: Autofill i18n: Set postal code and state field labels based on the selected country. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Properly merged with ToT Created 9 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/autofill/address.h ('k') | chrome/browser/autofill/address_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "chrome/browser/autofill/address.h" 5 #include "chrome/browser/autofill/address.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "chrome/browser/autofill/autofill_country.h"
9 #include "chrome/browser/autofill/autofill_type.h" 10 #include "chrome/browser/autofill/autofill_type.h"
10 #include "chrome/browser/autofill/field_types.h" 11 #include "chrome/browser/autofill/field_types.h"
11 12
12 namespace { 13 namespace {
13 14
14 const char16 kAddressSplitChars[] = {'-', ',', '#', '.', ' ', 0}; 15 const char16 kAddressSplitChars[] = {'-', ',', '#', '.', ' ', 0};
15 16
16 const AutoFillType::FieldTypeSubGroup kAutoFillAddressTypes[] = { 17 const AutoFillType::FieldTypeSubGroup kAutoFillAddressTypes[] = {
17 AutoFillType::ADDRESS_LINE1, 18 AutoFillType::ADDRESS_LINE1,
18 AutoFillType::ADDRESS_LINE2, 19 AutoFillType::ADDRESS_LINE2,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 74
74 if (!city_.empty()) 75 if (!city_.empty())
75 available_types->insert(ADDRESS_HOME_CITY); 76 available_types->insert(ADDRESS_HOME_CITY);
76 77
77 if (!state_.empty()) 78 if (!state_.empty())
78 available_types->insert(ADDRESS_HOME_STATE); 79 available_types->insert(ADDRESS_HOME_STATE);
79 80
80 if (!zip_code_.empty()) 81 if (!zip_code_.empty())
81 available_types->insert(ADDRESS_HOME_ZIP); 82 available_types->insert(ADDRESS_HOME_ZIP);
82 83
83 if (!country_.empty()) 84 if (!country_code_.empty())
84 available_types->insert(ADDRESS_HOME_COUNTRY); 85 available_types->insert(ADDRESS_HOME_COUNTRY);
85 } 86 }
86 87
87 void Address::FindInfoMatches(const AutoFillType& type, 88 void Address::FindInfoMatches(const AutoFillType& type,
88 const string16& info, 89 const string16& info,
89 std::vector<string16>* matched_text) const { 90 std::vector<string16>* matched_text) const {
90 DCHECK(matched_text); 91 DCHECK(matched_text);
91 92
92 string16 match; 93 string16 match;
93 if (type.field_type() == UNKNOWN_TYPE) { 94 if (type.field_type() == UNKNOWN_TYPE) {
(...skipping 18 matching lines...) Expand all
112 if (field_type == ADDRESS_HOME_CITY) 113 if (field_type == ADDRESS_HOME_CITY)
113 return city_; 114 return city_;
114 115
115 if (field_type == ADDRESS_HOME_STATE) 116 if (field_type == ADDRESS_HOME_STATE)
116 return state_; 117 return state_;
117 118
118 if (field_type == ADDRESS_HOME_ZIP) 119 if (field_type == ADDRESS_HOME_ZIP)
119 return zip_code_; 120 return zip_code_;
120 121
121 if (field_type == ADDRESS_HOME_COUNTRY) 122 if (field_type == ADDRESS_HOME_COUNTRY)
122 return country_; 123 return Country();
123 124
124 return string16(); 125 return string16();
125 } 126 }
126 127
127 void Address::SetInfo(const AutoFillType& type, const string16& value) { 128 void Address::SetInfo(const AutoFillType& type, const string16& value) {
128 FieldTypeSubGroup subgroup = type.subgroup(); 129 FieldTypeSubGroup subgroup = type.subgroup();
129 if (subgroup == AutoFillType::ADDRESS_LINE1) 130 if (subgroup == AutoFillType::ADDRESS_LINE1)
130 set_line1(value); 131 set_line1(value);
131 else if (subgroup == AutoFillType::ADDRESS_LINE2) 132 else if (subgroup == AutoFillType::ADDRESS_LINE2)
132 set_line2(value); 133 set_line2(value);
133 else if (subgroup == AutoFillType::ADDRESS_CITY) 134 else if (subgroup == AutoFillType::ADDRESS_CITY)
134 city_ = value; 135 city_ = value;
135 else if (subgroup == AutoFillType::ADDRESS_STATE) 136 else if (subgroup == AutoFillType::ADDRESS_STATE)
136 state_ = value; 137 state_ = value;
137 else if (subgroup == AutoFillType::ADDRESS_COUNTRY) 138 else if (subgroup == AutoFillType::ADDRESS_COUNTRY)
138 country_ = value; 139 SetCountry(value);
139 else if (subgroup == AutoFillType::ADDRESS_ZIP) 140 else if (subgroup == AutoFillType::ADDRESS_ZIP)
140 zip_code_ = value; 141 zip_code_ = value;
141 else 142 else
142 NOTREACHED(); 143 NOTREACHED();
143 } 144 }
144 145
145 void Address::Clear() { 146 void Address::Clear() {
146 line1_tokens_.clear(); 147 line1_tokens_.clear();
147 line1_.clear(); 148 line1_.clear();
148 line2_tokens_.clear(); 149 line2_tokens_.clear();
149 line2_.clear(); 150 line2_.clear();
150 city_.clear(); 151 city_.clear();
151 state_.clear(); 152 state_.clear();
152 country_.clear(); 153 country_code_.clear();
153 zip_code_.clear(); 154 zip_code_.clear();
154 } 155 }
155 156
156 Address::Address(const Address& address) 157 Address::Address(const Address& address)
157 : FormGroup(), 158 : FormGroup(),
158 line1_tokens_(address.line1_tokens_), 159 line1_tokens_(address.line1_tokens_),
159 line2_tokens_(address.line2_tokens_), 160 line2_tokens_(address.line2_tokens_),
160 line1_(address.line1_), 161 line1_(address.line1_),
161 line2_(address.line2_), 162 line2_(address.line2_),
162 city_(address.city_), 163 city_(address.city_),
163 state_(address.state_), 164 state_(address.state_),
164 country_(address.country_), 165 country_code_(address.country_code_),
165 zip_code_(address.zip_code_) { 166 zip_code_(address.zip_code_) {
166 } 167 }
167 168
169 string16 Address::Country() const {
170 if (country_code().empty())
171 return string16();
172
173 std::string app_locale = AutoFillCountry::ApplicationLocale();
174 return AutoFillCountry(country_code(), app_locale).name();
175 }
176
168 void Address::set_line1(const string16& line1) { 177 void Address::set_line1(const string16& line1) {
169 line1_ = line1; 178 line1_ = line1;
170 line1_tokens_.clear(); 179 line1_tokens_.clear();
171 Tokenize(line1, kAddressSplitChars, &line1_tokens_); 180 Tokenize(line1, kAddressSplitChars, &line1_tokens_);
172 LineTokens::iterator iter; 181 LineTokens::iterator iter;
173 for (iter = line1_tokens_.begin(); iter != line1_tokens_.end(); ++iter) 182 for (iter = line1_tokens_.begin(); iter != line1_tokens_.end(); ++iter)
174 *iter = StringToLowerASCII(*iter); 183 *iter = StringToLowerASCII(*iter);
175 } 184 }
176 185
177 void Address::set_line2(const string16& line2) { 186 void Address::set_line2(const string16& line2) {
178 line2_ = line2; 187 line2_ = line2;
179 line2_tokens_.clear(); 188 line2_tokens_.clear();
180 Tokenize(line2, kAddressSplitChars, &line2_tokens_); 189 Tokenize(line2, kAddressSplitChars, &line2_tokens_);
181 LineTokens::iterator iter; 190 LineTokens::iterator iter;
182 for (iter = line2_tokens_.begin(); iter != line2_tokens_.end(); ++iter) 191 for (iter = line2_tokens_.begin(); iter != line2_tokens_.end(); ++iter)
183 *iter = StringToLowerASCII(*iter); 192 *iter = StringToLowerASCII(*iter);
184 } 193 }
185 194
195 void Address::SetCountry(const string16& country) {
196 std::string app_locale = AutoFillCountry::ApplicationLocale();
197 country_code_ = AutoFillCountry::GetCountryCode(country, app_locale);
198 }
199
186 bool Address::IsLine1(const string16& text) const { 200 bool Address::IsLine1(const string16& text) const {
187 return IsLineMatch(text, line1_tokens_); 201 return IsLineMatch(text, line1_tokens_);
188 } 202 }
189 203
190 bool Address::IsLine2(const string16& text) const { 204 bool Address::IsLine2(const string16& text) const {
191 return IsLineMatch(text, line2_tokens_); 205 return IsLineMatch(text, line2_tokens_);
192 } 206 }
193 207
194 bool Address::IsCity(const string16& text) const { 208 bool Address::IsCity(const string16& text) const {
195 return (StringToLowerASCII(city_) == StringToLowerASCII(text)); 209 return (StringToLowerASCII(city_) == StringToLowerASCII(text));
196 } 210 }
197 211
198 bool Address::IsState(const string16& text) const { 212 bool Address::IsState(const string16& text) const {
199 return (StringToLowerASCII(state_) == StringToLowerASCII(text)); 213 return (StringToLowerASCII(state_) == StringToLowerASCII(text));
200 } 214 }
201 215
202 bool Address::IsCountry(const string16& text) const { 216 bool Address::IsCountry(const string16& text) const {
203 return (StringToLowerASCII(country_) == StringToLowerASCII(text)); 217 std::string app_locale = AutoFillCountry::ApplicationLocale();
218 std::string country_code = AutoFillCountry::GetCountryCode(text, app_locale);
219 return (!country_code.empty() && country_code_ == country_code);
204 } 220 }
205 221
206 bool Address::IsZipCode(const string16& text) const { 222 bool Address::IsZipCode(const string16& text) const {
207 return zip_code_ == text; 223 return zip_code_ == text;
208 } 224 }
209 225
210 bool Address::FindInfoMatchesHelper(const FieldTypeSubGroup& subgroup, 226 bool Address::FindInfoMatchesHelper(const FieldTypeSubGroup& subgroup,
211 const string16& info, 227 const string16& info,
212 string16* match) const { 228 string16* match) const {
213 DCHECK(match); 229 DCHECK(match);
214 230
215 match->clear(); 231 match->clear();
216 if (subgroup == AutoFillType::ADDRESS_LINE1 && 232 if (subgroup == AutoFillType::ADDRESS_LINE1 &&
217 StartsWith(line1_, info, false)) { 233 StartsWith(line1_, info, false)) {
218 *match = line1_; 234 *match = line1_;
219 } else if (subgroup == AutoFillType::ADDRESS_LINE2 && 235 } else if (subgroup == AutoFillType::ADDRESS_LINE2 &&
220 StartsWith(line2_, info, false)) { 236 StartsWith(line2_, info, false)) {
221 *match = line2_; 237 *match = line2_;
222 } else if (subgroup == AutoFillType::ADDRESS_CITY && 238 } else if (subgroup == AutoFillType::ADDRESS_CITY &&
223 StartsWith(city_, info, false)) { 239 StartsWith(city_, info, false)) {
224 *match = city_; 240 *match = city_;
225 } else if (subgroup == AutoFillType::ADDRESS_STATE && 241 } else if (subgroup == AutoFillType::ADDRESS_STATE &&
226 StartsWith(state_, info, false)) { 242 StartsWith(state_, info, false)) {
227 *match = state_; 243 *match = state_;
228 } else if (subgroup == AutoFillType::ADDRESS_COUNTRY && 244 } else if (subgroup == AutoFillType::ADDRESS_COUNTRY &&
229 StartsWith(country_, info, false)) { 245 StartsWith(Country(), info, false)) {
230 *match = country_; 246 *match = Country();
231 } else if (subgroup == AutoFillType::ADDRESS_ZIP && 247 } else if (subgroup == AutoFillType::ADDRESS_ZIP &&
232 StartsWith(zip_code_, info, true)) { 248 StartsWith(zip_code_, info, true)) {
233 *match = zip_code_; 249 *match = zip_code_;
234 } 250 }
235 251
236 return !match->empty(); 252 return !match->empty();
237 } 253 }
238 254
239 bool Address::IsLineMatch(const string16& text, 255 bool Address::IsLineMatch(const string16& text,
240 const LineTokens& line_tokens) const { 256 const LineTokens& line_tokens) const {
(...skipping 24 matching lines...) Expand all
265 bool Address::IsWordInLine(const string16& word, 281 bool Address::IsWordInLine(const string16& word,
266 const LineTokens& line_tokens) const { 282 const LineTokens& line_tokens) const {
267 LineTokens::const_iterator iter; 283 LineTokens::const_iterator iter;
268 for (iter = line_tokens.begin(); iter != line_tokens.end(); ++iter) { 284 for (iter = line_tokens.begin(); iter != line_tokens.end(); ++iter) {
269 if (StringToLowerASCII(word) == *iter) 285 if (StringToLowerASCII(word) == *iter)
270 return true; 286 return true;
271 } 287 }
272 288
273 return false; 289 return false;
274 } 290 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/address.h ('k') | chrome/browser/autofill/address_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698