Skip to content

fix(win32): Move XAML focus to the WebView2 when the browser takes focus (backport #26263) - #26270

Merged
agneszitte merged 2 commits into
servicing/6.8from
mergify/bp/servicing/6.8/pr-26263
Nov 9, 2026
Merged

agneszitte merged 2 commits into
servicing/6.8from
mergify/bp/servicing/6.8/pr-26263

Conversation

@mergify

@mergify mergify Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

GitHub Issue: related to unoplatform/kahua-private#498

PR Type:

🐞 Bugfix

What changed? 🚀

On Win32 (Skia desktop), the WebView2 browser lives in a native child HWND. Clicking into it moves Win32 keyboard focus to the browser, but the click never reaches XAML. So a previously focused TextBox kept XAML focus: it never got LostFocus and kept drawing its blinking caret next to the browser's caret, while keystrokes went to the browser.

Win32NativeAotWebView now handles the controller's GotFocus and focuses the owning WebView2 with FocusState.Pointer, matching WinUI, where pressing a WebView2 focuses it (WebView2::HandlePointerPressed). It does nothing when the control has IsTabStop=false or is already focused. The other direction (WebView2 to TextBox) already worked: WM_POINTERDOWN reclaims Win32 focus.

Validation: I used the kahua-private#498 repro, with a probe that diffs screen captures of the TextBox and WebView2 regions to detect which carets actually blink, plus XAML, DOM and OS focus logging. In each case the sequence was: click the editor, click the TextBox, click the editor again.

  • Before: clicking the editor while the TextBox has focus leaves both carets blinking, and XAML focus stays on the TextBox.
  • After: LosingFocus TextBox -> WebView2, then SubjectBox.LostFocus, and only the browser caret blinks. TextBox to editor and back still works.

Checked on master (7.1.0-dev.115 app with the rebuilt runtime) and on 6.7.359.

Backports: 6.7 and 6.8 still ship the managed Microsoft.Web.WebView2 backend (Win32NativeWebView, the net9 default, or selected with UNO_WEBVIEW2_BACKEND). It needs the same handler, which I'll add to the backport PRs. Verified on 6.7 with both backends.

No runtime test: Given_WebView2 excludes SkiaWin32, and the bug needs real Win32 focus moving into the browser process.

PR Checklist ✅

🤖 Generated with Claude Code


This is an automatic backport of pull request #26263 done by [Mergify](https://mergify.com).

The browser lives in a native child HWND, so clicking into it never reaches
XAML: the previously focused element (e.g. a TextBox) kept XAML focus and its
blinking caret while keystrokes went to the browser, leaving two carets.
Focus the WebView2 (FocusState.Pointer) on the controller's GotFocus, matching
WinUI where pressing the WebView2 focuses it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 5c58266)
….WebView2 backend

Same fix as for the WebView2Aot backend, for the managed backend still used
by net9 apps and UNO_WEBVIEW2_BACKEND=microsoft.web.webview2 on this line.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@agneszitte
agneszitte merged commit 12d4d2c into servicing/6.8 Nov 9, 2026
29 of 42 checks passed
@agneszitte
agneszitte deleted the mergify/bp/servicing/6.8/pr-26263 branch November 9, 2026 23:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants