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" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 base::string16 phone = | 51 base::string16 phone = |
52 GetInfoForDisplay(AutofillType(PHONE_HOME_WHOLE_NUMBER)); | 52 GetInfoForDisplay(AutofillType(PHONE_HOME_WHOLE_NUMBER)); |
53 if (phone.empty()) | 53 if (phone.empty()) |
54 return false; | 54 return false; |
55 | 55 |
56 // Format the address. | 56 // Format the address. |
57 ::i18n::addressinput::AddressData address_data; | 57 ::i18n::addressinput::AddressData address_data; |
58 i18ninput::CreateAddressData( | 58 i18ninput::CreateAddressData( |
59 base::Bind(&DataModelWrapper::GetInfo, base::Unretained(this)), | 59 base::Bind(&DataModelWrapper::GetInfo, base::Unretained(this)), |
60 &address_data); | 60 &address_data); |
| 61 address_data.language_code = GetLanguageCode(); |
61 std::vector<std::string> lines; | 62 std::vector<std::string> lines; |
62 address_data.FormatForDisplay(&lines); | 63 address_data.FormatForDisplay(&lines); |
63 | 64 |
64 // Email and phone number aren't part of address formatting. | 65 // Email and phone number aren't part of address formatting. |
65 base::string16 non_address_info; | 66 base::string16 non_address_info; |
66 base::string16 email = GetInfoForDisplay(AutofillType(EMAIL_ADDRESS)); | 67 base::string16 email = GetInfoForDisplay(AutofillType(EMAIL_ADDRESS)); |
67 if (!email.empty()) | 68 if (!email.empty()) |
68 non_address_info += base::ASCIIToUTF16("\n") + email; | 69 non_address_info += base::ASCIIToUTF16("\n") + email; |
69 | 70 |
70 non_address_info += base::ASCIIToUTF16("\n") + phone; | 71 non_address_info += base::ASCIIToUTF16("\n") + phone; |
71 | 72 |
72 // The separator is locale-specific. | 73 // The separator is locale-specific. |
73 std::string compact_separator = | 74 std::string compact_separator = |
74 ::i18n::addressinput::GetCompactAddressLinesSeparator( | 75 ::i18n::addressinput::GetCompactAddressLinesSeparator(GetLanguageCode()); |
75 g_browser_process->GetApplicationLocale()); | |
76 *vertically_compact = | 76 *vertically_compact = |
77 base::UTF8ToUTF16(JoinString(lines, compact_separator)) + | 77 base::UTF8ToUTF16(JoinString(lines, compact_separator)) + |
78 non_address_info; | 78 non_address_info; |
79 *horizontally_compact = base::UTF8ToUTF16(JoinString(lines, "\n")) + | 79 *horizontally_compact = base::UTF8ToUTF16(JoinString(lines, "\n")) + |
80 non_address_info; | 80 non_address_info; |
81 | 81 |
82 return true; | 82 return true; |
83 } | 83 } |
84 | 84 |
| 85 const std::string& DataModelWrapper::GetLanguageCode() const { |
| 86 return g_browser_process->GetApplicationLocale(); |
| 87 } |
| 88 |
85 bool DataModelWrapper::FillFormStructure( | 89 bool DataModelWrapper::FillFormStructure( |
86 const std::vector<ServerFieldType>& types, | 90 const std::vector<ServerFieldType>& types, |
87 const FormStructure::InputFieldComparator& compare, | 91 const FormStructure::InputFieldComparator& compare, |
88 FormStructure* form_structure) const { | 92 FormStructure* form_structure) const { |
89 return form_structure->FillFields( | 93 return form_structure->FillFields( |
90 types, | 94 types, |
91 compare, | 95 compare, |
92 base::Bind(&DataModelWrapper::GetInfo, base::Unretained(this)), | 96 base::Bind(&DataModelWrapper::GetInfo, base::Unretained(this)), |
93 g_browser_process->GetApplicationLocale()); | 97 g_browser_process->GetApplicationLocale()); |
94 } | 98 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 i18n::PhoneObject phone(phone_number, region); | 146 i18n::PhoneObject phone(phone_number, region); |
143 return phone.GetFormattedNumber(); | 147 return phone.GetFormattedNumber(); |
144 } | 148 } |
145 | 149 |
146 return phone_number; | 150 return phone_number; |
147 } | 151 } |
148 | 152 |
149 return DataModelWrapper::GetInfoForDisplay(type); | 153 return DataModelWrapper::GetInfoForDisplay(type); |
150 } | 154 } |
151 | 155 |
| 156 const std::string& AutofillProfileWrapper::GetLanguageCode() const { |
| 157 return profile_->language_code(); |
| 158 } |
| 159 |
152 size_t AutofillProfileWrapper::GetVariantForType(const AutofillType& type) | 160 size_t AutofillProfileWrapper::GetVariantForType(const AutofillType& type) |
153 const { | 161 const { |
154 if (type.group() == variant_group_) | 162 if (type.group() == variant_group_) |
155 return variant_; | 163 return variant_; |
156 | 164 |
157 return 0; | 165 return 0; |
158 } | 166 } |
159 | 167 |
160 // AutofillShippingAddressWrapper | 168 // AutofillShippingAddressWrapper |
161 | 169 |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 return base::string16(); | 363 return base::string16(); |
356 | 364 |
357 if (field == ::i18n::addressinput::COUNTRY) { | 365 if (field == ::i18n::addressinput::COUNTRY) { |
358 return AutofillCountry(address_->country_code, | 366 return AutofillCountry(address_->country_code, |
359 g_browser_process->GetApplicationLocale()).name(); | 367 g_browser_process->GetApplicationLocale()).name(); |
360 } | 368 } |
361 | 369 |
362 return base::UTF8ToUTF16(address_->GetFieldValue(field)); | 370 return base::UTF8ToUTF16(address_->GetFieldValue(field)); |
363 } | 371 } |
364 | 372 |
| 373 const std::string& I18nAddressDataWrapper::GetLanguageCode() const { |
| 374 return address_->language_code; |
| 375 } |
| 376 |
365 } // namespace autofill | 377 } // namespace autofill |
OLD | NEW |