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

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

Issue 13331007: Multi-account AccountChooser for interactive autocomplete. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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/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
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 checked_item_(prefs->GetBoolean(prefs::kAutofillDialogPayWithoutWallet) ?
112 kAutofillItemId : kWalletItemId),
113 had_wallet_error_(false) {
114 AddCheckItem(kWalletItemId,
115 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_GOOGLE_WALLET));
116 SetIcon(
117 kWalletItemId,
118 ui::ResourceBundle::GetSharedInstance().GetImageNamed(IDR_WALLET_ICON));
119 AddCheckItemWithStringId(kAutofillItemId,
120 IDS_AUTOFILL_DIALOG_PAY_WITHOUT_WALLET);
121 }
122
123 AccountChooserModel::~AccountChooserModel() {
124 }
125
126 bool AccountChooserModel::IsCommandIdChecked(int command_id) const {
127 return command_id == checked_item_;
128 }
129
130 bool AccountChooserModel::IsCommandIdEnabled(int command_id) const {
131 if (command_id == kWalletItemId && had_wallet_error_)
132 return false;
133
134 return true;
135 }
136
137 bool AccountChooserModel::GetAcceleratorForCommandId(
138 int command_id,
139 ui::Accelerator* accelerator) {
140 return false;
141 }
142
143 void AccountChooserModel::ExecuteCommand(int command_id, int event_flags) {
144 if (checked_item_ == command_id)
145 return;
146
147 checked_item_ = command_id;
148 account_delegate_->AccountChoiceChanged();
149 }
150
151 void AccountChooserModel::SetHadWalletError() {
152 had_wallet_error_ = true;
153 ExecuteCommand(kAutofillItemId, 0);
154 }
155
156 void AccountChooserModel::SetHadWalletSigninError() {
157 ExecuteCommand(kAutofillItemId, 0);
158 }
159
160 bool AccountChooserModel::WalletIsSelected() const {
161 return checked_item_ == kWalletItemId;
162 }
163
164 // MonthComboboxModel ---------------------------------------------------------- 99 // MonthComboboxModel ----------------------------------------------------------
165 100
166 MonthComboboxModel::MonthComboboxModel() {} 101 MonthComboboxModel::MonthComboboxModel() {}
167 102
168 MonthComboboxModel::~MonthComboboxModel() {} 103 MonthComboboxModel::~MonthComboboxModel() {}
169 104
170 int MonthComboboxModel::GetItemCount() const { 105 int MonthComboboxModel::GetItemCount() const {
171 // 12 months plus the empty entry. 106 // 12 months plus the empty entry.
172 return 13; 107 return 13;
173 } 108 }
(...skipping 24 matching lines...) Expand all
198 } 133 }
199 134
200 string16 YearComboboxModel::GetItemAt(int index) { 135 string16 YearComboboxModel::GetItemAt(int index) {
201 if (index == 0) 136 if (index == 0)
202 return string16(); 137 return string16();
203 138
204 return base::IntToString16(this_year_ + index - 1); 139 return base::IntToString16(this_year_ + index - 1);
205 } 140 }
206 141
207 } // autofill 142 } // autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698