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/compiler_specific.h" |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
11 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
| 13 #include "ui/base/accelerators/accelerator.h" |
12 #include "ui/base/ui_base_export.h" | 14 #include "ui/base/ui_base_export.h" |
13 | 15 |
14 namespace ui { | 16 namespace ui { |
15 | 17 |
16 class Accelerator; | |
17 | |
18 // A model representing the rows of buttons that should be inserted in a button | 18 // A model representing the rows of buttons that should be inserted in a button |
19 // containing menu item. | 19 // containing menu item. |
20 class UI_BASE_EXPORT ButtonMenuItemModel { | 20 class UI_BASE_EXPORT ButtonMenuItemModel { |
21 public: | 21 public: |
22 // Types of buttons. | 22 // Types of buttons. |
23 enum ButtonType { | 23 enum ButtonType { |
24 TYPE_SPACE, | 24 TYPE_SPACE, |
25 TYPE_BUTTON, | 25 TYPE_BUTTON, |
26 TYPE_BUTTON_LABEL | 26 TYPE_BUTTON_LABEL |
27 }; | 27 }; |
28 | 28 |
29 class UI_BASE_EXPORT Delegate { | 29 class UI_BASE_EXPORT Delegate |
| 30 : NON_EXPORTED_BASE(public AcceleratorProvider) { |
30 public: | 31 public: |
31 // Some command ids have labels that change over time. | 32 // Some command ids have labels that change over time. |
32 virtual bool IsItemForCommandIdDynamic(int command_id) const; | 33 virtual bool IsItemForCommandIdDynamic(int command_id) const; |
33 virtual base::string16 GetLabelForCommandId(int command_id) const; | 34 virtual base::string16 GetLabelForCommandId(int command_id) const; |
34 | 35 |
35 // Performs the action associated with the specified command id. | 36 // Performs the action associated with the specified command id. |
36 virtual void ExecuteCommand(int command_id, int event_flags) = 0; | 37 virtual void ExecuteCommand(int command_id, int event_flags) = 0; |
37 virtual bool IsCommandIdEnabled(int command_id) const; | 38 virtual bool IsCommandIdEnabled(int command_id) const; |
38 virtual bool DoesCommandIdDismissMenu(int command_id) const; | 39 virtual bool DoesCommandIdDismissMenu(int command_id) const; |
39 | 40 |
40 // Gets the accelerator for the specified command id. Returns true if the | 41 // AcceleratorProvider overrides: |
41 // command id has a valid accelerator, false otherwise. By default, returns | 42 // By default, returns false for all commands. Can be further overridden. |
42 // false for all commands. | 43 bool GetAcceleratorForCommandId( |
43 virtual bool GetAcceleratorForCommandId(int command_id, | 44 int command_id, |
44 ui::Accelerator* accelerator) const; | 45 ui::Accelerator* accelerator) const override; |
45 | 46 |
46 protected: | 47 protected: |
47 virtual ~Delegate() {} | 48 ~Delegate() override {} |
48 }; | 49 }; |
49 | 50 |
50 ButtonMenuItemModel(int string_id, ButtonMenuItemModel::Delegate* delegate); | 51 ButtonMenuItemModel(int string_id, ButtonMenuItemModel::Delegate* delegate); |
51 ~ButtonMenuItemModel(); | 52 ~ButtonMenuItemModel(); |
52 | 53 |
53 // Adds a button that will emit |command_id|. All buttons created through | 54 // Adds a button that will emit |command_id|. All buttons created through |
54 // this method will have the same size, based on the largest button. | 55 // this method will have the same size, based on the largest button. |
55 void AddGroupItemWithStringId(int command_id, int string_id); | 56 void AddGroupItemWithStringId(int command_id, int string_id); |
56 | 57 |
57 // Adds a button that has an icon instead of a label. | 58 // Adds a button that has an icon instead of a label. |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 std::vector<Item> items_; | 118 std::vector<Item> items_; |
118 | 119 |
119 Delegate* delegate_; | 120 Delegate* delegate_; |
120 | 121 |
121 DISALLOW_COPY_AND_ASSIGN(ButtonMenuItemModel); | 122 DISALLOW_COPY_AND_ASSIGN(ButtonMenuItemModel); |
122 }; | 123 }; |
123 | 124 |
124 } // namespace ui | 125 } // namespace ui |
125 | 126 |
126 #endif // UI_BASE_MODELS_BUTTON_MENU_ITEM_MODEL_H_ | 127 #endif // UI_BASE_MODELS_BUTTON_MENU_ITEM_MODEL_H_ |
OLD | NEW |