specify positioning item for popup menus
This commit is contained in:
parent
7842a657d0
commit
072ab0ddea
7 changed files with 20 additions and 10 deletions
|
@ -52,7 +52,8 @@ class Menu : public mate::TrackableObject<Menu>,
|
||||||
void MenuWillShow(ui::SimpleMenuModel* source) override;
|
void MenuWillShow(ui::SimpleMenuModel* source) override;
|
||||||
|
|
||||||
virtual void Popup(Window* window) = 0;
|
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_;
|
scoped_ptr<AtomMenuModel> model_;
|
||||||
Menu* parent_;
|
Menu* parent_;
|
||||||
|
|
|
@ -20,7 +20,7 @@ class MenuMac : public Menu {
|
||||||
MenuMac();
|
MenuMac();
|
||||||
|
|
||||||
void Popup(Window* window) override;
|
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_;
|
base::scoped_nsobject<AtomMenuController> menu_controller_;
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ void MenuMac::Popup(Window* window) {
|
||||||
forView:web_contents->GetContentNativeView()];
|
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();
|
NativeWindow* native_window = window->window();
|
||||||
if (!native_window)
|
if (!native_window)
|
||||||
return;
|
return;
|
||||||
|
@ -64,7 +64,13 @@ void MenuMac::PopupAt(Window* window, int x, int y) {
|
||||||
NSView* view = web_contents->GetContentNativeView();
|
NSView* view = web_contents->GetContentNativeView();
|
||||||
|
|
||||||
// Show the menu.
|
// 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)
|
atLocation:NSMakePoint(x, [view frame].size.height - y)
|
||||||
inView:view];
|
inView:view];
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ void MenuViews::Popup(Window* window) {
|
||||||
PopupAtPoint(window, gfx::Screen::GetNativeScreen()->GetCursorScreenPoint());
|
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());
|
NativeWindow* native_window = static_cast<NativeWindow*>(window->window());
|
||||||
if (!native_window)
|
if (!native_window)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -18,7 +18,7 @@ class MenuViews : public Menu {
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void Popup(Window* window) override;
|
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:
|
private:
|
||||||
void PopupAtPoint(Window* window, const gfx::Point& point);
|
void PopupAtPoint(Window* window, const gfx::Point& point);
|
||||||
|
|
|
@ -158,7 +158,7 @@ Menu.prototype._init = function() {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
Menu.prototype.popup = function(window, x, y) {
|
Menu.prototype.popup = function(window, x, y, positioningItem) {
|
||||||
if ((window != null ? window.constructor : void 0) !== BrowserWindow) {
|
if ((window != null ? window.constructor : void 0) !== BrowserWindow) {
|
||||||
// Shift.
|
// Shift.
|
||||||
y = x;
|
y = x;
|
||||||
|
@ -166,7 +166,7 @@ Menu.prototype.popup = function(window, x, y) {
|
||||||
window = BrowserWindow.getFocusedWindow();
|
window = BrowserWindow.getFocusedWindow();
|
||||||
}
|
}
|
||||||
if ((x != null) && (y != null)) {
|
if ((x != null) && (y != null)) {
|
||||||
return this._popupAt(window, x, y);
|
return this._popupAt(window, x, y, positioningItem || 0);
|
||||||
} else {
|
} else {
|
||||||
return this._popup(window);
|
return this._popup(window);
|
||||||
}
|
}
|
||||||
|
|
|
@ -237,15 +237,18 @@ Generally, the `template` is just an array of `options` for constructing a
|
||||||
You can also attach other fields to the element of the `template` and they
|
You can also attach other fields to the element of the `template` and they
|
||||||
will become properties of the constructed menu items.
|
will become properties of the constructed menu items.
|
||||||
|
|
||||||
### `Menu.popup([browserWindow, x, y])`
|
### `Menu.popup([browserWindow, x, y, positioningItem])`
|
||||||
|
|
||||||
* `browserWindow` BrowserWindow (optional)
|
* `browserWindow` BrowserWindow (optional)
|
||||||
* `x` Number (optional)
|
* `x` Number (optional)
|
||||||
* `y` Number (**required** if `x` is used)
|
* `y` Number (**required** if `x` is used)
|
||||||
|
* `positioningItem` Number (optional) _OS X_
|
||||||
|
|
||||||
Pops up this menu as a context menu in the `browserWindow`. You
|
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
|
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)`
|
### `Menu.append(menuItem)`
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue