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 namespace autofill { | 17 namespace autofill { |
18 | 18 |
19 class SuggestionsMenuModel; | 19 class SuggestionsMenuModel; |
20 | 20 |
21 class SuggestionsMenuModelDelegate { | 21 class SuggestionsMenuModelDelegate { |
22 public: | 22 public: |
23 virtual ~SuggestionsMenuModelDelegate(); | 23 virtual ~SuggestionsMenuModelDelegate(); |
24 | 24 |
25 // Called when a menu item has been activated. | 25 // Called when a menu item has been activated. |
26 virtual void SuggestionItemSelected(SuggestionsMenuModel* model, | 26 virtual void SuggestionItemSelected(const SuggestionsMenuModel& model) = 0; |
27 size_t index) = 0; | |
28 }; | 27 }; |
29 | 28 |
30 // A model for the dropdowns that allow the user to select from different | 29 // A model for the dropdowns that allow the user to select from different |
31 // sets of known data. It wraps a SimpleMenuModel, providing a mapping between | 30 // sets of known data. It wraps a SimpleMenuModel, providing a mapping between |
32 // index and item GUID. | 31 // index and item GUID. |
33 class SuggestionsMenuModel : public ui::SimpleMenuModel, | 32 class SuggestionsMenuModel : public ui::SimpleMenuModel, |
34 public ui::SimpleMenuModel::Delegate { | 33 public ui::SimpleMenuModel::Delegate { |
35 public: | 34 public: |
36 explicit SuggestionsMenuModel(SuggestionsMenuModelDelegate* delegate); | 35 explicit SuggestionsMenuModel(SuggestionsMenuModelDelegate* delegate); |
37 virtual ~SuggestionsMenuModel(); | 36 virtual ~SuggestionsMenuModel(); |
(...skipping 23 matching lines...) Expand all Loading... |
61 // Resets the model to empty. | 60 // Resets the model to empty. |
62 void Reset(); | 61 void Reset(); |
63 | 62 |
64 // Returns the ID key for the item at |index|. | 63 // Returns the ID key for the item at |index|. |
65 std::string GetItemKeyAt(int index) const; | 64 std::string GetItemKeyAt(int index) const; |
66 | 65 |
67 // Returns the ID key for the item at |checked_item_|, or an empty string if | 66 // Returns the ID key for the item at |checked_item_|, or an empty string if |
68 // there are no items. | 67 // there are no items. |
69 std::string GetItemKeyForCheckedItem() const; | 68 std::string GetItemKeyForCheckedItem() const; |
70 | 69 |
71 // Sets which item is checked. | |
72 void SetCheckedItem(const std::string& item_key); | |
73 void SetCheckedIndex(size_t index); | |
74 | |
75 int checked_item() { return checked_item_; } | 70 int checked_item() { return checked_item_; } |
76 | 71 |
77 // ui::SimpleMenuModel::Delegate implementation. | 72 // ui::SimpleMenuModel::Delegate implementation. |
78 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; | 73 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; |
79 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; | 74 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; |
80 virtual bool GetAcceleratorForCommandId( | 75 virtual bool GetAcceleratorForCommandId( |
81 int command_id, | 76 int command_id, |
82 ui::Accelerator* accelerator) OVERRIDE; | 77 ui::Accelerator* accelerator) OVERRIDE; |
83 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE; | 78 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE; |
84 | 79 |
85 private: | 80 private: |
86 // The items this model represents, in presentation order. The first | 81 // The items this model represents, in presentation order. The first |
87 // string is the "key" which identifies the item. The second is the | 82 // string is the "key" which identifies the item. The second is the |
88 // display string for the item. | 83 // display string for the item. |
89 std::vector<std::pair<std::string, string16> > items_; | 84 std::vector<std::pair<std::string, string16> > items_; |
90 | 85 |
91 SuggestionsMenuModelDelegate* delegate_; | 86 SuggestionsMenuModelDelegate* delegate_; |
92 | 87 |
93 // The command id (and index) of the item which is currently checked. Only one | 88 // The command id (and index) of the item which is currently checked. |
94 // item is checked at a time. | |
95 int checked_item_; | 89 int checked_item_; |
96 | 90 |
97 DISALLOW_COPY_AND_ASSIGN(SuggestionsMenuModel); | 91 DISALLOW_COPY_AND_ASSIGN(SuggestionsMenuModel); |
98 }; | 92 }; |
99 | 93 |
100 // A model for possible months in the Gregorian calendar. | 94 // A model for possible months in the Gregorian calendar. |
101 class MonthComboboxModel : public ui::ComboboxModel { | 95 class MonthComboboxModel : public ui::ComboboxModel { |
102 public: | 96 public: |
103 MonthComboboxModel(); | 97 MonthComboboxModel(); |
104 virtual ~MonthComboboxModel(); | 98 virtual ~MonthComboboxModel(); |
(...skipping 21 matching lines...) Expand all Loading... |
126 private: | 120 private: |
127 // The current year (e.g., 2012). | 121 // The current year (e.g., 2012). |
128 int this_year_; | 122 int this_year_; |
129 | 123 |
130 DISALLOW_COPY_AND_ASSIGN(YearComboboxModel); | 124 DISALLOW_COPY_AND_ASSIGN(YearComboboxModel); |
131 }; | 125 }; |
132 | 126 |
133 } // autofill | 127 } // autofill |
134 | 128 |
135 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_MODELS_H_ | 129 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_MODELS_H_ |
OLD | NEW |