| 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 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/string16.h" | 10 #include "base/string16.h" |
| 11 #include "app/menus/button_menu_item_model.h" |
| 11 #include "app/menus/menu_model.h" | 12 #include "app/menus/menu_model.h" |
| 12 #include "third_party/skia/include/core/SkBitmap.h" | 13 #include "third_party/skia/include/core/SkBitmap.h" |
| 13 | 14 |
| 14 namespace menus { | 15 namespace menus { |
| 15 | 16 |
| 16 // A simple MenuModel implementation with an imperative API for adding menu | 17 // A simple MenuModel implementation with an imperative API for adding menu |
| 17 // items. This makes it easy to construct fixed menus. Menus populated by | 18 // items. This makes it easy to construct fixed menus. Menus populated by |
| 18 // dynamic data sources may be better off implementing MenuModel directly. | 19 // dynamic data sources may be better off implementing MenuModel directly. |
| 19 // The breadth of MenuModel is not exposed through this API. | 20 // The breadth of MenuModel is not exposed through this API. |
| 20 class SimpleMenuModel : public MenuModel { | 21 class SimpleMenuModel : public MenuModel { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 virtual ~SimpleMenuModel(); | 54 virtual ~SimpleMenuModel(); |
| 54 | 55 |
| 55 // Methods for adding items to the model. | 56 // Methods for adding items to the model. |
| 56 void AddItem(int command_id, const string16& label); | 57 void AddItem(int command_id, const string16& label); |
| 57 void AddItemWithStringId(int command_id, int string_id); | 58 void AddItemWithStringId(int command_id, int string_id); |
| 58 void AddSeparator(); | 59 void AddSeparator(); |
| 59 void AddCheckItem(int command_id, const string16& label); | 60 void AddCheckItem(int command_id, const string16& label); |
| 60 void AddCheckItemWithStringId(int command_id, int string_id); | 61 void AddCheckItemWithStringId(int command_id, int string_id); |
| 61 void AddRadioItem(int command_id, const string16& label, int group_id); | 62 void AddRadioItem(int command_id, const string16& label, int group_id); |
| 62 void AddRadioItemWithStringId(int command_id, int string_id, int group_id); | 63 void AddRadioItemWithStringId(int command_id, int string_id, int group_id); |
| 64 |
| 65 // These three methods take pointers to various sub-models. These models |
| 66 // should be owned by the same owner of this SimpleMenuModel. |
| 67 void AddButtonItem(int command_id, ButtonMenuItemModel* model); |
| 63 void AddSubMenu(int command_id, const string16& label, MenuModel* model); | 68 void AddSubMenu(int command_id, const string16& label, MenuModel* model); |
| 64 void AddSubMenuWithStringId(int command_id, int string_id, MenuModel* model); | 69 void AddSubMenuWithStringId(int command_id, int string_id, MenuModel* model); |
| 65 | 70 |
| 66 // Methods for inserting items into the model. | 71 // Methods for inserting items into the model. |
| 67 void InsertItemAt(int index, int command_id, const string16& label); | 72 void InsertItemAt(int index, int command_id, const string16& label); |
| 68 void InsertItemWithStringIdAt(int index, int command_id, int string_id); | 73 void InsertItemWithStringIdAt(int index, int command_id, int string_id); |
| 69 void InsertSeparatorAt(int index); | 74 void InsertSeparatorAt(int index); |
| 70 void InsertCheckItemAt(int index, int command_id, const string16& label); | 75 void InsertCheckItemAt(int index, int command_id, const string16& label); |
| 71 void InsertCheckItemWithStringIdAt(int index, int command_id, int string_id); | 76 void InsertCheckItemWithStringIdAt(int index, int command_id, int string_id); |
| 72 void InsertRadioItemAt( | 77 void InsertRadioItemAt( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 95 virtual int GetItemCount() const; | 100 virtual int GetItemCount() const; |
| 96 virtual ItemType GetTypeAt(int index) const; | 101 virtual ItemType GetTypeAt(int index) const; |
| 97 virtual int GetCommandIdAt(int index) const; | 102 virtual int GetCommandIdAt(int index) const; |
| 98 virtual string16 GetLabelAt(int index) const; | 103 virtual string16 GetLabelAt(int index) const; |
| 99 virtual bool IsLabelDynamicAt(int index) const; | 104 virtual bool IsLabelDynamicAt(int index) const; |
| 100 virtual bool GetAcceleratorAt(int index, | 105 virtual bool GetAcceleratorAt(int index, |
| 101 menus::Accelerator* accelerator) const; | 106 menus::Accelerator* accelerator) const; |
| 102 virtual bool IsItemCheckedAt(int index) const; | 107 virtual bool IsItemCheckedAt(int index) const; |
| 103 virtual int GetGroupIdAt(int index) const; | 108 virtual int GetGroupIdAt(int index) const; |
| 104 virtual bool GetIconAt(int index, SkBitmap* icon) const; | 109 virtual bool GetIconAt(int index, SkBitmap* icon) const; |
| 110 virtual menus::ButtonMenuItemModel* GetButtonMenuItemAt(int index) const; |
| 105 virtual bool IsEnabledAt(int index) const; | 111 virtual bool IsEnabledAt(int index) const; |
| 106 virtual void HighlightChangedTo(int index); | 112 virtual void HighlightChangedTo(int index); |
| 107 virtual void ActivatedAt(int index); | 113 virtual void ActivatedAt(int index); |
| 108 virtual MenuModel* GetSubmenuModelAt(int index) const; | 114 virtual MenuModel* GetSubmenuModelAt(int index) const; |
| 109 | 115 |
| 110 protected: | 116 protected: |
| 111 // Some variants of this model (SystemMenuModel) relies on items to be | 117 // Some variants of this model (SystemMenuModel) relies on items to be |
| 112 // 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 |
| 113 // forcing customers to insert things backwards, we return the indices | 119 // forcing customers to insert things backwards, we return the indices |
| 114 // 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 |
| 115 // returns what it's passed. | 121 // returns what it's passed. |
| 116 virtual int FlipIndex(int index) const { return index; } | 122 virtual int FlipIndex(int index) const { return index; } |
| 117 | 123 |
| 118 Delegate* delegate() { return delegate_; } | 124 Delegate* delegate() { return delegate_; } |
| 119 | 125 |
| 120 private: | 126 private: |
| 121 struct Item { | 127 struct Item { |
| 122 int command_id; | 128 int command_id; |
| 123 string16 label; | 129 string16 label; |
| 124 SkBitmap icon; | 130 SkBitmap icon; |
| 125 ItemType type; | 131 ItemType type; |
| 126 int group_id; | 132 int group_id; |
| 127 MenuModel* submenu; | 133 MenuModel* submenu; |
| 134 ButtonMenuItemModel* button_model; |
| 128 }; | 135 }; |
| 129 std::vector<Item> items_; | 136 std::vector<Item> items_; |
| 130 | 137 |
| 131 // Functions for inserting items into |items_|. | 138 // Functions for inserting items into |items_|. |
| 132 void AppendItem(const Item& item); | 139 void AppendItem(const Item& item); |
| 133 void InsertItemAtIndex(const Item& item, int index); | 140 void InsertItemAtIndex(const Item& item, int index); |
| 134 void ValidateItem(const Item& item); | 141 void ValidateItem(const Item& item); |
| 135 | 142 |
| 136 Delegate* delegate_; | 143 Delegate* delegate_; |
| 137 | 144 |
| 138 DISALLOW_COPY_AND_ASSIGN(SimpleMenuModel); | 145 DISALLOW_COPY_AND_ASSIGN(SimpleMenuModel); |
| 139 }; | 146 }; |
| 140 | 147 |
| 141 } // namespace menus | 148 } // namespace menus |
| 142 | 149 |
| 143 #endif // APP_MENUS_SIMPLE_MENU_MODEL_H_ | 150 #endif // APP_MENUS_SIMPLE_MENU_MODEL_H_ |
| OLD | NEW |