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

Side by Side Diff: views/controls/menu/menu_delegate.h

Issue 6622002: Do all OOLing in the views code. linux_views now builds clean with the clang plugin. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 9 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 | Annotate | Revision Log
OLDNEW
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 VIEWS_CONTROLS_MENU_MENU_DELEGATE_H_ 5 #ifndef VIEWS_CONTROLS_MENU_MENU_DELEGATE_H_
6 #define VIEWS_CONTROLS_MENU_MENU_DELEGATE_H_ 6 #define VIEWS_CONTROLS_MENU_MENU_DELEGATE_H_
7 #pragma once 7 #pragma once
8 8
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 29 matching lines...) Expand all
40 40
41 // Indicates the drop should occur after the item. 41 // Indicates the drop should occur after the item.
42 DROP_AFTER, 42 DROP_AFTER,
43 43
44 // Indicates the drop should occur on the item. 44 // Indicates the drop should occur on the item.
45 DROP_ON 45 DROP_ON
46 }; 46 };
47 47
48 // Whether or not an item should be shown as checked. This is invoked for 48 // Whether or not an item should be shown as checked. This is invoked for
49 // radio buttons and check buttons. 49 // radio buttons and check buttons.
50 virtual bool IsItemChecked(int id) const { 50 virtual bool IsItemChecked(int id) const;
51 return false;
52 }
53 51
54 // The string shown for the menu item. This is only invoked when an item is 52 // The string shown for the menu item. This is only invoked when an item is
55 // added with an empty label. 53 // added with an empty label.
56 virtual std::wstring GetLabel(int id) const { 54 virtual std::wstring GetLabel(int id) const;
57 return std::wstring();
58 }
59 55
60 // The tooltip shown for the menu item. This is invoked when the user 56 // The tooltip shown for the menu item. This is invoked when the user
61 // hovers over the item, and no tooltip text has been set for that item. 57 // hovers over the item, and no tooltip text has been set for that item.
62 virtual std::wstring GetTooltipText(int id, const gfx::Point& screen_loc) { 58 virtual std::wstring GetTooltipText(int id, const gfx::Point& screen_loc);
63 return std::wstring();
64 }
65 59
66 // If there is an accelerator for the menu item with id |id| it is set in 60 // If there is an accelerator for the menu item with id |id| it is set in
67 // |accelerator| and true is returned. 61 // |accelerator| and true is returned.
68 virtual bool GetAccelerator(int id, Accelerator* accelerator) { 62 virtual bool GetAccelerator(int id, Accelerator* accelerator);
69 return false;
70 }
71 63
72 // Shows the context menu with the specified id. This is invoked when the 64 // Shows the context menu with the specified id. This is invoked when the
73 // user does the appropriate gesture to show a context menu. The id 65 // user does the appropriate gesture to show a context menu. The id
74 // identifies the id of the menu to show the context menu for. 66 // identifies the id of the menu to show the context menu for.
75 // is_mouse_gesture is true if this is the result of a mouse gesture. 67 // is_mouse_gesture is true if this is the result of a mouse gesture.
76 // If this is not the result of a mouse gesture |p| is the recommended 68 // If this is not the result of a mouse gesture |p| is the recommended
77 // location to display the content menu at. In either case, |p| is in 69 // location to display the content menu at. In either case, |p| is in
78 // screen coordinates. 70 // screen coordinates.
79 // Returns true if a context menu was displayed, otherwise false 71 // Returns true if a context menu was displayed, otherwise false
80 virtual bool ShowContextMenu(MenuItemView* source, 72 virtual bool ShowContextMenu(MenuItemView* source,
81 int id, 73 int id,
82 const gfx::Point& p, 74 const gfx::Point& p,
83 bool is_mouse_gesture) { 75 bool is_mouse_gesture);
84 return false;
85 }
86 76
87 // Controller 77 // Controller
88 virtual bool SupportsCommand(int id) const { 78 virtual bool SupportsCommand(int id) const;
89 return true; 79 virtual bool IsCommandEnabled(int id) const;
90 } 80 virtual bool GetContextualLabel(int id, std::wstring* out) const;
91 virtual bool IsCommandEnabled(int id) const {
92 return true;
93 }
94 virtual bool GetContextualLabel(int id, std::wstring* out) const {
95 return false;
96 }
97 virtual void ExecuteCommand(int id) { 81 virtual void ExecuteCommand(int id) {
98 } 82 }
99 83
100 // If nested menus are showing (nested menus occur when a menu shows a context 84 // If nested menus are showing (nested menus occur when a menu shows a context
101 // menu) this is invoked to determine if all the menus should be closed when 85 // menu) this is invoked to determine if all the menus should be closed when
102 // the user selects the menu with the command |id|. This returns true to 86 // the user selects the menu with the command |id|. This returns true to
103 // indicate that all menus should be closed. Return false if only the 87 // indicate that all menus should be closed. Return false if only the
104 // context menu should be closed. 88 // context menu should be closed.
105 virtual bool ShouldCloseAllMenusOnExecute(int id) { 89 virtual bool ShouldCloseAllMenusOnExecute(int id);
106 return true;
107 }
108 90
109 // Executes the specified command. mouse_event_flags give the flags of the 91 // Executes the specified command. mouse_event_flags give the flags of the
110 // mouse event that triggered this to be invoked (views::MouseEvent 92 // mouse event that triggered this to be invoked (views::MouseEvent
111 // flags). mouse_event_flags is 0 if this is triggered by a user gesture 93 // flags). mouse_event_flags is 0 if this is triggered by a user gesture
112 // other than a mouse event. 94 // other than a mouse event.
113 virtual void ExecuteCommand(int id, int mouse_event_flags) { 95 virtual void ExecuteCommand(int id, int mouse_event_flags);
114 ExecuteCommand(id);
115 }
116 96
117 // Returns true if the specified mouse event is one the user can use 97 // Returns true if the specified mouse event is one the user can use
118 // to trigger, or accept, the mouse. Defaults to left or right mouse buttons. 98 // to trigger, or accept, the mouse. Defaults to left or right mouse buttons.
119 virtual bool IsTriggerableEvent(const MouseEvent& e) { 99 virtual bool IsTriggerableEvent(const MouseEvent& e);
120 return e.IsLeftMouseButton() || e.IsRightMouseButton();
121 }
122 100
123 // Invoked to determine if drops can be accepted for a submenu. This is 101 // Invoked to determine if drops can be accepted for a submenu. This is
124 // ONLY invoked for menus that have submenus and indicates whether or not 102 // ONLY invoked for menus that have submenus and indicates whether or not
125 // a drop can occur on any of the child items of the item. For example, 103 // a drop can occur on any of the child items of the item. For example,
126 // consider the following menu structure: 104 // consider the following menu structure:
127 // 105 //
128 // A 106 // A
129 // B 107 // B
130 // C 108 // C
131 // 109 //
132 // Where A has a submenu with children B and C. This is ONLY invoked for 110 // Where A has a submenu with children B and C. This is ONLY invoked for
133 // A, not B and C. 111 // A, not B and C.
134 // 112 //
135 113
136 // To restrict which children can be dropped on override GetDropOperation. 114 // To restrict which children can be dropped on override GetDropOperation.
137 virtual bool CanDrop(MenuItemView* menu, const OSExchangeData& data) { 115 virtual bool CanDrop(MenuItemView* menu, const OSExchangeData& data);
Nico 2011/03/04 22:53:02 I think I renamed this and the 2 methods below to
138 return false;
139 }
140 116
141 // See view for a description of this method. 117 // See view for a description of this method.
142 virtual bool GetDropFormats( 118 virtual bool GetDropFormats(
143 MenuItemView* menu, 119 MenuItemView* menu,
144 int* formats, 120 int* formats,
145 std::set<OSExchangeData::CustomFormat>* custom_formats) { 121 std::set<OSExchangeData::CustomFormat>* custom_formats);
146 return false;
147 }
148 122
149 // See view for a description of this method. 123 // See view for a description of this method.
150 virtual bool AreDropTypesRequired(MenuItemView* menu) { 124 virtual bool AreDropTypesRequired(MenuItemView* menu);
151 return false;
152 }
153 125
154 // Returns the drop operation for the specified target menu item. This is 126 // Returns the drop operation for the specified target menu item. This is
155 // only invoked if CanDrop returned true for the parent menu. position 127 // only invoked if CanDrop returned true for the parent menu. position
156 // is set based on the location of the mouse, reset to specify a different 128 // is set based on the location of the mouse, reset to specify a different
157 // position. 129 // position.
158 // 130 //
159 // If a drop should not be allowed, returned ui::DragDropTypes::DRAG_NONE. 131 // If a drop should not be allowed, returned ui::DragDropTypes::DRAG_NONE.
160 virtual int GetDropOperation(MenuItemView* item, 132 virtual int GetDropOperation(MenuItemView* item,
161 const DropTargetEvent& event, 133 const DropTargetEvent& event,
162 DropPosition* position) { 134 DropPosition* position);
163 NOTREACHED() << "If you override CanDrop, you need to override this too";
164 return ui::DragDropTypes::DRAG_NONE;
165 }
166 135
167 // Invoked to perform the drop operation. This is ONLY invoked if 136 // Invoked to perform the drop operation. This is ONLY invoked if
168 // canDrop returned true for the parent menu item, and GetDropOperation 137 // canDrop returned true for the parent menu item, and GetDropOperation
169 // returned an operation other than ui::DragDropTypes::DRAG_NONE. 138 // returned an operation other than ui::DragDropTypes::DRAG_NONE.
170 // 139 //
171 // menu indicates the menu the drop occurred on. 140 // menu indicates the menu the drop occurred on.
172 virtual int OnPerformDrop(MenuItemView* menu, 141 virtual int OnPerformDrop(MenuItemView* menu,
173 DropPosition position, 142 DropPosition position,
174 const DropTargetEvent& event) { 143 const DropTargetEvent& event);
175 NOTREACHED() << "If you override CanDrop, you need to override this too";
176 return ui::DragDropTypes::DRAG_NONE;
177 }
178 144
179 // Invoked to determine if it is possible for the user to drag the specified 145 // Invoked to determine if it is possible for the user to drag the specified
180 // menu item. 146 // menu item.
181 virtual bool CanDrag(MenuItemView* menu) { 147 virtual bool CanDrag(MenuItemView* menu);
182 return false;
183 }
184 148
185 // Invoked to write the data for a drag operation to data. sender is the 149 // Invoked to write the data for a drag operation to data. sender is the
186 // MenuItemView being dragged. 150 // MenuItemView being dragged.
187 virtual void WriteDragData(MenuItemView* sender, OSExchangeData* data) { 151 virtual void WriteDragData(MenuItemView* sender, OSExchangeData* data);
188 NOTREACHED() << "If you override CanDrag, you must override this too.";
189 }
190 152
191 // Invoked to determine the drag operations for a drag session of sender. 153 // Invoked to determine the drag operations for a drag session of sender.
192 // See DragDropTypes for possible values. 154 // See DragDropTypes for possible values.
193 virtual int GetDragOperations(MenuItemView* sender) { 155 virtual int GetDragOperations(MenuItemView* sender);
194 NOTREACHED() << "If you override CanDrag, you must override this too.";
195 return 0;
196 }
197 156
198 // Notification the menu has closed. This is only sent when running the 157 // Notification the menu has closed. This is only sent when running the
199 // menu for a drop. 158 // menu for a drop.
200 virtual void DropMenuClosed(MenuItemView* menu) { 159 virtual void DropMenuClosed(MenuItemView* menu) {
201 } 160 }
202 161
203 // Notification that the user has highlighted the specified item. 162 // Notification that the user has highlighted the specified item.
204 virtual void SelectionChanged(MenuItemView* menu) { 163 virtual void SelectionChanged(MenuItemView* menu) {
205 } 164 }
206 165
207 // If the user drags the mouse outside the bounds of the menu the delegate 166 // If the user drags the mouse outside the bounds of the menu the delegate
208 // is queried for a sibling menu to show. If this returns non-null the 167 // is queried for a sibling menu to show. If this returns non-null the
209 // current menu is hidden, and the menu returned from this method is shown. 168 // current menu is hidden, and the menu returned from this method is shown.
210 // 169 //
211 // The delegate owns the returned menu, not the controller. 170 // The delegate owns the returned menu, not the controller.
212 virtual MenuItemView* GetSiblingMenu(MenuItemView* menu, 171 virtual MenuItemView* GetSiblingMenu(MenuItemView* menu,
213 const gfx::Point& screen_point, 172 const gfx::Point& screen_point,
214 MenuItemView::AnchorPosition* anchor, 173 MenuItemView::AnchorPosition* anchor,
215 bool* has_mnemonics, 174 bool* has_mnemonics,
216 MenuButton** button) { 175 MenuButton** button);
217 return NULL;
218 }
219 176
220 // Returns the max width menus can grow to be. 177 // Returns the max width menus can grow to be.
221 virtual int GetMaxWidthForMenu() { 178 virtual int GetMaxWidthForMenu();
222 // NOTE: this needs to be large enough to accommodate the wrench menu with
223 // big fonts.
224 return 800;
225 }
226 }; 179 };
227 180
228 } // namespace views 181 } // namespace views
229 182
230 #endif // VIEWS_CONTROLS_MENU_MENU_DELEGATE_H_ 183 #endif // VIEWS_CONTROLS_MENU_MENU_DELEGATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698