| 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 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 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "base/string16.h" | 11 #include "base/string16.h" |
| 12 #include "ui/base/models/menu_model.h" | 12 #include "ui/base/models/menu_model.h" |
| 13 | 13 |
| 14 namespace gfx { | 14 namespace gfx { |
| 15 class ImageSkia; | 15 class Image; |
| 16 } | 16 } |
| 17 | 17 |
| 18 namespace ui { | 18 namespace ui { |
| 19 | 19 |
| 20 class ButtonMenuItemModel; | 20 class ButtonMenuItemModel; |
| 21 | 21 |
| 22 // A simple MenuModel implementation with an imperative API for adding menu | 22 // A simple MenuModel implementation with an imperative API for adding menu |
| 23 // items. This makes it easy to construct fixed menus. Menus populated by | 23 // items. This makes it easy to construct fixed menus. Menus populated by |
| 24 // dynamic data sources may be better off implementing MenuModel directly. | 24 // dynamic data sources may be better off implementing MenuModel directly. |
| 25 // The breadth of MenuModel is not exposed through this API. | 25 // The breadth of MenuModel is not exposed through this API. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 37 virtual bool GetAcceleratorForCommandId( | 37 virtual bool GetAcceleratorForCommandId( |
| 38 int command_id, | 38 int command_id, |
| 39 ui::Accelerator* accelerator) = 0; | 39 ui::Accelerator* accelerator) = 0; |
| 40 | 40 |
| 41 // Some command ids have labels and icons that change over time. | 41 // Some command ids have labels and icons that change over time. |
| 42 virtual bool IsItemForCommandIdDynamic(int command_id) const; | 42 virtual bool IsItemForCommandIdDynamic(int command_id) const; |
| 43 virtual string16 GetLabelForCommandId(int command_id) const; | 43 virtual string16 GetLabelForCommandId(int command_id) const; |
| 44 // Gets the icon for the item with the specified id, returning true if there | 44 // Gets the icon for the item with the specified id, returning true if there |
| 45 // is an icon, false otherwise. | 45 // is an icon, false otherwise. |
| 46 virtual bool GetIconForCommandId(int command_id, | 46 virtual bool GetIconForCommandId(int command_id, |
| 47 gfx::ImageSkia* icon) const; | 47 gfx::Image* icon) const; |
| 48 | 48 |
| 49 // Notifies the delegate that the item with the specified command id was | 49 // Notifies the delegate that the item with the specified command id was |
| 50 // visually highlighted within the menu. | 50 // visually highlighted within the menu. |
| 51 virtual void CommandIdHighlighted(int command_id); | 51 virtual void CommandIdHighlighted(int command_id); |
| 52 | 52 |
| 53 // Performs the action associated with the specified command id. | 53 // Performs the action associated with the specified command id. |
| 54 virtual void ExecuteCommand(int command_id) = 0; | 54 virtual void ExecuteCommand(int command_id) = 0; |
| 55 // Performs the action associates with the specified command id | 55 // Performs the action associates with the specified command id |
| 56 // with |event_flags|. | 56 // with |event_flags|. |
| 57 virtual void ExecuteCommand(int command_id, int event_flags); | 57 virtual void ExecuteCommand(int command_id, int event_flags); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 void InsertRadioItemAt( | 95 void InsertRadioItemAt( |
| 96 int index, int command_id, const string16& label, int group_id); | 96 int index, int command_id, const string16& label, int group_id); |
| 97 void InsertRadioItemWithStringIdAt( | 97 void InsertRadioItemWithStringIdAt( |
| 98 int index, int command_id, int string_id, int group_id); | 98 int index, int command_id, int string_id, int group_id); |
| 99 void InsertSubMenuAt( | 99 void InsertSubMenuAt( |
| 100 int index, int command_id, const string16& label, MenuModel* model); | 100 int index, int command_id, const string16& label, MenuModel* model); |
| 101 void InsertSubMenuWithStringIdAt( | 101 void InsertSubMenuWithStringIdAt( |
| 102 int index, int command_id, int string_id, MenuModel* model); | 102 int index, int command_id, int string_id, MenuModel* model); |
| 103 | 103 |
| 104 // Sets the icon for the item at |index|. | 104 // Sets the icon for the item at |index|. |
| 105 void SetIcon(int index, const gfx::ImageSkia& icon); | 105 void SetIcon(int index, const gfx::Image& icon); |
| 106 | 106 |
| 107 // Clears all items. Note that it does not free MenuModel of submenu. | 107 // Clears all items. Note that it does not free MenuModel of submenu. |
| 108 void Clear(); | 108 void Clear(); |
| 109 | 109 |
| 110 // Returns the index of the item that has the given |command_id|. Returns | 110 // Returns the index of the item that has the given |command_id|. Returns |
| 111 // -1 if not found. | 111 // -1 if not found. |
| 112 int GetIndexOfCommandId(int command_id); | 112 int GetIndexOfCommandId(int command_id); |
| 113 | 113 |
| 114 // Overridden from MenuModel: | 114 // Overridden from MenuModel: |
| 115 virtual bool HasIcons() const OVERRIDE; | 115 virtual bool HasIcons() const OVERRIDE; |
| 116 virtual int GetItemCount() const OVERRIDE; | 116 virtual int GetItemCount() const OVERRIDE; |
| 117 virtual ItemType GetTypeAt(int index) const OVERRIDE; | 117 virtual ItemType GetTypeAt(int index) const OVERRIDE; |
| 118 virtual int GetCommandIdAt(int index) const OVERRIDE; | 118 virtual int GetCommandIdAt(int index) const OVERRIDE; |
| 119 virtual string16 GetLabelAt(int index) const OVERRIDE; | 119 virtual string16 GetLabelAt(int index) const OVERRIDE; |
| 120 virtual bool IsItemDynamicAt(int index) const OVERRIDE; | 120 virtual bool IsItemDynamicAt(int index) const OVERRIDE; |
| 121 virtual bool GetAcceleratorAt(int index, | 121 virtual bool GetAcceleratorAt(int index, |
| 122 ui::Accelerator* accelerator) const OVERRIDE; | 122 ui::Accelerator* accelerator) const OVERRIDE; |
| 123 virtual bool IsItemCheckedAt(int index) const OVERRIDE; | 123 virtual bool IsItemCheckedAt(int index) const OVERRIDE; |
| 124 virtual int GetGroupIdAt(int index) const OVERRIDE; | 124 virtual int GetGroupIdAt(int index) const OVERRIDE; |
| 125 virtual bool GetIconAt(int index, gfx::ImageSkia* icon) OVERRIDE; | 125 virtual bool GetIconAt(int index, gfx::Image* icon) OVERRIDE; |
| 126 virtual ui::ButtonMenuItemModel* GetButtonMenuItemAt( | 126 virtual ui::ButtonMenuItemModel* GetButtonMenuItemAt( |
| 127 int index) const OVERRIDE; | 127 int index) const OVERRIDE; |
| 128 virtual bool IsEnabledAt(int index) const OVERRIDE; | 128 virtual bool IsEnabledAt(int index) const OVERRIDE; |
| 129 virtual bool IsVisibleAt(int index) const OVERRIDE; | 129 virtual bool IsVisibleAt(int index) const OVERRIDE; |
| 130 virtual void HighlightChangedTo(int index) OVERRIDE; | 130 virtual void HighlightChangedTo(int index) OVERRIDE; |
| 131 virtual void ActivatedAt(int index) OVERRIDE; | 131 virtual void ActivatedAt(int index) OVERRIDE; |
| 132 virtual void ActivatedAt(int index, int event_flags) OVERRIDE; | 132 virtual void ActivatedAt(int index, int event_flags) OVERRIDE; |
| 133 virtual MenuModel* GetSubmenuModelAt(int index) const OVERRIDE; | 133 virtual MenuModel* GetSubmenuModelAt(int index) const OVERRIDE; |
| 134 virtual void MenuWillShow() OVERRIDE; | 134 virtual void MenuWillShow() OVERRIDE; |
| 135 virtual void MenuClosed() OVERRIDE; | 135 virtual void MenuClosed() OVERRIDE; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 MenuModelDelegate* menu_model_delegate_; | 172 MenuModelDelegate* menu_model_delegate_; |
| 173 | 173 |
| 174 base::WeakPtrFactory<SimpleMenuModel> method_factory_; | 174 base::WeakPtrFactory<SimpleMenuModel> method_factory_; |
| 175 | 175 |
| 176 DISALLOW_COPY_AND_ASSIGN(SimpleMenuModel); | 176 DISALLOW_COPY_AND_ASSIGN(SimpleMenuModel); |
| 177 }; | 177 }; |
| 178 | 178 |
| 179 } // namespace ui | 179 } // namespace ui |
| 180 | 180 |
| 181 #endif // UI_BASE_MODELS_SIMPLE_MENU_MODEL_H_ | 181 #endif // UI_BASE_MODELS_SIMPLE_MENU_MODEL_H_ |
| OLD | NEW |