summaryrefslogtreecommitdiffstats
path: root/webkit/glue/webmenurunner_mac.mm
diff options
context:
space:
mode:
authorpaul@chromium.org <paul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-28 23:34:37 +0000
committerpaul@chromium.org <paul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-28 23:34:37 +0000
commitcf9995bcc40e8fd67551f660b7fe37cfd00b2c79 (patch)
treef60576273e0a6b61b89b9fb678ea6491dea0d7cd /webkit/glue/webmenurunner_mac.mm
parent3544b434280f752c4934346ce58adb5d2ea5e24b (diff)
downloadchromium_src-cf9995bcc40e8fd67551f660b7fe37cfd00b2c79.zip
chromium_src-cf9995bcc40e8fd67551f660b7fe37cfd00b2c79.tar.gz
chromium_src-cf9995bcc40e8fd67551f660b7fe37cfd00b2c79.tar.bz2
Style fixes for previous review:
http://codereview.chromium.org/92062 I didn't make WebMenuRunner's menu_ a scoped_nsobject, because I'm not sure how that will ever be released (~scoped_nsobject won't get called from a Cocoa object's dealloc?). Review URL: http://codereview.chromium.org/99088 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14798 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/webmenurunner_mac.mm')
-rw-r--r--webkit/glue/webmenurunner_mac.mm40
1 files changed, 25 insertions, 15 deletions
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