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

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

Issue 124533003: Add country combobox to change country and rebuild address inputs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 6 years, 11 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/country_combobox_model.h" 5 #include "chrome/browser/ui/autofill/country_combobox_model.h"
6 6
7 #include "base/logging.h"
7 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
9 #include "components/autofill/core/browser/autofill_country.h" 10 #include "components/autofill/core/browser/autofill_country.h"
10 #include "components/autofill/core/browser/personal_data_manager.h" 11 #include "components/autofill/core/browser/personal_data_manager.h"
11 #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"
12 14
13 namespace autofill { 15 namespace autofill {
14 16
15 CountryComboboxModel::CountryComboboxModel(const PersonalDataManager& manager) { 17 CountryComboboxModel::CountryComboboxModel(const PersonalDataManager& manager)
18 : default_index_(0) {
16 // Insert the default country at the top as well as in the ordered list. 19 // Insert the default country at the top as well as in the ordered list.
17 std::string app_locale = g_browser_process->GetApplicationLocale(); 20 const std::string& app_locale = g_browser_process->GetApplicationLocale();
18 std::string default_country_code = 21 std::string default_country_code =
19 manager.GetDefaultCountryCodeForNewAddress(); 22 manager.GetDefaultCountryCodeForNewAddress();
20 DCHECK(!default_country_code.empty()); 23 DCHECK(!default_country_code.empty());
21 24
22 countries_.push_back(new AutofillCountry(default_country_code, app_locale)); 25 countries_.push_back(new AutofillCountry(default_country_code, app_locale));
23 // The separator item. 26 // The separator item.
24 countries_.push_back(NULL); 27 countries_.push_back(NULL);
25 28
26 // The sorted list of countries. 29 // The sorted list of countries.
27 std::vector<std::string> country_codes; 30 std::vector<std::string> country_codes;
(...skipping 26 matching lines...) Expand all
54 57
55 // The separator item. Implemented for platforms that don't yet support 58 // The separator item. Implemented for platforms that don't yet support
56 // IsItemSeparatorAt(). 59 // IsItemSeparatorAt().
57 return base::ASCIIToUTF16("---"); 60 return base::ASCIIToUTF16("---");
58 } 61 }
59 62
60 bool CountryComboboxModel::IsItemSeparatorAt(int index) { 63 bool CountryComboboxModel::IsItemSeparatorAt(int index) {
61 return !countries_[index]; 64 return !countries_[index];
62 } 65 }
63 66
67 int CountryComboboxModel::GetDefaultIndex() const {
68 return default_index_;
69 }
70
71 void CountryComboboxModel::AddObserver(ui::ComboboxModelObserver* observer) {
72 observers_.AddObserver(observer);
73 }
74
75 void CountryComboboxModel::RemoveObserver(ui::ComboboxModelObserver* observer) {
76 observers_.RemoveObserver(observer);
77 }
78
79 void CountryComboboxModel::ResetDefault() {
80 SetDefaultIndex(0);
81 }
82
83 void CountryComboboxModel::SetDefaultCountry(const std::string& country_code) {
84 DCHECK_EQ(2U, country_code.length());
85
86 if (country_code == GetDefaultCountryCode())
Evan Stade 2014/01/15 23:12:29 I don't know if you missed, disagreed with, or wha
Dan Beam 2014/01/16 01:39:13 Done.
87 return;
88
89 for (size_t i = 0; i < countries_.size(); ++i) {
90 if (countries_[i] && countries_[i]->country_code() == country_code) {
91 SetDefaultIndex(i);
92 return;
93 }
94 }
95
96 NOTREACHED();
97 }
98
99 std::string CountryComboboxModel::GetDefaultCountryCode() const {
100 return countries_[default_index_]->country_code();
101 }
102
103 void CountryComboboxModel::SetDefaultIndex(int index) {
104 DCHECK_GE(index, 0);
105 DCHECK_LT(index, static_cast<int>(countries_.size()));
106 DCHECK(!IsItemSeparatorAt(index));
107
108 if (index == default_index_)
109 return;
110
111 default_index_ = index;
112 FOR_EACH_OBSERVER(ui::ComboboxModelObserver, observers_,
113 OnComboboxModelChanged(this));
114 }
115
64 } // namespace autofill 116 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698