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 |
11 #include "base/string16.h" | 11 #include "base/string16.h" |
12 #include "app/menus/menu_model.h" | 12 #include "app/menus/menu_model.h" |
13 | 13 |
14 namespace menus { | 14 namespace menus { |
15 | 15 |
16 class ButtonMenuItemModel; | 16 class ButtonMenuItemModel; |
17 | 17 |
18 // A simple MenuModel implementation with an imperative API for adding menu | 18 // A simple MenuModel implementation with an imperative API for adding menu |
19 // items. This makes it easy to construct fixed menus. Menus populated by | 19 // items. This makes it easy to construct fixed menus. Menus populated by |
20 // dynamic data sources may be better off implementing MenuModel directly. | 20 // dynamic data sources may be better off implementing MenuModel directly. |
21 // The breadth of MenuModel is not exposed through this API. | 21 // The breadth of MenuModel is not exposed through this API. |
22 class SimpleMenuModel : public MenuModel { | 22 class SimpleMenuModel : public MenuModel { |
23 public: | 23 public: |
24 class Delegate { | 24 class Delegate { |
25 public: | 25 public: |
26 // Methods for determining the state of specific command ids. | 26 // Methods for determining the state of specific command ids. |
27 virtual bool IsCommandIdChecked(int command_id) const = 0; | 27 virtual bool IsCommandIdChecked(int command_id) const = 0; |
28 virtual bool IsCommandIdEnabled(int command_id) const = 0; | 28 virtual bool IsCommandIdEnabled(int command_id) const = 0; |
| 29 virtual bool IsCommandIdVisible(int command_id) const; |
29 | 30 |
30 // Gets the accelerator for the specified command id. Returns true if the | 31 // Gets the accelerator for the specified command id. Returns true if the |
31 // command id has a valid accelerator, false otherwise. | 32 // command id has a valid accelerator, false otherwise. |
32 virtual bool GetAcceleratorForCommandId( | 33 virtual bool GetAcceleratorForCommandId( |
33 int command_id, | 34 int command_id, |
34 menus::Accelerator* accelerator) = 0; | 35 menus::Accelerator* accelerator) = 0; |
35 | 36 |
36 // Some command ids have labels that change over time. | 37 // Some command ids have labels that change over time. |
37 virtual bool IsLabelForCommandIdDynamic(int command_id) const; | 38 virtual bool IsLabelForCommandIdDynamic(int command_id) const; |
38 virtual string16 GetLabelForCommandId(int command_id) const; | 39 virtual string16 GetLabelForCommandId(int command_id) const; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 virtual int GetCommandIdAt(int index) const; | 101 virtual int GetCommandIdAt(int index) const; |
101 virtual string16 GetLabelAt(int index) const; | 102 virtual string16 GetLabelAt(int index) const; |
102 virtual bool IsLabelDynamicAt(int index) const; | 103 virtual bool IsLabelDynamicAt(int index) const; |
103 virtual bool GetAcceleratorAt(int index, | 104 virtual bool GetAcceleratorAt(int index, |
104 menus::Accelerator* accelerator) const; | 105 menus::Accelerator* accelerator) const; |
105 virtual bool IsItemCheckedAt(int index) const; | 106 virtual bool IsItemCheckedAt(int index) const; |
106 virtual int GetGroupIdAt(int index) const; | 107 virtual int GetGroupIdAt(int index) const; |
107 virtual bool GetIconAt(int index, SkBitmap* icon) const; | 108 virtual bool GetIconAt(int index, SkBitmap* icon) const; |
108 virtual menus::ButtonMenuItemModel* GetButtonMenuItemAt(int index) const; | 109 virtual menus::ButtonMenuItemModel* GetButtonMenuItemAt(int index) const; |
109 virtual bool IsEnabledAt(int index) const; | 110 virtual bool IsEnabledAt(int index) const; |
| 111 virtual bool IsVisibleAt(int index) const; |
110 virtual void HighlightChangedTo(int index); | 112 virtual void HighlightChangedTo(int index); |
111 virtual void ActivatedAt(int index); | 113 virtual void ActivatedAt(int index); |
112 virtual MenuModel* GetSubmenuModelAt(int index) const; | 114 virtual MenuModel* GetSubmenuModelAt(int index) const; |
113 | 115 |
114 protected: | 116 protected: |
115 // Some variants of this model (SystemMenuModel) relies on items to be | 117 // Some variants of this model (SystemMenuModel) relies on items to be |
116 // inserted backwards. This is counter-intuitive for the API, so rather than | 118 // inserted backwards. This is counter-intuitive for the API, so rather than |
117 // forcing customers to insert things backwards, we return the indices | 119 // forcing customers to insert things backwards, we return the indices |
118 // backwards instead. That's what this method is for. By default, it just | 120 // backwards instead. That's what this method is for. By default, it just |
119 // returns what it's passed. | 121 // returns what it's passed. |
120 virtual int FlipIndex(int index) const { return index; } | 122 virtual int FlipIndex(int index) const; |
121 | 123 |
122 Delegate* delegate() { return delegate_; } | 124 Delegate* delegate() { return delegate_; } |
123 | 125 |
124 private: | 126 private: |
125 struct Item; | 127 struct Item; |
126 std::vector<Item> items_; | 128 std::vector<Item> items_; |
127 | 129 |
128 // Functions for inserting items into |items_|. | 130 // Functions for inserting items into |items_|. |
129 void AppendItem(const Item& item); | 131 void AppendItem(const Item& item); |
130 void InsertItemAtIndex(const Item& item, int index); | 132 void InsertItemAtIndex(const Item& item, int index); |
131 void ValidateItem(const Item& item); | 133 void ValidateItem(const Item& item); |
132 | 134 |
133 Delegate* delegate_; | 135 Delegate* delegate_; |
134 | 136 |
135 DISALLOW_COPY_AND_ASSIGN(SimpleMenuModel); | 137 DISALLOW_COPY_AND_ASSIGN(SimpleMenuModel); |
136 }; | 138 }; |
137 | 139 |
138 } // namespace menus | 140 } // namespace menus |
139 | 141 |
140 #endif // APP_MENUS_SIMPLE_MENU_MODEL_H_ | 142 #endif // APP_MENUS_SIMPLE_MENU_MODEL_H_ |
OLD | NEW |