// Copyright © 2021 The CefSharp Authors. All rights reserved. // // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. namespace CefSharp.Handler { /// /// Inherit from this class to handle context menu events. /// public class ContextMenuHandler : IContextMenuHandler { /// void IContextMenuHandler.OnBeforeContextMenu(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model) { OnBeforeContextMenu(chromiumWebBrowser, browser, frame, parameters, model); } /// /// Called before a context menu is displayed. The model can be cleared to show no context menu or /// modified to show a custom menu. /// /// the ChromiumWebBrowser control /// the browser object /// The frame the request is coming from /// provides information about the context menu state /// initially contains the default context menu protected virtual void OnBeforeContextMenu(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model) { } /// bool IContextMenuHandler.OnContextMenuCommand(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags) { return OnContextMenuCommand(chromiumWebBrowser, browser, frame, parameters, commandId, eventFlags); } /// /// Called to execute a command selected from the context menu. See /// cef_menu_id_t for the command ids that have default implementations. All /// user-defined command ids should be between MENU_ID_USER_FIRST and /// MENU_ID_USER_LAST. /// /// the ChromiumWebBrowser control /// the browser object /// The frame the request is coming from /// will have the same values as what was passed to /// menu command id /// event flags /// Return true if the command was handled or false for the default implementation. protected virtual bool OnContextMenuCommand(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags) { return false; } /// void IContextMenuHandler.OnContextMenuDismissed(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame) { OnContextMenuDismissed(chromiumWebBrowser, browser, frame); } /// /// Called when the context menu is dismissed irregardless of whether the menu /// was canceled or a command was selected. /// /// the ChromiumWebBrowser control /// the browser object /// The frame the request is coming from protected virtual void OnContextMenuDismissed(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame) { } /// bool IContextMenuHandler.RunContextMenu(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback) { return RunContextMenu(chromiumWebBrowser, browser, frame, parameters, model, callback); } /// /// Called to allow custom display of the context menu. /// For custom display return true and execute callback either synchronously or asynchronously with the selected command Id. /// For default display return false. Do not keep references to parameters or model outside of this callback. /// /// the ChromiumWebBrowser control /// the browser object /// The frame the request is coming from /// provides information about the context menu state /// contains the context menu model resulting from OnBeforeContextMenu /// the callback to execute for custom display /// For custom display return true and execute callback either synchronously or asynchronously with the selected command ID. protected virtual bool RunContextMenu(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback) { return false; } } }