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 |
(...skipping 16 matching lines...) Expand all Loading... |
27 size_t index) = 0; | 27 size_t index) = 0; |
28 }; | 28 }; |
29 | 29 |
30 // A model for the dropdowns that allow the user to select from different | 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 | 31 // sets of known data. It wraps a SimpleMenuModel, providing a mapping between |
32 // index and item GUID. | 32 // index and item GUID. |
33 class SuggestionsMenuModel : public ui::SimpleMenuModel, | 33 class SuggestionsMenuModel : public ui::SimpleMenuModel, |
34 public ui::SimpleMenuModel::Delegate { | 34 public ui::SimpleMenuModel::Delegate { |
35 public: | 35 public: |
36 explicit SuggestionsMenuModel(SuggestionsMenuModelDelegate* delegate); | 36 explicit SuggestionsMenuModel(SuggestionsMenuModelDelegate* delegate); |
37 virtual ~SuggestionsMenuModel(); | 37 ~SuggestionsMenuModel() override; |
38 | 38 |
39 // Adds an item and its identifying key to the model. Keys needn't be unique. | 39 // Adds an item and its identifying key to the model. Keys needn't be unique. |
40 void AddKeyedItem(const std::string& key, | 40 void AddKeyedItem(const std::string& key, |
41 const base::string16& display_label); | 41 const base::string16& display_label); |
42 | 42 |
43 // As above, but also accepts an image which will be displayed alongside the | 43 // As above, but also accepts an image which will be displayed alongside the |
44 // text. | 44 // text. |
45 void AddKeyedItemWithIcon(const std::string& key, | 45 void AddKeyedItemWithIcon(const std::string& key, |
46 const base::string16& display_label, | 46 const base::string16& display_label, |
47 const gfx::Image& icon); | 47 const gfx::Image& icon); |
(...skipping 25 matching lines...) Expand all Loading... |
73 // Sets which item is checked. | 73 // Sets which item is checked. |
74 void SetCheckedItem(const std::string& item_key); | 74 void SetCheckedItem(const std::string& item_key); |
75 void SetCheckedIndex(size_t index); | 75 void SetCheckedIndex(size_t index); |
76 | 76 |
77 int checked_item() const { return checked_item_; } | 77 int checked_item() const { return checked_item_; } |
78 | 78 |
79 // Enable/disable an item by key. | 79 // Enable/disable an item by key. |
80 void SetEnabled(const std::string& item_key, bool enabled); | 80 void SetEnabled(const std::string& item_key, bool enabled); |
81 | 81 |
82 // ui::SimpleMenuModel::Delegate implementation. | 82 // ui::SimpleMenuModel::Delegate implementation. |
83 virtual bool IsCommandIdChecked(int command_id) const override; | 83 bool IsCommandIdChecked(int command_id) const override; |
84 virtual bool IsCommandIdEnabled(int command_id) const override; | 84 bool IsCommandIdEnabled(int command_id) const override; |
85 virtual bool GetAcceleratorForCommandId( | 85 bool GetAcceleratorForCommandId(int command_id, |
86 int command_id, | 86 ui::Accelerator* accelerator) override; |
87 ui::Accelerator* accelerator) override; | 87 void ExecuteCommand(int command_id, int event_flags) override; |
88 virtual void ExecuteCommand(int command_id, int event_flags) override; | |
89 | 88 |
90 private: | 89 private: |
91 // Represents an item in this model. | 90 // Represents an item in this model. |
92 struct Item { | 91 struct Item { |
93 std::string key; // The key of the item. | 92 std::string key; // The key of the item. |
94 bool enabled; // Whether the item is selectable. | 93 bool enabled; // Whether the item is selectable. |
95 }; | 94 }; |
96 // The items this model represents in presentation order. | 95 // The items this model represents in presentation order. |
97 // Note: the index in this vector is the |command_id| of the item. | 96 // Note: the index in this vector is the |command_id| of the item. |
98 std::vector<Item> items_; | 97 std::vector<Item> items_; |
99 | 98 |
100 // Returns the command id (and index) of the item by the |key|. | 99 // Returns the command id (and index) of the item by the |key|. |
101 size_t GetItemIndex(const std::string& item_key); | 100 size_t GetItemIndex(const std::string& item_key); |
102 | 101 |
103 SuggestionsMenuModelDelegate* delegate_; | 102 SuggestionsMenuModelDelegate* delegate_; |
104 | 103 |
105 // The command id (and index) of the item which is currently checked. Only one | 104 // The command id (and index) of the item which is currently checked. Only one |
106 // item is checked at a time. | 105 // item is checked at a time. |
107 int checked_item_; | 106 int checked_item_; |
108 | 107 |
109 DISALLOW_COPY_AND_ASSIGN(SuggestionsMenuModel); | 108 DISALLOW_COPY_AND_ASSIGN(SuggestionsMenuModel); |
110 }; | 109 }; |
111 | 110 |
112 // A model for possible months in the Gregorian calendar. | 111 // A model for possible months in the Gregorian calendar. |
113 class MonthComboboxModel : public ui::ComboboxModel { | 112 class MonthComboboxModel : public ui::ComboboxModel { |
114 public: | 113 public: |
115 MonthComboboxModel(); | 114 MonthComboboxModel(); |
116 virtual ~MonthComboboxModel(); | 115 ~MonthComboboxModel() override; |
117 | 116 |
118 static base::string16 FormatMonth(int index); | 117 static base::string16 FormatMonth(int index); |
119 | 118 |
120 // ui::Combobox implementation: | 119 // ui::Combobox implementation: |
121 virtual int GetItemCount() const override; | 120 int GetItemCount() const override; |
122 virtual base::string16 GetItemAt(int index) override; | 121 base::string16 GetItemAt(int index) override; |
123 | 122 |
124 private: | 123 private: |
125 DISALLOW_COPY_AND_ASSIGN(MonthComboboxModel); | 124 DISALLOW_COPY_AND_ASSIGN(MonthComboboxModel); |
126 }; | 125 }; |
127 | 126 |
128 // A model for years between now and a decade hence. | 127 // A model for years between now and a decade hence. |
129 class YearComboboxModel : public ui::ComboboxModel { | 128 class YearComboboxModel : public ui::ComboboxModel { |
130 public: | 129 public: |
131 YearComboboxModel(); | 130 YearComboboxModel(); |
132 virtual ~YearComboboxModel(); | 131 ~YearComboboxModel() override; |
133 | 132 |
134 // ui::Combobox implementation: | 133 // ui::Combobox implementation: |
135 virtual int GetItemCount() const override; | 134 int GetItemCount() const override; |
136 virtual base::string16 GetItemAt(int index) override; | 135 base::string16 GetItemAt(int index) override; |
137 | 136 |
138 private: | 137 private: |
139 // The current year (e.g., 2012). | 138 // The current year (e.g., 2012). |
140 int this_year_; | 139 int this_year_; |
141 | 140 |
142 DISALLOW_COPY_AND_ASSIGN(YearComboboxModel); | 141 DISALLOW_COPY_AND_ASSIGN(YearComboboxModel); |
143 }; | 142 }; |
144 | 143 |
145 } // namespace autofill | 144 } // namespace autofill |
146 | 145 |
147 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_MODELS_H_ | 146 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_MODELS_H_ |
OLD | NEW |