Chromium Code Reviews| 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* 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 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 number if child views excluding icon_view. | |
|
msw
2012/06/28 01:56:38
nit: "if"->"of".
yefimt
2012/06/28 16:53:34
Done.
| |
| 411 int NonIconChildViewsCount() const; | |
| 412 | |
| 413 // Get recursively max icon views width. | |
|
msw
2012/06/28 01:56:38
nit: grammar/clarity. Perhaps: "Returns the max ic
yefimt
2012/06/28 16:53:34
Done.
| |
| 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 Loading... | |
| 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 | |
|
msw
2012/06/28 01:56:38
nit: combine comments onto one line or add punctua
yefimt
2012/06/28 16:53:34
Done.
| |
| 454 // (applies to root menu item only). | |
| 448 bool has_icons_; | 455 bool has_icons_; |
| 449 | 456 |
| 457 // Pointer to a view with a menu icon. | |
| 458 View* icon_view_; | |
| 459 | |
| 450 // The tooltip to show on hover for this menu item. | 460 // The tooltip to show on hover for this menu item. |
| 451 string16 tooltip_; | 461 string16 tooltip_; |
| 452 | 462 |
| 463 // Width of a menu icon area. | |
| 464 static int icon_area_width_; | |
| 465 | |
| 453 // X-coordinate of where the label starts. | 466 // X-coordinate of where the label starts. |
| 454 static int label_start_; | 467 static int label_start_; |
| 455 | 468 |
| 456 // Margins between the right of the item and the label. | 469 // Margins between the right of the item and the label. |
| 457 static int item_right_margin_; | 470 static int item_right_margin_; |
| 458 | 471 |
| 459 // Preferred height of menu items. Reset every time a menu is run. | 472 // Preferred height of menu items. Reset every time a menu is run. |
| 460 static int pref_menu_height_; | 473 static int pref_menu_height_; |
| 461 | 474 |
| 462 // Previously calculated preferred size to reduce GetStringWidth calls in | 475 // 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 | 492 // If set to false, the right margin will be removed for menu lines |
| 480 // containing other elements. | 493 // containing other elements. |
| 481 bool use_right_margin_; | 494 bool use_right_margin_; |
| 482 | 495 |
| 483 DISALLOW_COPY_AND_ASSIGN(MenuItemView); | 496 DISALLOW_COPY_AND_ASSIGN(MenuItemView); |
| 484 }; | 497 }; |
| 485 | 498 |
| 486 } // namespace views | 499 } // namespace views |
| 487 | 500 |
| 488 #endif // UI_VIEWS_CONTROLS_MENU_MENU_ITEM_VIEW_H_ | 501 #endif // UI_VIEWS_CONTROLS_MENU_MENU_ITEM_VIEW_H_ |
| OLD | NEW |