You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: specs/ContextMenuRequested.md
+11-22Lines changed: 11 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
There currently is no method using WebView2 APIs to customize the default context menu experience. Currently, the only option using WebView2 APIs is to show or disable the default context menu. We have been requested by WebView2 app developers to allow for customization of the context menu experience. This has produced two different customization paths for context menus. The first option is to allow the app developers to create their own context menu UI using data passed from the WebView and the second is to allow app developers to add and remove items from the default context menus.
4
4
5
5
# Description
6
-
We propose two new events for WebView2, `CoreWebView2ContextMenuRequested` that will allow developers to listen to context menus being requested by the end user in the WebView2 and `CoreWebView2CustomItemSelected` that will notify the developer that one of their inserted context menu items was selected. When a context menu is requested in WebView2, the app developer will receive:
6
+
We propose two new events for WebView2, `CoreWebView2ContextMenuRequested` that will allow developers to listen to context menus being requested by the end user in the WebView2 and `CoreWebView2CustomItemSelected` that will notify the developer that one of their inserted context menu items was selected. `CoreWebView2ContextMenuRequested` will only be raised if the page allows the context menu to appear. If the WebView2 `AreDefaultContextMenusEnabled` setting is set to `False`, this event will not be raised. When a context menu is requested in WebView2, the app developer will receive:
7
7
8
8
1. An ordered list of ContextMenuItem objects (contains name, label, kind, Shortcut Desc and other properties) to be shown in the context menu.
9
9
2. The coordinates where the context menu was requested in relation to the upper left corner of the webview bounds.
@@ -315,26 +315,8 @@ The developer can use the data provided in the Event arguments to display a cust
315
315
```
316
316
# Remarks
317
317
318
-
1. Developers should only use command IDs from context menu items for the relevant context menu and event arg. Attempting to mix will result in unexpected and invalid outputs.
319
-
320
-
2. Developers should never add an item as a child of itself, this will cause undefined results.
321
-
322
-
3. Forbidden usage of the IsEnabled property include setting the property for menu items that are not a custom menu item or of type separator.
323
-
324
-
4. Forbidden usage of the IsChecked property include setting the property for menu items that are not a custom context menu item or not of type Check Box and Radio.
325
-
326
-
5. The `ContextMenuTargetKind` will always represent the active element that caused the context menu request. If there is a selection with multiple images, audio and text, for example, the element that the user selects within this selection will still be the option represented by the `ContextMenuTargetKind` enum.
327
-
328
318
# API Notes
329
319
330
-
1. The `ContextMenuRequested` event will only be raised if the page allows the context menu to appear. If the settings option for `AreDefaultContextMenusEnabled` is set to false, then the `ContextMenuRequested` event will not be raised.
331
-
332
-
2. The Label uses ampersands as a prefix to indicate the accelator key.
333
-
334
-
3. Command Ids will be unique for custom menu items and no guarantee they will be the same for each menu item case, must always use the command Id given by the event arg.
335
-
336
-
4. When creating a new custom context menu item using `CreateContextMenuItem`, the item's `IsEnabled` property will default to `TRUE` and `IsChecked` property will default to `FALSE`.
337
-
338
320
# API Details
339
321
```cpp
340
322
interface ICoreWebView2_4;
@@ -348,6 +330,9 @@ The developer can use the data provided in the Event arguments to display a cust
348
330
349
331
/// Indicates the kind of context for which the context menu was created
350
332
/// for the `ICoreWebView2ContextMenuTarget::get_Kind` method.
333
+
/// This enum will always represent the active element that caused the context menu request.
334
+
/// If there is a selection with multiple images, audio and text, for example, the element that
335
+
/// the end user right clicks on within this selection will be the option represented by this enum.
351
336
[v1_enum]
352
337
typedefenum COREWEBVIEW2_CONTEXT_MENU_TARGET_KIND
353
338
{
@@ -421,14 +406,14 @@ The developer can use the data provided in the Event arguments to display a cust
0 commit comments