Update V8 to version 4.7.45.
[chromium-blink-merge.git] / ui / base / models / menu_model.h
blob5b461cd3074601a7d47048db1191b93ff0c22312
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
3 // found in the LICENSE file.
5 #ifndef UI_BASE_MODELS_MENU_MODEL_H_
6 #define UI_BASE_MODELS_MENU_MODEL_H_
8 #include "base/strings/string16.h"
9 #include "ui/base/models/menu_model_delegate.h"
10 #include "ui/base/models/menu_separator_types.h"
11 #include "ui/base/ui_base_export.h"
12 #include "ui/gfx/image/image_skia.h"
13 #include "ui/gfx/native_widget_types.h"
15 namespace gfx {
16 class FontList;
17 class Image;
20 namespace ui {
22 class Accelerator;
23 class ButtonMenuItemModel;
25 // An interface implemented by an object that provides the content of a menu.
26 class UI_BASE_EXPORT MenuModel {
27 public:
28 // The type of item.
29 enum ItemType {
30 TYPE_COMMAND,
31 TYPE_CHECK,
32 TYPE_RADIO,
33 TYPE_SEPARATOR,
34 TYPE_BUTTON_ITEM,
35 TYPE_SUBMENU
38 virtual ~MenuModel() {}
40 // Returns true if any of the items within the model have icons. Not all
41 // platforms support icons in menus natively and so this is a hint for
42 // triggering a custom rendering mode.
43 virtual bool HasIcons() const = 0;
45 // Returns the number of items in the menu.
46 virtual int GetItemCount() const = 0;
48 // Returns the type of item at the specified index.
49 virtual ItemType GetTypeAt(int index) const = 0;
51 // Returns the separator type at the specified index.
52 virtual ui::MenuSeparatorType GetSeparatorTypeAt(int index) const = 0;
54 // Returns the command id of the item at the specified index.
55 virtual int GetCommandIdAt(int index) const = 0;
57 // Returns the label of the item at the specified index.
58 virtual base::string16 GetLabelAt(int index) const = 0;
60 // Returns the sublabel of the item at the specified index. The sublabel
61 // is rendered beneath the label and using the font GetLabelFontAt().
62 virtual base::string16 GetSublabelAt(int index) const;
64 // Returns the minor text of the item at the specified index. The minor text
65 // is rendered to the right of the label and using the font GetLabelFontAt().
66 virtual base::string16 GetMinorTextAt(int index) const;
68 // Returns true if the menu item (label/sublabel/icon) at the specified
69 // index can change over the course of the menu's lifetime. If this function
70 // returns true, the label, sublabel and icon of the menu item will be
71 // updated each time the menu is shown.
72 virtual bool IsItemDynamicAt(int index) const = 0;
74 // Returns the font list used for the label at the specified index.
75 // If NULL, then the default font list should be used.
76 virtual const gfx::FontList* GetLabelFontListAt(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 virtual bool GetAcceleratorAt(int index,
81 ui::Accelerator* accelerator) const = 0;
83 // Returns the checked state of the item at the specified index.
84 virtual bool IsItemCheckedAt(int index) const = 0;
86 // Returns the id of the group of radio items that the item at the specified
87 // index belongs to.
88 virtual int GetGroupIdAt(int index) const = 0;
90 // Gets the icon for the item at the specified index, returning true if there
91 // is an icon, false otherwise.
92 virtual bool GetIconAt(int index, gfx::Image* icon) = 0;
94 // Returns the model for a menu item with a line of buttons at |index|.
95 virtual ButtonMenuItemModel* GetButtonMenuItemAt(int index) const = 0;
97 // Returns the enabled state of the item at the specified index.
98 virtual bool IsEnabledAt(int index) const = 0;
100 // Returns true if the menu item is visible.
101 virtual bool IsVisibleAt(int index) const;
103 // Returns the model for the submenu at the specified index.
104 virtual MenuModel* GetSubmenuModelAt(int index) const = 0;
106 // Called when the highlighted menu item changes to the item at the specified
107 // index.
108 virtual void HighlightChangedTo(int index) = 0;
110 // Called when the item at the specified index has been activated.
111 virtual void ActivatedAt(int index) = 0;
113 // Called when the item has been activated with given event flags.
114 // (for the case where the activation involves a navigation).
115 // |event_flags| is a bit mask of ui::EventFlags.
116 virtual void ActivatedAt(int index, int event_flags);
118 // Called when the menu is about to be shown.
119 virtual void MenuWillShow() {}
121 // Called when the menu has been closed.
122 virtual void MenuClosed() {}
124 // Set the MenuModelDelegate. Owned by the caller of this function.
125 virtual void SetMenuModelDelegate(MenuModelDelegate* delegate) = 0;
127 // Gets the MenuModelDelegate.
128 virtual MenuModelDelegate* GetMenuModelDelegate() const = 0;
130 // Retrieves the model and index that contains a specific command id. Returns
131 // true if an item with the specified command id is found. |model| is inout,
132 // and specifies the model to start searching from.
133 static bool GetModelAndIndexForCommandId(int command_id,
134 MenuModel** model,
135 int* index);
138 } // namespace ui
140 #endif // UI_BASE_MODELS_MENU_MODEL_H_