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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 // Returns the icon. |
| 243 const gfx::ImageSkia& GetIcon() const { return icon_; } | 243 const gfx::ImageSkia& GetIcon() const { return icon_; } |
| 244 | 244 |
| 245 // Set/Get a View to be used instead of icon. | |
| 246 // It always be inserted as a first child view. | |
| 247 void SetIconView(View* icon_view); | |
| 248 View* GetIconView(); | |
|
Aaron Boodman
2012/06/19 00:06:33
If these are just simple getters and setters, the
Aaron Boodman
2012/06/19 21:45:38
Nevermind, I forgot to remove this comment.
| |
| 249 | |
| 245 // Sets the command id of this menu item. | 250 // Sets the command id of this menu item. |
| 246 void SetCommand(int command) { command_ = command; } | 251 void SetCommand(int command) { command_ = command; } |
| 247 | 252 |
| 248 // Returns the command id of this item. | 253 // Returns the command id of this item. |
| 249 int GetCommand() const { return command_; } | 254 int GetCommand() const { return command_; } |
| 250 | 255 |
| 251 // Paints the menu item. | 256 // Paints the menu item. |
| 252 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | 257 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; |
| 253 | 258 |
| 254 // Returns the preferred size of this item. | 259 // Returns the preferred size of this item. |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 270 // Returns the mnemonic for this MenuItemView, or 0 if this MenuItemView | 275 // Returns the mnemonic for this MenuItemView, or 0 if this MenuItemView |
| 271 // doesn't have a mnemonic. | 276 // doesn't have a mnemonic. |
| 272 char16 GetMnemonic(); | 277 char16 GetMnemonic(); |
| 273 | 278 |
| 274 // Do we have icons? This only has effect on the top menu. Turning this on | 279 // Do we have icons? This only has effect on the top menu. Turning this on |
| 275 // makes the menus slightly wider and taller. | 280 // makes the menus slightly wider and taller. |
| 276 void set_has_icons(bool has_icons) { | 281 void set_has_icons(bool has_icons) { |
| 277 has_icons_ = has_icons; | 282 has_icons_ = has_icons; |
| 278 } | 283 } |
| 279 | 284 |
| 285 void set_has_icon_views(bool has_icon_views) { | |
| 286 has_icon_views_ = has_icon_views; | |
| 287 } | |
| 288 | |
| 280 // Returns the descendant with the specified command. | 289 // Returns the descendant with the specified command. |
| 281 MenuItemView* GetMenuItemByID(int id); | 290 MenuItemView* GetMenuItemByID(int id); |
| 282 | 291 |
| 283 // Invoke if you remove/add children to the menu while it's showing. This | 292 // Invoke if you remove/add children to the menu while it's showing. This |
| 284 // recalculates the bounds. | 293 // recalculates the bounds. |
| 285 void ChildrenChanged(); | 294 void ChildrenChanged(); |
| 286 | 295 |
| 287 // Sizes any child views. | 296 // Sizes any child views. |
| 288 virtual void Layout() OVERRIDE; | 297 virtual void Layout() OVERRIDE; |
| 289 | 298 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 303 // level only). | 312 // level only). |
| 304 void set_menu_position(MenuPosition menu_position) { | 313 void set_menu_position(MenuPosition menu_position) { |
| 305 requested_menu_position_ = menu_position; | 314 requested_menu_position_ = menu_position; |
| 306 } | 315 } |
| 307 | 316 |
| 308 // Suppress the right margin if this is set to false. | 317 // Suppress the right margin if this is set to false. |
| 309 void set_use_right_margin(bool use_right_margin) { | 318 void set_use_right_margin(bool use_right_margin) { |
| 310 use_right_margin_ = use_right_margin; | 319 use_right_margin_ = use_right_margin; |
| 311 } | 320 } |
| 312 | 321 |
| 322 virtual Border* GetMenuBorder(); | |
| 323 virtual Background* GetMenuBackground(); | |
| 324 | |
| 313 protected: | 325 protected: |
| 314 // Creates a MenuItemView. This is used by the various AddXXX methods. | 326 // Creates a MenuItemView. This is used by the various AddXXX methods. |
| 315 MenuItemView(MenuItemView* parent, int command, Type type); | 327 MenuItemView(MenuItemView* parent, int command, Type type); |
| 316 | 328 |
| 317 // MenuRunner owns MenuItemView and should be the only one deleting it. | 329 // MenuRunner owns MenuItemView and should be the only one deleting it. |
| 318 virtual ~MenuItemView(); | 330 virtual ~MenuItemView(); |
| 319 | 331 |
| 320 virtual void ChildPreferredSizeChanged(View* child) OVERRIDE; | 332 virtual void ChildPreferredSizeChanged(View* child) OVERRIDE; |
| 321 | 333 |
| 322 virtual std::string GetClassName() const OVERRIDE; | 334 virtual std::string GetClassName() const OVERRIDE; |
| 323 | 335 |
| 336 // Calculates all sizes that we can from the OS. | |
| 337 // | |
| 338 // This is invoked prior to Running a menu. | |
| 339 void UpdateMenuPartSizes(); | |
| 340 | |
| 324 private: | 341 private: |
| 325 friend class internal::MenuRunnerImpl; // For access to ~MenuItemView. | 342 friend class internal::MenuRunnerImpl; // For access to ~MenuItemView. |
| 326 | 343 |
| 327 // Calculates all sizes that we can from the OS. | |
| 328 // | |
| 329 // This is invoked prior to Running a menu. | |
| 330 static void UpdateMenuPartSizes(bool has_icons); | |
| 331 | |
| 332 // Called by the two constructors to initialize this menu item. | 344 // Called by the two constructors to initialize this menu item. |
| 333 void Init(MenuItemView* parent, | 345 void Init(MenuItemView* parent, |
| 334 int command, | 346 int command, |
| 335 MenuItemView::Type type, | 347 MenuItemView::Type type, |
| 336 MenuDelegate* delegate); | 348 MenuDelegate* delegate); |
| 337 | 349 |
| 338 // The RunXXX methods call into this to set up the necessary state before | 350 // The RunXXX methods call into this to set up the necessary state before |
| 339 // running. | 351 // running. |
| 340 void PrepareForRun(bool has_mnemonics, bool show_mnemonics); | 352 void PrepareForRun(bool has_mnemonics, bool show_mnemonics); |
| 341 | 353 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 398 void set_actual_menu_position(MenuPosition actual_menu_position) { | 410 void set_actual_menu_position(MenuPosition actual_menu_position) { |
| 399 actual_menu_position_ = actual_menu_position; | 411 actual_menu_position_ = actual_menu_position; |
| 400 } | 412 } |
| 401 | 413 |
| 402 void set_controller(MenuController* controller) { controller_ = controller; } | 414 void set_controller(MenuController* controller) { controller_ = controller; } |
| 403 | 415 |
| 404 // Returns true if this MenuItemView contains a single child | 416 // Returns true if this MenuItemView contains a single child |
| 405 // that is responsible for rendering the content. | 417 // that is responsible for rendering the content. |
| 406 bool IsContainer() const; | 418 bool IsContainer() const; |
| 407 | 419 |
| 420 // Returns true if menu item has non icon view child. | |
| 421 bool HasNonIconChildViews(); | |
| 422 | |
| 408 // The delegate. This is only valid for the root menu item. You shouldn't | 423 // 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 | 424 // use this directly, instead use GetDelegate() which walks the tree as |
| 410 // as necessary. | 425 // as necessary. |
| 411 MenuDelegate* delegate_; | 426 MenuDelegate* delegate_; |
| 412 | 427 |
| 413 // The controller for the run operation, or NULL if the menu isn't showing. | 428 // The controller for the run operation, or NULL if the menu isn't showing. |
| 414 MenuController* controller_; | 429 MenuController* controller_; |
| 415 | 430 |
| 416 // Used to detect when Cancel was invoked. | 431 // Used to detect when Cancel was invoked. |
| 417 bool canceled_; | 432 bool canceled_; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 438 // Icon. | 453 // Icon. |
| 439 gfx::ImageSkia icon_; | 454 gfx::ImageSkia icon_; |
| 440 | 455 |
| 441 // Does the title have a mnemonic? Only useful on the root menu item. | 456 // Does the title have a mnemonic? Only useful on the root menu item. |
| 442 bool has_mnemonics_; | 457 bool has_mnemonics_; |
| 443 | 458 |
| 444 // Should we show the mnemonic? Mnemonics are shown if this is true or | 459 // 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. | 460 // MenuConfig says mnemonics should be shown. Only used on the root menu item. |
| 446 bool show_mnemonics_; | 461 bool show_mnemonics_; |
| 447 | 462 |
| 463 // One of them is set if menu has icons or icon_views | |
| 464 // (applies to root menu item only). | |
| 448 bool has_icons_; | 465 bool has_icons_; |
| 466 bool has_icon_views_; | |
| 467 | |
| 468 // Menu item has icon view | |
| 469 bool has_icon_view_; | |
| 449 | 470 |
| 450 // The tooltip to show on hover for this menu item. | 471 // The tooltip to show on hover for this menu item. |
| 451 string16 tooltip_; | 472 string16 tooltip_; |
| 452 | 473 |
| 453 // X-coordinate of where the label starts. | 474 // X-coordinate of where the label starts. |
| 454 static int label_start_; | 475 static int label_start_; |
| 455 | 476 |
| 456 // Margins between the right of the item and the label. | 477 // Margins between the right of the item and the label. |
| 457 static int item_right_margin_; | 478 static int item_right_margin_; |
| 458 | 479 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 479 // If set to false, the right margin will be removed for menu lines | 500 // If set to false, the right margin will be removed for menu lines |
| 480 // containing other elements. | 501 // containing other elements. |
| 481 bool use_right_margin_; | 502 bool use_right_margin_; |
| 482 | 503 |
| 483 DISALLOW_COPY_AND_ASSIGN(MenuItemView); | 504 DISALLOW_COPY_AND_ASSIGN(MenuItemView); |
| 484 }; | 505 }; |
| 485 | 506 |
| 486 } // namespace views | 507 } // namespace views |
| 487 | 508 |
| 488 #endif // UI_VIEWS_CONTROLS_MENU_MENU_ITEM_VIEW_H_ | 509 #endif // UI_VIEWS_CONTROLS_MENU_MENU_ITEM_VIEW_H_ |
| OLD | NEW |