在Chromium Embedded 3(DCEF3)中禁用上下文菜单
我正在尝试禁用Chromium Embedded(DCEF3)窗口中的鼠标右键(上下文菜单),但是我没有得到,我没有发现任何设置可以原生进行此操作。
I'm trying to disable the right mouse button (the context menu) in the window of Chromium Embedded (DCEF3) but I'm not getting, I did not find any settings to do this natively.
例如,我可以禁用查看源代码,我正在使用下面的代码,但我确实想要禁用上下文菜单,或者不希望它出现。
I can for example disable the "View Source", I am using the code below, but I really want is to disable the context menu, or do not want it to appear.
注意:我正在DLL Chromium.dll中使用此库,该库与 Inno Setup一起使用,等同于Inno Web Brower。
Note: I'm using this in DLL "Chromium.dll" a libray to be used with the "Inno Setup", equal to Inno Web Brower.
procedure TInnoChromium.OnContextMenuCommand(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame;
const params: ICefContextMenuParams; commandId: Integer;
eventFlags: TCefEventFlags; out Result: Boolean);
begin
if (commandId = 132) then Result := True; // MENU_ID_VIEW_SOURCE
end;
要禁用DCEF 3中的上下文菜单,您将需要处理 OnBeforeContextMenu
事件并清除其 model
参数。这就是引用所陈述的内容(我强调):
To disable the context menu in DCEF 3 you'll need to handle the OnBeforeContextMenu
event and clear its model
parameter. That's what the reference states (emphasized by me):
OnBeforeContextMenu
在显示上下文菜单之前调用。 |参数|提供有关上下文菜单状态的
信息。 |型号|最初包含
的默认上下文菜单。 |型号|可以清除以不显示
上下文菜单,也可以修改以显示自定义菜单。不要保留
对| params |的引用。或| model |
Called before a context menu is displayed. |params| provides information about the context menu state. |model| initially contains the default context menu. The |model| can be cleared to show no context menu or modified to show a custom menu. Do not keep references to |params| or |model| outside of this callback.
因此,要完全禁用上下文菜单,您将编写如下内容:
So, to completely disable the context menu you will write something like this:
uses
cefvcl, ceflib;
type
TInnoChromium = class
...
private
FChromium: TChromium;
procedure BeforeContextMenu(Sender: TObject; const browser: ICefBrowser;
const frame: ICefFrame;
public
constructor Create;
end;
implementation
constructor TInnoChromium.Create;
begin
FChromium := TChromium.Create(nil);
...
FChromium.OnBeforeContextMenu := BeforeContextMenu;
end;
procedure TInnoChromium.BeforeContextMenu(Sender: TObject; const browser: ICefBrowser;
const frame: ICefFrame; const params: ICefContextMenuParams; const model: ICefMenuModel);
begin
// to disable the context menu clear the model parameter
model.Clear;
end;