7

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.

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;
4

2 回答 2

17

要在 DCEF 3 中禁用上下文菜单,您需要处理OnBeforeContextMenu事件并清除其model参数。这就是参考文献所说的(我强调):

OnBeforeContextMenu

在显示上下文菜单之前调用。|参数| 提供有关上下文菜单状态的信息。|型号| 最初包含默认上下文菜单。|型号| 可以清除以不显示上下文菜单或修改以显示自定义菜单。不要保留对 |params| 的引用 或 |型号| 在这个回调之外。

因此,要完全禁用上下文菜单,您将编写如下内容:

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;
于 2013-09-06T07:36:42.803 回答
2

注意:在 C++ 版本中:

void ClientHandler::OnBeforeContextMenu(
    CefRefPtr<CefBrowser> browser,
    CefRefPtr<CefFrame> frame,
    CefRefPtr<CefContextMenuParams> params,
    CefRefPtr<CefMenuModel> model) {
  CEF_REQUIRE_UI_THREAD();

    //Clear disables the context menu
    model->Clear();
  }
}
于 2015-03-02T12:30:19.587 回答