Skip to content

Commit 87b4451

Browse files
author
Hosam Tageldin
committed
Added ContainsLink instead of the Link enum since multiple context types can contain a link
1 parent 665491d commit 87b4451

1 file changed

Lines changed: 25 additions & 23 deletions

File tree

specs/ContextMenuRequested.md

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -61,27 +61,27 @@ The developer can add or remove entries to the default WebView context menu. For
6161
CHECK_FAILURE(items->RemoveValueAtIndex(removeIndex));
6262
}
6363
}
64-
// Adding a custom context menu item for links that will display the link's URI.
65-
else if (context == COREWEBVIEW2_CONTEXT_KIND_LINK)
64+
// Adding a custom context menu item for the page that will display the page's URI.
65+
else if (context == COREWEBVIEW2_CONTEXT_KIND_PAGE)
6666
{
6767
wil::com_ptr<ICoreWebView2Environment> webviewEnvironment;
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 Link", L"Shorcut", nullptr, COREWEBVIEW2_CONTEXT_MENU_ITEM_KIND_NORMAL, true, false, &newMenuItem));
71+
CHECK_FAILURE(webviewEnvironment->CreateContextMenuItem(L"Display page Uri", L"Shorcut", nullptr, COREWEBVIEW2_CONTEXT_MENU_ITEM_KIND_NORMAL, true, false, &newMenuItem));
7272
newMenuItem->add_CustomItemSelected(Callback<ICoreWebView2CustomItemSelectedEventHandler>(
7373
[this, info](
7474
ICoreWebView2* sender,
7575
IUnknown* args)
7676
{
77-
wil::unique_cotaskmem_string linkUri;
78-
CHECK_FAILURE(info->get_LinkUri(&linkUri));
79-
std::wstring linkString = linkUri.get();
80-
m_appWindow->RunAsync([this, linkString]()
77+
wil::unique_cotaskmem_string pageUri;
78+
CHECK_FAILURE(info->get_PageUri(&pageUri));
79+
std::wstring pageString = pageUri.get();
80+
m_appWindow->RunAsync([this, pageString]()
8181
{
8282
MessageBox(
83-
m_appWindow->GetMainWindow(), linkString.c_str(),
84-
L"Display Link", MB_OK);
83+
m_appWindow->GetMainWindow(), pageString.c_str(),
84+
L"Display Page Uri", MB_OK);
8585
});
8686
return S_OK;
8787
})
@@ -114,7 +114,7 @@ The developer can use the data provided in the Event arguments to display a cust
114114
HMENU hPopupMenu = CreatePopupMenu();
115115
AddMenuItems(hPopupMenu, items);
116116
HWND hWnd;
117-
CHECK_FAILURE(m_appWindow->GetWebViewController()->get_ParentWindow(&hWnd));
117+
m_controller->get_ParentWindow(&hWnd);
118118
SetForegroundWindow(hWnd);
119119
wil::com_ptr<ICoreWebView2ContextMenuInfo> parameters;
120120
CHECK_FAILURE(args->get_ContextMenuInfo(&parameters));
@@ -224,17 +224,17 @@ The developer can use the data provided in the Event arguments to display a cust
224224
// removes the last item in the collection
225225
menuList.RemoveAt(menuList.Count - 1);
226226
}
227-
else if (context == CoreWebView2ContextKind.Link)
227+
else if (context == CoreWebView2ContextKind.Page)
228228
{
229229
// add new item to end of collection
230230
CoreWebView2ContextMenuItem newItem = webView.CoreWebView2.Environment.CreateContextMenuItem(
231-
"Display Link", "Shorcut", null, CoreWebView2ContextMenuItemKind.Normal,1, 0);
231+
"Display Page Uri", "Shorcut", null, CoreWebView2ContextMenuItemKind.Normal,1, 0);
232232
newItem.CustomItemSelected += delegate (object send, Object ex)
233233
{
234-
string linkUri = args.ContextMenuInfo.LinkUri;
234+
string pageUri = args.ContextMenuInfo.PageUri;
235235
System.Threading.SynchronizationContext.Current.Post((_) =>
236236
{
237-
MessageBox.Show(linkUri, "Display Link", MessageBoxButton.YesNo);
237+
MessageBox.Show(pageUri, "Page Uri", MessageBoxButton.YesNo);
238238
}, null);
239239
}
240240
menuList.Insert(menuList.Count, newItem);
@@ -405,9 +405,6 @@ The developer can use the data provided in the Event arguments to display a cust
405405
/// Indicates that the context menu was created for a selection.
406406
COREWEBVIEW2_CONTEXT_KIND_SELECTION,
407407

408-
/// Indicates that the context menu was created for a link.
409-
COREWEBVIEW2_CONTEXT_KIND_LINK,
410-
411408
/// Indicates that the context menu was created for an editable component.
412409
COREWEBVIEW2_CONTEXT_KIND_EDITABLE,
413410
@@ -625,10 +622,14 @@ The developer can use the data provided in the Event arguments to display a cust
625622
/// FALSE if invoked on another frame.
626623
[propget] HRESULT IsMainFrame([out, retval] BOOL* value);
627624

625+
/// Returns TRUE if the context menu request occured on a component
626+
/// that contained a link.
627+
[propget] HRESULT ContainsLink([out, retval] BOOL* value);
628+
628629
/// Gets the uri of the page.
629630
[propget] HRESULT PageUri([out, retval] LPWSTR* value);
630631

631-
/// Gets the uri of the frame. Will match the PageUri is `get_IsMainFrame` is TRUE.
632+
/// Gets the uri of the frame. Will match the PageUri if `get_IsMainFrame` is TRUE.
632633
[propget] HRESULT FrameUri([out, retval] LPWSTR* value);
633634

634635
/// Gets the source uri of element (if context menu requested on a media element, null otherwise).
@@ -687,11 +688,10 @@ namespace Microsoft.Web.WebView2.Core
687688
{
688689
Page = 0,
689690
Selection = 1,
690-
Link = 2,
691-
Editable = 3,
692-
Audio = 4,
693-
Image = 5,
694-
Video = 6,
691+
Editable = 2,
692+
Audio = 3,
693+
Image = 4,
694+
Video = 5,
695695
};
696696
697697
enum CoreWebView2ContextMenuItemKind
@@ -716,6 +716,8 @@ namespace Microsoft.Web.WebView2.Core
716716
{
717717
Point Location { get; }
718718
CoreWebView2ContextKind ContextKind { get; }
719+
Boolean IsMainFrame { get; }
720+
Boolean ContainsLink { get; }
719721
String PageUri { get; }
720722
String FrameUri { get; }
721723
String SourceUri { get; }

0 commit comments

Comments
 (0)