mac: Remove duplicate code of Popup
This commit is contained in:
parent
360266ba5b
commit
5f195a789a
1 changed files with 17 additions and 38 deletions
|
@ -19,35 +19,7 @@ MenuMac::MenuMac() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuMac::Popup(Window* window) {
|
void MenuMac::Popup(Window* window) {
|
||||||
NativeWindow* native_window = window->window();
|
PopupAt(window, -1, -1, 0);
|
||||||
if (!native_window)
|
|
||||||
return;
|
|
||||||
content::WebContents* web_contents = native_window->web_contents();
|
|
||||||
if (!web_contents)
|
|
||||||
return;
|
|
||||||
|
|
||||||
NSWindow* nswindow = native_window->GetNativeWindow();
|
|
||||||
base::scoped_nsobject<AtomMenuController> menu_controller(
|
|
||||||
[[AtomMenuController alloc] initWithModel:model_.get()]);
|
|
||||||
|
|
||||||
// Fake out a context menu event.
|
|
||||||
NSEvent* currentEvent = [NSApp currentEvent];
|
|
||||||
NSPoint position = [nswindow mouseLocationOutsideOfEventStream];
|
|
||||||
NSTimeInterval eventTime = [currentEvent timestamp];
|
|
||||||
NSEvent* clickEvent = [NSEvent mouseEventWithType:NSRightMouseDown
|
|
||||||
location:position
|
|
||||||
modifierFlags:NSRightMouseDownMask
|
|
||||||
timestamp:eventTime
|
|
||||||
windowNumber:[nswindow windowNumber]
|
|
||||||
context:nil
|
|
||||||
eventNumber:0
|
|
||||||
clickCount:1
|
|
||||||
pressure:1.0];
|
|
||||||
|
|
||||||
// Show the menu.
|
|
||||||
[NSMenu popUpContextMenu:[menu_controller menu]
|
|
||||||
withEvent:clickEvent
|
|
||||||
forView:web_contents->GetContentNativeView()];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuMac::PopupAt(Window* window, int x, int y, int positioning_item) {
|
void MenuMac::PopupAt(Window* window, int x, int y, int positioning_item) {
|
||||||
|
@ -63,16 +35,23 @@ void MenuMac::PopupAt(Window* window, int x, int y, int positioning_item) {
|
||||||
NSMenu* menu = [menu_controller menu];
|
NSMenu* menu = [menu_controller menu];
|
||||||
NSView* view = web_contents->GetContentNativeView();
|
NSView* view = web_contents->GetContentNativeView();
|
||||||
|
|
||||||
|
// Which menu item to show.
|
||||||
|
NSMenuItem* item = nil;
|
||||||
|
if (positioning_item < [menu numberOfItems] && positioning_item >= 0)
|
||||||
|
item = [menu itemAtIndex:positioning_item];
|
||||||
|
|
||||||
|
// (-1, -1) means showing on mouse location.
|
||||||
|
NSPoint position;
|
||||||
|
if (x == -1 || y == -1) {
|
||||||
|
NSWindow* nswindow = native_window->GetNativeWindow();
|
||||||
|
position = [view convertPoint:[nswindow mouseLocationOutsideOfEventStream]
|
||||||
|
fromView:nil];
|
||||||
|
} else {
|
||||||
|
position = NSMakePoint(x, [view frame].size.height - y);
|
||||||
|
}
|
||||||
|
|
||||||
// Show the menu.
|
// Show the menu.
|
||||||
if (positioning_item >= [menu numberOfItems]) {
|
[menu popUpMenuPositioningItem:item atLocation:position inView:view];
|
||||||
positioning_item = [menu numberOfItems] - 1;
|
|
||||||
}
|
|
||||||
if (positioning_item < 0) {
|
|
||||||
positioning_item = 0;
|
|
||||||
}
|
|
||||||
[menu popUpMenupositioning_item:[menu itemAtIndex:positioning_item]
|
|
||||||
atLocation:NSMakePoint(x, [view frame].size.height - y)
|
|
||||||
inView:view];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue