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/autofill_dialog_models.h" | 5 #include "chrome/browser/ui/autofill/autofill_dialog_models.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 int command_id, | 89 int command_id, |
90 ui::Accelerator* accelerator) { | 90 ui::Accelerator* accelerator) { |
91 return false; | 91 return false; |
92 } | 92 } |
93 | 93 |
94 void SuggestionsMenuModel::ExecuteCommand(int command_id, int event_flags) { | 94 void SuggestionsMenuModel::ExecuteCommand(int command_id, int event_flags) { |
95 checked_item_ = command_id; | 95 checked_item_ = command_id; |
96 delegate_->SuggestionItemSelected(*this); | 96 delegate_->SuggestionItemSelected(*this); |
97 } | 97 } |
98 | 98 |
99 // AccountChooserModel --------------------------------------------------------- | |
100 | |
101 const int AccountChooserModel::kWalletItemId = 0; | |
102 const int AccountChooserModel::kAutofillItemId = 1; | |
103 | |
104 AccountChooserModelDelegate::~AccountChooserModelDelegate() {} | |
105 | |
106 AccountChooserModel::AccountChooserModel( | |
107 AccountChooserModelDelegate* delegate, | |
108 PrefService* prefs) | |
109 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), | |
110 account_delegate_(delegate), | |
111 prefs_(prefs), | |
112 checked_item_(kWalletItemId), | |
113 had_wallet_error_(false) { | |
114 pref_change_registrar_.Init(prefs); | |
115 pref_change_registrar_.Add( | |
116 prefs::kAutofillDialogPayWithoutWallet, | |
117 base::Bind(&AccountChooserModel::PrefChanged, base::Unretained(this))); | |
118 | |
119 // TODO(estade): proper strings and l10n. | |
120 AddCheckItem(kWalletItemId, ASCIIToUTF16("Google Wallet")); | |
121 SetIcon( | |
122 kWalletItemId, | |
123 ui::ResourceBundle::GetSharedInstance().GetImageNamed(IDR_WALLET_ICON)); | |
124 AddCheckItemWithStringId(kAutofillItemId, | |
125 IDS_AUTOFILL_DIALOG_PAY_WITHOUT_WALLET); | |
126 UpdateCheckmarkFromPref(); | |
127 } | |
128 | |
129 AccountChooserModel::~AccountChooserModel() { | |
130 } | |
131 | |
132 bool AccountChooserModel::IsCommandIdChecked(int command_id) const { | |
133 return command_id == checked_item_; | |
134 } | |
135 | |
136 bool AccountChooserModel::IsCommandIdEnabled(int command_id) const { | |
137 if (command_id == kWalletItemId && had_wallet_error_) | |
138 return false; | |
139 | |
140 return true; | |
141 } | |
142 | |
143 bool AccountChooserModel::GetAcceleratorForCommandId( | |
144 int command_id, | |
145 ui::Accelerator* accelerator) { | |
146 return false; | |
147 } | |
148 | |
149 void AccountChooserModel::ExecuteCommand(int command_id, int event_flags) { | |
150 if (checked_item_ == command_id) | |
151 return; | |
152 | |
153 checked_item_ = command_id; | |
154 account_delegate_->AccountChoiceChanged(); | |
155 } | |
156 | |
157 void AccountChooserModel::SetHadWalletError() { | |
158 had_wallet_error_ = true; | |
159 checked_item_ = kAutofillItemId; | |
160 account_delegate_->AccountChoiceChanged(); | |
161 } | |
162 | |
163 void AccountChooserModel::SetHadWalletSigninError() { | |
164 checked_item_ = kAutofillItemId; | |
165 account_delegate_->AccountChoiceChanged(); | |
166 } | |
167 | |
168 bool AccountChooserModel::WalletIsSelected() const { | |
169 return checked_item_ == kWalletItemId; | |
170 } | |
171 | |
172 void AccountChooserModel::PrefChanged(const std::string& pref) { | |
173 DCHECK(pref == prefs::kAutofillDialogPayWithoutWallet); | |
174 UpdateCheckmarkFromPref(); | |
175 account_delegate_->AccountChoiceChanged(); | |
176 } | |
177 | |
178 void AccountChooserModel::UpdateCheckmarkFromPref() { | |
179 if (prefs_->GetBoolean(prefs::kAutofillDialogPayWithoutWallet)) | |
180 checked_item_ = kAutofillItemId; | |
181 else | |
182 checked_item_ = kWalletItemId; | |
183 } | |
184 | |
185 // MonthComboboxModel ---------------------------------------------------------- | 99 // MonthComboboxModel ---------------------------------------------------------- |
186 | 100 |
187 MonthComboboxModel::MonthComboboxModel() {} | 101 MonthComboboxModel::MonthComboboxModel() {} |
188 | 102 |
189 MonthComboboxModel::~MonthComboboxModel() {} | 103 MonthComboboxModel::~MonthComboboxModel() {} |
190 | 104 |
191 int MonthComboboxModel::GetItemCount() const { | 105 int MonthComboboxModel::GetItemCount() const { |
192 // 12 months plus the empty entry. | 106 // 12 months plus the empty entry. |
193 return 13; | 107 return 13; |
194 } | 108 } |
(...skipping 24 matching lines...) Expand all Loading... |
219 } | 133 } |
220 | 134 |
221 string16 YearComboboxModel::GetItemAt(int index) { | 135 string16 YearComboboxModel::GetItemAt(int index) { |
222 if (index == 0) | 136 if (index == 0) |
223 return string16(); | 137 return string16(); |
224 | 138 |
225 return base::IntToString16(this_year_ + index - 1); | 139 return base::IntToString16(this_year_ + index - 1); |
226 } | 140 } |
227 | 141 |
228 } // autofill | 142 } // autofill |
OLD | NEW |