Skip to content

Commit 0d805ae

Browse files
author
Hosam Tageldin
committed
Moved Notes/Remarks comments to specific methods and parameters
1 parent ab04077 commit 0d805ae

1 file changed

Lines changed: 11 additions & 22 deletions

File tree

specs/ContextMenuRequested.md

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
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.
44

55
# 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:
77

88
1. An ordered list of ContextMenuItem objects (contains name, label, kind, Shortcut Desc and other properties) to be shown in the context menu.
99
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
315315
```
316316
# Remarks
317317

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-
328318
# API Notes
329319

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-
338320
# API Details
339321
```cpp
340322
interface ICoreWebView2_4;
@@ -348,6 +330,9 @@ The developer can use the data provided in the Event arguments to display a cust
348330

349331
/// Indicates the kind of context for which the context menu was created
350332
/// 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.
351336
[v1_enum]
352337
typedef enum COREWEBVIEW2_CONTEXT_MENU_TARGET_KIND
353338
{
@@ -421,14 +406,14 @@ The developer can use the data provided in the Event arguments to display a cust
421406
/// Gets the `ContextMenuItem` kind.
422407
[propget] HRESULT Kind([out, retval] COREWEBVIEW2_CONTEXT_MENU_ITEM_KIND* value);
423408

424-
/// Sets the enabled property of the `ContextMenuItem`. Should only be used in the case of a
409+
/// Sets the enabled property of the `ContextMenuItem`. Must only be used in the case of a
425410
/// custom context menu item. The default value for this is `TRUE`.
426411
[propput] HRESULT IsEnabled([in] BOOL value);
427412

428413
/// Gets the enabled property of the `ContextMenuItem`.
429414
[propget] HRESULT IsEnabled([out, retval] BOOL* value);
430415

431-
/// Sets the checked property of the `ContextMenuItem`. Should only used for custom context
416+
/// Sets the checked property of the `ContextMenuItem`. Must only be used for custom context
432417
/// menu items that are of type Check box or Radio.
433418
[propput] HRESULT isChecked([in] BOOL value);
434419

@@ -496,6 +481,8 @@ The developer can use the data provided in the Event arguments to display a cust
496481
/// CoreWebView2 will rewind the stream before decoding. Command Id for new
497482
/// custom menu items will be unique for the lifespan of the ContextMenuRequested
498483
/// event. They will be a unique value between 52600 and 52650.
484+
/// The returned `ContextMenuItem` object's `IsEnabled` property will default to `TRUE`
485+
/// and `IsChecked` property will default to `FALSE`.
499486
HRESULT CreateContextMenuItem(
500487
[in] LPCWSTR label,
501488
[in] IStream* iconStream,
@@ -543,7 +530,9 @@ The developer can use the data provided in the Event arguments to display a cust
543530
[propget] HRESULT Location([out, retval] POINT* value);
544531

545532
/// Sets the selected command for the WebView to execute. The value is
546-
/// obtained via the `ContextMenuItem` CommandId property
533+
/// obtained via the `ContextMenuItem` CommandId property.
534+
/// This value should always be from context menu items for the relevant context menu and
535+
/// event arg. Attempting to mix will result in invalid outputs.
547536
/// The default value is -1 which means that no selected occured.
548537
[propput] HRESULT SelectedCommandId([in] INT32 value);
549538

0 commit comments

Comments
 (0)