Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Side by Side Diff: ui/base/models/simple_menu_model.h

Issue 2138353002: SimpleMenuModel and ButtonMenuItemModel implement AcceleratorProvider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@menumodel-accelerator-default
Patch Set: Fix compile on Windows. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/base/models/button_menu_item_model.h ('k') | ui/base/models/simple_menu_model.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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_SIMPLE_MENU_MODEL_H_ 5 #ifndef UI_BASE_MODELS_SIMPLE_MENU_MODEL_H_
6 #define UI_BASE_MODELS_SIMPLE_MENU_MODEL_H_ 6 #define UI_BASE_MODELS_SIMPLE_MENU_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/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
12 #include "base/strings/string16.h" 13 #include "base/strings/string16.h"
14 #include "ui/base/accelerators/accelerator.h"
13 #include "ui/base/models/menu_model.h" 15 #include "ui/base/models/menu_model.h"
14 16
15 namespace gfx { 17 namespace gfx {
16 class Image; 18 class Image;
17 } 19 }
18 20
19 namespace ui { 21 namespace ui {
20 22
21 class ButtonMenuItemModel; 23 class ButtonMenuItemModel;
22 24
23 // A simple MenuModel implementation with an imperative API for adding menu 25 // A simple MenuModel implementation with an imperative API for adding menu
24 // items. This makes it easy to construct fixed menus. Menus populated by 26 // items. This makes it easy to construct fixed menus. Menus populated by
25 // dynamic data sources may be better off implementing MenuModel directly. 27 // dynamic data sources may be better off implementing MenuModel directly.
26 // The breadth of MenuModel is not exposed through this API. 28 // The breadth of MenuModel is not exposed through this API.
27 class UI_BASE_EXPORT SimpleMenuModel : public MenuModel { 29 class UI_BASE_EXPORT SimpleMenuModel : public MenuModel {
28 public: 30 public:
29 class UI_BASE_EXPORT Delegate { 31 class UI_BASE_EXPORT Delegate
32 : NON_EXPORTED_BASE(public AcceleratorProvider) {
30 public: 33 public:
31 virtual ~Delegate() {} 34 ~Delegate() override {}
32 35
33 // Methods for determining the state of specific command ids. 36 // Methods for determining the state of specific command ids.
34 virtual bool IsCommandIdChecked(int command_id) const = 0; 37 virtual bool IsCommandIdChecked(int command_id) const = 0;
35 virtual bool IsCommandIdEnabled(int command_id) const = 0; 38 virtual bool IsCommandIdEnabled(int command_id) const = 0;
36 virtual bool IsCommandIdVisible(int command_id) const; 39 virtual bool IsCommandIdVisible(int command_id) const;
37 40
38 // Gets the accelerator for the specified command id. Returns true if the
39 // command id has a valid accelerator, false otherwise. By default, returns
40 // false for all commands.
41 virtual bool GetAcceleratorForCommandId(int command_id,
42 ui::Accelerator* accelerator) const;
43
44 // Some command ids have labels, sublabels, minor text and icons that change 41 // Some command ids have labels, sublabels, minor text and icons that change
45 // over time. 42 // over time.
46 virtual bool IsItemForCommandIdDynamic(int command_id) const; 43 virtual bool IsItemForCommandIdDynamic(int command_id) const;
47 virtual base::string16 GetLabelForCommandId(int command_id) const; 44 virtual base::string16 GetLabelForCommandId(int command_id) const;
48 virtual base::string16 GetSublabelForCommandId(int command_id) const; 45 virtual base::string16 GetSublabelForCommandId(int command_id) const;
49 virtual base::string16 GetMinorTextForCommandId(int command_id) const; 46 virtual base::string16 GetMinorTextForCommandId(int command_id) const;
50 // Gets the icon for the item with the specified id, returning true if there 47 // Gets the icon for the item with the specified id, returning true if there
51 // is an icon, false otherwise. 48 // is an icon, false otherwise.
52 virtual bool GetIconForCommandId(int command_id, 49 virtual bool GetIconForCommandId(int command_id,
53 gfx::Image* icon) const; 50 gfx::Image* icon) const;
54 51
55 // Notifies the delegate that the item with the specified command id was 52 // Notifies the delegate that the item with the specified command id was
56 // visually highlighted within the menu. 53 // visually highlighted within the menu.
57 virtual void CommandIdHighlighted(int command_id); 54 virtual void CommandIdHighlighted(int command_id);
58 55
59 // Performs the action associates with the specified command id. 56 // Performs the action associates with the specified command id.
60 // The passed |event_flags| are the flags from the event which issued this 57 // The passed |event_flags| are the flags from the event which issued this
61 // command and they can be examined to find modifier keys. 58 // command and they can be examined to find modifier keys.
62 virtual void ExecuteCommand(int command_id, int event_flags) = 0; 59 virtual void ExecuteCommand(int command_id, int event_flags) = 0;
63 60
64 // Notifies the delegate that the menu is about to show. 61 // Notifies the delegate that the menu is about to show.
65 virtual void MenuWillShow(SimpleMenuModel* source); 62 virtual void MenuWillShow(SimpleMenuModel* source);
66 63
67 // Notifies the delegate that the menu has closed. 64 // Notifies the delegate that the menu has closed.
68 virtual void MenuClosed(SimpleMenuModel* source); 65 virtual void MenuClosed(SimpleMenuModel* source);
66
67 // AcceleratorProvider overrides:
68 // By default, returns false for all commands. Can be further overridden.
69 bool GetAcceleratorForCommandId(
70 int command_id,
71 ui::Accelerator* accelerator) const override;
69 }; 72 };
70 73
71 // The Delegate can be NULL, though if it is items can't be checked or 74 // The Delegate can be NULL, though if it is items can't be checked or
72 // disabled. 75 // disabled.
73 explicit SimpleMenuModel(Delegate* delegate); 76 explicit SimpleMenuModel(Delegate* delegate);
74 ~SimpleMenuModel() override; 77 ~SimpleMenuModel() override;
75 78
76 // Methods for adding items to the model. 79 // Methods for adding items to the model.
77 void AddItem(int command_id, const base::string16& label); 80 void AddItem(int command_id, const base::string16& label);
78 void AddItemWithStringId(int command_id, int string_id); 81 void AddItemWithStringId(int command_id, int string_id);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 MenuModelDelegate* menu_model_delegate_; 197 MenuModelDelegate* menu_model_delegate_;
195 198
196 base::WeakPtrFactory<SimpleMenuModel> method_factory_; 199 base::WeakPtrFactory<SimpleMenuModel> method_factory_;
197 200
198 DISALLOW_COPY_AND_ASSIGN(SimpleMenuModel); 201 DISALLOW_COPY_AND_ASSIGN(SimpleMenuModel);
199 }; 202 };
200 203
201 } // namespace ui 204 } // namespace ui
202 205
203 #endif // UI_BASE_MODELS_SIMPLE_MENU_MODEL_H_ 206 #endif // UI_BASE_MODELS_SIMPLE_MENU_MODEL_H_
OLDNEW
« no previous file with comments | « ui/base/models/button_menu_item_model.h ('k') | ui/base/models/simple_menu_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698