Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_BASE_COCOA_MENU_CONTROLLER_H_ | 5 #ifndef UI_BASE_COCOA_MENU_CONTROLLER_H_ |
| 6 #define UI_BASE_COCOA_MENU_CONTROLLER_H_ | 6 #define UI_BASE_COCOA_MENU_CONTROLLER_H_ |
| 7 | 7 |
| 8 #import <Cocoa/Cocoa.h> | 8 #import <Cocoa/Cocoa.h> |
| 9 | 9 |
| 10 #include "base/mac/scoped_nsobject.h" | 10 #include "base/mac/scoped_nsobject.h" |
| 11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
| 12 #include "ui/base/ui_base_export.h" | 12 #include "ui/base/ui_base_export.h" |
| 13 | 13 |
| 14 namespace ui { | 14 namespace ui { |
| 15 class MenuModel; | 15 class MenuModel; |
| 16 } | 16 } |
| 17 | 17 |
| 18 UI_BASE_EXPORT extern NSString* const kMenuControllerMenuWillOpenNotification; | 18 UI_BASE_EXPORT extern NSString* const kMenuControllerMenuWillOpenNotification; |
| 19 UI_BASE_EXPORT extern NSString* const kMenuControllerMenuDidCloseNotification; | 19 UI_BASE_EXPORT extern NSString* const kMenuControllerMenuDidCloseNotification; |
| 20 | 20 |
| 21 // A controller for the cross-platform menu model. The menu that's created | 21 // A controller for the cross-platform menu model. The menu that's created |
| 22 // has the tag and represented object set for each menu item. The object is a | 22 // has the tag and represented object set for each menu item. The object is a |
| 23 // NSValue holding a pointer to the model for that level of the menu (to | 23 // NSValue holding a pointer to the model for that level of the menu (to |
| 24 // allow for hierarchical menus). The tag is the index into that model for | 24 // allow for hierarchical menus). The tag is the index into that model for |
| 25 // that particular item. It is important that the model outlives this object | 25 // that particular item. It is important that the model outlives this object |
| 26 // as it only maintains weak references. | 26 // as it only maintains weak references. |
| 27 UI_BASE_EXPORT | 27 UI_BASE_EXPORT |
| 28 @interface MenuController : NSObject<NSMenuDelegate> { | 28 @interface MenuController : NSObject<NSMenuDelegate> { |
| 29 @protected | 29 @protected |
| 30 ui::MenuModel* model_; // weak | 30 ui::MenuModel* model_; // Weak. |
| 31 base::scoped_nsobject<NSMenu> menu_; | 31 base::scoped_nsobject<NSMenu> menu_; |
| 32 BOOL useWithPopUpButtonCell_; // If YES, 0th item is blank | |
| 33 BOOL isMenuOpen_; | |
| 34 } | 32 } |
| 35 | 33 |
| 36 @property(nonatomic, assign) ui::MenuModel* model; | 34 @property(nonatomic, assign) ui::MenuModel* model; |
| 35 | |
| 36 // Whether to activate selected menu items via a posted task. This may allow the | |
| 37 // selection to be handled earlier, whilst the menu is fading out. If the posted | |
| 38 // task wasn't processed by the time the action is normally sent, it will be | |
| 39 // sent synchronously at that stage. | |
| 40 @property(nonatomic, assign) BOOL postItemSelectedAsTask; | |
| 41 | |
| 37 // Note that changing this will have no effect if you use | 42 // Note that changing this will have no effect if you use |
| 38 // |-initWithModel:useWithPopUpButtonCell:| or after the first call to |-menu|. | 43 // |-initWithModel:useWithPopUpButtonCell:| or after the first call to |-menu|. |
| 39 @property(nonatomic) BOOL useWithPopUpButtonCell; | 44 @property(nonatomic) BOOL useWithPopUpButtonCell; |
| 40 | 45 |
| 41 + (base::string16)elideMenuTitle:(const base::string16&)title | 46 + (base::string16)elideMenuTitle:(const base::string16&)title |
| 42 toWidth:(int)width; | 47 toWidth:(int)width; |
| 43 | 48 |
| 44 // NIB-based initializer. This does not create a menu. Clients can set the | 49 // NIB-based initializer. This does not create a menu. Clients can set the |
| 45 // properties of the object and the menu will be created upon the first call to | 50 // properties of the object and the menu will be created upon the first call to |
| 46 // |-menu|. Note that the menu will be immutable after creation. | 51 // |-menu|. Note that the menu will be immutable after creation. |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 64 // Whether the menu is currently open. | 69 // Whether the menu is currently open. |
| 65 - (BOOL)isMenuOpen; | 70 - (BOOL)isMenuOpen; |
| 66 | 71 |
| 67 // NSMenuDelegate methods this class implements. Subclasses should call super | 72 // NSMenuDelegate methods this class implements. Subclasses should call super |
| 68 // if extending the behavior. | 73 // if extending the behavior. |
| 69 - (void)menuWillOpen:(NSMenu*)menu; | 74 - (void)menuWillOpen:(NSMenu*)menu; |
| 70 - (void)menuDidClose:(NSMenu*)menu; | 75 - (void)menuDidClose:(NSMenu*)menu; |
| 71 | 76 |
| 72 @end | 77 @end |
| 73 | 78 |
| 74 // Exposed only for unit testing, do not call directly. | 79 // Protected methods that subclassers can override and/or invoke. |
| 75 @interface MenuController (PrivateExposedForTesting) | 80 @interface MenuController (Protected) |
| 81 | |
| 82 // Called before the menu is to be displayed to update the state (enabled, | |
| 83 // radio, etc) of each item in the menu. Also will update the title if the item | |
| 84 // is marked as "dynamic". | |
| 76 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item; | 85 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item; |
|
tapted
2017/05/10 03:49:06
(This is called outside of testcode, so I merged t
| |
| 77 @end | |
| 78 | 86 |
| 79 // Protected methods that subclassers can override. | 87 // Adds an item or a hierarchical menu to the item at the |index|, associated |
| 80 @interface MenuController (Protected) | 88 // with the entry in the model identified by |modelIndex|. |
|
Robert Sesek
2017/05/10 13:37:27
nit: no modelIndex in the args
tapted
2017/05/11 00:24:06
Updated:
// Adds the item at |index| in |model| a
| |
| 81 - (void)addItemToMenu:(NSMenu*)menu | 89 - (void)addItemToMenu:(NSMenu*)menu |
| 82 atIndex:(NSInteger)index | 90 atIndex:(NSInteger)index |
| 83 fromModel:(ui::MenuModel*)model; | 91 fromModel:(ui::MenuModel*)model; |
| 92 | |
| 93 // Creates a NSMenu from the given model. If the model has submenus, this can | |
| 94 // be invoked recursively. | |
| 84 - (NSMenu*)menuFromModel:(ui::MenuModel*)model; | 95 - (NSMenu*)menuFromModel:(ui::MenuModel*)model; |
| 85 // Returns the maximum width for the menu item. Returns -1 to indicate | 96 |
| 86 // that there's no maximum width. | 97 // Returns the maximum width for the menu item. Returns -1 to indicate that |
| 98 // there's no maximum width. | |
| 87 - (int)maxWidthForMenuModel:(ui::MenuModel*)model | 99 - (int)maxWidthForMenuModel:(ui::MenuModel*)model |
| 88 modelIndex:(int)modelIndex; | 100 modelIndex:(int)modelIndex; |
| 89 @end | 101 @end |
| 90 | 102 |
| 91 #endif // UI_BASE_COCOA_MENU_CONTROLLER_H_ | 103 #endif // UI_BASE_COCOA_MENU_CONTROLLER_H_ |
| OLD | NEW |