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 #ifndef CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_MODELS_H_ | 5 #ifndef CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_MODELS_H_ |
6 #define CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_MODELS_H_ | 6 #define CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_MODELS_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/string16.h" | 13 #include "base/string16.h" |
14 #include "ui/base/models/combobox_model.h" | 14 #include "ui/base/models/combobox_model.h" |
15 #include "ui/base/models/simple_menu_model.h" | 15 #include "ui/base/models/simple_menu_model.h" |
16 | 16 |
17 class PrefService; | |
18 | |
19 namespace autofill { | 17 namespace autofill { |
20 | 18 |
21 class SuggestionsMenuModel; | 19 class SuggestionsMenuModel; |
22 | 20 |
23 class SuggestionsMenuModelDelegate { | 21 class SuggestionsMenuModelDelegate { |
24 public: | 22 public: |
25 virtual ~SuggestionsMenuModelDelegate(); | 23 virtual ~SuggestionsMenuModelDelegate(); |
26 | 24 |
27 // Called when a menu item has been activated. | 25 // Called when a menu item has been activated. |
28 virtual void SuggestionItemSelected(const SuggestionsMenuModel& model) = 0; | 26 virtual void SuggestionItemSelected(const SuggestionsMenuModel& model) = 0; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 std::vector<std::pair<std::string, string16> > items_; | 84 std::vector<std::pair<std::string, string16> > items_; |
87 | 85 |
88 SuggestionsMenuModelDelegate* delegate_; | 86 SuggestionsMenuModelDelegate* delegate_; |
89 | 87 |
90 // The command id (and index) of the item which is currently checked. | 88 // The command id (and index) of the item which is currently checked. |
91 int checked_item_; | 89 int checked_item_; |
92 | 90 |
93 DISALLOW_COPY_AND_ASSIGN(SuggestionsMenuModel); | 91 DISALLOW_COPY_AND_ASSIGN(SuggestionsMenuModel); |
94 }; | 92 }; |
95 | 93 |
96 // A delegate interface to allow the AccountChooserModel to inform its owner | |
97 // of changes. | |
98 class AccountChooserModelDelegate { | |
99 public: | |
100 virtual ~AccountChooserModelDelegate(); | |
101 | |
102 // Called when the active account has changed. | |
103 virtual void AccountChoiceChanged() = 0; | |
104 }; | |
105 | |
106 // A menu model for the account chooser. This allows users to switch between | |
107 // using Wallet and local Autofill. TODO(estade): this should support multiple | |
108 // Wallet accounts. | |
109 class AccountChooserModel : public ui::SimpleMenuModel, | |
110 public ui::SimpleMenuModel::Delegate { | |
111 public: | |
112 AccountChooserModel(AccountChooserModelDelegate* delegate, | |
113 PrefService* prefs); | |
114 virtual ~AccountChooserModel(); | |
115 | |
116 // ui::SimpleMenuModel::Delegate implementation. | |
117 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; | |
118 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; | |
119 virtual bool GetAcceleratorForCommandId( | |
120 int command_id, | |
121 ui::Accelerator* accelerator) OVERRIDE; | |
122 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE; | |
123 | |
124 // Should be called when the Wallet server returns an error. | |
125 void SetHadWalletError(); | |
126 | |
127 // Should be called when the Online Wallet sign-in attempt has failed. | |
128 void SetHadWalletSigninError(); | |
129 | |
130 bool had_wallet_error() const { return had_wallet_error_; } | |
131 | |
132 bool WalletIsSelected() const; | |
133 | |
134 int checked_item() const { return checked_item_; } | |
135 | |
136 // Command IDs of the items in this menu. For now, we only support a single | |
137 // account, so there's only one wallet item. | |
138 static const int kWalletItemId; | |
139 static const int kAutofillItemId; | |
140 | |
141 private: | |
142 AccountChooserModelDelegate* account_delegate_; | |
143 | |
144 // The command id of the currently active item. | |
145 int checked_item_; | |
146 | |
147 // Whether there has been a Wallet error while the owning dialog has been | |
148 // open. | |
149 bool had_wallet_error_; | |
150 | |
151 DISALLOW_COPY_AND_ASSIGN(AccountChooserModel); | |
152 }; | |
153 | |
154 // A model for possible months in the Gregorian calendar. | 94 // A model for possible months in the Gregorian calendar. |
155 class MonthComboboxModel : public ui::ComboboxModel { | 95 class MonthComboboxModel : public ui::ComboboxModel { |
156 public: | 96 public: |
157 MonthComboboxModel(); | 97 MonthComboboxModel(); |
158 virtual ~MonthComboboxModel(); | 98 virtual ~MonthComboboxModel(); |
159 | 99 |
160 static string16 FormatMonth(int index); | 100 static string16 FormatMonth(int index); |
161 | 101 |
162 // ui::Combobox implementation: | 102 // ui::Combobox implementation: |
163 virtual int GetItemCount() const OVERRIDE; | 103 virtual int GetItemCount() const OVERRIDE; |
(...skipping 16 matching lines...) Expand all Loading... |
180 private: | 120 private: |
181 // The current year (e.g., 2012). | 121 // The current year (e.g., 2012). |
182 int this_year_; | 122 int this_year_; |
183 | 123 |
184 DISALLOW_COPY_AND_ASSIGN(YearComboboxModel); | 124 DISALLOW_COPY_AND_ASSIGN(YearComboboxModel); |
185 }; | 125 }; |
186 | 126 |
187 } // autofill | 127 } // autofill |
188 | 128 |
189 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_MODELS_H_ | 129 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_MODELS_H_ |
OLD | NEW |