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_COMBOBOXES_H_ | 5 #ifndef CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_MODELS_H_ |
6 #define CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_COMBOBOXES_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 | 16 |
16 namespace autofill { | 17 namespace autofill { |
17 | 18 |
18 // A model for the comboboxes that allow the user to select from different sets | 19 class SuggestionsMenuModel; |
19 // of known data. | 20 |
20 class SuggestionsComboboxModel : public ui::ComboboxModel { | 21 class SuggestionsMenuModelDelegate { |
21 public: | 22 public: |
22 SuggestionsComboboxModel(); | 23 virtual ~SuggestionsMenuModelDelegate(); |
23 virtual ~SuggestionsComboboxModel(); | 24 |
25 virtual void SuggestionItemSelected(const SuggestionsMenuModel& model, | |
26 const std::string& key) = 0; | |
Ilya Sherman
2013/01/07 20:56:02
nit: Do you need the key? The controller doesn't
Evan Stade
2013/01/07 21:38:14
Done.
| |
27 | |
28 }; | |
29 | |
30 // 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 | |
32 // index and item GUID. | |
33 class SuggestionsMenuModel : public ui::SimpleMenuModel, | |
34 public ui::SimpleMenuModel::Delegate { | |
35 public: | |
36 explicit SuggestionsMenuModel(SuggestionsMenuModelDelegate* delegate); | |
37 virtual ~SuggestionsMenuModel(); | |
24 | 38 |
25 // Adds an item and its identifying key to the model. | 39 // Adds an item and its identifying key to the model. |
26 void AddItem(const std::string& key, const string16& display_label); | 40 void AddKeyedItem(const std::string& key, const string16& display_label); |
27 | 41 |
28 // Returns the ID key for the item at |index|. | 42 // Returns the ID key for the item at |index|. |
29 std::string GetItemKeyAt(int index) const; | 43 std::string GetItemKeyAt(int index) const; |
30 | 44 |
31 // ui::Combobox implementation: | 45 int checked_item() { return checked_item_; } |
32 virtual int GetItemCount() const OVERRIDE; | 46 |
33 virtual string16 GetItemAt(int index) OVERRIDE; | 47 // ui::SimpleMenuModel::Delegate implementation. |
48 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; | |
49 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; | |
50 virtual bool GetAcceleratorForCommandId( | |
51 int command_id, | |
52 ui::Accelerator* accelerator) OVERRIDE; | |
53 virtual void ExecuteCommand(int command_id) OVERRIDE; | |
34 | 54 |
35 private: | 55 private: |
36 // The items this model represents, in presentation order. The first | 56 // The items this model represents, in presentation order. The first |
37 // string is the "key" which identifies the item. The second is the | 57 // string is the "key" which identifies the item. The second is the |
38 // display string for the item. | 58 // display string for the item. |
39 std::vector<std::pair<std::string, string16> > items_; | 59 std::vector<std::pair<std::string, string16> > items_; |
40 | 60 |
41 DISALLOW_COPY_AND_ASSIGN(SuggestionsComboboxModel); | 61 SuggestionsMenuModelDelegate* delegate_; |
62 | |
63 // The command id (and index) of the item which is currently checked. | |
64 int checked_item_; | |
65 | |
66 DISALLOW_COPY_AND_ASSIGN(SuggestionsMenuModel); | |
42 }; | 67 }; |
43 | 68 |
44 // A model for possible months in the Gregorian calendar. | 69 // A model for possible months in the Gregorian calendar. |
45 class MonthComboboxModel : public ui::ComboboxModel { | 70 class MonthComboboxModel : public ui::ComboboxModel { |
46 public: | 71 public: |
47 MonthComboboxModel(); | 72 MonthComboboxModel(); |
48 virtual ~MonthComboboxModel(); | 73 virtual ~MonthComboboxModel(); |
49 | 74 |
50 // ui::Combobox implementation: | 75 // ui::Combobox implementation: |
51 virtual int GetItemCount() const OVERRIDE; | 76 virtual int GetItemCount() const OVERRIDE; |
(...skipping 15 matching lines...) Expand all Loading... | |
67 | 92 |
68 private: | 93 private: |
69 // The current year (e.g., 2012). | 94 // The current year (e.g., 2012). |
70 int this_year_; | 95 int this_year_; |
71 | 96 |
72 DISALLOW_COPY_AND_ASSIGN(YearComboboxModel); | 97 DISALLOW_COPY_AND_ASSIGN(YearComboboxModel); |
73 }; | 98 }; |
74 | 99 |
75 } // autofill | 100 } // autofill |
76 | 101 |
77 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_COMBOBOXES_H_ | 102 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_MODELS_H_ |
OLD | NEW |