 Chromium Code Reviews
 Chromium Code Reviews 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
    
  
    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| 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 #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 Loading... | |
| 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* GetIconView(); | |
| 
sky
2012/06/26 21:42:13
GetIconView() -> icon_view() and inline it.
 
yefimt
2012/06/26 22:50:19
Done.
 | |
| 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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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 true if menu item has non icon view child. | |
| 411 bool HasNonIconChildViews(); | |
| 412 | |
| 408 // The delegate. This is only valid for the root menu item. You shouldn't | 413 // 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 | 414 // use this directly, instead use GetDelegate() which walks the tree as | 
| 410 // as necessary. | 415 // as necessary. | 
| 411 MenuDelegate* delegate_; | 416 MenuDelegate* delegate_; | 
| 412 | 417 | 
| 413 // The controller for the run operation, or NULL if the menu isn't showing. | 418 // The controller for the run operation, or NULL if the menu isn't showing. | 
| 414 MenuController* controller_; | 419 MenuController* controller_; | 
| 415 | 420 | 
| 416 // Used to detect when Cancel was invoked. | 421 // Used to detect when Cancel was invoked. | 
| 417 bool canceled_; | 422 bool canceled_; | 
| (...skipping 10 matching lines...) Expand all Loading... | |
| 428 | 433 | 
| 429 // Command id. | 434 // Command id. | 
| 430 int command_; | 435 int command_; | 
| 431 | 436 | 
| 432 // Submenu, created via CreateSubmenu. | 437 // Submenu, created via CreateSubmenu. | 
| 433 SubmenuView* submenu_; | 438 SubmenuView* submenu_; | 
| 434 | 439 | 
| 435 // Title. | 440 // Title. | 
| 436 string16 title_; | 441 string16 title_; | 
| 437 | 442 | 
| 438 // Icon. | |
| 439 gfx::ImageSkia icon_; | |
| 440 | |
| 441 // Does the title have a mnemonic? Only useful on the root menu item. | 443 // Does the title have a mnemonic? Only useful on the root menu item. | 
| 442 bool has_mnemonics_; | 444 bool has_mnemonics_; | 
| 443 | 445 | 
| 444 // Should we show the mnemonic? Mnemonics are shown if this is true or | 446 // 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. | 447 // MenuConfig says mnemonics should be shown. Only used on the root menu item. | 
| 446 bool show_mnemonics_; | 448 bool show_mnemonics_; | 
| 447 | 449 | 
| 450 // Set if menu has icons or icon_views | |
| 451 // (applies to root menu item only). | |
| 448 bool has_icons_; | 452 bool has_icons_; | 
| 449 | 453 | 
| 454 // Pointer to a view with a menu icon. | |
| 455 View* icon_view_; | |
| 456 | |
| 450 // The tooltip to show on hover for this menu item. | 457 // The tooltip to show on hover for this menu item. | 
| 451 string16 tooltip_; | 458 string16 tooltip_; | 
| 452 | 459 | 
| 460 // Width of a menu icon area. | |
| 461 static int icon_area_width_; | |
| 462 | |
| 453 // X-coordinate of where the label starts. | 463 // X-coordinate of where the label starts. | 
| 454 static int label_start_; | 464 static int label_start_; | 
| 455 | 465 | 
| 456 // Margins between the right of the item and the label. | 466 // Margins between the right of the item and the label. | 
| 457 static int item_right_margin_; | 467 static int item_right_margin_; | 
| 458 | 468 | 
| 459 // Preferred height of menu items. Reset every time a menu is run. | 469 // Preferred height of menu items. Reset every time a menu is run. | 
| 460 static int pref_menu_height_; | 470 static int pref_menu_height_; | 
| 461 | 471 | 
| 462 // Previously calculated preferred size to reduce GetStringWidth calls in | 472 // Previously calculated preferred size to reduce GetStringWidth calls in | 
| (...skipping 16 matching lines...) Expand all Loading... | |
| 479 // If set to false, the right margin will be removed for menu lines | 489 // If set to false, the right margin will be removed for menu lines | 
| 480 // containing other elements. | 490 // containing other elements. | 
| 481 bool use_right_margin_; | 491 bool use_right_margin_; | 
| 482 | 492 | 
| 483 DISALLOW_COPY_AND_ASSIGN(MenuItemView); | 493 DISALLOW_COPY_AND_ASSIGN(MenuItemView); | 
| 484 }; | 494 }; | 
| 485 | 495 | 
| 486 } // namespace views | 496 } // namespace views | 
| 487 | 497 | 
| 488 #endif // UI_VIEWS_CONTROLS_MENU_MENU_ITEM_VIEW_H_ | 498 #endif // UI_VIEWS_CONTROLS_MENU_MENU_ITEM_VIEW_H_ | 
| OLD | NEW |