Fix the menu popup on OS X.
This commit is contained in:
parent
d6103dd639
commit
9ef9f6bf95
2 changed files with 11 additions and 16 deletions
|
@ -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);
|
||||
|
|
|
@ -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()];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue