diff options
-rw-r--r-- | chrome/browser/renderer_host/render_widget_host_view_mac.mm | 13 | ||||
-rw-r--r-- | webkit/glue/webmenurunner_mac.h | 34 | ||||
-rw-r--r-- | webkit/glue/webmenurunner_mac.mm | 40 | ||||
-rwxr-xr-x | webkit/tools/test_shell/mac/test_webview_delegate.mm | 15 |
4 files changed, 54 insertions, 48 deletions
diff --git a/chrome/browser/renderer_host/render_widget_host_view_mac.mm b/chrome/browser/renderer_host/render_widget_host_view_mac.mm index da5347a..d6f67fe 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_mac.mm +++ b/chrome/browser/renderer_host/render_widget_host_view_mac.mm @@ -282,18 +282,19 @@ void RenderWidgetHostViewMac::ShowPopupWithItems( bounds.width(), bounds.height()); // Display the menu. - WebMenuRunner* menu_runner = - [[[WebMenuRunner alloc] initWithItems:items] autorelease]; + scoped_nsobject<WebMenuRunner> menu_runner; + menu_runner.reset([[WebMenuRunner alloc] initWithItems:items]); [menu_runner runMenuInView:parent_view_ withBounds:position initialIndex:selected_item]; int window_num = [[parent_view_ window] windowNumber]; - NSEvent* event = CreateEventForMenuAction([menu_runner menuItemWasChosen], - window_num, item_height, - [menu_runner indexOfSelectedItem], - position, view_rect); + NSEvent* event = + webkit_glue::EventWithMenuAction([menu_runner menuItemWasChosen], + window_num, item_height, + [menu_runner indexOfSelectedItem], + position, view_rect); if ([menu_runner menuItemWasChosen]) { // Simulate a menu selection event. diff --git a/webkit/glue/webmenurunner_mac.h b/webkit/glue/webmenurunner_mac.h index eceaa3f..8d822a4 100644 --- a/webkit/glue/webmenurunner_mac.h +++ b/webkit/glue/webmenurunner_mac.h @@ -9,6 +9,7 @@ #include <vector> +#include "base/scoped_nsobject.h" #include "webkit/glue/webwidget_delegate.h" @@ -20,8 +21,8 @@ @interface WebMenuRunner : NSObject { @private - // The actual menu object, which we own. - NSMenu* menu_; + // The native menu control. + scoped_nsobject<NSMenu> menu_; // A flag set to YES if a menu item was chosen, or NO if the menu was // dismissed without selecting an item. @@ -33,20 +34,11 @@ // Initializes the MenuDelegate with a list of items sent from WebKit. - (id)initWithItems:(const std::vector<WebMenuItem>&)items; -- (void)dealloc; - -// Worker function used during initialization. -- (void)addItem:(const WebMenuItem&)item; // Returns YES if an item was selected from the menu, NO if the menu was // dismissed. - (BOOL)menuItemWasChosen; -// A callback for the menu controller object to call when an item is selected -// from the menu. This is not called if the menu is dismissed without a -// selection. -- (void)menuItemSelected:(id)sender; - // Displays and runs a native popup menu. - (void)runMenuInView:(NSView*)view withBounds:(NSRect)bounds @@ -58,14 +50,16 @@ @end // @interface WebMenuRunner -// Helper function for manufacturing input events to send to WebKit. If -// |item_chosen| is YES, we manufacture a mouse click event that corresponds to -// the menu item that was selected, |selected_index|, based on the position of -// the mouse click. Of |item_chosen| is NO, we create a keyboard event that -// simulates an ESC (menu dismissal) action. The event is designed to be sent to -// WebKit for processing by the PopupMenu class. -NSEvent* CreateEventForMenuAction(BOOL item_chosen, int window_num, - int item_height, int selected_index, - NSRect menu_bounds, NSRect view_bounds); +namespace webkit_glue { +// Helper function for users of WebMenuRunner, for manufacturing input events to +// send to WebKit. If |item_chosen| is YES, we manufacture a mouse click event +// that corresponds to the menu item that was selected, |selected_index|, based +// on the position of the mouse click. Of |item_chosen| is NO, we create a +// keyboard event that simulates an ESC (menu dismissal) action. The event is +// designed to be sent to WebKit for processing by the PopupMenu class. +NSEvent* EventWithMenuAction(BOOL item_chosen, int window_num, + int item_height, int selected_index, + NSRect menu_bounds, NSRect view_bounds); +} // namespace webkit_glue #endif // WEBKIT_GLUE_WEBMENURUNNER_MAC_H_ diff --git a/webkit/glue/webmenurunner_mac.mm b/webkit/glue/webmenurunner_mac.mm index 32bedf3..c6b2b243 100644 --- a/webkit/glue/webmenurunner_mac.mm +++ b/webkit/glue/webmenurunner_mac.mm @@ -6,13 +6,24 @@ #include "base/sys_string_conversions.h" +@interface WebMenuRunner (PrivateAPI) + +// Worker function used during initialization. +- (void)addItem:(const WebMenuItem&)item; + +// A callback for the menu controller object to call when an item is selected +// from the menu. This is not called if the menu is dismissed without a +// selection. +- (void)menuItemSelected:(id)sender; + +@end // WebMenuRunner (PrivateAPI) + @implementation WebMenuRunner - (id)initWithItems:(const std::vector<WebMenuItem>&)items { if ((self = [super init])) { - menu_ = [[NSMenu alloc] initWithTitle:@""]; + menu_.reset([[NSMenu alloc] initWithTitle:@""]); [menu_ setAutoenablesItems:NO]; - menuItemWasChosen_ = NO; index_ = -1; for (int i = 0; i < static_cast<int>(items.size()); ++i) [self addItem:items[i]]; @@ -20,11 +31,6 @@ return self; } -- (void)dealloc { - [menu_ release]; - [super dealloc]; -} - - (void)addItem:(const WebMenuItem&)item { if (item.type == WebMenuItem::SEPARATOR) { [menu_ addItem:[NSMenuItem separatorItem]]; @@ -32,11 +38,11 @@ } NSString* title = base::SysUTF16ToNSString(item.label); - NSMenuItem* menu_item = [menu_ addItemWithTitle:title - action:@selector(menuItemSelected:) - keyEquivalent:@""]; - [menu_item setEnabled:(item.enabled && item.type != WebMenuItem::GROUP)]; - [menu_item setTarget:self]; + NSMenuItem* menuItem = [menu_ addItemWithTitle:title + action:@selector(menuItemSelected:) + keyEquivalent:@""]; + [menuItem setEnabled:(item.enabled && item.type != WebMenuItem::GROUP)]; + [menuItem setTarget:self]; } // Reflects the result of the user's interaction with the popup menu. If NO, the @@ -76,10 +82,12 @@ @end // WebMenuRunner +namespace webkit_glue { + // Helper function for manufacturing input events to send to WebKit. -NSEvent* CreateEventForMenuAction(BOOL item_chosen, int window_num, - int item_height, int selected_index, - NSRect menu_bounds, NSRect view_bounds) { +NSEvent* EventWithMenuAction(BOOL item_chosen, int window_num, + int item_height, int selected_index, + NSRect menu_bounds, NSRect view_bounds) { NSEvent* event = nil; double event_time = (double)(AbsoluteToDuration(UpTime())) / 1000.0; @@ -128,3 +136,5 @@ NSEvent* CreateEventForMenuAction(BOOL item_chosen, int window_num, return event; } + +} // namespace webkit_glue diff --git a/webkit/tools/test_shell/mac/test_webview_delegate.mm b/webkit/tools/test_shell/mac/test_webview_delegate.mm index a1d1815..d6bcf02 100755 --- a/webkit/tools/test_shell/mac/test_webview_delegate.mm +++ b/webkit/tools/test_shell/mac/test_webview_delegate.mm @@ -5,8 +5,8 @@ #include "webkit/tools/test_shell/test_webview_delegate.h" #import <Cocoa/Cocoa.h> -#include "base/sys_string_conversions.h" #include "base/string_util.h" +#include "base/sys_string_conversions.h" #include "third_party/WebKit/WebKit/chromium/public/WebRect.h" #include "webkit/glue/webcursor.h" #include "webkit/glue/webview.h" @@ -79,8 +79,8 @@ void TestWebViewDelegate::ShowAsPopupWithItems( bounds.width, bounds.height); // Display the menu. - WebMenuRunner* menu_runner = - [[[WebMenuRunner alloc] initWithItems:items] autorelease]; + scoped_nsobject<WebMenuRunner> menu_runner; + menu_runner.reset([[WebMenuRunner alloc] initWithItems:items]); [menu_runner runMenuInView:shell_->webViewWnd() withBounds:position @@ -91,11 +91,12 @@ void TestWebViewDelegate::ShowAsPopupWithItems( // position based on the selected index and provided bounds. WebWidgetHost* popup = shell_->popupHost(); int window_num = [shell_->mainWnd() windowNumber]; + NSEvent* event = + webkit_glue::EventWithMenuAction([menu_runner menuItemWasChosen], + window_num, item_height, + [menu_runner indexOfSelectedItem], + position, view_rect); - NSEvent* event = CreateEventForMenuAction([menu_runner menuItemWasChosen], - window_num, item_height, - [menu_runner indexOfSelectedItem], - position, view_rect); if ([menu_runner menuItemWasChosen]) { // Construct a mouse up event to simulate the selection of an appropriate // menu item. |