browser: handle flash context menu
This commit is contained in:
parent
cb91d4487b
commit
c969052f12
10 changed files with 177 additions and 22 deletions
|
@ -1,4 +1,5 @@
|
|||
EventEmitter = require('events').EventEmitter
|
||||
Menu = require './menu'
|
||||
NavigationController = require './navigation-controller'
|
||||
binding = process.atomBinding 'web_contents'
|
||||
ipc = require 'ipc'
|
||||
|
@ -34,6 +35,36 @@ PDFPageSize =
|
|||
width_microns: 279400
|
||||
custom_display_name: "Tabloid"
|
||||
|
||||
clickHandler = (action) ->
|
||||
@_executeContextMenuCommand action
|
||||
|
||||
convertToMenuTemplate = (items, handler) ->
|
||||
template = []
|
||||
for item in items
|
||||
do (item) ->
|
||||
transformed =
|
||||
if item.type is 'submenu'
|
||||
type: 'submenu'
|
||||
label: item.label
|
||||
enabled: item.enabled
|
||||
submenu: convertToMenuTemplate item.subItems, handler
|
||||
else if item.type is 'separator'
|
||||
type: 'separator'
|
||||
else if item.type is 'checkbox'
|
||||
type: 'checkbox'
|
||||
label: item.label
|
||||
enabled: item.enabled
|
||||
checked: item.checked
|
||||
else
|
||||
type: 'normal'
|
||||
label: item.label
|
||||
enabled: item.enabled
|
||||
if item.id?
|
||||
transformed.click = ->
|
||||
handler item.id
|
||||
template.push transformed
|
||||
template
|
||||
|
||||
wrapWebContents = (webContents) ->
|
||||
# webContents is an EventEmitter.
|
||||
webContents.__proto__ = EventEmitter.prototype
|
||||
|
@ -65,6 +96,16 @@ wrapWebContents = (webContents) ->
|
|||
Object.defineProperty event, 'returnValue', set: (value) -> event.sendReply JSON.stringify(value)
|
||||
ipc.emit channel, event, args...
|
||||
|
||||
# Handle context menu action request from renderer widget.
|
||||
webContents.on '-context-menu', (event, params) ->
|
||||
if params.isPepperMenu
|
||||
template = convertToMenuTemplate(params.menuItems, clickHandler.bind(webContents))
|
||||
menu = Menu.buildFromTemplate template
|
||||
# The menu is expected to show asynchronously.
|
||||
setImmediate ->
|
||||
menu.popup params.x, params.y
|
||||
webContents._notifyContextMenuClosed()
|
||||
|
||||
webContents.printToPDF = (options, callback) ->
|
||||
printingSetting =
|
||||
pageRage: []
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue