Repository navigation
Canvas 36: add application items to the engine's own context menu - #73
Merged
Merged
Conversation
STORY-012-001 asks for the augment model beside Canvas 9's replace model: the engine's own right-click menu keeps every native item and carries the application's items (the Agentic App Framework's "Ask" on a selection). The analysis records the WebKitGTK spike, including that the lightweight component's engine menu opens at the top-left corner of the screen today. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XGTCDAC4LCHTgaKR6k2xMh
New augment-model API beside Canvas 9's replace model: WebViewComponent.addContextMenuContributor / removeContextMenuContributor / isContextMenuContributionSupported, WebViewContextMenuContributor, WebViewContextMenuItem and WebViewContextMenuContext. Every native item stays; contributed items are appended after a separator, and the chosen item's action runs once on the EDT with what the click hit (selected text, link, image, media, editable, click point, selection rectangle). - ContextMenuDispatcher builds the context from native hit-test data plus the newest Canvas 9 shim record (extended with the selection rectangle and text-control selection), asks contributors, and binds activation to a token of the newest shown menu. No JavaScript path reaches activation. - Linux: WebKitGTK "context-menu" signal with GAction items (optional runtime symbols). Lightweight: the engine menu now opens at the pointer (moved from the parked window via a GtkMenu::popped-up hook), and a right-button press is forwarded at release so GTK can grab the pointer; before this a normal right-click opened no menu at all. - macOS: class-wide -[WKWebView willOpenMenu:withEvent:] hook appending NSMenuItems. - Windows: ICoreWebView2_11 ContextMenuRequested with CreateContextMenuItem. - ContextMenuDispatcherTest, WebViewNativeContextMenuDemo with an automatic Linux check, run-*-native-context-menu-demo scripts, README. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XGTCDAC4LCHTgaKR6k2xMh
shannah
marked this pull request as ready for review
October 23, 2026 14:19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Applications can now add their own items to the browser engine's own right-click menu. The engine keeps every native item (Copy, Look Up, spelling suggestions, Back/Reload, Inspect Element when debugging, and so on), and the application's items are appended after them, below one separator. This is an augment model that sits next to Canvas 9's replace model (
WebViewMouseListener+WebViewContextMenu). Consumer: webliteca/agentic-app-framework's "Ask" item on a text selection.SPDD:
requirements/[User-story-12]…,spdd/analysis/…-[Analysis]-add-application-items-to-the-native-context-menu.md, and Canvas 36 (spdd/prompt/36-20261019-1500-[Feat]-Add-Application-Items-To-The-Native-Context-Menu.md). The code was produced from Canvas 36 with/spdd-generate. One finding from verification (D9b, below) went back into the Canvas before the code changed.API (additive, binary-compatible)
setDefaultContextMenuEnabled(true)the listener is told and the engine menu opens with the contributed items. Verified on Linux._is doubled on GTK,&is doubled on WebView2, and macOS titles are literal. Labels travel as UTF-16, so emoji survive.String[]answer back. The Canvas 9 base64/pipe record now has 5 more fields at the end: the selection rectangle and the selection inside a text field. The existing parser already accepts extra trailing fields.Per-platform status
context-menu+GActionitems, using optional runtime-loaded symbols-[WKWebView willOpenMenu:withEvent:]hook that appendsNSMenuItemsICoreWebView2_11::add_ContextMenuRequested+ICoreWebView2Environment9::CreateContextMenuItemLinux lightweight: what was verified (
NCMDEMO_AUTO=1 ./run-linux-native-context-menu-demo.shunder Xvfb →PASS, plus xdotool runs):Literal: snake_case & <b>no markup</b> 😀shows exactly as written;mvn test: 297 tests, 0 failures (26 new, inContextMenuDispatcherTest).Linux lightweight fixes that came with this (D9 / D9b)
GtkMenu::popped-upemission hook moves the menu under the pointer and keeps it inside the monitor's work area.BUTTON3press and forwards it together with the release. One side effect: a page's right-buttonmousedownandcontextmenunow fire at release, as they do on Windows.Limitations
WKWebViewownswillOpenMenu:withEvent:(the hook handles both cases);&in labels as an access key.Demo
demos/WebViewNativeContextMenuDemoandrun-{linux,mac}-native-context-menu-demo.sh/run-windows-native-context-menu-demo.bat.Generated by Claude Code