- add sources.
[platform/framework/web/crosswalk.git] / src / ui / base / models / menu_model.h
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.
4
5 #ifndef UI_BASE_MODELS_MENU_MODEL_H_
6 #define UI_BASE_MODELS_MENU_MODEL_H_
7
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_export.h"
12 #include "ui/gfx/image/image_skia.h"
13 #include "ui/gfx/native_widget_types.h"
14
15 namespace gfx {
16 class Font;
17 class Image;
18 }
19
20 namespace ui {
21
22 class Accelerator;
23 class ButtonMenuItemModel;
24
25 // An interface implemented by an object that provides the content of a menu.
26 class UI_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
36   };
37
38   virtual ~MenuModel() {}
39
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;
44
45   // Returns the number of items in the menu.
46   virtual int GetItemCount() const = 0;
47
48   // Returns the type of item at the specified index.
49   virtual ItemType GetTypeAt(int index) const = 0;
50
51   // Returns the separator type at the specified index.
52   virtual ui::MenuSeparatorType GetSeparatorTypeAt(int index) const = 0;
53
54   // Returns the command id of the item at the specified index.
55   virtual int GetCommandIdAt(int index) const = 0;
56
57   // Returns the label of the item at the specified index.
58   virtual base::string16 GetLabelAt(int index) const = 0;
59
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;
63
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;
67
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;
73
74   // Returns the font used for the label at the specified index.
75   // If NULL, then the default font should be used.
76   virtual const gfx::Font* GetLabelFontAt(int index) const;
77
78   // Gets the acclerator 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;
82
83   // Returns the checked state of the item at the specified index.
84   virtual bool IsItemCheckedAt(int index) const = 0;
85
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;
89
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;
93
94   // Returns the model for a menu item with a line of buttons at |index|.
95   virtual ButtonMenuItemModel* GetButtonMenuItemAt(int index) const = 0;
96
97   // Returns the enabled state of the item at the specified index.
98   virtual bool IsEnabledAt(int index) const = 0;
99
100   // Returns true if the menu item is visible.
101   virtual bool IsVisibleAt(int index) const;
102
103   // Returns the model for the submenu at the specified index.
104   virtual MenuModel* GetSubmenuModelAt(int index) const = 0;
105
106   // Called when the highlighted menu item changes to the item at the specified
107   // index.
108   virtual void HighlightChangedTo(int index) = 0;
109
110   // Called when the item at the specified index has been activated.
111   virtual void ActivatedAt(int index) = 0;
112
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);
117
118   // Called when the menu is about to be shown.
119   virtual void MenuWillShow() {}
120
121   // Called when the menu has been closed.
122   virtual void MenuClosed() {}
123
124   // Set the MenuModelDelegate. Owned by the caller of this function.
125   virtual void SetMenuModelDelegate(MenuModelDelegate* delegate) = 0;
126
127   // Gets the MenuModelDelegate.
128   virtual MenuModelDelegate* GetMenuModelDelegate() const = 0;
129
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);
136 };
137
138 }  // namespace ui
139
140 #endif  // UI_BASE_MODELS_MENU_MODEL_H_