| 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_BUTTON_MENU_ITEM_MODEL_H_ | 5 #ifndef UI_BASE_MODELS_BUTTON_MENU_ITEM_MODEL_H_ |
| 6 #define UI_BASE_MODELS_BUTTON_MENU_ITEM_MODEL_H_ | 6 #define UI_BASE_MODELS_BUTTON_MENU_ITEM_MODEL_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| 11 #include "ui/base/ui_base_export.h" | 11 #include "ui/base/ui_base_export.h" |
| 12 | 12 |
| 13 namespace ui { | 13 namespace ui { |
| 14 | 14 |
| 15 class Accelerator; |
| 16 |
| 15 // A model representing the rows of buttons that should be inserted in a button | 17 // A model representing the rows of buttons that should be inserted in a button |
| 16 // containing menu item. | 18 // containing menu item. |
| 17 class UI_BASE_EXPORT ButtonMenuItemModel { | 19 class UI_BASE_EXPORT ButtonMenuItemModel { |
| 18 public: | 20 public: |
| 19 // Types of buttons. | 21 // Types of buttons. |
| 20 enum ButtonType { | 22 enum ButtonType { |
| 21 TYPE_SPACE, | 23 TYPE_SPACE, |
| 22 TYPE_BUTTON, | 24 TYPE_BUTTON, |
| 23 TYPE_BUTTON_LABEL | 25 TYPE_BUTTON_LABEL |
| 24 }; | 26 }; |
| 25 | 27 |
| 26 class UI_BASE_EXPORT Delegate { | 28 class UI_BASE_EXPORT Delegate { |
| 27 public: | 29 public: |
| 28 // Some command ids have labels that change over time. | 30 // Some command ids have labels that change over time. |
| 29 virtual bool IsItemForCommandIdDynamic(int command_id) const; | 31 virtual bool IsItemForCommandIdDynamic(int command_id) const; |
| 30 virtual base::string16 GetLabelForCommandId(int command_id) const; | 32 virtual base::string16 GetLabelForCommandId(int command_id) const; |
| 31 | 33 |
| 32 // Performs the action associated with the specified command id. | 34 // Performs the action associated with the specified command id. |
| 33 virtual void ExecuteCommand(int command_id, int event_flags) = 0; | 35 virtual void ExecuteCommand(int command_id, int event_flags) = 0; |
| 34 virtual bool IsCommandIdEnabled(int command_id) const; | 36 virtual bool IsCommandIdEnabled(int command_id) const; |
| 35 virtual bool DoesCommandIdDismissMenu(int command_id) const; | 37 virtual bool DoesCommandIdDismissMenu(int command_id) const; |
| 36 | 38 |
| 39 // Gets the accelerator for the specified command id. Returns true if the |
| 40 // command id has a valid accelerator, false otherwise. |
| 41 virtual bool GetAcceleratorForCommandId(int command_id, |
| 42 ui::Accelerator* accelerator) = 0; |
| 43 |
| 37 protected: | 44 protected: |
| 38 virtual ~Delegate() {} | 45 virtual ~Delegate() {} |
| 39 }; | 46 }; |
| 40 | 47 |
| 41 ButtonMenuItemModel(int string_id, ButtonMenuItemModel::Delegate* delegate); | 48 ButtonMenuItemModel(int string_id, ButtonMenuItemModel::Delegate* delegate); |
| 42 ~ButtonMenuItemModel(); | 49 ~ButtonMenuItemModel(); |
| 43 | 50 |
| 44 // Adds a button that will emit |command_id|. All buttons created through | 51 // Adds a button that will emit |command_id|. All buttons created through |
| 45 // this method will have the same size, based on the largest button. | 52 // this method will have the same size, based on the largest button. |
| 46 void AddGroupItemWithStringId(int command_id, int string_id); | 53 void AddGroupItemWithStringId(int command_id, int string_id); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 61 | 68 |
| 62 // Returns what kind of item is at |index|. | 69 // Returns what kind of item is at |index|. |
| 63 ButtonType GetTypeAt(int index) const; | 70 ButtonType GetTypeAt(int index) const; |
| 64 | 71 |
| 65 // Changes a position into a command ID. | 72 // Changes a position into a command ID. |
| 66 int GetCommandIdAt(int index) const; | 73 int GetCommandIdAt(int index) const; |
| 67 | 74 |
| 68 // Whether the label for item |index| changes. | 75 // Whether the label for item |index| changes. |
| 69 bool IsItemDynamicAt(int index) const; | 76 bool IsItemDynamicAt(int index) const; |
| 70 | 77 |
| 78 // Gets the accelerator information for the specified index, returning true if |
| 79 // there is a shortcut accelerator for the item, false otherwise. |
| 80 bool GetAcceleratorAt(int index, ui::Accelerator* accelerator) const; |
| 81 |
| 71 // Returns the current label value for the button at |index|. | 82 // Returns the current label value for the button at |index|. |
| 72 base::string16 GetLabelAt(int index) const; | 83 base::string16 GetLabelAt(int index) const; |
| 73 | 84 |
| 74 // If the button at |index| should have an icon instead, returns true and | 85 // If the button at |index| should have an icon instead, returns true and |
| 75 // sets the IDR |icon|. | 86 // sets the IDR |icon|. |
| 76 bool GetIconAt(int index, int* icon) const; | 87 bool GetIconAt(int index, int* icon) const; |
| 77 | 88 |
| 78 // If the button at |index| should have its size equalized along with all | 89 // If the button at |index| should have its size equalized along with all |
| 79 // other items that have their PartOfGroup bit set. | 90 // other items that have their PartOfGroup bit set. |
| 80 bool PartOfGroup(int index) const; | 91 bool PartOfGroup(int index) const; |
| 81 | 92 |
| 82 // Called from implementations. | 93 // Called when the item at the specified index has been activated. |
| 83 void ActivatedCommand(int command_id); | 94 void ActivatedAt(int index); |
| 84 | 95 |
| 85 // Returns the enabled state of the button at |index|. | 96 // Returns the enabled state of the button at |index|. |
| 86 bool IsEnabledAt(int index) const; | 97 bool IsEnabledAt(int index) const; |
| 87 | 98 |
| 88 // Returns whether clicking on the button at |index| dismisses the menu. | 99 // Returns whether clicking on the button at |index| dismisses the menu. |
| 89 bool DismissesMenuAt(int index) const; | 100 bool DismissesMenuAt(int index) const; |
| 90 | 101 |
| 91 // Returns the enabled state of the command specified by |command_id|. | 102 // Returns the enabled state of the command specified by |command_id|. |
| 92 bool IsCommandIdEnabled(int command_id) const; | 103 bool IsCommandIdEnabled(int command_id) const; |
| 93 | 104 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 104 std::vector<Item> items_; | 115 std::vector<Item> items_; |
| 105 | 116 |
| 106 Delegate* delegate_; | 117 Delegate* delegate_; |
| 107 | 118 |
| 108 DISALLOW_COPY_AND_ASSIGN(ButtonMenuItemModel); | 119 DISALLOW_COPY_AND_ASSIGN(ButtonMenuItemModel); |
| 109 }; | 120 }; |
| 110 | 121 |
| 111 } // namespace ui | 122 } // namespace ui |
| 112 | 123 |
| 113 #endif // UI_BASE_MODELS_BUTTON_MENU_ITEM_MODEL_H_ | 124 #endif // UI_BASE_MODELS_BUTTON_MENU_ITEM_MODEL_H_ |
| OLD | NEW |