| 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 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 // Sets the command id of this menu item. | 256 // Sets the command id of this menu item. |
| 257 void SetCommand(int command) { command_ = command; } | 257 void SetCommand(int command) { command_ = command; } |
| 258 | 258 |
| 259 // Returns the command id of this item. | 259 // Returns the command id of this item. |
| 260 int GetCommand() const { return command_; } | 260 int GetCommand() const { return command_; } |
| 261 | 261 |
| 262 // Paints the menu item. | 262 // Paints the menu item. |
| 263 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | 263 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; |
| 264 | 264 |
| 265 // Returns the preferred size of this item. | 265 // Returns the preferred size of this item. |
| 266 virtual gfx::Size GetPreferredSize() OVERRIDE; | 266 virtual gfx::Size GetPreferredSize() const OVERRIDE; |
| 267 | 267 |
| 268 // Return the preferred dimensions of the item in pixel. | 268 // Return the preferred dimensions of the item in pixel. |
| 269 const MenuItemDimensions& GetDimensions(); | 269 const MenuItemDimensions& GetDimensions() const; |
| 270 | 270 |
| 271 // Returns the object responsible for controlling showing the menu. | 271 // Returns the object responsible for controlling showing the menu. |
| 272 MenuController* GetMenuController(); | 272 MenuController* GetMenuController(); |
| 273 const MenuController* GetMenuController() const; | 273 const MenuController* GetMenuController() const; |
| 274 | 274 |
| 275 // Returns the delegate. This returns the delegate of the root menu item. | 275 // Returns the delegate. This returns the delegate of the root menu item. |
| 276 MenuDelegate* GetDelegate(); | 276 MenuDelegate* GetDelegate(); |
| 277 const MenuDelegate* GetDelegate() const; | 277 const MenuDelegate* GetDelegate() const; |
| 278 void set_delegate(MenuDelegate* delegate) { delegate_ = delegate; } | 278 void set_delegate(MenuDelegate* delegate) { delegate_ = delegate; } |
| 279 | 279 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 MenuItemView(MenuItemView* parent, int command, Type type); | 323 MenuItemView(MenuItemView* parent, int command, Type type); |
| 324 | 324 |
| 325 // MenuRunner owns MenuItemView and should be the only one deleting it. | 325 // MenuRunner owns MenuItemView and should be the only one deleting it. |
| 326 virtual ~MenuItemView(); | 326 virtual ~MenuItemView(); |
| 327 | 327 |
| 328 virtual void ChildPreferredSizeChanged(View* child) OVERRIDE; | 328 virtual void ChildPreferredSizeChanged(View* child) OVERRIDE; |
| 329 | 329 |
| 330 virtual const char* GetClassName() const OVERRIDE; | 330 virtual const char* GetClassName() const OVERRIDE; |
| 331 | 331 |
| 332 // Returns the preferred size (and padding) of any children. | 332 // Returns the preferred size (and padding) of any children. |
| 333 virtual gfx::Size GetChildPreferredSize(); | 333 virtual gfx::Size GetChildPreferredSize() const; |
| 334 | 334 |
| 335 // Returns the various margins. | 335 // Returns the various margins. |
| 336 int GetTopMargin(); | 336 int GetTopMargin() const; |
| 337 int GetBottomMargin(); | 337 int GetBottomMargin() const; |
| 338 | 338 |
| 339 private: | 339 private: |
| 340 friend class internal::MenuRunnerImpl; // For access to ~MenuItemView. | 340 friend class internal::MenuRunnerImpl; // For access to ~MenuItemView. |
| 341 | 341 |
| 342 enum PaintButtonMode { PB_NORMAL, PB_FOR_DRAG }; | 342 enum PaintButtonMode { PB_NORMAL, PB_FOR_DRAG }; |
| 343 | 343 |
| 344 // Calculates all sizes that we can from the OS. | 344 // Calculates all sizes that we can from the OS. |
| 345 // | 345 // |
| 346 // This is invoked prior to Running a menu. | 346 // This is invoked prior to Running a menu. |
| 347 void UpdateMenuPartSizes(); | 347 void UpdateMenuPartSizes(); |
| 348 | 348 |
| 349 // Called by the two constructors to initialize this menu item. | 349 // Called by the two constructors to initialize this menu item. |
| 350 void Init(MenuItemView* parent, | 350 void Init(MenuItemView* parent, |
| 351 int command, | 351 int command, |
| 352 MenuItemView::Type type, | 352 MenuItemView::Type type, |
| 353 MenuDelegate* delegate); | 353 MenuDelegate* delegate); |
| 354 | 354 |
| 355 // The RunXXX methods call into this to set up the necessary state before | 355 // The RunXXX methods call into this to set up the necessary state before |
| 356 // running. |is_first_menu| is true if no menus are currently showing. | 356 // running. |is_first_menu| is true if no menus are currently showing. |
| 357 void PrepareForRun(bool is_first_menu, | 357 void PrepareForRun(bool is_first_menu, |
| 358 bool has_mnemonics, | 358 bool has_mnemonics, |
| 359 bool show_mnemonics); | 359 bool show_mnemonics); |
| 360 | 360 |
| 361 // Returns the flags passed to DrawStringRect. | 361 // Returns the flags passed to DrawStringRect. |
| 362 int GetDrawStringFlags(); | 362 int GetDrawStringFlags(); |
| 363 | 363 |
| 364 // Returns the font list to use for menu text. | 364 // Returns the font list to use for menu text. |
| 365 const gfx::FontList& GetFontList(); | 365 const gfx::FontList& GetFontList() const; |
| 366 | 366 |
| 367 // If this menu item has no children a child is added showing it has no | 367 // If this menu item has no children a child is added showing it has no |
| 368 // children. Otherwise AddEmtpyMenus is recursively invoked on child menu | 368 // children. Otherwise AddEmtpyMenus is recursively invoked on child menu |
| 369 // items that have children. | 369 // items that have children. |
| 370 void AddEmptyMenus(); | 370 void AddEmptyMenus(); |
| 371 | 371 |
| 372 // Undoes the work of AddEmptyMenus. | 372 // Undoes the work of AddEmptyMenus. |
| 373 void RemoveEmptyMenus(); | 373 void RemoveEmptyMenus(); |
| 374 | 374 |
| 375 // Given bounds within our View, this helper routine mirrors the bounds if | 375 // Given bounds within our View, this helper routine mirrors the bounds if |
| 376 // necessary. | 376 // necessary. |
| 377 void AdjustBoundsForRTLUI(gfx::Rect* rect) const; | 377 void AdjustBoundsForRTLUI(gfx::Rect* rect) const; |
| 378 | 378 |
| 379 // Actual paint implementation. If mode is PB_FOR_DRAG, portions of the menu | 379 // Actual paint implementation. If mode is PB_FOR_DRAG, portions of the menu |
| 380 // are not rendered. | 380 // are not rendered. |
| 381 void PaintButton(gfx::Canvas* canvas, PaintButtonMode mode); | 381 void PaintButton(gfx::Canvas* canvas, PaintButtonMode mode); |
| 382 | 382 |
| 383 // Paints the right-side text. | 383 // Paints the right-side text. |
| 384 void PaintMinorText(gfx::Canvas* canvas, bool render_selection); | 384 void PaintMinorText(gfx::Canvas* canvas, bool render_selection); |
| 385 | 385 |
| 386 // Destroys the window used to display this menu and recursively destroys | 386 // Destroys the window used to display this menu and recursively destroys |
| 387 // the windows used to display all descendants. | 387 // the windows used to display all descendants. |
| 388 void DestroyAllMenuHosts(); | 388 void DestroyAllMenuHosts(); |
| 389 | 389 |
| 390 // Returns the text that should be displayed on the end (right) of the menu | 390 // Returns the text that should be displayed on the end (right) of the menu |
| 391 // item. This will be the accelerator (if one exists), otherwise |subtitle_|. | 391 // item. This will be the accelerator (if one exists), otherwise |subtitle_|. |
| 392 base::string16 GetMinorText(); | 392 base::string16 GetMinorText() const; |
| 393 | 393 |
| 394 // Calculates and returns the MenuItemDimensions. | 394 // Calculates and returns the MenuItemDimensions. |
| 395 MenuItemDimensions CalculateDimensions(); | 395 MenuItemDimensions CalculateDimensions() const; |
| 396 | 396 |
| 397 // Get the horizontal position at which to draw the menu item's label. | 397 // Get the horizontal position at which to draw the menu item's label. |
| 398 int GetLabelStartForThisItem(); | 398 int GetLabelStartForThisItem() const; |
| 399 | 399 |
| 400 // Used by MenuController to cache the menu position in use by the | 400 // Used by MenuController to cache the menu position in use by the |
| 401 // active menu. | 401 // active menu. |
| 402 MenuPosition actual_menu_position() const { return actual_menu_position_; } | 402 MenuPosition actual_menu_position() const { return actual_menu_position_; } |
| 403 void set_actual_menu_position(MenuPosition actual_menu_position) { | 403 void set_actual_menu_position(MenuPosition actual_menu_position) { |
| 404 actual_menu_position_ = actual_menu_position; | 404 actual_menu_position_ = actual_menu_position; |
| 405 } | 405 } |
| 406 | 406 |
| 407 void set_controller(MenuController* controller) { controller_ = controller; } | 407 void set_controller(MenuController* controller) { controller_ = controller; } |
| 408 | 408 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 static int label_start_; | 481 static int label_start_; |
| 482 | 482 |
| 483 // Margins between the right of the item and the label. | 483 // Margins between the right of the item and the label. |
| 484 static int item_right_margin_; | 484 static int item_right_margin_; |
| 485 | 485 |
| 486 // Preferred height of menu items. Reset every time a menu is run. | 486 // Preferred height of menu items. Reset every time a menu is run. |
| 487 static int pref_menu_height_; | 487 static int pref_menu_height_; |
| 488 | 488 |
| 489 // Cached dimensions. This is cached as text sizing calculations are quite | 489 // Cached dimensions. This is cached as text sizing calculations are quite |
| 490 // costly. | 490 // costly. |
| 491 MenuItemDimensions dimensions_; | 491 mutable MenuItemDimensions dimensions_; |
| 492 | 492 |
| 493 // Removed items to be deleted in ChildrenChanged(). | 493 // Removed items to be deleted in ChildrenChanged(). |
| 494 std::vector<View*> removed_items_; | 494 std::vector<View*> removed_items_; |
| 495 | 495 |
| 496 // Margins in pixels. | 496 // Margins in pixels. |
| 497 int top_margin_; | 497 int top_margin_; |
| 498 int bottom_margin_; | 498 int bottom_margin_; |
| 499 | 499 |
| 500 // Horizontal icon margins in pixels, which can differ between MenuItems. | 500 // Horizontal icon margins in pixels, which can differ between MenuItems. |
| 501 // These values will be set in the layout process. | 501 // These values will be set in the layout process. |
| 502 int left_icon_margin_; | 502 mutable int left_icon_margin_; |
| 503 int right_icon_margin_; | 503 mutable int right_icon_margin_; |
| 504 | 504 |
| 505 // |menu_position_| is the requested position with respect to the bounds. | 505 // |menu_position_| is the requested position with respect to the bounds. |
| 506 // |actual_menu_position_| is used by the controller to cache the | 506 // |actual_menu_position_| is used by the controller to cache the |
| 507 // position of the menu being shown. | 507 // position of the menu being shown. |
| 508 MenuPosition requested_menu_position_; | 508 MenuPosition requested_menu_position_; |
| 509 MenuPosition actual_menu_position_; | 509 MenuPosition actual_menu_position_; |
| 510 | 510 |
| 511 // If set to false, the right margin will be removed for menu lines | 511 // If set to false, the right margin will be removed for menu lines |
| 512 // containing other elements. | 512 // containing other elements. |
| 513 bool use_right_margin_; | 513 bool use_right_margin_; |
| 514 | 514 |
| 515 DISALLOW_COPY_AND_ASSIGN(MenuItemView); | 515 DISALLOW_COPY_AND_ASSIGN(MenuItemView); |
| 516 }; | 516 }; |
| 517 | 517 |
| 518 } // namespace views | 518 } // namespace views |
| 519 | 519 |
| 520 #endif // UI_VIEWS_CONTROLS_MENU_MENU_ITEM_VIEW_H_ | 520 #endif // UI_VIEWS_CONTROLS_MENU_MENU_ITEM_VIEW_H_ |
| OLD | NEW |