Repository navigation
fix(win32): Move XAML focus to the WebView2 when the browser takes focus (backport #26263) - #26270
Merged
Merged
Conversation
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)
1 of 5 tasks
….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]>
Xiaoy312
approved these changes
Nov 9, 2026
Contributor
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
TextBoxkept XAML focus: it never gotLostFocusand kept drawing its blinking caret next to the browser's caret, while keystrokes went to the browser.Win32NativeAotWebViewnow handles the controller'sGotFocusand focuses the owning WebView2 withFocusState.Pointer, matching WinUI, where pressing a WebView2 focuses it (WebView2::HandlePointerPressed). It does nothing when the control hasIsTabStop=falseor is already focused. The other direction (WebView2 toTextBox) already worked:WM_POINTERDOWNreclaims Win32 focus.Validation: I used the kahua-private#498 repro, with a probe that diffs screen captures of the
TextBoxand 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 theTextBox, click the editor again.TextBoxhas focus leaves both carets blinking, and XAML focus stays on theTextBox.LosingFocus TextBox -> WebView2, thenSubjectBox.LostFocus, and only the browser caret blinks.TextBoxto 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.WebView2backend (Win32NativeWebView, the net9 default, or selected withUNO_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_WebView2excludes SkiaWin32, and the bug needs real Win32 focus moving into the browser process.PR Checklist ✅
Screenshots Compare Test Runresults.🤖 Generated with Claude Code
This is an automatic backport of pull request #26263 done by [Mergify](https://mergify.com).