Cancel IME composition when window loses focus

Commit: 15e4e76e | 2025-11-06 05:05:21+00:00

← Back to List

Cancel IME composition when window loses focus

Minor
Commit Hash: 15e4e76e2191eb01cfcdb79c957677c32390db5e
Commit Time: 2025-11-06 05:05:21+00:00
Impact Level: Minor
Generated By: webview2-upstream-sentry
Upstream Review: View Upstream Review 🔗

📋 Summary

This commit adds a new feature on macOS that automatically cancels ongoing IME (Input Method Editor) composition when a window loses focus. The specific changes include:
1. A new macOS-specific feature flag kCancelCompositionWhenWindowLosesFocus (enabled by default) is added in content/common/features.h and features.cc
2. In the windowDidResignKey: method of render_widget_host_view_cocoa.mm, when the window loses key status, if the feature flag is enabled, [self cancelComposition] is called to cancel the current IME composition

This fix is designed to prevent IME composition state from remaining active in the background, avoiding incorrect input being committed when the window regains focus.

🎯 Impact Analysis

This change has a direct and positive impact on WebView2Mac. The modification occurs in content/app_shim_remote_cocoa/render_widget_host_view_cocoa.mm, which is one of the core files that WebView2Mac depends on through the Remote Cocoa architecture. The specific impacts are as follows:

1. **Functional Improvement**: WebView2Mac will benefit from this fix, ensuring that ongoing IME composition is properly canceled when the host window loses focus, preventing subsequent input errors.

2. **User Experience Enhancement**: For users of IME input methods such as Chinese, Japanese, and Korean, this fix prevents input anomalies during window switching, improving the consistency and reliability of the input experience.

3. **Behavior Change**: The new feature is enabled by default, meaning WebView2Mac windows will automatically cancel IME composition when losing focus. This is a behavior change, but it's an improvement rather than a breaking change.

4. **Controllability**: Implemented as a feature flag, it provides flexibility for downstream consumers. If this behavior causes issues, it can be rolled back by disabling the feature flag.

5. **Compatibility**: The change only affects the macOS platform and enhances functionality within the existing RenderWidgetHostViewCocoa class without breaking existing APIs or interfaces.

Overall, this is a low-risk functional improvement that directly enhances WebView2Mac's robustness in handling input methods, especially in multi-window scenarios.

Impacted Classes:

RenderWidgetHostViewCocoa features::kCancelCompositionWhenWindowLosesFocus