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

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, 6 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
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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // Returns the icon.
243 const gfx::ImageSkia& GetIcon() const { return icon_; } 243 const gfx::ImageSkia& GetIcon();
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();
244 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
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 // level only). 308 // level only).
304 void set_menu_position(MenuPosition menu_position) { 309 void set_menu_position(MenuPosition menu_position) {
305 requested_menu_position_ = menu_position; 310 requested_menu_position_ = menu_position;
306 } 311 }
307 312
308 // Suppress the right margin if this is set to false. 313 // Suppress the right margin if this is set to false.
309 void set_use_right_margin(bool use_right_margin) { 314 void set_use_right_margin(bool use_right_margin) {
310 use_right_margin_ = use_right_margin; 315 use_right_margin_ = use_right_margin;
311 } 316 }
312 317
318 virtual Border* GetMenuBorder();
319 virtual Background* GetMenuBackground();
320
313 protected: 321 protected:
314 // Creates a MenuItemView. This is used by the various AddXXX methods. 322 // Creates a MenuItemView. This is used by the various AddXXX methods.
315 MenuItemView(MenuItemView* parent, int command, Type type); 323 MenuItemView(MenuItemView* parent, int command, Type type);
316 324
317 // MenuRunner owns MenuItemView and should be the only one deleting it. 325 // MenuRunner owns MenuItemView and should be the only one deleting it.
318 virtual ~MenuItemView(); 326 virtual ~MenuItemView();
319 327
320 virtual void ChildPreferredSizeChanged(View* child) OVERRIDE; 328 virtual void ChildPreferredSizeChanged(View* child) OVERRIDE;
321 329
322 virtual std::string GetClassName() const OVERRIDE; 330 virtual std::string GetClassName() const OVERRIDE;
323 331
324 private: 332 private:
325 friend class internal::MenuRunnerImpl; // For access to ~MenuItemView. 333 friend class internal::MenuRunnerImpl; // For access to ~MenuItemView.
326 334
327 // Calculates all sizes that we can from the OS. 335 // Calculates all sizes that we can from the OS.
328 // 336 //
329 // This is invoked prior to Running a menu. 337 // This is invoked prior to Running a menu.
330 static void UpdateMenuPartSizes(bool has_icons); 338 void UpdateMenuPartSizes();
331 339
332 // Called by the two constructors to initialize this menu item. 340 // Called by the two constructors to initialize this menu item.
333 void Init(MenuItemView* parent, 341 void Init(MenuItemView* parent,
334 int command, 342 int command,
335 MenuItemView::Type type, 343 MenuItemView::Type type,
336 MenuDelegate* delegate); 344 MenuDelegate* delegate);
337 345
338 // The RunXXX methods call into this to set up the necessary state before 346 // The RunXXX methods call into this to set up the necessary state before
339 // running. 347 // running.
340 void PrepareForRun(bool has_mnemonics, bool show_mnemonics); 348 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) { 406 void set_actual_menu_position(MenuPosition actual_menu_position) {
399 actual_menu_position_ = actual_menu_position; 407 actual_menu_position_ = actual_menu_position;
400 } 408 }
401 409
402 void set_controller(MenuController* controller) { controller_ = controller; } 410 void set_controller(MenuController* controller) { controller_ = controller; }
403 411
404 // Returns true if this MenuItemView contains a single child 412 // Returns true if this MenuItemView contains a single child
405 // that is responsible for rendering the content. 413 // that is responsible for rendering the content.
406 bool IsContainer() const; 414 bool IsContainer() const;
407 415
416 // Returns true if menu item has non icon view child.
417 bool HasNonIconChildViews();
418
408 // The delegate. This is only valid for the root menu item. You shouldn't 419 // 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 420 // use this directly, instead use GetDelegate() which walks the tree as
410 // as necessary. 421 // as necessary.
411 MenuDelegate* delegate_; 422 MenuDelegate* delegate_;
412 423
413 // The controller for the run operation, or NULL if the menu isn't showing. 424 // The controller for the run operation, or NULL if the menu isn't showing.
414 MenuController* controller_; 425 MenuController* controller_;
415 426
416 // Used to detect when Cancel was invoked. 427 // Used to detect when Cancel was invoked.
417 bool canceled_; 428 bool canceled_;
(...skipping 10 matching lines...) Expand all
428 439
429 // Command id. 440 // Command id.
430 int command_; 441 int command_;
431 442
432 // Submenu, created via CreateSubmenu. 443 // Submenu, created via CreateSubmenu.
433 SubmenuView* submenu_; 444 SubmenuView* submenu_;
434 445
435 // Title. 446 // Title.
436 string16 title_; 447 string16 title_;
437 448
438 // Icon. 449 // Empty icon.
439 gfx::ImageSkia icon_; 450 static gfx::ImageSkia empty_icon_;
440 451
441 // Does the title have a mnemonic? Only useful on the root menu item. 452 // Does the title have a mnemonic? Only useful on the root menu item.
442 bool has_mnemonics_; 453 bool has_mnemonics_;
443 454
444 // Should we show the mnemonic? Mnemonics are shown if this is true or 455 // 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. 456 // MenuConfig says mnemonics should be shown. Only used on the root menu item.
446 bool show_mnemonics_; 457 bool show_mnemonics_;
447 458
459 // Set if menu has icons or icon_views
460 // (applies to root menu item only).
448 bool has_icons_; 461 bool has_icons_;
449 462
463 enum IconViewType {
464 NONE,
465 IMAGE_VIEW,
466 SOME_VIEW
Aaron Boodman 2012/06/21 08:15:30 Agree with sky that it would be nicer to have an e
yefimt 2012/06/22 22:14:40 Done.
467 };
468 // Type of an icon view.
469 IconViewType icon_view_type_;
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
474 static int icon_width_;
475
453 // X-coordinate of where the label starts. 476 // X-coordinate of where the label starts.
454 static int label_start_; 477 static int label_start_;
455 478
456 // Margins between the right of the item and the label. 479 // Margins between the right of the item and the label.
457 static int item_right_margin_; 480 static int item_right_margin_;
458 481
459 // Preferred height of menu items. Reset every time a menu is run. 482 // Preferred height of menu items. Reset every time a menu is run.
460 static int pref_menu_height_; 483 static int pref_menu_height_;
461 484
462 // Previously calculated preferred size to reduce GetStringWidth calls in 485 // 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 502 // If set to false, the right margin will be removed for menu lines
480 // containing other elements. 503 // containing other elements.
481 bool use_right_margin_; 504 bool use_right_margin_;
482 505
483 DISALLOW_COPY_AND_ASSIGN(MenuItemView); 506 DISALLOW_COPY_AND_ASSIGN(MenuItemView);
484 }; 507 };
485 508
486 } // namespace views 509 } // namespace views
487 510
488 #endif // UI_VIEWS_CONTROLS_MENU_MENU_ITEM_VIEW_H_ 511 #endif // UI_VIEWS_CONTROLS_MENU_MENU_ITEM_VIEW_H_
OLDNEW
« no previous file with comments | « no previous file | ui/views/controls/menu/menu_item_view.cc » ('j') | ui/views/controls/menu/menu_item_view.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698