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

Side by Side Diff: ui/views/controls/menu/menu_item_view.h

Issue 10532171: Added support for icon views (view used instead of icon in a menu item). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added support for icon views (view used instead of icon in a menu item). Created 8 years, 5 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
« no previous file with comments | « ui/views/controls/menu/menu_delegate.cc ('k') | ui/views/controls/menu/menu_item_view.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_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 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 232
233 // Sets the |tooltip| for a menu item view with |item_id| identifier. 233 // Sets the |tooltip| for a menu item view with |item_id| identifier.
234 void SetTooltip(const string16& tooltip, int item_id); 234 void SetTooltip(const string16& tooltip, int item_id);
235 235
236 // Sets the icon for the descendant identified by item_id. 236 // Sets the icon for the descendant identified by item_id.
237 void SetIcon(const gfx::ImageSkia& icon, int item_id); 237 void SetIcon(const gfx::ImageSkia& icon, int item_id);
238 238
239 // Sets the icon of this menu item. 239 // Sets the icon of this menu item.
240 void SetIcon(const gfx::ImageSkia& icon); 240 void SetIcon(const gfx::ImageSkia& icon);
241 241
242 // Returns the icon. 242 // Sets the view used to render the icon. This clobbers any icon set via
243 const gfx::ImageSkia& GetIcon() const { return icon_; } 243 // SetIcon(). MenuItemView takes ownership of |icon_view|.
244 void SetIconView(View* icon_view);
245 View* icon_view() { return icon_view_; }
244 246
245 // Sets the command id of this menu item. 247 // Sets the command id of this menu item.
246 void SetCommand(int command) { command_ = command; } 248 void SetCommand(int command) { command_ = command; }
247 249
248 // Returns the command id of this item. 250 // Returns the command id of this item.
249 int GetCommand() const { return command_; } 251 int GetCommand() const { return command_; }
250 252
251 // Paints the menu item. 253 // Paints the menu item.
252 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 254 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
253 255
(...skipping 26 matching lines...) Expand all
280 // Returns the descendant with the specified command. 282 // Returns the descendant with the specified command.
281 MenuItemView* GetMenuItemByID(int id); 283 MenuItemView* GetMenuItemByID(int id);
282 284
283 // Invoke if you remove/add children to the menu while it's showing. This 285 // Invoke if you remove/add children to the menu while it's showing. This
284 // recalculates the bounds. 286 // recalculates the bounds.
285 void ChildrenChanged(); 287 void ChildrenChanged();
286 288
287 // Sizes any child views. 289 // Sizes any child views.
288 virtual void Layout() OVERRIDE; 290 virtual void Layout() OVERRIDE;
289 291
290 // Returns the amount of space needed to accomodate the accelerator. The 292 // Returns the amount of space needed to accommodate the accelerator. The
291 // space needed for the accelerator is NOT included in the preferred width. 293 // space needed for the accelerator is NOT included in the preferred width.
292 int GetAcceleratorTextWidth(); 294 int GetAcceleratorTextWidth();
293 295
294 // Returns true if the menu has mnemonics. This only useful on the root menu 296 // Returns true if the menu has mnemonics. This only useful on the root menu
295 // item. 297 // item.
296 bool has_mnemonics() const { return has_mnemonics_; } 298 bool has_mnemonics() const { return has_mnemonics_; }
297 299
298 // Set top and bottom margins in pixels. If no margin is set or a 300 // Set top and bottom margins in pixels. If no margin is set or a
299 // negative margin is specified then MenuConfig values are used. 301 // negative margin is specified then MenuConfig values are used.
300 void SetMargins(int top_margin, int bottom_margin); 302 void SetMargins(int top_margin, int bottom_margin);
(...skipping 19 matching lines...) Expand all
320 virtual void ChildPreferredSizeChanged(View* child) OVERRIDE; 322 virtual void ChildPreferredSizeChanged(View* child) OVERRIDE;
321 323
322 virtual std::string GetClassName() const OVERRIDE; 324 virtual std::string GetClassName() const OVERRIDE;
323 325
324 private: 326 private:
325 friend class internal::MenuRunnerImpl; // For access to ~MenuItemView. 327 friend class internal::MenuRunnerImpl; // For access to ~MenuItemView.
326 328
327 // Calculates all sizes that we can from the OS. 329 // Calculates all sizes that we can from the OS.
328 // 330 //
329 // This is invoked prior to Running a menu. 331 // This is invoked prior to Running a menu.
330 static void UpdateMenuPartSizes(bool has_icons); 332 void UpdateMenuPartSizes();
331 333
332 // Called by the two constructors to initialize this menu item. 334 // Called by the two constructors to initialize this menu item.
333 void Init(MenuItemView* parent, 335 void Init(MenuItemView* parent,
334 int command, 336 int command,
335 MenuItemView::Type type, 337 MenuItemView::Type type,
336 MenuDelegate* delegate); 338 MenuDelegate* delegate);
337 339
338 // The RunXXX methods call into this to set up the necessary state before 340 // The RunXXX methods call into this to set up the necessary state before
339 // running. 341 // running.
340 void PrepareForRun(bool has_mnemonics, bool show_mnemonics); 342 void PrepareForRun(bool has_mnemonics, bool show_mnemonics);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 void set_actual_menu_position(MenuPosition actual_menu_position) { 400 void set_actual_menu_position(MenuPosition actual_menu_position) {
399 actual_menu_position_ = actual_menu_position; 401 actual_menu_position_ = actual_menu_position;
400 } 402 }
401 403
402 void set_controller(MenuController* controller) { controller_ = controller; } 404 void set_controller(MenuController* controller) { controller_ = controller; }
403 405
404 // Returns true if this MenuItemView contains a single child 406 // Returns true if this MenuItemView contains a single child
405 // that is responsible for rendering the content. 407 // that is responsible for rendering the content.
406 bool IsContainer() const; 408 bool IsContainer() const;
407 409
410 // Returns number of child views excluding icon_view.
411 int NonIconChildViewsCount() const;
412
413 // Returns the max icon width; recurses over submenus.
414 int GetMaxIconViewWidth() const;
415
408 // The delegate. This is only valid for the root menu item. You shouldn't 416 // The delegate. This is only valid for the root menu item. You shouldn't
409 // use this directly, instead use GetDelegate() which walks the tree as 417 // use this directly, instead use GetDelegate() which walks the tree as
410 // as necessary. 418 // as necessary.
411 MenuDelegate* delegate_; 419 MenuDelegate* delegate_;
412 420
413 // The controller for the run operation, or NULL if the menu isn't showing. 421 // The controller for the run operation, or NULL if the menu isn't showing.
414 MenuController* controller_; 422 MenuController* controller_;
415 423
416 // Used to detect when Cancel was invoked. 424 // Used to detect when Cancel was invoked.
417 bool canceled_; 425 bool canceled_;
(...skipping 10 matching lines...) Expand all
428 436
429 // Command id. 437 // Command id.
430 int command_; 438 int command_;
431 439
432 // Submenu, created via CreateSubmenu. 440 // Submenu, created via CreateSubmenu.
433 SubmenuView* submenu_; 441 SubmenuView* submenu_;
434 442
435 // Title. 443 // Title.
436 string16 title_; 444 string16 title_;
437 445
438 // Icon.
439 gfx::ImageSkia icon_;
440
441 // Does the title have a mnemonic? Only useful on the root menu item. 446 // Does the title have a mnemonic? Only useful on the root menu item.
442 bool has_mnemonics_; 447 bool has_mnemonics_;
443 448
444 // Should we show the mnemonic? Mnemonics are shown if this is true or 449 // Should we show the mnemonic? Mnemonics are shown if this is true or
445 // MenuConfig says mnemonics should be shown. Only used on the root menu item. 450 // MenuConfig says mnemonics should be shown. Only used on the root menu item.
446 bool show_mnemonics_; 451 bool show_mnemonics_;
447 452
453 // Set if menu has icons or icon_views (applies to root menu item only).
448 bool has_icons_; 454 bool has_icons_;
449 455
456 // Pointer to a view with a menu icon.
457 View* icon_view_;
458
450 // The tooltip to show on hover for this menu item. 459 // The tooltip to show on hover for this menu item.
451 string16 tooltip_; 460 string16 tooltip_;
452 461
462 // Width of a menu icon area.
463 static int icon_area_width_;
464
453 // X-coordinate of where the label starts. 465 // X-coordinate of where the label starts.
454 static int label_start_; 466 static int label_start_;
455 467
456 // Margins between the right of the item and the label. 468 // Margins between the right of the item and the label.
457 static int item_right_margin_; 469 static int item_right_margin_;
458 470
459 // Preferred height of menu items. Reset every time a menu is run. 471 // Preferred height of menu items. Reset every time a menu is run.
460 static int pref_menu_height_; 472 static int pref_menu_height_;
461 473
462 // Previously calculated preferred size to reduce GetStringWidth calls in 474 // Previously calculated preferred size to reduce GetStringWidth calls in
(...skipping 16 matching lines...) Expand all
479 // If set to false, the right margin will be removed for menu lines 491 // If set to false, the right margin will be removed for menu lines
480 // containing other elements. 492 // containing other elements.
481 bool use_right_margin_; 493 bool use_right_margin_;
482 494
483 DISALLOW_COPY_AND_ASSIGN(MenuItemView); 495 DISALLOW_COPY_AND_ASSIGN(MenuItemView);
484 }; 496 };
485 497
486 } // namespace views 498 } // namespace views
487 499
488 #endif // UI_VIEWS_CONTROLS_MENU_MENU_ITEM_VIEW_H_ 500 #endif // UI_VIEWS_CONTROLS_MENU_MENU_ITEM_VIEW_H_
OLDNEW
« no previous file with comments | « ui/views/controls/menu/menu_delegate.cc ('k') | ui/views/controls/menu/menu_item_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698