Skip to content

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

Merged
Xiaoy312 merged 1 commit into
masterfrom
dev/xygu/20261109/webview2-xaml-focus
Nov 9, 2026
Merged

Xiaoy312 merged 1 commit into
masterfrom
dev/xygu/20261109/webview2-xaml-focus

Conversation

@Xiaoy312

@Xiaoy312 Xiaoy312 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

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]>
@Xiaoy312

Xiaoy312 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

@Mergifyio backport release/stable/6.7 servicing/6.8

@mergify

mergify Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

backport release/stable/6.7 servicing/6.8

✅ Backports have been created

Details

@ramezgerges

Copy link
Copy Markdown
Contributor

This behaviour is the same for all native elements, not just webview, and for all platforms, not just windows. I'm wondering if we should go for a more broad fix.

@Xiaoy312
Xiaoy312 enabled auto-merge November 9, 2026 20:35
@unodevops

Copy link
Copy Markdown
Contributor

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

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 244921 found UI Test snapshots differences: skia-linux-screenshots: 242, skia-windows-screenshots: 342

Details
  • skia-linux-screenshots: 242 changed over 2494

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Border_CornerRadius_Binding.png-dark
    • Border_CornerRadius_Binding.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • ClipboardTests.png-dark
    • ClipboardTests.png
    • AnimatedBackVisualSourceSamplePage.png
    • BasicAcrylicBrushTest2.png-dark
    • BasicAcrylicBrushTest2.png
    • BreadcrumbBarPage.png-dark
    • BreadcrumbBarPage.png
    • CompositionPath.png-dark
    • CompositionPath.png
    • BenchmarkDotNet.png-dark
    • BenchmarkDotNet.png
    • CornerRadiusControls.png-dark
    • CornerRadiusControls.png
    • AnimatedVisualsTestbedPage.png
    • AutomationProperties_AutomationId.png-dark
    • AutomationProperties_AutomationId.png
  • skia-windows-screenshots: 342 changed over 2494

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AutomationProperties_AutomationId.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • AppWindowTitleBar Properties.png-dark
    • Basics.png-dark
    • Basics.png
    • BenchmarkDotNet.png-dark
    • BenchmarkDotNet.png
    • BasicAcrylicBrushTest2.png-dark
    • BasicAcrylicBrushTest2.png
    • ClipboardTests.png-dark
    • ComboBox_MaxDropdownHeight.png-dark
    • ComboBox_MaxDropdownHeight.png
    • CompositionPath.png-dark
    • CompositionPath.png
    • CornerRadiusControls.png-dark
    • CornerRadiusControls.png
    • AnimatedVisualsTestbedPage.png-dark
    • AnimatedVisualsTestbedPage.png
    • AppWindowTitleBar Properties.png

@agneszitte
agneszitte disabled auto-merge November 9, 2026 22:53
@Xiaoy312
Xiaoy312 merged commit 64d48f9 into master Nov 9, 2026
52 checks passed
@Xiaoy312
Xiaoy312 deleted the dev/xygu/20261109/webview2-xaml-focus branch November 9, 2026 22:53
agneszitte added a commit that referenced this pull request Nov 9, 2026
…r-26263

fix(win32): Move XAML focus to the WebView2 when the browser takes focus (backport #26263)
agneszitte added a commit that referenced this pull request Nov 10, 2026
…6.7/pr-26263

fix(win32): Move XAML focus to the WebView2 when the browser takes focus (backport #26263)
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.

4 participants