#include "browser/api/atom_api_menu.h"
-#import "chrome/browser/ui/cocoa/menu_controller.h"
-
namespace atom {
namespace api {
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);
#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"
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
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()];
}
}