OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 APP_MENUS_SIMPLE_MENU_MODEL_H_ | 5 #ifndef APP_MENUS_SIMPLE_MENU_MODEL_H_ |
6 #define APP_MENUS_SIMPLE_MENU_MODEL_H_ | 6 #define APP_MENUS_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 menus::Accelerator* accelerator) const; | 111 menus::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 menus::ButtonMenuItemModel* GetButtonMenuItemAt(int index) const; | 115 virtual menus::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 std::vector<Item> items_; | 135 std::vector<Item> items_; |
132 | 136 |
133 // Functions for inserting items into |items_|. | 137 // Functions for inserting items into |items_|. |
134 void AppendItem(const Item& item); | 138 void AppendItem(const Item& item); |
135 void InsertItemAtIndex(const Item& item, int index); | 139 void InsertItemAtIndex(const Item& item, int index); |
136 void ValidateItem(const Item& item); | 140 void ValidateItem(const Item& item); |
137 | 141 |
138 Delegate* delegate_; | 142 Delegate* delegate_; |
139 | 143 |
140 DISALLOW_COPY_AND_ASSIGN(SimpleMenuModel); | 144 DISALLOW_COPY_AND_ASSIGN(SimpleMenuModel); |
141 }; | 145 }; |
142 | 146 |
143 } // namespace menus | 147 } // namespace menus |
144 | 148 |
145 #endif // APP_MENUS_SIMPLE_MENU_MODEL_H_ | 149 #endif // APP_MENUS_SIMPLE_MENU_MODEL_H_ |
OLD | NEW |