Introduce support for triggering context menu via keyboard (Ctrl+Enter) on macOS

Commit: 268c876c | 2026-02-26 22:05:47

← Back to List

Introduce support for triggering context menu via keyboard (Ctrl+Enter) on macOS

Moderate
Commit Hash: 268c876c191cd4712c2d1043aab9760fb71d9be5
Commit Time: 2026-02-26 22:05:47
Impact Level: Moderate
Generated By: webview2-upstream-sentry
Upstream Review: View Upstream Review 🔗

📋 Summary

This commit adds support for the standard Ctrl+Enter macOS keyboard shortcut to open context menus by implementing the contextMenuKeyDown handler. Changes span multiple layers: BridgedContentView in components/remote_cocoa/app_shim/bridged_content_view.mm gains a contextMenuKeyDown: method that translates Ctrl+Enter into a VKEY_APPS/CONTEXT_MENU key event and dispatches it; RenderWidgetHostViewCocoa in content/app_shim_remote_cocoa/render_widget_host_view_cocoa.mm gains a contextMenuKeyDown: method that creates a context menu key event when not in text input mode; Blink layer (web_view_impl.cc, web_frame_widget_impl.cc) removes the IS_MAC exclusion so Mac can handle VKEY_APPS triggering SendContextMenuEvent; ui/views/widget/root_view.cc removes the IS_MAC exclusion and adds Mac-specific VKEY_APPS validation (only triggers on kKeyPressed without Command modifier).

🎯 Impact Analysis

This change has a direct impact on WebView2Mac. Modifications involve two key Remote Cocoa layer files: bridged_content_view.mm (Views layer Cocoa view bridge) and render_widget_host_view_cocoa.mm (renderer process Cocoa view). The new contextMenuKeyDown: methods in both files affect keyboard-triggered context menu behavior in WebView2Mac. When a user presses Ctrl+Enter in a webpage hosted by WebView2Mac while not in text input mode, RenderWidgetHostViewCocoa converts it to a context menu key event sent to the renderer, where Blink will show the context menu. Views layer controls (via BridgedContentView) also gain keyboard context menu triggering. Edge downstream has no overrides for contextMenuKeyDown or related keyboard context menu logic. This is a new feature addition and a positive improvement, but it is recommended to verify that the Ctrl+Enter shortcut in WebView2Mac does not conflict with host application custom shortcuts.

Impacted Classes:

remote_cocoa::BridgedContentView RenderWidgetHostViewCocoa blink::WebViewImpl blink::WebFrameWidgetImpl views::internal::RootView