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; | 17 class PrefService; |
18 | 18 |
19 namespace autofill { | 19 namespace autofill { |
20 | 20 |
21 class SuggestionsMenuModel; | 21 class SuggestionsMenuModel; |
22 | 22 |
23 class SuggestionsMenuModelDelegate { | 23 class SuggestionsMenuModelDelegate { |
24 public: | 24 public: |
25 virtual ~SuggestionsMenuModelDelegate(); | 25 virtual ~SuggestionsMenuModelDelegate(); |
26 | 26 |
27 // Called when a menu item has been activated. | 27 // Called when a menu item has been activated. |
28 virtual void SuggestionItemSelected(const SuggestionsMenuModel& model) = 0; | 28 virtual void SuggestionItemSelected(SuggestionsMenuModel* model, |
| 29 const std::string& item_key) = 0; |
29 }; | 30 }; |
30 | 31 |
31 // A model for the dropdowns that allow the user to select from different | 32 // A model for the dropdowns that allow the user to select from different |
32 // sets of known data. It wraps a SimpleMenuModel, providing a mapping between | 33 // sets of known data. It wraps a SimpleMenuModel, providing a mapping between |
33 // index and item GUID. | 34 // index and item GUID. |
34 class SuggestionsMenuModel : public ui::SimpleMenuModel, | 35 class SuggestionsMenuModel : public ui::SimpleMenuModel, |
35 public ui::SimpleMenuModel::Delegate { | 36 public ui::SimpleMenuModel::Delegate { |
36 public: | 37 public: |
37 explicit SuggestionsMenuModel(SuggestionsMenuModelDelegate* delegate); | 38 explicit SuggestionsMenuModel(SuggestionsMenuModelDelegate* delegate); |
38 virtual ~SuggestionsMenuModel(); | 39 virtual ~SuggestionsMenuModel(); |
(...skipping 23 matching lines...) Expand all Loading... |
62 // Resets the model to empty. | 63 // Resets the model to empty. |
63 void Reset(); | 64 void Reset(); |
64 | 65 |
65 // Returns the ID key for the item at |index|. | 66 // Returns the ID key for the item at |index|. |
66 std::string GetItemKeyAt(int index) const; | 67 std::string GetItemKeyAt(int index) const; |
67 | 68 |
68 // Returns the ID key for the item at |checked_item_|, or an empty string if | 69 // Returns the ID key for the item at |checked_item_|, or an empty string if |
69 // there are no items. | 70 // there are no items. |
70 std::string GetItemKeyForCheckedItem() const; | 71 std::string GetItemKeyForCheckedItem() const; |
71 | 72 |
| 73 // Sets which item is checked. |
| 74 void SetCheckedItem(const std::string& item_key); |
| 75 |
72 int checked_item() { return checked_item_; } | 76 int checked_item() { return checked_item_; } |
73 | 77 |
74 // ui::SimpleMenuModel::Delegate implementation. | 78 // ui::SimpleMenuModel::Delegate implementation. |
75 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; | 79 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; |
76 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; | 80 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; |
77 virtual bool GetAcceleratorForCommandId( | 81 virtual bool GetAcceleratorForCommandId( |
78 int command_id, | 82 int command_id, |
79 ui::Accelerator* accelerator) OVERRIDE; | 83 ui::Accelerator* accelerator) OVERRIDE; |
80 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE; | 84 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE; |
81 | 85 |
82 private: | 86 private: |
83 // The items this model represents, in presentation order. The first | 87 // The items this model represents, in presentation order. The first |
84 // string is the "key" which identifies the item. The second is the | 88 // string is the "key" which identifies the item. The second is the |
85 // display string for the item. | 89 // display string for the item. |
86 std::vector<std::pair<std::string, string16> > items_; | 90 std::vector<std::pair<std::string, string16> > items_; |
87 | 91 |
88 SuggestionsMenuModelDelegate* delegate_; | 92 SuggestionsMenuModelDelegate* delegate_; |
89 | 93 |
90 // The command id (and index) of the item which is currently checked. | 94 // The command id (and index) of the item which is currently checked. Only one |
| 95 // item is checked at a time. |
91 int checked_item_; | 96 int checked_item_; |
92 | 97 |
93 DISALLOW_COPY_AND_ASSIGN(SuggestionsMenuModel); | 98 DISALLOW_COPY_AND_ASSIGN(SuggestionsMenuModel); |
94 }; | 99 }; |
95 | 100 |
96 // A delegate interface to allow the AccountChooserModel to inform its owner | 101 // A delegate interface to allow the AccountChooserModel to inform its owner |
97 // of changes. | 102 // of changes. |
98 class AccountChooserModelDelegate { | 103 class AccountChooserModelDelegate { |
99 public: | 104 public: |
100 virtual ~AccountChooserModelDelegate(); | 105 virtual ~AccountChooserModelDelegate(); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 private: | 185 private: |
181 // The current year (e.g., 2012). | 186 // The current year (e.g., 2012). |
182 int this_year_; | 187 int this_year_; |
183 | 188 |
184 DISALLOW_COPY_AND_ASSIGN(YearComboboxModel); | 189 DISALLOW_COPY_AND_ASSIGN(YearComboboxModel); |
185 }; | 190 }; |
186 | 191 |
187 } // autofill | 192 } // autofill |
188 | 193 |
189 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_MODELS_H_ | 194 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_MODELS_H_ |
OLD | NEW |