]> khamidou — GitHub mirrors - electron.git/commitdiff
Fix the menu popup on OS X.
authorCheng Zhao <zcbenz@gmail.com>
Tue, 14 May 2013 11:25:14 +0000 (19:25 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Tue, 14 May 2013 11:25:14 +0000 (19:25 +0800)
browser/api/atom_api_menu_mac.h
browser/api/atom_api_menu_mac.mm

index efaccd4bd06723ddc067ebeaf9f63147a6a8126f..d4ac19406ebcc18b5d4ebdcea8b122c83b9aab11 100644 (file)
@@ -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<MenuController> controller_;
+  virtual void Popup(NativeWindow* window) OVERRIDE;
 
  private:
   DISALLOW_COPY_AND_ASSIGN(MenuMac);
index 7ad2b68ad4f2f53a457d13b38765cbf032a33fa7..f93b8cb92fba6a84915da93fb73923c60c02446b 100644 (file)
@@ -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<v8::Object> 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<MenuController> 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()];
   }
 }