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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 TOPRIGHT | 93 TOPRIGHT |
94 }; | 94 }; |
95 | 95 |
96 // Where the menu should be drawn, above or below the bounds (when | 96 // Where the menu should be drawn, above or below the bounds (when |
97 // the bounds is non-empty). POSITION_BEST_FIT (default) positions | 97 // the bounds is non-empty). POSITION_BEST_FIT (default) positions |
98 // the menu below the bounds unless the menu does not fit on the | 98 // the menu below the bounds unless the menu does not fit on the |
99 // screen and the re is more space above. | 99 // screen and the re is more space above. |
100 enum MenuPosition { | 100 enum MenuPosition { |
101 POSITION_BEST_FIT, | 101 POSITION_BEST_FIT, |
102 POSITION_ABOVE_BOUNDS, | 102 POSITION_ABOVE_BOUNDS, |
103 POSITION_BELOW_BOUNDS, | 103 POSITION_BELOW_BOUNDS |
104 POSITION_OVER_BOUNDS | |
105 }; | 104 }; |
106 | 105 |
107 // Constructor for use with the top level menu item. This menu is never | 106 // Constructor for use with the top level menu item. This menu is never |
108 // shown to the user, rather its use as the parent for all menu items. | 107 // shown to the user, rather its use as the parent for all menu items. |
109 explicit MenuItemView(MenuDelegate* delegate); | 108 explicit MenuItemView(MenuDelegate* delegate); |
110 | 109 |
111 // Overridden from View: | 110 // Overridden from View: |
112 virtual bool GetTooltipText(const gfx::Point& p, | 111 virtual bool GetTooltipText(const gfx::Point& p, |
113 string16* tooltip) const OVERRIDE; | 112 string16* tooltip) const OVERRIDE; |
114 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; | 113 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
210 MenuItemView* GetParentMenuItem() { return parent_menu_item_; } | 209 MenuItemView* GetParentMenuItem() { return parent_menu_item_; } |
211 const MenuItemView* GetParentMenuItem() const { return parent_menu_item_; } | 210 const MenuItemView* GetParentMenuItem() const { return parent_menu_item_; } |
212 | 211 |
213 // Sets/Gets the title. | 212 // Sets/Gets the title. |
214 void SetTitle(const string16& title); | 213 void SetTitle(const string16& title); |
215 const string16& title() const { return title_; } | 214 const string16& title() const { return title_; } |
216 | 215 |
217 // Returns the type of this menu. | 216 // Returns the type of this menu. |
218 const Type& GetType() const { return type_; } | 217 const Type& GetType() const { return type_; } |
219 | 218 |
220 // Returns the requested menu position. | |
221 const MenuPosition& GetRequestedMenuPosition() { | |
222 return requested_menu_position_; | |
223 } | |
224 | |
225 // Sets whether this item is selected. This is invoked as the user moves | 219 // Sets whether this item is selected. This is invoked as the user moves |
226 // the mouse around the menu while open. | 220 // the mouse around the menu while open. |
227 void SetSelected(bool selected); | 221 void SetSelected(bool selected); |
228 | 222 |
229 // Returns true if the item is selected. | 223 // Returns true if the item is selected. |
230 bool IsSelected() const { return selected_; } | 224 bool IsSelected() const { return selected_; } |
231 | 225 |
232 // Sets the |tooltip| for a menu item view with |item_id| identifier. | 226 // Sets the |tooltip| for a menu item view with |item_id| identifier. |
233 void SetTooltip(const string16& tooltip, int item_id); | 227 void SetTooltip(const string16& tooltip, int item_id); |
234 | 228 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
293 int GetAcceleratorTextWidth(); | 287 int GetAcceleratorTextWidth(); |
294 | 288 |
295 // Returns true if the menu has mnemonics. This only useful on the root menu | 289 // Returns true if the menu has mnemonics. This only useful on the root menu |
296 // item. | 290 // item. |
297 bool has_mnemonics() const { return has_mnemonics_; } | 291 bool has_mnemonics() const { return has_mnemonics_; } |
298 | 292 |
299 // Set top and bottom margins in pixels. If no margin is set or a | 293 // Set top and bottom margins in pixels. If no margin is set or a |
300 // negative margin is specified then MenuConfig values are used. | 294 // negative margin is specified then MenuConfig values are used. |
301 void SetMargins(int top_margin, int bottom_margin); | 295 void SetMargins(int top_margin, int bottom_margin); |
302 | 296 |
303 // Set the position of the menu with respect to the bounds (top | |
304 // level only). | |
305 void set_menu_position(MenuPosition menu_position) { | |
306 requested_menu_position_ = menu_position; | |
307 } | |
308 | |
309 // Suppress the right margin if this is set to false. | 297 // Suppress the right margin if this is set to false. |
310 void set_use_right_margin(bool use_right_margin) { | 298 void set_use_right_margin(bool use_right_margin) { |
311 use_right_margin_ = use_right_margin; | 299 use_right_margin_ = use_right_margin; |
312 } | 300 } |
313 | 301 |
314 protected: | 302 protected: |
315 // Creates a MenuItemView. This is used by the various AddXXX methods. | 303 // Creates a MenuItemView. This is used by the various AddXXX methods. |
316 MenuItemView(MenuItemView* parent, int command, Type type); | 304 MenuItemView(MenuItemView* parent, int command, Type type); |
317 | 305 |
318 // MenuRunner owns MenuItemView and should be the only one deleting it. | 306 // MenuRunner owns MenuItemView and should be the only one deleting it. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
388 void DestroyAllMenuHosts(); | 376 void DestroyAllMenuHosts(); |
389 | 377 |
390 // Returns the accelerator text. | 378 // Returns the accelerator text. |
391 string16 GetAcceleratorText(); | 379 string16 GetAcceleratorText(); |
392 | 380 |
393 // Calculates the preferred size. | 381 // Calculates the preferred size. |
394 gfx::Size CalculatePreferredSize(); | 382 gfx::Size CalculatePreferredSize(); |
395 | 383 |
396 // Used by MenuController to cache the menu position in use by the | 384 // Used by MenuController to cache the menu position in use by the |
397 // active menu. | 385 // active menu. |
398 MenuPosition actual_menu_position() const { return actual_menu_position_; } | 386 MenuPosition menu_position() const { return menu_position_; } |
399 void set_actual_menu_position(MenuPosition actual_menu_position) { | 387 void set_menu_position(MenuPosition menu_position) { |
400 actual_menu_position_ = actual_menu_position; | 388 menu_position_ = menu_position; |
401 } | 389 } |
402 | 390 |
403 void set_controller(MenuController* controller) { controller_ = controller; } | 391 void set_controller(MenuController* controller) { controller_ = controller; } |
404 | 392 |
405 // Returns true if this MenuItemView contains a single child | 393 // Returns true if this MenuItemView contains a single child |
406 // that is responsible for rendering the content. | 394 // that is responsible for rendering the content. |
407 bool IsContainer() const; | 395 bool IsContainer() const; |
408 | 396 |
409 // Returns number of child views excluding icon_view. | 397 // Returns number of child views excluding icon_view. |
410 int NonIconChildViewsCount() const; | 398 int NonIconChildViewsCount() const; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
474 // GetPreferredSize. | 462 // GetPreferredSize. |
475 gfx::Size pref_size_; | 463 gfx::Size pref_size_; |
476 | 464 |
477 // Removed items to be deleted in ChildrenChanged(). | 465 // Removed items to be deleted in ChildrenChanged(). |
478 std::vector<View*> removed_items_; | 466 std::vector<View*> removed_items_; |
479 | 467 |
480 // Margins in pixels. | 468 // Margins in pixels. |
481 int top_margin_; | 469 int top_margin_; |
482 int bottom_margin_; | 470 int bottom_margin_; |
483 | 471 |
484 // |menu_position_| is the requested position with respect to the bounds. | 472 // |menu_position_| is used by the controller to cache the |
485 // |actual_menu_position_| is used by the controller to cache the | |
486 // position of the menu being shown. | 473 // position of the menu being shown. |
487 MenuPosition requested_menu_position_; | 474 MenuPosition menu_position_; |
sky
2012/08/07 00:31:57
I don't like that showing a menu many change the m
Harry McCleave
2012/08/07 01:26:36
Done.
| |
488 MenuPosition actual_menu_position_; | |
489 | 475 |
490 // If set to false, the right margin will be removed for menu lines | 476 // If set to false, the right margin will be removed for menu lines |
491 // containing other elements. | 477 // containing other elements. |
492 bool use_right_margin_; | 478 bool use_right_margin_; |
493 | 479 |
494 DISALLOW_COPY_AND_ASSIGN(MenuItemView); | 480 DISALLOW_COPY_AND_ASSIGN(MenuItemView); |
495 }; | 481 }; |
496 | 482 |
497 } // namespace views | 483 } // namespace views |
498 | 484 |
499 #endif // UI_VIEWS_CONTROLS_MENU_MENU_ITEM_VIEW_H_ | 485 #endif // UI_VIEWS_CONTROLS_MENU_MENU_ITEM_VIEW_H_ |
OLD | NEW |