Merge pull request #8739 from electron/pepper-context-menu

Use owner browser window in pepper context menu
This commit is contained in:
Kevin Sawicki 2017-02-24 09:05:33 -08:00 committed by GitHub
commit d01250eceb
2 changed files with 6 additions and 3 deletions

View file

@ -147,12 +147,12 @@ Menu.prototype.popup = function (window, x, y, positioningItem) {
let asyncPopup = false let asyncPopup = false
// menu.popup(x, y, positioningItem) // menu.popup(x, y, positioningItem)
if (typeof window !== 'object' || window.constructor !== BrowserWindow) { if (window != null && (typeof window !== 'object' || window.constructor !== BrowserWindow)) {
// Shift. // Shift.
positioningItem = y positioningItem = y
y = x y = x
x = window x = window
window = BrowserWindow.getFocusedWindow() window = null
} }
// menu.popup(window, {}) // menu.popup(window, {})
@ -164,6 +164,9 @@ Menu.prototype.popup = function (window, x, y, positioningItem) {
asyncPopup = options.async asyncPopup = options.async
} }
// Default to showing in focused window.
if (window == null) window = BrowserWindow.getFocusedWindow()
// Default to showing under mouse location. // Default to showing under mouse location.
if (typeof x !== 'number') x = -1 if (typeof x !== 'number') x = -1
if (typeof y !== 'number') y = -1 if (typeof y !== 'number') y = -1

View file

@ -253,7 +253,7 @@ WebContents.prototype._init = function () {
this.on('pepper-context-menu', function (event, params) { this.on('pepper-context-menu', function (event, params) {
// Access Menu via electron.Menu to prevent circular require // Access Menu via electron.Menu to prevent circular require
const menu = electron.Menu.buildFromTemplate(params.menu) const menu = electron.Menu.buildFromTemplate(params.menu)
menu.popup(params.x, params.y) menu.popup(event.sender.getOwnerBrowserWindow(), params.x, params.y)
}) })
// The devtools requests the webContents to reload. // The devtools requests the webContents to reload.