API Review: Custom context menu Spellcheck#5553
API Review: Custom context menu Spellcheck#5553anuragkumar878 wants to merge 12 commits intomainfrom
Conversation
|
@microsoft-github-policy-service agree company="Microsoft" |
There was a problem hiding this comment.
Pull request overview
This PR introduces a new API review spec to extend the existing WebView2 ContextMenuRequested customization flow with spellcheck support, enabling hosts that render custom context menus to surface and apply spellcheck suggestions.
Changes:
- Adds a new spec describing custom-context-menu spellcheck scenarios and motivation.
- Provides Win32 C++ and C# example flows for querying suggestions, handling async readiness, and applying a suggestion.
- Proposes new Win32 COM interfaces (
ICoreWebView2ContextMenuTarget2,ICoreWebView2ContextMenuRequestedEventArgs2) plus corresponding .NET/WinRT projections.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
shrinaths
left a comment
There was a problem hiding this comment.
Review Summary
The architecture and design are sound — DeferredCapabilityDiscovery, ContextMenuItemCollection return type, unified SelectedCommandId commanding, and always-async callback are all well done. The comments below focus on bringing the spec up to the polish expected for Windows API review board submission:
Must fix:
- Placeholder UUIDs (lines 260, 298, 320) — generate real values
- .NET projection should use [interface_name] pattern, not EventArgs2 class (line 363)
- Verify MIDL3 format requirement with SDK team (line 233)
Should fix:
- Rename title to "Spellcheck Support for Custom Context Menus"
- Complete the samples (both C++ and C# have undefined helpers / placeholder comments)
- Add CHECK_FAILURE() consistently in C++ sample
- Fix SelectedCommandId default value in error table (it's -1, not 0)
Nit:
- Consistent casing of "spellcheck" in prose
- Avoid contractions per Microsoft style guide
- Use /// doc comments in .NET projection
- Clean up casual language ("for example -")
| // ... use spellCheck ... | ||
| } | ||
|
|
||
| // Future: no new EventArgs versions needed, just new flag constants. |
There was a problem hiding this comment.
Discussion of future work in this area is interesting, but would be good to move to the appendix to avoid confusion since we're not actually doing that work here. Also for the IDL and elsewhere in the document other than background and appendix
| [this, args, spellCheck, items, deferral, | ||
| word = std::wstring(misspelledWord.get())]() | ||
| { | ||
| spellCheck->GetSpellCheckSuggestionsAsync( |
There was a problem hiding this comment.
The implication of this sample code is that GetSpellCheckSuggestionsAsync is fast enough that you can delay showing the entire context menu until it async completes. Is this always true? I thought at some point the browser would show an initial context menu and then update it async later when the spell check suggestions become available. This should be documented.
| cur->get_Name(&name); | ||
| // Skip built-in spellcheck items already | ||
| // handled above. | ||
| if (wcsstr(name.get(), L"spellCheck")) |
There was a problem hiding this comment.
Why is this built-in spellcheck item here and what is the relationship between it and this new spellcheck work? Should we be placing the new spell check menu items in place of this menu item rather than at the top? We should document this.
|
|
||
| **Async contract:** The handler fires exactly once, always asynchronously (posted to the caller's | ||
| message loop, never invoked inline). Only one handler may be registered; a second call returns | ||
| `E_ILLEGAL_METHOD_CALL`. |
There was a problem hiding this comment.
Does this mean you can't call GetSpellCheckSuggestionsAsync twice? We should be able to call GetSpellCheckSuggestionsAsync more than once. Or what exactly does it mean by 'Only one handler may be registered'? If this trying to describe standard async method behavior then you can just say that instead.
| /// Retrieves the capability-specific interface for a deferred | ||
| /// capability. Returns null if the capability is not applicable. | ||
| /// </summary> | ||
| T GetDeferredCapability<T>(); |
There was a problem hiding this comment.
The deferred capability APIs seem unnecessarily complex. Instead lets put CoreWebView2ContextMenuSpellCheck directly as a SpellCheck property on ICoreWebView2ContextMenuRequestedEventArgs2. We already have to handle cases where its an old runtime and the newer interface isn't supported and have the end dev have a way to detect and handle this case. For additional cases where its a newer runtime but spell check is not available we can have a null SpellCheck property.
| deferral.Complete(); | ||
| } | ||
| }; | ||
| contextMenu.Show(webView, new Point(args.Location.X, args.Location.Y)); |
There was a problem hiding this comment.
The C++ sample uses the RunAsync method to get out of the event handler before doing its work. Do we need similar here?
| /// and its `CommandId` can be passed to `put_SelectedCommandId` to apply | ||
| /// the correction. | ||
| /// | ||
| /// Only one handler may be registered per event invocation. A second call |
| /// the correction. | ||
| /// | ||
| /// Only one handler may be registered per event invocation. A second call | ||
| /// returns `E_ILLEGAL_METHOD_CALL`. |
There was a problem hiding this comment.
Same question about calling the method multiple times I had at the top. We shouldn't throw if you call the method more than once.
Spellcheck Suggestions for Custom Context Menus
Enables host apps rendering custom context menus to discover, retrieve, and apply spellcheck suggestions for misspelled words in editable fields. Introduces a
deferred capability discovery pattern on EventArgs2 that is extensible to future async capabilities without additional EventArgs versions.
New Interfaces:
ICoreWebView2ContextMenuRequestedEventArgs2 extends ICoreWebView2ContextMenuRequestedEventArgs
ICoreWebView2ContextMenuSpellCheck (acquired via GetDeferredCapability)
Fires immediately (via PostTask) if suggestions are already resolved, or deferred until ready.
ICoreWebView2GetSpellCheckSuggestionsCompletedHandler
ICoreWebView2ContextMenuItem with Label (suggestion text) and CommandId (opaque identifier).
Usage flow:
Key design decisions: