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 CHROME_BROWSER_UI_COCOA_MENU_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_UI_COCOA_MENU_CONTROLLER_H_ |
6 #define CHROME_BROWSER_UI_COCOA_MENU_CONTROLLER_H_ | 6 #define CHROME_BROWSER_UI_COCOA_MENU_CONTROLLER_H_ |
7 | 7 |
8 #import <Cocoa/Cocoa.h> | 8 #import <Cocoa/Cocoa.h> |
9 | 9 |
10 #include "base/memory/scoped_nsobject.h" | 10 #include "base/memory/scoped_nsobject.h" |
| 11 #include "base/string16.h" |
11 | 12 |
12 namespace ui { | 13 namespace ui { |
13 class MenuModel; | 14 class MenuModel; |
14 } | 15 } |
15 | 16 |
16 // A controller for the cross-platform menu model. The menu that's created | 17 // A controller for the cross-platform menu model. The menu that's created |
17 // has the tag and represented object set for each menu item. The object is a | 18 // has the tag and represented object set for each menu item. The object is a |
18 // NSValue holding a pointer to the model for that level of the menu (to | 19 // NSValue holding a pointer to the model for that level of the menu (to |
19 // allow for hierarchical menus). The tag is the index into that model for | 20 // allow for hierarchical menus). The tag is the index into that model for |
20 // that particular item. It is important that the model outlives this object | 21 // that particular item. It is important that the model outlives this object |
21 // as it only maintains weak references. | 22 // as it only maintains weak references. |
22 @interface MenuController : NSObject<NSMenuDelegate> { | 23 @interface MenuController : NSObject<NSMenuDelegate> { |
23 @protected | 24 @protected |
24 ui::MenuModel* model_; // weak | 25 ui::MenuModel* model_; // weak |
25 scoped_nsobject<NSMenu> menu_; | 26 scoped_nsobject<NSMenu> menu_; |
26 BOOL useWithPopUpButtonCell_; // If YES, 0th item is blank | 27 BOOL useWithPopUpButtonCell_; // If YES, 0th item is blank |
27 BOOL isMenuOpen_; | 28 BOOL isMenuOpen_; |
28 } | 29 } |
29 | 30 |
30 @property(nonatomic, assign) ui::MenuModel* model; | 31 @property(nonatomic, assign) ui::MenuModel* model; |
31 // Note that changing this will have no effect if you use | 32 // Note that changing this will have no effect if you use |
32 // |-initWithModel:useWithPopUpButtonCell:| or after the first call to |-menu|. | 33 // |-initWithModel:useWithPopUpButtonCell:| or after the first call to |-menu|. |
33 @property(nonatomic) BOOL useWithPopUpButtonCell; | 34 @property(nonatomic) BOOL useWithPopUpButtonCell; |
34 | 35 |
| 36 + (string16)elideMenuTitle:(const string16&)title |
| 37 toWidth:(int)width; |
| 38 |
35 // NIB-based initializer. This does not create a menu. Clients can set the | 39 // NIB-based initializer. This does not create a menu. Clients can set the |
36 // properties of the object and the menu will be created upon the first call to | 40 // properties of the object and the menu will be created upon the first call to |
37 // |-menu|. Note that the menu will be immutable after creation. | 41 // |-menu|. Note that the menu will be immutable after creation. |
38 - (id)init; | 42 - (id)init; |
39 | 43 |
40 // Builds a NSMenu from the pre-built model (must not be nil). Changes made | 44 // Builds a NSMenu from the pre-built model (must not be nil). Changes made |
41 // to the contents of the model after calling this will not be noticed. If | 45 // to the contents of the model after calling this will not be noticed. If |
42 // the menu will be displayed by a NSPopUpButtonCell, it needs to be of a | 46 // the menu will be displayed by a NSPopUpButtonCell, it needs to be of a |
43 // slightly different form (0th item is empty). Note this attribute of the menu | 47 // slightly different form (0th item is empty). Note this attribute of the menu |
44 // cannot be changed after it has been created. | 48 // cannot be changed after it has been created. |
(...skipping 19 matching lines...) Expand all Loading... |
64 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item; | 68 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item; |
65 @end | 69 @end |
66 | 70 |
67 // Protected methods that subclassers can override. | 71 // Protected methods that subclassers can override. |
68 @interface MenuController (Protected) | 72 @interface MenuController (Protected) |
69 - (void)addItemToMenu:(NSMenu*)menu | 73 - (void)addItemToMenu:(NSMenu*)menu |
70 atIndex:(NSInteger)index | 74 atIndex:(NSInteger)index |
71 fromModel:(ui::MenuModel*)model | 75 fromModel:(ui::MenuModel*)model |
72 modelIndex:(int)modelIndex; | 76 modelIndex:(int)modelIndex; |
73 - (NSMenu*)menuFromModel:(ui::MenuModel*)model; | 77 - (NSMenu*)menuFromModel:(ui::MenuModel*)model; |
| 78 // Returns the maximum width for the menu item. Returns -1 to indicate |
| 79 // that there's no maximum width. |
| 80 - (int)maxWidthForMenuModel:(ui::MenuModel*)model |
| 81 modelIndex:(int)modelIndex; |
74 @end | 82 @end |
75 | 83 |
76 #endif // CHROME_BROWSER_UI_COCOA_MENU_CONTROLLER_H_ | 84 #endif // CHROME_BROWSER_UI_COCOA_MENU_CONTROLLER_H_ |
OLD | NEW |