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

Side by Side Diff: chrome/browser/ui/autofill/data_model_wrapper.cc

Issue 148273010: rAc: fix international address formatting (mostly) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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
OLDNEW
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 #include "chrome/browser/ui/autofill/data_model_wrapper.h" 5 #include "chrome/browser/ui/autofill/data_model_wrapper.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 } 49 }
50 50
51 gfx::Image DataModelWrapper::GetIcon() { 51 gfx::Image DataModelWrapper::GetIcon() {
52 return gfx::Image(); 52 return gfx::Image();
53 } 53 }
54 54
55 #if !defined(OS_ANDROID) 55 #if !defined(OS_ANDROID)
56 bool DataModelWrapper::GetDisplayText( 56 bool DataModelWrapper::GetDisplayText(
57 base::string16* vertically_compact, 57 base::string16* vertically_compact,
58 base::string16* horizontally_compact) { 58 base::string16* horizontally_compact) {
59 base::string16 phone =
60 GetInfoForDisplay(AutofillType(PHONE_HOME_WHOLE_NUMBER));
61 if (phone.empty())
62 return false;
Dan Beam 2014/01/29 04:15:09 ^ but out of curiosity, why return false for only
63
59 // Format the address. 64 // Format the address.
60 ::i18n::addressinput::AddressData address_data; 65 ::i18n::addressinput::AddressData address_data;
61 address_data.recipient = UTF16ToUTF8( 66 address_data.recipient = UTF16ToUTF8(
62 GetInfoForDisplay(AutofillType(NAME_FULL))); 67 GetInfoForDisplay(AutofillType(NAME_FULL)));
63 address_data.country_code = UTF16ToUTF8( 68 address_data.country_code = UTF16ToASCII(
64 GetInfoForDisplay(AutofillType(ADDRESS_HOME_COUNTRY))); 69 GetInfoForDisplay(AutofillType(HTML_TYPE_COUNTRY_CODE,
70 HTML_MODE_SHIPPING)));
Dan Beam 2014/01/29 03:26:59 ^ what's the effective difference here?
Evan Stade 2014/01/29 04:11:00 returns country code instead of human-readable nam
Dan Beam 2014/01/29 07:14:45 not lgtm -- this breaks FieldMapWrapper (which ass
65 address_data.administrative_area = UTF16ToUTF8( 71 address_data.administrative_area = UTF16ToUTF8(
66 GetInfoForDisplay(AutofillType(ADDRESS_HOME_STATE))); 72 GetInfoForDisplay(AutofillType(ADDRESS_HOME_STATE)));
67 address_data.locality = UTF16ToUTF8( 73 address_data.locality = UTF16ToUTF8(
68 GetInfoForDisplay(AutofillType(ADDRESS_HOME_CITY))); 74 GetInfoForDisplay(AutofillType(ADDRESS_HOME_CITY)));
69 address_data.dependent_locality = UTF16ToUTF8( 75 address_data.dependent_locality = UTF16ToUTF8(
70 GetInfoForDisplay(AutofillType(ADDRESS_HOME_DEPENDENT_LOCALITY))); 76 GetInfoForDisplay(AutofillType(ADDRESS_HOME_DEPENDENT_LOCALITY)));
71 address_data.sorting_code = UTF16ToUTF8( 77 address_data.sorting_code = UTF16ToUTF8(
72 GetInfoForDisplay(AutofillType(ADDRESS_HOME_SORTING_CODE))); 78 GetInfoForDisplay(AutofillType(ADDRESS_HOME_SORTING_CODE)));
73 address_data.postal_code = UTF16ToUTF8( 79 address_data.postal_code = UTF16ToUTF8(
74 GetInfoForDisplay(AutofillType(ADDRESS_HOME_ZIP))); 80 GetInfoForDisplay(AutofillType(ADDRESS_HOME_ZIP)));
75 81
76 address_data.address_lines.push_back(UTF16ToUTF8( 82 address_data.address_lines.push_back(UTF16ToUTF8(
77 GetInfoForDisplay(AutofillType(ADDRESS_HOME_LINE1)))); 83 GetInfoForDisplay(AutofillType(ADDRESS_HOME_LINE1))));
78 base::string16 address2 = GetInfoForDisplay(AutofillType(ADDRESS_HOME_LINE2)); 84 base::string16 address2 = GetInfoForDisplay(AutofillType(ADDRESS_HOME_LINE2));
79 if (!address2.empty()) 85 if (!address2.empty())
80 address_data.address_lines.push_back(UTF16ToUTF8(address2)); 86 address_data.address_lines.push_back(UTF16ToUTF8(address2));
81 87
82 std::vector<std::string> lines; 88 std::vector<std::string> lines;
83 address_data.FormatForDisplay(&lines); 89 address_data.FormatForDisplay(&lines);
84 90
85 // Email and phone number aren't part of address formatting. 91 // Email and phone number aren't part of address formatting.
86 base::string16 non_address_info; 92 base::string16 non_address_info;
87 base::string16 email = GetInfoForDisplay(AutofillType(EMAIL_ADDRESS)); 93 base::string16 email = GetInfoForDisplay(AutofillType(EMAIL_ADDRESS));
88 if (!email.empty()) 94 if (!email.empty())
89 non_address_info += ASCIIToUTF16("\n") + email; 95 non_address_info += ASCIIToUTF16("\n") + email;
90 96
91 non_address_info += ASCIIToUTF16("\n") + 97 non_address_info += ASCIIToUTF16("\n") + phone;
92 GetInfoForDisplay(AutofillType(PHONE_HOME_WHOLE_NUMBER));
93 98
94 // The separator is locale-specific. 99 // The separator is locale-specific.
95 std::string compact_separator = 100 std::string compact_separator =
96 ::i18n::addressinput::GetCompactAddressLinesSeparator( 101 ::i18n::addressinput::GetCompactAddressLinesSeparator(
97 g_browser_process->GetApplicationLocale()); 102 g_browser_process->GetApplicationLocale());
98 *vertically_compact = 103 *vertically_compact =
99 base::UTF8ToUTF16(JoinString(lines, compact_separator)) + 104 base::UTF8ToUTF16(JoinString(lines, compact_separator)) +
100 non_address_info; 105 non_address_info;
101 *horizontally_compact = base::UTF8ToUTF16(JoinString(lines, "\n")) + 106 *horizontally_compact = base::UTF8ToUTF16(JoinString(lines, "\n")) +
102 non_address_info; 107 non_address_info;
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 if (type.GetStorableType() == PHONE_HOME_WHOLE_NUMBER) 274 if (type.GetStorableType() == PHONE_HOME_WHOLE_NUMBER)
270 return address_->DisplayPhoneNumber(); 275 return address_->DisplayPhoneNumber();
271 276
272 return DataModelWrapper::GetInfoForDisplay(type); 277 return DataModelWrapper::GetInfoForDisplay(type);
273 } 278 }
274 279
275 #if !defined(OS_ANDROID) 280 #if !defined(OS_ANDROID)
276 bool WalletAddressWrapper::GetDisplayText( 281 bool WalletAddressWrapper::GetDisplayText(
277 base::string16* vertically_compact, 282 base::string16* vertically_compact,
278 base::string16* horizontally_compact) { 283 base::string16* horizontally_compact) {
279 if (!address_->is_complete_address() || 284 if (!address_->is_complete_address())
280 GetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER)).empty()) {
281 return false; 285 return false;
282 }
283 286
284 return DataModelWrapper::GetDisplayText(vertically_compact, 287 return DataModelWrapper::GetDisplayText(vertically_compact,
285 horizontally_compact); 288 horizontally_compact);
286 } 289 }
287 #endif 290 #endif
288 291
289 // WalletInstrumentWrapper 292 // WalletInstrumentWrapper
290 293
291 WalletInstrumentWrapper::WalletInstrumentWrapper( 294 WalletInstrumentWrapper::WalletInstrumentWrapper(
292 const wallet::WalletItems::MaskedInstrument* instrument) 295 const wallet::WalletItems::MaskedInstrument* instrument)
(...skipping 24 matching lines...) Expand all
317 gfx::Image WalletInstrumentWrapper::GetIcon() { 320 gfx::Image WalletInstrumentWrapper::GetIcon() {
318 return instrument_->CardIcon(); 321 return instrument_->CardIcon();
319 } 322 }
320 323
321 #if !defined(OS_ANDROID) 324 #if !defined(OS_ANDROID)
322 bool WalletInstrumentWrapper::GetDisplayText( 325 bool WalletInstrumentWrapper::GetDisplayText(
323 base::string16* vertically_compact, 326 base::string16* vertically_compact,
324 base::string16* horizontally_compact) { 327 base::string16* horizontally_compact) {
325 // TODO(dbeam): handle other instrument statuses? http://crbug.com/233048 328 // TODO(dbeam): handle other instrument statuses? http://crbug.com/233048
326 if (instrument_->status() == wallet::WalletItems::MaskedInstrument::EXPIRED || 329 if (instrument_->status() == wallet::WalletItems::MaskedInstrument::EXPIRED ||
327 !instrument_->address().is_complete_address() || 330 !instrument_->address().is_complete_address()) {
328 GetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER)).empty()) {
329 return false; 331 return false;
330 } 332 }
331 333
332 DataModelWrapper::GetDisplayText(vertically_compact, horizontally_compact); 334 if (!DataModelWrapper::GetDisplayText(vertically_compact,
335 horizontally_compact)) {
336 return false;
337 }
338
333 // TODO(estade): descriptive_name() is user-provided. Should we use it or 339 // TODO(estade): descriptive_name() is user-provided. Should we use it or
334 // just type + last 4 digits? 340 // just type + last 4 digits?
335 base::string16 line1 = instrument_->descriptive_name() + ASCIIToUTF16("\n"); 341 base::string16 line1 = instrument_->descriptive_name() + ASCIIToUTF16("\n");
336 *vertically_compact = line1 + *vertically_compact; 342 *vertically_compact = line1 + *vertically_compact;
337 *horizontally_compact = line1 + *horizontally_compact; 343 *horizontally_compact = line1 + *horizontally_compact;
338 return true; 344 return true;
339 } 345 }
340 #endif 346 #endif
341 347
342 // FullWalletBillingWrapper 348 // FullWalletBillingWrapper
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 : field_map_(field_map) {} 400 : field_map_(field_map) {}
395 401
396 FieldMapWrapper::~FieldMapWrapper() {} 402 FieldMapWrapper::~FieldMapWrapper() {}
397 403
398 base::string16 FieldMapWrapper::GetInfo(const AutofillType& type) const { 404 base::string16 FieldMapWrapper::GetInfo(const AutofillType& type) const {
399 FieldValueMap::const_iterator it = field_map_.find(type.server_type()); 405 FieldValueMap::const_iterator it = field_map_.find(type.server_type());
400 return it != field_map_.end() ? it->second : base::string16(); 406 return it != field_map_.end() ? it->second : base::string16();
401 } 407 }
402 408
403 } // namespace autofill 409 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698