Merge pull request #4192 from evgenyzinoviev/menu-pr

Menu.popup: specify positioning item (OS X)
This commit is contained in:
Cheng Zhao 2016-01-22 10:49:17 -07:00
commit ea9b0cfed0
7 changed files with 20 additions and 10 deletions

View file

@ -52,7 +52,8 @@ class Menu : public mate::TrackableObject<Menu>,
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_;

View file

@ -20,7 +20,7 @@ class MenuMac : public Menu {
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_;

View file

@ -50,7 +50,7 @@ void MenuMac::Popup(Window* window) {
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;
@ -64,7 +64,13 @@ void MenuMac::PopupAt(Window* window, int x, int y) {
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];
}

View file

@ -20,7 +20,7 @@ void MenuViews::Popup(Window* window) {
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;

View file

@ -18,7 +18,7 @@ class MenuViews : public Menu {
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);

View file

@ -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) {
// Shift.
y = x;
@ -166,7 +166,7 @@ Menu.prototype.popup = function(window, x, y) {
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);
}