Skip to content

fix(wasm): iPad soft-keyboard focus (dismiss, LostFocus, bring-into-view) (backport #23890) - #24251

Merged
kazo0 merged 8 commits into
release/stable/6.7from
mergify/bp/release/stable/6.7/pr-23890
Aug 28, 2026
Merged

kazo0 merged 8 commits into
release/stable/6.7from
mergify/bp/release/stable/6.7/pr-23890

Conversation

@mergify

@mergify mergify Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

GitHub Issue: Associated with an internal tracking issue (customer-reported).

PR Type:

🐞 Bugfix

What changed? 🚀

Fixes focus-related bugs specific to the Skia WebAssembly head on touch devices (iPad Safari/Chrome). They stem from the single shared, invisible <input id="uno-input"> that is positioned over the one <canvas> used for all text entry. None of them affect WinUI or the native (non-Skia) heads.

1. Soft keyboard opens on a TextBox tap, then immediately dismisses itself.
Touch browsers synthesize a trailing compatibility mousedown after a tap's focus change; it lands on the non-focusable canvas and its default action blurs the just-focused #uno-input, closing the keyboard. Uno already preventDefaults pointer events, but per the Pointer Events spec that does not suppress the synthesized mouse-compatibility events. Fix: a one-shot, touch/pen-scoped guard that swallows the single trailing canvas mousedown/click following the input's focusin (armed on focus, disarmed on the next pointerdown). Desktop mouse is unaffected — there mousedown precedes focus, so the guard never arms.

2. LostFocus never fires when the keyboard is dismissed this way.
Focus was driven one-way (managed → native): nothing listened for the browser blurring #uno-input on its own, so FocusManager stayed out of sync and LostFocus never fired. Fix: a blur listener on the input reports genuine, browser-initiated blurs to a new OnNativeBlur export, which calls TextBox.Unfocus() — the same terminal focus-clearing path the iOS and native WASM heads already use. Managed-initiated blurs are suppressed so a focus switch never clears the wrong control.

3. A focused field near the bottom is not scrolled above the keyboard.
The Skia WASM head had no InputPane producer — nothing ever set InputPane.OccludedRect, so the shared bring-into-view path never ran. Fix: a visualViewport listener computes the keyboard occlusion (gated on the invisible input being focused, so browser-chrome resizes don't count) and feeds InputPane.OccludedRect, mirroring the iOS/Android heads. This also makes InputPane.Showing/Hiding fire on this head, matching the other platforms.

Follow-up fixes from on-device testing feedback

4. Bring-into-view could leave the focused field partially (or fully) behind the keyboard — e.g. inside a side panel with its own ScrollViewer.
Three compounding defects in the shared occlusion-padding path (__SKIA__; the consuming code, not the new producer):

  • ScrollContentPresenter.Pad reduced the padding by the space below the focused element inside the viewport, so the minimal BringIntoView landed the element exactly that gap below the keyboard top. It now pads the full occluded overlap — which is what the Android head has always done (it passed Rect.Empty), so the parameter is gone and both platforms share one behavior.
  • The OnBringIntoViewRequested path subtracted _occludedRectPadding.Bottom from the viewport on __SKIA__ as well as __ANDROID__. On Skia the padding flows through ScrollViewer.Padding → presenter Margin, which ViewportHeight already reflects — subtracting again double-counted. Now Android-only (there the padding goes to the native view, invisible to managed layout).
  • On WASM the occlusion streams per animation frame, and the old restore-then-re-pad cycle measured a viewport whose layout still reflected the previous pad — converging to roughly half the needed padding. InputPane.skia.cs now keeps the pad applied across re-pads of the same presenter (Pad compensates internally), settles layout before measuring and before StartBringIntoView, and only restores when the target presenter changes or the pane hides. Restoring now puts back the app's original Padding instead of resetting it to zero.

5. Tapping another TextBox while the keyboard is up dismissed it.
Moving focus A→B destroyed the shared input (EndEntry(A) blurred + removed it) before StartEntry(B) recreated it — a "nothing editable focused" gap that commits the soft-keyboard dismissal on iPadOS. Reworked lifecycle:

  • focus() now retargets the existing input in place (value, inputmode, enterkeyhint) when the element kind matches — it never blurs, so the keyboard stays up.
  • When the kind must change (input ↔ textarea ↔ password, or an IME composition is active), the new element is focused before the old one is removed — an editable-to-editable handoff with no gap.
  • A managed blur (EndEntry) defers the real detach by one microtask; the focus() of a TextBox-to-TextBox move supersedes it. Genuine dismissals (tap outside, Done key) detach as before.
  • Blur now carries the owning TextBox's handle so a stale blur can never tear down a successor's entry session, and the retarget path re-arms the fix-1 guard (it fires no focusin).

Drive-by: updateSize() set the invisible input's width/height without px units, so the styles were ignored; the input rect is what Safari uses as its scroll-reveal target, so it now gets real dimensions.

Validation

  • Compiles clean: the runtime head and the full SamplesApp.Skia.WebAssembly.Browser app (TS + C#).
  • Fix 4 is device-independent and covered by runtime tests on Skia Desktop, verified fail-before/pass-after by running them against the pre-fix code:
    • Given_InputPane.When_Focused_TextBox_Has_Content_Below_Then_Scrolled_Above_Occlusion — the reported side-panel geometry distilled: old code left the field ~38 px under the keyboard; now asserts the field rect ends fully above the occlusion.
    • Given_InputPane.When_OccludedRect_Cleared_Then_ScrollViewer_Padding_Restored — app-set ScrollViewer.Padding survives an occlusion cycle (additive pad, restore on clear).
    • Given_InputPane.When_OccludedRect_Set_Then_Focused_TextBox_Scrolled_Into_View strengthened with the same geometric assertion.
    • Regression sweep: all 55 Given_ScrollViewer/Given_ScrollViewer_Zoom runtime tests pass (outside keyboard scenarios the removed subtraction was always zero).
  • Fix 5: full Given_TextBox runtime suite executed on Skia WASM in a browser — 148 passed / 27 skipped, and the only 2 failures are sub-pixel rounding assertions that fail byte-identically on a baseline build without these changes (pre-existing, environment-specific).
  • Manual on-device sample SoftKeyboardFocusTests (GotFocus/LostFocus counters, live OccludedRect readout, bottom field). Fixes 1, 2, and 5, and the on-device occlusion math, reproduce only on a real iPad, so final device validation there is still required — this PR is a draft pending that.
  • Android note: Pad keeps Android's existing full-intersection behavior; the additive padding and restore-on-clear are shared improvements validated by code review + the Skia runtime tests (no Android runtime run here).

Known remaining item from the same feedback (tracked for a follow-up): Safari auto-pans its visual viewport to reveal the DOM input when it sits below the keyboard, which can fight the XAML-level scroll (most visible with the taller multi-tab Safari header) and let the whole page pan instead of inner ScrollViewers.

PR Checklist ✅


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

@github-actions github-actions Bot added platform/wasm 🌐 Categorizes an issue or PR as relevant to the WebAssembly platform platform/android 🤖 Categorizes an issue or PR as relevant to the Android platform area/skia ✏️ Categorizes an issue or PR as relevant to Skia area/automation Categorizes an issue or PR as relevant to project automation labels Aug 27, 2026
@kazo0

kazo0 commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 230676 did not find any UI Test snapshots differences.

@mergify

mergify Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@kazo0
kazo0 merged commit 4a4f800 into release/stable/6.7 Aug 28, 2026
49 checks passed
@kazo0
kazo0 deleted the mergify/bp/release/stable/6.7/pr-23890 branch August 28, 2026 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/automation Categorizes an issue or PR as relevant to project automation area/skia ✏️ Categorizes an issue or PR as relevant to Skia platform/android 🤖 Categorizes an issue or PR as relevant to the Android platform platform/wasm 🌐 Categorizes an issue or PR as relevant to the WebAssembly platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants