OLD | NEW |
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_VIEWS_CONTROLS_MENU_MENU_ITEM_VIEW_H_ | 5 #ifndef UI_VIEWS_CONTROLS_MENU_MENU_ITEM_VIEW_H_ |
6 #define UI_VIEWS_CONTROLS_MENU_MENU_ITEM_VIEW_H_ | 6 #define UI_VIEWS_CONTROLS_MENU_MENU_ITEM_VIEW_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 // The height of the menu item. | 125 // The height of the menu item. |
126 int height; | 126 int height; |
127 }; | 127 }; |
128 | 128 |
129 // Constructor for use with the top level menu item. This menu is never | 129 // Constructor for use with the top level menu item. This menu is never |
130 // shown to the user, rather its use as the parent for all menu items. | 130 // shown to the user, rather its use as the parent for all menu items. |
131 explicit MenuItemView(MenuDelegate* delegate); | 131 explicit MenuItemView(MenuDelegate* delegate); |
132 | 132 |
133 // Overridden from View: | 133 // Overridden from View: |
134 virtual bool GetTooltipText(const gfx::Point& p, | 134 virtual bool GetTooltipText(const gfx::Point& p, |
135 string16* tooltip) const OVERRIDE; | 135 base::string16* tooltip) const OVERRIDE; |
136 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; | 136 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; |
137 | 137 |
138 // Returns the preferred height of menu items. This is only valid when the | 138 // Returns the preferred height of menu items. This is only valid when the |
139 // menu is about to be shown. | 139 // menu is about to be shown. |
140 static int pref_menu_height() { return pref_menu_height_; } | 140 static int pref_menu_height() { return pref_menu_height_; } |
141 | 141 |
142 // X-coordinate of where the label starts. | 142 // X-coordinate of where the label starts. |
143 static int label_start() { return label_start_; } | 143 static int label_start() { return label_start_; } |
144 | 144 |
145 // Returns if a given |anchor| is a bubble or not. | 145 // Returns if a given |anchor| is a bubble or not. |
146 static bool IsBubble(MenuItemView::AnchorPosition anchor); | 146 static bool IsBubble(MenuItemView::AnchorPosition anchor); |
147 | 147 |
148 // Returns the accessible name to be used with screen readers. Mnemonics are | 148 // Returns the accessible name to be used with screen readers. Mnemonics are |
149 // removed and the menu item accelerator text is appended. | 149 // removed and the menu item accelerator text is appended. |
150 static string16 GetAccessibleNameForMenuItem( | 150 static base::string16 GetAccessibleNameForMenuItem( |
151 const string16& item_text, const string16& accelerator_text); | 151 const base::string16& item_text, const base::string16& accelerator_text); |
152 | 152 |
153 // Hides and cancels the menu. This does nothing if the menu is not open. | 153 // Hides and cancels the menu. This does nothing if the menu is not open. |
154 void Cancel(); | 154 void Cancel(); |
155 | 155 |
156 // Add an item to the menu at a specified index. ChildrenChanged() should | 156 // Add an item to the menu at a specified index. ChildrenChanged() should |
157 // called after adding menu items if the menu may be active. | 157 // called after adding menu items if the menu may be active. |
158 MenuItemView* AddMenuItemAt(int index, | 158 MenuItemView* AddMenuItemAt(int index, |
159 int item_id, | 159 int item_id, |
160 const string16& label, | 160 const base::string16& label, |
161 const string16& sublabel, | 161 const base::string16& sublabel, |
162 const string16& minor_text, | 162 const base::string16& minor_text, |
163 const gfx::ImageSkia& icon, | 163 const gfx::ImageSkia& icon, |
164 Type type, | 164 Type type, |
165 ui::MenuSeparatorType separator_style); | 165 ui::MenuSeparatorType separator_style); |
166 | 166 |
167 // Remove an item from the menu at a specified index. The removed MenuItemView | 167 // Remove an item from the menu at a specified index. The removed MenuItemView |
168 // is deleted when ChildrenChanged() is invoked. | 168 // is deleted when ChildrenChanged() is invoked. |
169 void RemoveMenuItemAt(int index); | 169 void RemoveMenuItemAt(int index); |
170 | 170 |
171 // Appends an item to this menu. | 171 // Appends an item to this menu. |
172 // item_id The id of the item, used to identify it in delegate callbacks | 172 // item_id The id of the item, used to identify it in delegate callbacks |
173 // or (if delegate is NULL) to identify the command associated | 173 // or (if delegate is NULL) to identify the command associated |
174 // with this item with the controller specified in the ctor. Note | 174 // with this item with the controller specified in the ctor. Note |
175 // that this value should not be 0 as this has a special meaning | 175 // that this value should not be 0 as this has a special meaning |
176 // ("NULL command, no item selected") | 176 // ("NULL command, no item selected") |
177 // label The text label shown. | 177 // label The text label shown. |
178 // type The type of item. | 178 // type The type of item. |
179 MenuItemView* AppendMenuItem(int item_id, | 179 MenuItemView* AppendMenuItem(int item_id, |
180 const string16& label, | 180 const base::string16& label, |
181 Type type); | 181 Type type); |
182 | 182 |
183 // Append a submenu to this menu. | 183 // Append a submenu to this menu. |
184 // The returned pointer is owned by this menu. | 184 // The returned pointer is owned by this menu. |
185 MenuItemView* AppendSubMenu(int item_id, | 185 MenuItemView* AppendSubMenu(int item_id, |
186 const string16& label); | 186 const base::string16& label); |
187 | 187 |
188 // Append a submenu with an icon to this menu. | 188 // Append a submenu with an icon to this menu. |
189 // The returned pointer is owned by this menu. | 189 // The returned pointer is owned by this menu. |
190 MenuItemView* AppendSubMenuWithIcon(int item_id, | 190 MenuItemView* AppendSubMenuWithIcon(int item_id, |
191 const string16& label, | 191 const base::string16& label, |
192 const gfx::ImageSkia& icon); | 192 const gfx::ImageSkia& icon); |
193 | 193 |
194 // This is a convenience for standard text label menu items where the label | 194 // This is a convenience for standard text label menu items where the label |
195 // is provided with this call. | 195 // is provided with this call. |
196 MenuItemView* AppendMenuItemWithLabel(int item_id, | 196 MenuItemView* AppendMenuItemWithLabel(int item_id, |
197 const string16& label); | 197 const base::string16& label); |
198 | 198 |
199 // This is a convenience for text label menu items where the label is | 199 // This is a convenience for text label menu items where the label is |
200 // provided by the delegate. | 200 // provided by the delegate. |
201 MenuItemView* AppendDelegateMenuItem(int item_id); | 201 MenuItemView* AppendDelegateMenuItem(int item_id); |
202 | 202 |
203 // Adds a separator to this menu | 203 // Adds a separator to this menu |
204 void AppendSeparator(); | 204 void AppendSeparator(); |
205 | 205 |
206 // Appends a menu item with an icon. This is for the menu item which | 206 // Appends a menu item with an icon. This is for the menu item which |
207 // needs an icon. Calling this function forces the Menu class to draw | 207 // needs an icon. Calling this function forces the Menu class to draw |
208 // the menu, instead of relying on Windows. | 208 // the menu, instead of relying on Windows. |
209 MenuItemView* AppendMenuItemWithIcon(int item_id, | 209 MenuItemView* AppendMenuItemWithIcon(int item_id, |
210 const string16& label, | 210 const base::string16& label, |
211 const gfx::ImageSkia& icon); | 211 const gfx::ImageSkia& icon); |
212 | 212 |
213 // All the AppendXXX methods funnel into this. | 213 // All the AppendXXX methods funnel into this. |
214 MenuItemView* AppendMenuItemImpl(int item_id, | 214 MenuItemView* AppendMenuItemImpl(int item_id, |
215 const string16& label, | 215 const base::string16& label, |
216 const string16& sublabel, | 216 const base::string16& sublabel, |
217 const string16& minor_text, | 217 const base::string16& minor_text, |
218 const gfx::ImageSkia& icon, | 218 const gfx::ImageSkia& icon, |
219 Type type, | 219 Type type, |
220 ui::MenuSeparatorType separator_style); | 220 ui::MenuSeparatorType separator_style); |
221 | 221 |
222 // Returns the view that contains child menu items. If the submenu has | 222 // Returns the view that contains child menu items. If the submenu has |
223 // not been creates, this creates it. | 223 // not been creates, this creates it. |
224 virtual SubmenuView* CreateSubmenu(); | 224 virtual SubmenuView* CreateSubmenu(); |
225 | 225 |
226 // Returns true if this menu item has a submenu. | 226 // Returns true if this menu item has a submenu. |
227 virtual bool HasSubmenu() const; | 227 virtual bool HasSubmenu() const; |
228 | 228 |
229 // Returns the view containing child menu items. | 229 // Returns the view containing child menu items. |
230 virtual SubmenuView* GetSubmenu() const; | 230 virtual SubmenuView* GetSubmenu() const; |
231 | 231 |
232 // Returns the parent menu item. | 232 // Returns the parent menu item. |
233 MenuItemView* GetParentMenuItem() { return parent_menu_item_; } | 233 MenuItemView* GetParentMenuItem() { return parent_menu_item_; } |
234 const MenuItemView* GetParentMenuItem() const { return parent_menu_item_; } | 234 const MenuItemView* GetParentMenuItem() const { return parent_menu_item_; } |
235 | 235 |
236 // Sets/Gets the title. | 236 // Sets/Gets the title. |
237 void SetTitle(const string16& title); | 237 void SetTitle(const base::string16& title); |
238 const string16& title() const { return title_; } | 238 const base::string16& title() const { return title_; } |
239 | 239 |
240 // Sets the subtitle. | 240 // Sets the subtitle. |
241 void SetSubtitle(const string16& subtitle); | 241 void SetSubtitle(const base::string16& subtitle); |
242 | 242 |
243 // Sets the minor text. | 243 // Sets the minor text. |
244 void SetMinorText(const string16& minor_text); | 244 void SetMinorText(const base::string16& minor_text); |
245 | 245 |
246 // Returns the type of this menu. | 246 // Returns the type of this menu. |
247 const Type& GetType() const { return type_; } | 247 const Type& GetType() const { return type_; } |
248 | 248 |
249 // Sets whether this item is selected. This is invoked as the user moves | 249 // Sets whether this item is selected. This is invoked as the user moves |
250 // the mouse around the menu while open. | 250 // the mouse around the menu while open. |
251 void SetSelected(bool selected); | 251 void SetSelected(bool selected); |
252 | 252 |
253 // Returns true if the item is selected. | 253 // Returns true if the item is selected. |
254 bool IsSelected() const { return selected_; } | 254 bool IsSelected() const { return selected_; } |
255 | 255 |
256 // Sets the |tooltip| for a menu item view with |item_id| identifier. | 256 // Sets the |tooltip| for a menu item view with |item_id| identifier. |
257 void SetTooltip(const string16& tooltip, int item_id); | 257 void SetTooltip(const base::string16& tooltip, int item_id); |
258 | 258 |
259 // Sets the icon for the descendant identified by item_id. | 259 // Sets the icon for the descendant identified by item_id. |
260 void SetIcon(const gfx::ImageSkia& icon, int item_id); | 260 void SetIcon(const gfx::ImageSkia& icon, int item_id); |
261 | 261 |
262 // Sets the icon of this menu item. | 262 // Sets the icon of this menu item. |
263 void SetIcon(const gfx::ImageSkia& icon); | 263 void SetIcon(const gfx::ImageSkia& icon); |
264 | 264 |
265 // Sets the view used to render the icon. This clobbers any icon set via | 265 // Sets the view used to render the icon. This clobbers any icon set via |
266 // SetIcon(). MenuItemView takes ownership of |icon_view|. | 266 // SetIcon(). MenuItemView takes ownership of |icon_view|. |
267 void SetIconView(View* icon_view); | 267 void SetIconView(View* icon_view); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 | 396 |
397 // Paints the right-side text. | 397 // Paints the right-side text. |
398 void PaintMinorText(gfx::Canvas* canvas, bool render_selection); | 398 void PaintMinorText(gfx::Canvas* canvas, bool render_selection); |
399 | 399 |
400 // Destroys the window used to display this menu and recursively destroys | 400 // Destroys the window used to display this menu and recursively destroys |
401 // the windows used to display all descendants. | 401 // the windows used to display all descendants. |
402 void DestroyAllMenuHosts(); | 402 void DestroyAllMenuHosts(); |
403 | 403 |
404 // Returns the text that should be displayed on the end (right) of the menu | 404 // Returns the text that should be displayed on the end (right) of the menu |
405 // item. This will be the accelerator (if one exists), otherwise |subtitle_|. | 405 // item. This will be the accelerator (if one exists), otherwise |subtitle_|. |
406 string16 GetMinorText(); | 406 base::string16 GetMinorText(); |
407 | 407 |
408 // Calculates and returns the MenuItemDimensions. | 408 // Calculates and returns the MenuItemDimensions. |
409 MenuItemDimensions CalculateDimensions(); | 409 MenuItemDimensions CalculateDimensions(); |
410 | 410 |
411 // Get the horizontal position at which to draw the menu item's label. | 411 // Get the horizontal position at which to draw the menu item's label. |
412 int GetLabelStartForThisItem(); | 412 int GetLabelStartForThisItem(); |
413 | 413 |
414 // Used by MenuController to cache the menu position in use by the | 414 // Used by MenuController to cache the menu position in use by the |
415 // active menu. | 415 // active menu. |
416 MenuPosition actual_menu_position() const { return actual_menu_position_; } | 416 MenuPosition actual_menu_position() const { return actual_menu_position_; } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 // Whether we're selected. | 457 // Whether we're selected. |
458 bool selected_; | 458 bool selected_; |
459 | 459 |
460 // Command id. | 460 // Command id. |
461 int command_; | 461 int command_; |
462 | 462 |
463 // Submenu, created via CreateSubmenu. | 463 // Submenu, created via CreateSubmenu. |
464 SubmenuView* submenu_; | 464 SubmenuView* submenu_; |
465 | 465 |
466 // Title. | 466 // Title. |
467 string16 title_; | 467 base::string16 title_; |
468 | 468 |
469 // Subtitle/sublabel. | 469 // Subtitle/sublabel. |
470 string16 subtitle_; | 470 base::string16 subtitle_; |
471 | 471 |
472 // Minor text. | 472 // Minor text. |
473 string16 minor_text_; | 473 base::string16 minor_text_; |
474 | 474 |
475 // Does the title have a mnemonic? Only useful on the root menu item. | 475 // Does the title have a mnemonic? Only useful on the root menu item. |
476 bool has_mnemonics_; | 476 bool has_mnemonics_; |
477 | 477 |
478 // Should we show the mnemonic? Mnemonics are shown if this is true or | 478 // Should we show the mnemonic? Mnemonics are shown if this is true or |
479 // MenuConfig says mnemonics should be shown. Only used on the root menu item. | 479 // MenuConfig says mnemonics should be shown. Only used on the root menu item. |
480 bool show_mnemonics_; | 480 bool show_mnemonics_; |
481 | 481 |
482 // Set if menu has icons or icon_views (applies to root menu item only). | 482 // Set if menu has icons or icon_views (applies to root menu item only). |
483 bool has_icons_; | 483 bool has_icons_; |
484 | 484 |
485 // Pointer to a view with a menu icon. | 485 // Pointer to a view with a menu icon. |
486 View* icon_view_; | 486 View* icon_view_; |
487 | 487 |
488 // The tooltip to show on hover for this menu item. | 488 // The tooltip to show on hover for this menu item. |
489 string16 tooltip_; | 489 base::string16 tooltip_; |
490 | 490 |
491 // Width of a menu icon area. | 491 // Width of a menu icon area. |
492 static int icon_area_width_; | 492 static int icon_area_width_; |
493 | 493 |
494 // X-coordinate of where the label starts. | 494 // X-coordinate of where the label starts. |
495 static int label_start_; | 495 static int label_start_; |
496 | 496 |
497 // Margins between the right of the item and the label. | 497 // Margins between the right of the item and the label. |
498 static int item_right_margin_; | 498 static int item_right_margin_; |
499 | 499 |
(...skipping 25 matching lines...) Expand all Loading... |
525 // If set to false, the right margin will be removed for menu lines | 525 // If set to false, the right margin will be removed for menu lines |
526 // containing other elements. | 526 // containing other elements. |
527 bool use_right_margin_; | 527 bool use_right_margin_; |
528 | 528 |
529 DISALLOW_COPY_AND_ASSIGN(MenuItemView); | 529 DISALLOW_COPY_AND_ASSIGN(MenuItemView); |
530 }; | 530 }; |
531 | 531 |
532 } // namespace views | 532 } // namespace views |
533 | 533 |
534 #endif // UI_VIEWS_CONTROLS_MENU_MENU_ITEM_VIEW_H_ | 534 #endif // UI_VIEWS_CONTROLS_MENU_MENU_ITEM_VIEW_H_ |
OLD | NEW |