Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / base / models / button_menu_item_model.h
blob01666fe71556eeaa7996bddf23a46ea1fa4b059b
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
3 // found in the LICENSE file.
5 #ifndef UI_BASE_MODELS_BUTTON_MENU_ITEM_MODEL_H_
6 #define UI_BASE_MODELS_BUTTON_MENU_ITEM_MODEL_H_
8 #include <vector>
10 #include "base/strings/string16.h"
11 #include "ui/base/ui_base_export.h"
13 namespace ui {
15 class Accelerator;
17 // A model representing the rows of buttons that should be inserted in a button
18 // containing menu item.
19 class UI_BASE_EXPORT ButtonMenuItemModel {
20 public:
21 // Types of buttons.
22 enum ButtonType {
23 TYPE_SPACE,
24 TYPE_BUTTON,
25 TYPE_BUTTON_LABEL
28 class UI_BASE_EXPORT Delegate {
29 public:
30 // Some command ids have labels that change over time.
31 virtual bool IsItemForCommandIdDynamic(int command_id) const;
32 virtual base::string16 GetLabelForCommandId(int command_id) const;
34 // Performs the action associated with the specified command id.
35 virtual void ExecuteCommand(int command_id, int event_flags) = 0;
36 virtual bool IsCommandIdEnabled(int command_id) const;
37 virtual bool DoesCommandIdDismissMenu(int command_id) const;
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;
44 protected:
45 virtual ~Delegate() {}
48 ButtonMenuItemModel(int string_id, ButtonMenuItemModel::Delegate* delegate);
49 ~ButtonMenuItemModel();
51 // Adds a button that will emit |command_id|. All buttons created through
52 // this method will have the same size, based on the largest button.
53 void AddGroupItemWithStringId(int command_id, int string_id);
55 // Adds a button that has an icon instead of a label.
56 void AddItemWithImage(int command_id, int icon_idr);
58 // Adds a non-clickable button with a desensitized label that doesn't do
59 // anything. Usually combined with IsItemForCommandIdDynamic() to add
60 // information.
61 void AddButtonLabel(int command_id, int string_id);
63 // Adds a small horizontal space.
64 void AddSpace();
66 // Returns the number of items for iteration.
67 int GetItemCount() const;
69 // Returns what kind of item is at |index|.
70 ButtonType GetTypeAt(int index) const;
72 // Changes a position into a command ID.
73 int GetCommandIdAt(int index) const;
75 // Whether the label for item |index| changes.
76 bool IsItemDynamicAt(int index) const;
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;
82 // Returns the current label value for the button at |index|.
83 base::string16 GetLabelAt(int index) const;
85 // If the button at |index| should have an icon instead, returns true and
86 // sets the IDR |icon|.
87 bool GetIconAt(int index, int* icon) const;
89 // If the button at |index| should have its size equalized along with all
90 // other items that have their PartOfGroup bit set.
91 bool PartOfGroup(int index) const;
93 // Called when the item at the specified index has been activated.
94 void ActivatedAt(int index);
96 // Returns the enabled state of the button at |index|.
97 bool IsEnabledAt(int index) const;
99 // Returns whether clicking on the button at |index| dismisses the menu.
100 bool DismissesMenuAt(int index) const;
102 // Returns the enabled state of the command specified by |command_id|.
103 bool IsCommandIdEnabled(int command_id) const;
105 // Returns whether clicking on |command_id| dismisses the menu.
106 bool DoesCommandIdDismissMenu(int command_id) const;
108 const base::string16& label() const { return item_label_; }
110 private:
111 // The non-clickable label to the left of the buttons.
112 base::string16 item_label_;
114 struct Item;
115 std::vector<Item> items_;
117 Delegate* delegate_;
119 DISALLOW_COPY_AND_ASSIGN(ButtonMenuItemModel);
122 } // namespace ui
124 #endif // UI_BASE_MODELS_BUTTON_MENU_ITEM_MODEL_H_