From: Cheng Zhao Date: Tue, 14 May 2013 11:25:14 +0000 (+0800) Subject: Fix the menu popup on OS X. X-Git-Tag: v0.1.0~181 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=9ef9f6bf95e36b0bdbb68a0f31db3ee5a58d2695;p=electron.git Fix the menu popup on OS X. --- diff --git a/browser/api/atom_api_menu_mac.h b/browser/api/atom_api_menu_mac.h index efaccd4b..d4ac1940 100644 --- a/browser/api/atom_api_menu_mac.h +++ b/browser/api/atom_api_menu_mac.h @@ -7,8 +7,6 @@ #include "browser/api/atom_api_menu.h" -#import "chrome/browser/ui/cocoa/menu_controller.h" - namespace atom { namespace api { @@ -19,9 +17,7 @@ class MenuMac : public Menu { virtual ~MenuMac(); protected: - virtual void Popup(NativeWindow* window, int x, int y) OVERRIDE; - - scoped_nsobject controller_; + virtual void Popup(NativeWindow* window) OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(MenuMac); diff --git a/browser/api/atom_api_menu_mac.mm b/browser/api/atom_api_menu_mac.mm index 7ad2b68a..f93b8cb9 100644 --- a/browser/api/atom_api_menu_mac.mm +++ b/browser/api/atom_api_menu_mac.mm @@ -7,6 +7,7 @@ #include "base/message_loop.h" #include "base/mac/scoped_sending_event.h" #include "browser/native_window.h" +#import "chrome/browser/ui/cocoa/menu_controller.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_view.h" @@ -15,25 +16,23 @@ namespace atom { namespace api { MenuMac::MenuMac(v8::Handle wrapper) - : Menu(wrapper), - controller_([[MenuController alloc] initWithModel:model_.get() - useWithPopUpButtonCell:NO]) { + : Menu(wrapper) { } MenuMac::~MenuMac() { } -void MenuMac::Popup(NativeWindow* native_window, int ox, int oy) { +void MenuMac::Popup(NativeWindow* native_window) { + scoped_nsobject menu_controller( + [[MenuController alloc] initWithModel:model_.get() + useWithPopUpButtonCell:NO]); + NSWindow* window = native_window->GetNativeWindow(); content::WebContents* web_contents = native_window->GetWebContents(); - CGFloat x = ox; - CGFloat y = oy; - // Fake out a context menu event. NSEvent* currentEvent = [NSApp currentEvent]; - NSView* web_view = web_contents->GetView()->GetNativeView(); - NSPoint position = { x, web_view.bounds.size.height - y }; + NSPoint position = [window mouseLocationOutsideOfEventStream]; NSTimeInterval eventTime = [currentEvent timestamp]; NSEvent* clickEvent = [NSEvent mouseEventWithType:NSRightMouseDown location:position @@ -57,9 +56,9 @@ void MenuMac::Popup(NativeWindow* native_window, int ox, int oy) { base::mac::ScopedSendingEvent sendingEventScoper; // Show the menu. - [NSMenu popUpContextMenu:[controller_ menu] + [NSMenu popUpContextMenu:[menu_controller menu] withEvent:clickEvent - forView:web_view]; + forView:web_contents->GetView()->GetContentNativeView()]; } }