OLD | NEW |
---|---|
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/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/ui/autofill/autofill_dialog_i18n_input.h" | 12 #include "chrome/browser/ui/autofill/autofill_dialog_i18n_input.h" |
13 #include "chrome/browser/ui/autofill/autofill_dialog_models.h" | 13 #include "chrome/browser/ui/autofill/autofill_dialog_models.h" |
14 #include "components/autofill/content/browser/wallet/full_wallet.h" | 14 #include "components/autofill/content/browser/wallet/full_wallet.h" |
15 #include "components/autofill/content/browser/wallet/wallet_address.h" | 15 #include "components/autofill/content/browser/wallet/wallet_address.h" |
16 #include "components/autofill/content/browser/wallet/wallet_items.h" | 16 #include "components/autofill/content/browser/wallet/wallet_items.h" |
17 #include "components/autofill/core/browser/address_i18n.h" | 17 #include "components/autofill/core/browser/address_i18n.h" |
18 #include "components/autofill/core/browser/autofill_country.h" | 18 #include "components/autofill/core/browser/autofill_country.h" |
19 #include "components/autofill/core/browser/autofill_data_model.h" | 19 #include "components/autofill/core/browser/autofill_data_model.h" |
20 #include "components/autofill/core/browser/autofill_field.h" | 20 #include "components/autofill/core/browser/autofill_field.h" |
21 #include "components/autofill/core/browser/autofill_profile.h" | 21 #include "components/autofill/core/browser/autofill_profile.h" |
22 #include "components/autofill/core/browser/autofill_type.h" | 22 #include "components/autofill/core/browser/autofill_type.h" |
23 #include "components/autofill/core/browser/credit_card.h" | 23 #include "components/autofill/core/browser/credit_card.h" |
24 #include "components/autofill/core/browser/form_structure.h" | 24 #include "components/autofill/core/browser/form_structure.h" |
25 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre ss_data.h" | 25 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_da ta.h" |
26 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre ss_ui.h" | 26 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_fi eld.h" |
27 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_fo rmatter.h" | |
27 #include "ui/base/resource/resource_bundle.h" | 28 #include "ui/base/resource/resource_bundle.h" |
28 #include "ui/gfx/image/image.h" | 29 #include "ui/gfx/image/image.h" |
29 | 30 |
30 namespace autofill { | 31 namespace autofill { |
31 | 32 |
32 DataModelWrapper::~DataModelWrapper() {} | 33 DataModelWrapper::~DataModelWrapper() {} |
33 | 34 |
34 void DataModelWrapper::FillInputs(DetailInputs* inputs) { | 35 void DataModelWrapper::FillInputs(DetailInputs* inputs) { |
35 for (size_t i = 0; i < inputs->size(); ++i) { | 36 for (size_t i = 0; i < inputs->size(); ++i) { |
36 (*inputs)[i].initial_value = | 37 (*inputs)[i].initial_value = |
(...skipping 17 matching lines...) Expand all Loading... | |
54 GetInfoForDisplay(AutofillType(PHONE_HOME_WHOLE_NUMBER)); | 55 GetInfoForDisplay(AutofillType(PHONE_HOME_WHOLE_NUMBER)); |
55 if (phone.empty()) | 56 if (phone.empty()) |
56 return false; | 57 return false; |
57 | 58 |
58 // Format the address. | 59 // Format the address. |
59 scoped_ptr< ::i18n::addressinput::AddressData> address_data = | 60 scoped_ptr< ::i18n::addressinput::AddressData> address_data = |
60 i18n::CreateAddressData( | 61 i18n::CreateAddressData( |
61 base::Bind(&DataModelWrapper::GetInfo, base::Unretained(this))); | 62 base::Bind(&DataModelWrapper::GetInfo, base::Unretained(this))); |
62 address_data->language_code = GetLanguageCode(); | 63 address_data->language_code = GetLanguageCode(); |
63 std::vector<std::string> lines; | 64 std::vector<std::string> lines; |
64 address_data->FormatForDisplay(&lines); | 65 ::i18n::addressinput::GetFormattedNationalAddress(*address_data, &lines); |
65 | 66 |
66 // Email and phone number aren't part of address formatting. | 67 // Email and phone number aren't part of address formatting. |
67 base::string16 non_address_info; | 68 base::string16 non_address_info; |
68 base::string16 email = GetInfoForDisplay(AutofillType(EMAIL_ADDRESS)); | 69 base::string16 email = GetInfoForDisplay(AutofillType(EMAIL_ADDRESS)); |
69 if (!email.empty()) | 70 if (!email.empty()) |
70 non_address_info += base::ASCIIToUTF16("\n") + email; | 71 non_address_info += base::ASCIIToUTF16("\n") + email; |
71 | 72 |
72 non_address_info += base::ASCIIToUTF16("\n") + phone; | 73 non_address_info += base::ASCIIToUTF16("\n") + phone; |
73 | 74 |
74 // The separator is locale-specific. | 75 // The separator is locale-specific. |
75 std::string compact_separator = | 76 std::string compact_separator = ", "; |
76 ::i18n::addressinput::GetCompactAddressLinesSeparator(GetLanguageCode()); | 77 // ::i18n::addressinput::GetCompactAddressLinesSeparator( |
78 // GetLanguageCode()); | |
please use gerrit instead
2014/06/05 22:22:48
Use ::i18n::addressinput::GetStreetAddressLinesAsS
please use gerrit instead
2014/06/09 23:28:16
Done.
| |
77 *vertically_compact = | 79 *vertically_compact = |
78 base::UTF8ToUTF16(JoinString(lines, compact_separator)) + | 80 base::UTF8ToUTF16(JoinString(lines, compact_separator)) + |
79 non_address_info; | 81 non_address_info; |
80 *horizontally_compact = base::UTF8ToUTF16(JoinString(lines, "\n")) + | 82 *horizontally_compact = base::UTF8ToUTF16(JoinString(lines, "\n")) + |
81 non_address_info; | 83 non_address_info; |
82 | 84 |
83 return true; | 85 return true; |
84 } | 86 } |
85 | 87 |
86 bool DataModelWrapper::FillFormStructure( | 88 bool DataModelWrapper::FillFormStructure( |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
384 | 386 |
385 base::string16 I18nAddressDataWrapper::GetInfo(const AutofillType& type) const { | 387 base::string16 I18nAddressDataWrapper::GetInfo(const AutofillType& type) const { |
386 ::i18n::addressinput::AddressField field; | 388 ::i18n::addressinput::AddressField field; |
387 if (!i18ninput::FieldForType(type.GetStorableType(), &field)) | 389 if (!i18ninput::FieldForType(type.GetStorableType(), &field)) |
388 return base::string16(); | 390 return base::string16(); |
389 | 391 |
390 if (field == ::i18n::addressinput::STREET_ADDRESS) | 392 if (field == ::i18n::addressinput::STREET_ADDRESS) |
391 return base::string16(); | 393 return base::string16(); |
392 | 394 |
393 if (field == ::i18n::addressinput::COUNTRY) { | 395 if (field == ::i18n::addressinput::COUNTRY) { |
394 return AutofillCountry(address_->country_code, | 396 return AutofillCountry(address_->region_code, |
395 g_browser_process->GetApplicationLocale()).name(); | 397 g_browser_process->GetApplicationLocale()).name(); |
396 } | 398 } |
397 | 399 |
398 return base::UTF8ToUTF16(address_->GetFieldValue(field)); | 400 return base::UTF8ToUTF16(address_->GetFieldValue(field)); |
399 } | 401 } |
400 | 402 |
401 const std::string& I18nAddressDataWrapper::GetLanguageCode() const { | 403 const std::string& I18nAddressDataWrapper::GetLanguageCode() const { |
402 return address_->language_code; | 404 return address_->language_code; |
403 } | 405 } |
404 | 406 |
405 } // namespace autofill | 407 } // namespace autofill |
OLD | NEW |