void MenuWillShow(ui::SimpleMenuModel* source) override;
virtual void Popup(Window* window) = 0;
- virtual void PopupAt(Window* window, int x, int y) = 0;
+ virtual void PopupAt(Window* window, int x, int y,
+ int positioningItem = 0) = 0;
scoped_ptr<AtomMenuModel> model_;
Menu* parent_;
MenuMac();
void Popup(Window* window) override;
- void PopupAt(Window* window, int x, int y) override;
+ void PopupAt(Window* window, int x, int y, int positioningItem = 0) override;
base::scoped_nsobject<AtomMenuController> menu_controller_;
forView:web_contents->GetContentNativeView()];
}
-void MenuMac::PopupAt(Window* window, int x, int y) {
+void MenuMac::PopupAt(Window* window, int x, int y, int positioningItem) {
NativeWindow* native_window = window->window();
if (!native_window)
return;
NSView* view = web_contents->GetContentNativeView();
// Show the menu.
- [menu popUpMenuPositioningItem:[menu itemAtIndex:0]
+ if (positioningItem >= [menu numberOfItems]) {
+ positioningItem = [menu numberOfItems] - 1;
+ }
+ if (positioningItem < 0) {
+ positioningItem = 0;
+ }
+ [menu popUpMenuPositioningItem:[menu itemAtIndex:positioningItem]
atLocation:NSMakePoint(x, [view frame].size.height - y)
inView:view];
}
PopupAtPoint(window, gfx::Screen::GetNativeScreen()->GetCursorScreenPoint());
}
-void MenuViews::PopupAt(Window* window, int x, int y) {
+void MenuViews::PopupAt(Window* window, int x, int y, int positioningItem) {
NativeWindow* native_window = static_cast<NativeWindow*>(window->window());
if (!native_window)
return;
protected:
void Popup(Window* window) override;
- void PopupAt(Window* window, int x, int y) override;
+ void PopupAt(Window* window, int x, int y, int positioningItem = 0) override;
private:
void PopupAtPoint(Window* window, const gfx::Point& point);
};
};
-Menu.prototype.popup = function(window, x, y) {
+Menu.prototype.popup = function(window, x, y, positioningItem) {
if ((window != null ? window.constructor : void 0) !== BrowserWindow) {
// Shift.
y = x;
window = BrowserWindow.getFocusedWindow();
}
if ((x != null) && (y != null)) {
- return this._popupAt(window, x, y);
+ return this._popupAt(window, x, y, positioningItem || 0);
} else {
return this._popup(window);
}
You can also attach other fields to the element of the `template` and they
will become properties of the constructed menu items.
-### `Menu.popup([browserWindow, x, y])`
+### `Menu.popup([browserWindow, x, y, positioningItem])`
* `browserWindow` BrowserWindow (optional)
* `x` Number (optional)
* `y` Number (**required** if `x` is used)
+* `positioningItem` Number (optional) _OS X_
Pops up this menu as a context menu in the `browserWindow`. You
can optionally provide a `x,y` coordinate to place the menu at, otherwise it
-will be placed at the current mouse cursor position.
+will be placed at the current mouse cursor position. `positioningItem` is the
+index of the menu item to be positioned under the mouse cursor at the specified
+coordinates (only supported on OS X).
### `Menu.append(menuItem)`