Refactoring of the macOS 26 Title Bar Right-Click Fix Solution

Commit: bba7ce65 | 2025-08-29 20:12:04+00:00

← Back to List

Refactoring of the macOS 26 Title Bar Right-Click Fix Solution

Moderate
Commit Hash: bba7ce651a9ce526356393923e183c70371fcea4
Commit Time: 2025-08-29 20:12:04+00:00
Impact Level: Moderate
Generated By: webview2-upstream-sentry
Upstream Review: View Upstream Review 🔗

📋 Summary

This submission implements a new fix for the issue of right-clicking on the title bar in macOS 26. The main changes include: removal of the original NSToolbarView swizzling mechanism (swizzle_ns_toolbar_view_hit_test.h/mm), and addition of a method override mechanism for NSNextStepFrame (override_ns_next_step_frame_hit_test.h/mm). The new solution ensures that right-click events are correctly delivered to Chrome’s view by overriding the _hitTestForEvent: method of NSNextStepFrame, thereby resolving the issue where the right-click menu could not be displayed in fullscreen mode. Additionally, a TabTitlebarView class has been added in immersive_mode_tabbed_controller_cocoa.mm to support the new event handling mechanism.

🎯 Impact Analysis

This change has a moderate impact on WebView2Mac. Firstly, the positive impacts include: the remote_cocoa component inherited by WebView2Mac will gain a more reliable mouse event handling mechanism, especially in fullscreen mode on macOS 26, where the right-click context menu functionality will become more stable. The new NSNextStepFrame override mechanism is more robust compared to the previous NSToolbarView swizzling approach, as NSNextStepFrame is the starting point for mouse event hit-testing and cannot be bypassed. Secondly, potential risks include: the new solution is more intrusive, as it overrides internal AppKit methods, which may face compatibility issues in future macOS versions. Components such as hosting_ns_window_bridge in WebView2Mac that rely on specific mouse event handling flows may need to be validated for compatibility with the new mechanism. Since the change involves underlying event handling mechanisms, it is recommended to conduct comprehensive testing of WebView2Mac’s context menu, drag-and-drop operations, and other interactive features.

Impacted Classes:

remote_cocoa::ImmersiveModeTabbedControllerCocoa NSNextStepFrame(新重写的AppKit类) TabTitlebarView(新增的自定义视图类) NSToolbarView(移除了相关的swizzling机制)