Translate menu template directly in C++
This commit is contained in:
parent
56e6b28370
commit
9236adfbf5
5 changed files with 100 additions and 98 deletions
|
@ -47,6 +47,7 @@
|
|||
#include "content/public/browser/storage_partition.h"
|
||||
#include "content/public/browser/site_instance.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
#include "content/public/common/context_menu_params.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "native_mate/object_template_builder.h"
|
||||
#include "net/http/http_response_headers.h"
|
||||
|
@ -407,8 +408,11 @@ void WebContents::RendererResponsive(content::WebContents* source) {
|
|||
}
|
||||
|
||||
bool WebContents::HandleContextMenu(const content::ContextMenuParams& params) {
|
||||
context_menu_context_ = params.custom_context;
|
||||
Emit("-context-menu", params);
|
||||
if (!params.custom_context.is_pepper_menu)
|
||||
return false;
|
||||
|
||||
Emit("pepper-context-menu", std::make_pair(params, web_contents()));
|
||||
web_contents()->NotifyContextMenuClosed(params.custom_context);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -848,15 +852,6 @@ void WebContents::RemoveWorkSpace(mate::Arguments* args,
|
|||
DevToolsRemoveFileSystem(path);
|
||||
}
|
||||
|
||||
void WebContents::ExecuteContextMenuCommand(int action) {
|
||||
web_contents()->ExecuteCustomContextMenuCommand(action,
|
||||
context_menu_context_);
|
||||
}
|
||||
|
||||
void WebContents::NotifyContextMenuClosed() {
|
||||
web_contents()->NotifyContextMenuClosed(context_menu_context_);
|
||||
}
|
||||
|
||||
void WebContents::Undo() {
|
||||
web_contents()->Undo();
|
||||
}
|
||||
|
@ -1068,10 +1063,6 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder(
|
|||
.SetMethod("_printToPDF", &WebContents::PrintToPDF)
|
||||
.SetMethod("addWorkSpace", &WebContents::AddWorkSpace)
|
||||
.SetMethod("removeWorkSpace", &WebContents::RemoveWorkSpace)
|
||||
.SetMethod("_executeContextMenuCommand",
|
||||
&WebContents::ExecuteContextMenuCommand)
|
||||
.SetMethod("_notifyContextMenuClosed",
|
||||
&WebContents::NotifyContextMenuClosed)
|
||||
.SetProperty("session", &WebContents::Session, true)
|
||||
.SetProperty("devToolsWebContents",
|
||||
&WebContents::DevToolsWebContents, true)
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
#include "atom/browser/api/trackable_object.h"
|
||||
#include "atom/browser/common_web_contents_delegate.h"
|
||||
#include "content/public/browser/web_contents_observer.h"
|
||||
#include "content/public/common/context_menu_params.h"
|
||||
#include "content/public/common/favicon_url.h"
|
||||
#include "native_mate/handle.h"
|
||||
#include "ui/gfx/image/image.h"
|
||||
|
@ -93,8 +92,6 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
|||
void SetAudioMuted(bool muted);
|
||||
bool IsAudioMuted();
|
||||
void Print(mate::Arguments* args);
|
||||
void ExecuteContextMenuCommand(int action);
|
||||
void NotifyContextMenuClosed();
|
||||
|
||||
// Print current page as PDF.
|
||||
void PrintToPDF(const base::DictionaryValue& setting,
|
||||
|
@ -259,9 +256,6 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
|||
// embedders' zoom level change.
|
||||
void OnZoomLevelChanged(double level);
|
||||
|
||||
// Recent unhandled context menu context.
|
||||
content::CustomContextMenuContext context_menu_context_;
|
||||
|
||||
v8::Global<v8::Value> session_;
|
||||
v8::Global<v8::Value> devtools_web_contents_;
|
||||
|
||||
|
|
|
@ -35,36 +35,6 @@ 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
|
||||
|
@ -96,15 +66,10 @@ 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()
|
||||
# Handle context menu action request from pepper plugin.
|
||||
webContents.on 'pepper-context-menu', (event, params) ->
|
||||
menu = Menu.buildFromTemplate params.menu
|
||||
menu.popup params.x, params.y
|
||||
|
||||
webContents.printToPDF = (options, callback) ->
|
||||
printingSetting =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue