Chromium Code Reviews| 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/country_combobox_model.h" | 5 #include "chrome/browser/ui/autofill/country_combobox_model.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "components/autofill/core/browser/autofill_country.h" | 10 #include "components/autofill/core/browser/autofill_country.h" |
| 11 #include "components/autofill/core/browser/personal_data_manager.h" | 11 #include "components/autofill/core/browser/personal_data_manager.h" |
| 12 #include "ui/base/l10n/l10n_util_collator.h" | 12 #include "ui/base/l10n/l10n_util_collator.h" |
| 13 #include "ui/base/models/combobox_model_observer.h" | 13 #include "ui/base/models/combobox_model_observer.h" |
| 14 | 14 |
| 15 // TODO(rouslan): Remove this check. http://crbug.com/337587 | 15 // TODO(rouslan): Remove this check. http://crbug.com/337587 |
| 16 #if defined(ENABLE_AUTOFILL_DIALOG) | 16 #if defined(ENABLE_AUTOFILL_DIALOG) |
| 17 #include "chrome/browser/ui/autofill/autofill_dialog_i18n_input.h" | 17 #include "chrome/browser/ui/autofill/autofill_dialog_i18n_input.h" |
| 18 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre ss_ui.h" | 18 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre ss_ui.h" |
| 19 #endif | 19 #endif |
| 20 | 20 |
| 21 namespace autofill { | 21 namespace autofill { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 bool ShouldShowCountry(const std::string& country_code) { | 25 bool ShouldShowCountry(const std::string& country_code, |
| 26 bool show_partially_supported_countries, | |
| 27 const std::set<base::string16>& candidate_countries) { | |
| 26 #if defined(ENABLE_AUTOFILL_DIALOG) | 28 #if defined(ENABLE_AUTOFILL_DIALOG) |
| 27 return i18ninput::CountryIsFullySupported(country_code); | 29 if (!show_partially_supported_countries && |
| 28 #else | 30 !i18ninput::CountryIsFullySupported(country_code)) { |
| 31 return false; | |
| 32 } | |
| 33 #endif | |
| 34 | |
|
Dan Beam
2014/03/05 04:19:16
^H
Evan Stade
2014/03/05 04:21:05
Done.
| |
| 35 | |
| 36 if (!candidate_countries.empty() && | |
| 37 !candidate_countries.count(base::ASCIIToUTF16(country_code))) { | |
| 38 return false; | |
| 39 } | |
| 40 | |
| 29 return true; | 41 return true; |
|
Dan Beam
2014/03/05 04:19:16
nit: i think this all could be
return candidate
Evan Stade
2014/03/05 04:21:05
no, if it's empty, anything goes
Dan Beam
2014/03/05 19:52:12
nit:
if (candidate_countries.empty())
retur
Evan Stade
2014/03/05 22:38:31
doesn't seem better... I prefer the layout of
if
| |
| 30 #endif | |
| 31 } | 42 } |
| 32 | 43 |
| 33 } // namespace | 44 } // namespace |
| 34 | 45 |
| 35 CountryComboboxModel::CountryComboboxModel( | 46 CountryComboboxModel::CountryComboboxModel( |
| 36 const PersonalDataManager& manager, | 47 const PersonalDataManager& manager, |
| 48 const std::set<base::string16>& country_filter, | |
| 37 bool show_partially_supported_countries) { | 49 bool show_partially_supported_countries) { |
| 38 // Insert the default country at the top as well as in the ordered list. | 50 // Insert the default country at the top as well as in the ordered list. |
| 39 const std::string& app_locale = g_browser_process->GetApplicationLocale(); | |
| 40 std::string default_country_code = | 51 std::string default_country_code = |
| 41 manager.GetDefaultCountryCodeForNewAddress(); | 52 manager.GetDefaultCountryCodeForNewAddress(); |
| 42 DCHECK(!default_country_code.empty()); | 53 DCHECK(!default_country_code.empty()); |
| 43 | 54 |
| 44 if (show_partially_supported_countries || | 55 const std::string& app_locale = g_browser_process->GetApplicationLocale(); |
| 45 ShouldShowCountry(default_country_code)) { | 56 if (ShouldShowCountry(default_country_code, |
| 57 show_partially_supported_countries, | |
| 58 country_filter)) { | |
| 46 countries_.push_back(new AutofillCountry(default_country_code, app_locale)); | 59 countries_.push_back(new AutofillCountry(default_country_code, app_locale)); |
| 47 // The separator item. | 60 // The separator item. |
| 48 countries_.push_back(NULL); | 61 countries_.push_back(NULL); |
| 49 } | 62 } |
| 50 | 63 |
| 51 // The sorted list of countries. | 64 // The sorted list of countries. |
| 52 #if defined(ENABLE_AUTOFILL_DIALOG) | 65 #if defined(ENABLE_AUTOFILL_DIALOG) |
| 53 const std::vector<std::string>& available_countries = | 66 const std::vector<std::string>& available_countries = |
| 54 ::i18n::addressinput::GetRegionCodes(); | 67 ::i18n::addressinput::GetRegionCodes(); |
| 55 #else | 68 #else |
| 56 std::vector<std::string> available_countries; | 69 std::vector<std::string> available_countries; |
| 57 AutofillCountry::GetAvailableCountries(&available_countries); | 70 AutofillCountry::GetAvailableCountries(&available_countries); |
| 58 #endif | 71 #endif |
| 59 | 72 |
| 60 std::vector<AutofillCountry*> sorted_countries; | 73 std::vector<AutofillCountry*> sorted_countries; |
| 61 for (std::vector<std::string>::const_iterator it = | 74 for (std::vector<std::string>::const_iterator it = |
| 62 available_countries.begin(); it != available_countries.end(); ++it) { | 75 available_countries.begin(); it != available_countries.end(); ++it) { |
| 63 if (show_partially_supported_countries || ShouldShowCountry(*it)) | 76 if (ShouldShowCountry(*it, |
| 77 show_partially_supported_countries, | |
| 78 country_filter)) { | |
| 64 sorted_countries.push_back(new AutofillCountry(*it, app_locale)); | 79 sorted_countries.push_back(new AutofillCountry(*it, app_locale)); |
| 80 } | |
| 65 } | 81 } |
| 66 | 82 |
| 67 l10n_util::SortStringsUsingMethod(app_locale, | 83 l10n_util::SortStringsUsingMethod(app_locale, |
| 68 &sorted_countries, | 84 &sorted_countries, |
| 69 &AutofillCountry::name); | 85 &AutofillCountry::name); |
| 70 countries_.insert(countries_.end(), | 86 countries_.insert(countries_.end(), |
| 71 sorted_countries.begin(), | 87 sorted_countries.begin(), |
| 72 sorted_countries.end()); | 88 sorted_countries.end()); |
| 73 } | 89 } |
| 74 | 90 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 90 | 106 |
| 91 bool CountryComboboxModel::IsItemSeparatorAt(int index) { | 107 bool CountryComboboxModel::IsItemSeparatorAt(int index) { |
| 92 return !countries_[index]; | 108 return !countries_[index]; |
| 93 } | 109 } |
| 94 | 110 |
| 95 std::string CountryComboboxModel::GetDefaultCountryCode() const { | 111 std::string CountryComboboxModel::GetDefaultCountryCode() const { |
| 96 return countries_[GetDefaultIndex()]->country_code(); | 112 return countries_[GetDefaultIndex()]->country_code(); |
| 97 } | 113 } |
| 98 | 114 |
| 99 } // namespace autofill | 115 } // namespace autofill |
| OLD | NEW |