OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 UI_BASE_MODELS_SIMPLE_MENU_MODEL_H_ | 5 #ifndef UI_BASE_MODELS_SIMPLE_MENU_MODEL_H_ |
6 #define UI_BASE_MODELS_SIMPLE_MENU_MODEL_H_ | 6 #define UI_BASE_MODELS_SIMPLE_MENU_MODEL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 30 matching lines...) Expand all Loading... |
41 // is an icon, false otherwise. | 41 // is an icon, false otherwise. |
42 virtual bool GetIconForCommandId(int command_id, SkBitmap* icon) const; | 42 virtual bool GetIconForCommandId(int command_id, SkBitmap* icon) const; |
43 | 43 |
44 // Notifies the delegate that the item with the specified command id was | 44 // Notifies the delegate that the item with the specified command id was |
45 // visually highlighted within the menu. | 45 // visually highlighted within the menu. |
46 virtual void CommandIdHighlighted(int command_id); | 46 virtual void CommandIdHighlighted(int command_id); |
47 | 47 |
48 // Performs the action associated with the specified command id. | 48 // Performs the action associated with the specified command id. |
49 virtual void ExecuteCommand(int command_id) = 0; | 49 virtual void ExecuteCommand(int command_id) = 0; |
50 | 50 |
| 51 // Notifies the delegate that the menu has closed. |
| 52 virtual void MenuClosed(); |
| 53 |
51 protected: | 54 protected: |
52 virtual ~Delegate() {} | 55 virtual ~Delegate() {} |
53 }; | 56 }; |
54 | 57 |
55 // The Delegate can be NULL, though if it is items can't be checked or | 58 // The Delegate can be NULL, though if it is items can't be checked or |
56 // disabled. | 59 // disabled. |
57 explicit SimpleMenuModel(Delegate* delegate); | 60 explicit SimpleMenuModel(Delegate* delegate); |
58 virtual ~SimpleMenuModel(); | 61 virtual ~SimpleMenuModel(); |
59 | 62 |
60 // Methods for adding items to the model. | 63 // Methods for adding items to the model. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 ui::Accelerator* accelerator) const; | 111 ui::Accelerator* accelerator) const; |
109 virtual bool IsItemCheckedAt(int index) const; | 112 virtual bool IsItemCheckedAt(int index) const; |
110 virtual int GetGroupIdAt(int index) const; | 113 virtual int GetGroupIdAt(int index) const; |
111 virtual bool GetIconAt(int index, SkBitmap* icon) const; | 114 virtual bool GetIconAt(int index, SkBitmap* icon) const; |
112 virtual ui::ButtonMenuItemModel* GetButtonMenuItemAt(int index) const; | 115 virtual ui::ButtonMenuItemModel* GetButtonMenuItemAt(int index) const; |
113 virtual bool IsEnabledAt(int index) const; | 116 virtual bool IsEnabledAt(int index) const; |
114 virtual bool IsVisibleAt(int index) const; | 117 virtual bool IsVisibleAt(int index) const; |
115 virtual void HighlightChangedTo(int index); | 118 virtual void HighlightChangedTo(int index); |
116 virtual void ActivatedAt(int index); | 119 virtual void ActivatedAt(int index); |
117 virtual MenuModel* GetSubmenuModelAt(int index) const; | 120 virtual MenuModel* GetSubmenuModelAt(int index) const; |
| 121 virtual void MenuClosed(); |
118 | 122 |
119 protected: | 123 protected: |
120 // Some variants of this model (SystemMenuModel) relies on items to be | 124 // Some variants of this model (SystemMenuModel) relies on items to be |
121 // inserted backwards. This is counter-intuitive for the API, so rather than | 125 // inserted backwards. This is counter-intuitive for the API, so rather than |
122 // forcing customers to insert things backwards, we return the indices | 126 // forcing customers to insert things backwards, we return the indices |
123 // backwards instead. That's what this method is for. By default, it just | 127 // backwards instead. That's what this method is for. By default, it just |
124 // returns what it's passed. | 128 // returns what it's passed. |
125 virtual int FlipIndex(int index) const; | 129 virtual int FlipIndex(int index) const; |
126 | 130 |
127 Delegate* delegate() { return delegate_; } | 131 Delegate* delegate() { return delegate_; } |
128 | 132 |
129 private: | 133 private: |
130 struct Item; | 134 struct Item; |
131 | 135 |
132 // Functions for inserting items into |items_|. | 136 // Functions for inserting items into |items_|. |
133 void AppendItem(const Item& item); | 137 void AppendItem(const Item& item); |
134 void InsertItemAtIndex(const Item& item, int index); | 138 void InsertItemAtIndex(const Item& item, int index); |
135 void ValidateItem(const Item& item); | 139 void ValidateItem(const Item& item); |
136 | 140 |
137 std::vector<Item> items_; | 141 std::vector<Item> items_; |
138 | 142 |
139 Delegate* delegate_; | 143 Delegate* delegate_; |
140 | 144 |
141 DISALLOW_COPY_AND_ASSIGN(SimpleMenuModel); | 145 DISALLOW_COPY_AND_ASSIGN(SimpleMenuModel); |
142 }; | 146 }; |
143 | 147 |
144 } // namespace ui | 148 } // namespace ui |
145 | 149 |
146 #endif // UI_BASE_MODELS_SIMPLE_MENU_MODEL_H_ | 150 #endif // UI_BASE_MODELS_SIMPLE_MENU_MODEL_H_ |
OLD | NEW |