Skip to content

Commit 13772c0

Browse files
author
Hosam Tageldin
committed
Changed some of the enums to booleans to allow more versatility with context types
1 parent 87b4451 commit 13772c0

1 file changed

Lines changed: 22 additions & 19 deletions

File tree

specs/ContextMenuRequested.md

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ There currently is no method using WebView2 APIs to customize the default contex
55
# Description
66
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:
77

8-
1. The list of default ContextMenuItem objects (contains name, Descriptor, kind/type, Shorcut Desc and other properties)
8+
1. The list of default ContextMenuItem objects (contains name, Descriptor, kind, Shortcut Desc and other properties)
99
2. The coordinates where the context menu was requested. For instance where the end user right clicked.
10-
3. A selection object that will include the type of context selected, and the appropriate context menu parameter data.
10+
3. A selection object that will include the kind of context selected, and the appropriate context menu parameter data.
1111

1212
and have the choice to:
1313

@@ -68,7 +68,7 @@ The developer can add or remove entries to the default WebView context menu. For
6868
CHECK_FAILURE(m_appWindow->GetWebViewEnvironment()->QueryInterface(
6969
IID_PPV_ARGS(&webviewEnvironment)));
7070
wil::com_ptr<ICoreWebView2ContextMenuItem> newMenuItem;
71-
CHECK_FAILURE(webviewEnvironment->CreateContextMenuItem(L"Display page Uri", L"Shorcut", nullptr, COREWEBVIEW2_CONTEXT_MENU_ITEM_KIND_NORMAL, true, false, &newMenuItem));
71+
CHECK_FAILURE(webviewEnvironment->CreateContextMenuItem(L"Display page Uri", L"Shortcut", nullptr, COREWEBVIEW2_CONTEXT_MENU_ITEM_KIND_NORMAL, true, false, &newMenuItem));
7272
newMenuItem->add_CustomItemSelected(Callback<ICoreWebView2CustomItemSelectedEventHandler>(
7373
[this, info](
7474
ICoreWebView2* sender,
@@ -228,7 +228,7 @@ The developer can use the data provided in the Event arguments to display a cust
228228
{
229229
// add new item to end of collection
230230
CoreWebView2ContextMenuItem newItem = webView.CoreWebView2.Environment.CreateContextMenuItem(
231-
"Display Page Uri", "Shorcut", null, CoreWebView2ContextMenuItemKind.Normal,1, 0);
231+
"Display Page Uri", "Shortcut", null, CoreWebView2ContextMenuItemKind.Normal,1, 0);
232232
newItem.CustomItemSelected += delegate (object send, Object ex)
233233
{
234234
string pageUri = args.ContextMenuInfo.PageUri;
@@ -402,17 +402,14 @@ The developer can use the data provided in the Event arguments to display a cust
402402
/// Indicates that the context menu was created for the page without any additional content.
403403
COREWEBVIEW2_CONTEXT_KIND_PAGE,
404404

405-
/// Indicates that the context menu was created for a selection.
406-
COREWEBVIEW2_CONTEXT_KIND_SELECTION,
405+
/// Indicates that the context menu was created for an image element.
406+
COREWEBVIEW2_CONTEXT_KIND_IMAGE,
407407

408-
/// Indicates that the context menu was created for an editable component.
409-
COREWEBVIEW2_CONTEXT_KIND_EDITABLE,
408+
/// Indicates that the context menu was created for selected text.
409+
COREWEBVIEW2_CONTEXT_KIND_SELECTED_TEXT,
410410
411411
/// Indicates that the context menu was created for an audio element.
412412
COREWEBVIEW2_CONTEXT_KIND_AUDIO,
413-
414-
/// Indicates that the context menu was created for an image element.
415-
COREWEBVIEW2_CONTEXT_KIND_IMAGE,
416413
417414
/// Indicates that the context menu was created for a video element.
418415
COREWEBVIEW2_CONTEXT_KIND_VIDEO,
@@ -535,7 +532,7 @@ The developer can use the data provided in the Event arguments to display a cust
535532
interface ICoreWebView2Environment : IUnknown
536533
{
537534
/// Create a `ContextMenuItem` object to insert into the WebView context menu.
538-
/// The `IsChecked` property will only be used if the menu item type is Radio or Checkbox.
535+
/// The `IsChecked` property will only be used if the menu item kind is Radio or Checkbox.
539536
/// For more information regarding paramters, see `ContextMenuItem`.
540537
HRESULT CreateContextMenuItem(
541538
[in] LPCWSTR label,
@@ -622,8 +619,13 @@ The developer can use the data provided in the Event arguments to display a cust
622619
/// FALSE if invoked on another frame.
623620
[propget] HRESULT IsMainFrame([out, retval] BOOL* value);
624621

625-
/// Returns TRUE if the context menu request occured on a component
626-
/// that contained a link.
622+
/// Returns TRUE if the context menu is requested on a selection.
623+
[propget] HRESULT HasSelection([out, retval] BOOL* value);
624+
625+
/// Returns TRUE if the context menu is requested on an editable component.
626+
[propget] HRESULT IsEditable([out, retval] BOOL* value);
627+
628+
/// Returns TRUE if the context menu is requested on a component that contains a link.
627629
[propget] HRESULT ContainsLink([out, retval] BOOL* value);
628630

629631
/// Gets the uri of the page.
@@ -641,7 +643,7 @@ The developer can use the data provided in the Event arguments to display a cust
641643
/// Gets the text of the link (if context menu requested on a link, null otherwise).
642644
[propget] HRESULT LinkText([out, retval] LPWSTR * value);
643645

644-
/// Gets the selected text (if context menu was invoked on a selection, null otherwise).
646+
/// Gets the selected text (available when HasSelection is TRUE, null otherwise).
645647
[propget] HRESULT SelectionText([out, retval] LPWSTR* value);
646648
}
647649
```
@@ -687,11 +689,10 @@ namespace Microsoft.Web.WebView2.Core
687689
enum CoreWebView2ContextKind
688690
{
689691
Page = 0,
690-
Selection = 1,
691-
Editable = 2,
692+
Image = 1,
693+
SelectedText = 2,
692694
Audio = 3,
693-
Image = 4,
694-
Video = 5,
695+
Video = 4,
695696
};
696697
697698
enum CoreWebView2ContextMenuItemKind
@@ -717,6 +718,8 @@ namespace Microsoft.Web.WebView2.Core
717718
Point Location { get; }
718719
CoreWebView2ContextKind ContextKind { get; }
719720
Boolean IsMainFrame { get; }
721+
Boolean HasSelection { get; }
722+
Boolean IsEditable { get; }
720723
Boolean ContainsLink { get; }
721724
String PageUri { get; }
722725
String FrameUri { get; }

0 commit comments

Comments
 (0)