-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy pathContextMenuHandler.cs
More file actions
101 lines (91 loc) · 5.31 KB
/
ContextMenuHandler.cs
File metadata and controls
101 lines (91 loc) · 5.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// 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
{
/// <summary>
/// Inherit from this class to handle context menu events.
/// </summary>
public class ContextMenuHandler : IContextMenuHandler
{
/// <inheritdoc/>
void IContextMenuHandler.OnBeforeContextMenu(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters,
IMenuModel model)
{
OnBeforeContextMenu(chromiumWebBrowser, browser, frame, parameters, model);
}
/// <summary>
/// Called before a context menu is displayed. The model can be cleared to show no context menu or
/// modified to show a custom menu.
/// </summary>
/// <param name="chromiumWebBrowser">the ChromiumWebBrowser control</param>
/// <param name="browser">the browser object</param>
/// <param name="frame">The frame the request is coming from</param>
/// <param name="parameters">provides information about the context menu state</param>
/// <param name="model">initially contains the default context menu</param>
protected virtual void OnBeforeContextMenu(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters,
IMenuModel model)
{
}
/// <inheritdoc/>
bool IContextMenuHandler.OnContextMenuCommand(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters,
CefMenuCommand commandId, CefEventFlags eventFlags)
{
return OnContextMenuCommand(chromiumWebBrowser, browser, frame, parameters, commandId, eventFlags);
}
/// <summary>
/// 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.
/// </summary>
/// <param name="chromiumWebBrowser">the ChromiumWebBrowser control</param>
/// <param name="browser">the browser object</param>
/// <param name="frame">The frame the request is coming from</param>
/// <param name="parameters">will have the same values as what was passed to</param>
/// <param name="commandId">menu command id</param>
/// <param name="eventFlags">event flags</param>
/// <returns>Return true if the command was handled or false for the default implementation.</returns>
protected virtual bool OnContextMenuCommand(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters,
CefMenuCommand commandId, CefEventFlags eventFlags)
{
return false;
}
/// <inheritdoc/>
void IContextMenuHandler.OnContextMenuDismissed(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame)
{
OnContextMenuDismissed(chromiumWebBrowser, browser, frame);
}
/// <summary>
/// Called when the context menu is dismissed irregardless of whether the menu
/// was empty or a command was selected.
/// </summary>
/// <param name="chromiumWebBrowser">the ChromiumWebBrowser control</param>
/// <param name="browser">the browser object</param>
/// <param name="frame">The frame the request is coming from</param>
protected virtual void OnContextMenuDismissed(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame)
{
}
/// <inheritdoc/>
bool IContextMenuHandler.RunContextMenu(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback)
{
return RunContextMenu(chromiumWebBrowser, browser, frame, parameters, model, callback);
}
/// <summary>
/// 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.
/// </summary>
/// <param name="chromiumWebBrowser">the ChromiumWebBrowser control</param>
/// <param name="browser">the browser object</param>
/// <param name="frame">The frame the request is coming from</param>
/// <param name="parameters">provides information about the context menu state</param>
/// <param name="model">contains the context menu model resulting from OnBeforeContextMenu</param>
/// <param name="callback">the callback to execute for custom display</param>
/// <returns>For custom display return true and execute callback either synchronously or asynchronously with the selected command ID.</returns>
protected virtual bool RunContextMenu(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback)
{
return false;
}
}
}