Revert "Use property isKeyWindow for key window condition check"

Commit: 679e39bc | 2025-11-26 04:17:23+00:00

โ† Back to List

Revert "Use property isKeyWindow for key window condition check"

Minor
Commit Hash: 679e39bca9ac08473a75014cc5b7e1731b0afa02
Commit Time: 2025-11-26 04:17:23+00:00
Impact Level: Minor
Generated By: webview2-upstream-sentry
Upstream Review: View Upstream Review ๐Ÿ”—

๐Ÿ“‹ Summary

This commit reverts a change to the macOS window key status checking mechanism. The original change modified the condition check in the -windowDidResignKey: method from [NSApp keyWindow] == [self window] to [self window].isKeyWindow, but this broke the original intention for the menu extra user scenario. The revert restores the condition check to [NSApp keyWindow] == [self window] to ensure that when a menu extra (on the system status bar) is activated, the application does not incorrectly process window resignation events.

The specific change is located in the -windowDidResignKey: method in content/app_shim_remote_cocoa/render_widget_host_view_cocoa.mm (line 1768).

๐ŸŽฏ Impact Analysis

The impact of this revert on WebView2Mac is **Minor**.

**Impact Analysis:**

1. **Scope of Impact:** This revert affects the -windowDidResignKey: method of the RenderWidgetHostViewCocoa class, which handles notifications when the window loses keyboard focus. WebView2Mac uses RenderWidgetHostViewCocoa from remote_cocoa to manage NSView through inheritance and composition, so it will be affected by this change.

2. **Functional Impact:** The revert restores the original logic for handling menu extra activation. In the original implementation, when a user clicks a menu extra on the system status bar, the application receives a windowDidResignKey notification, but [NSApp keyWindow] may still point to the current window. In this case, the application should ignore this notification because the window has not actually lost focusโ€”only the menu extra has temporarily gained focus. If the window subsequently truly loses focus, another windowDidResignKey notification will be received.

3. **WebView2Mac-Specific Impact:**
- As an embedded control, WebView2Mac typically does not directly manage menu extras on the system status bar, so the menu extra scenario has minimal impact on WebView2Mac
- The revert ensures correct window focus state determination, helping WebView2Mac properly handle focus change events, such as canceling ongoing text composition
- If a WebView2Mac host application uses menu extra functionality, the revert can prevent unnecessary focus loss notifications from being propagated to the renderer process

4. **Risk Assessment:** The revert itself is intended to fix issues caused by the original change and restore a verified stable implementation, so the risk is low.

Impacted Classes:

RenderWidgetHostViewCocoa remote_cocoa::mojom::RenderWidgetHostNSViewHost