Repository navigation
Conversation
On WebAssembly and on Skia Android the platform applies the composition text itself and reports it before syncing it to the TextBox (the input event that follows compositionupdate, Android's EndBatchEdit). The TextBox and the RichEditBox raised TextCompositionChanged on that report, while Text still held the previous text: a handler reading Text.Substring(e.StartIndex, e.Length) threw, and one that moved focus made the rest of the update land in the next TextBox. Hold the event back until the platform's text sync has landed, after TextChanging, as for text the TextBox applies itself. RichEditBox holds its Composition and ConversionTargetChanged automation events with it. An update whose text the control refused, and so isn't in Text, is not raised. This changes the order of the events on every platform-applied update, on Android too. A TextCompositionStarted or TextCompositionEnded handler can also move focus before the browser's text is synced; the browser host no longer syncs the old input's value into the TextBox that took focus. The composition's range can also outlast its text, after a coercion or a deletion, so TextCompositionChanged, and TextCompositionEnded for a composition that ends without a commit, now get the part of the range that is in the text. A commit's TextCompositionEnded keeps the committed text's own range: Skia Android raises it before syncing that text. On WebAssembly, a composition whose committed text the TextBox changed (a filter, MaxLength) ends without a commit, with its range in the text. Skia Android now reports where its composing region starts, as the browser already does, so a composition the keyboard opens on an existing word is placed there rather than at the caret.
A composition open on the hidden input never ended when that input was replaced (the same TextBox re-entered with another focus state, as a tap does after keyboard focus) or removed while the TextBox kept focus (accessibility handing it over to its semantic element). The browser's compositionend for the old input is ignored on purpose, so the TextBox stayed composing and never raised TextCompositionEnded. End it when the input is replaced or removed.
While a composition edits the hidden input, the browser owns its value, so a TextBox text that differs from it is written back when the composition ends. For an edit a BeforeTextChanging handler cancelled, that left the refused character in the input while the keyboard went on composing: the next keystrokes were built on it and refused too, so typing "a", a rejected "x", then "b" left Text at "a". Write the TextBox's text back at once when the TextBox rejects an edit without its text changing at all (a BeforeTextChanging cancel, or a read-only TextBox), which ends the browser's composition, and end it for the TextBox too. Anything else is still reconciled when the composition ends, so the keyboard keeps its composition: an edit a TextChanging handler changes, even back to the previous text (a length limit), and a refusal past MaxLength. A conversion can then bring the composition back within the limit (にほん to 日本 with MaxLength 2).
The hidden input under a read-only TextBox stayed editable, so a mobile browser opened the soft keyboard for it and let the user type until the TextBox reverted each edit. WinUI doesn't show the touch keyboard for a read-only TextBox. Set readOnly on the hidden input when the TextBox or RichEditBox is read-only, and update it when IsReadOnly changes. (A read-only RichEditBox already suppressed the soft keyboard; it gets readOnly for consistency.) A read-only input still takes focus, a caret and a selection, and still gets key events and copy: the browser only refuses edits to it. Keyboard navigation, selection and Ctrl+C keep working, since the TextBox handles the keys and the browser copies the input's selection. Mobile browsers show or hide the soft keyboard when an element takes focus, not when readOnly flips on the focused one. So focus moving between a read-only and an editable TextBox focuses a new input instead of reusing the focused one, and IsReadOnly changing on the focused TextBox enters a new input as focus does, except during a composition.
When the TextBox refuses an edit the browser applied to the hidden input (MaxLength, BeforeTextChanging, read-only), the caret went back to where the edit started only a dispatcher tick later. Until then the TextBox and the input both had it where the refused edit left it, so a key typed in between landed there: typing "x" (refused) then "y" in the middle of "abc" gave "abyc" instead of "aybc". Put the caret back while the refused edit is being applied, and push it to the input even when it didn't change, since writing the text back moved the input's caret. The restore a tick later is skipped on this path: it would now move the caret of a key typed in between.
Soft keyboard sequences from an earlier round of browser IME work that master already handles, kept as regression guards: a code-less Backspace in a PasswordBox, a caret moved during a composition, a composition ending on an input that was replaced, a line break typed during a composition, a caret move in a textarea, and text set or cleared from code during a composition.
|
Azure Pipelines: 1 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tick the box to add this pull request to the merge queue (same as
|
Port of the TextBox part of master's e86befc: the selectionchange handler only followed an <input>, so a caret move the keyboard made in a multi-line TextBox's <textarea> never reached the TextBox. When_Browser_Multiline_Selection_Follows_Native (unoplatform#26434, next commit) covers it.
Port of unoplatform#26434 (for unoplatform#26432), commits faba3ed, 096daef, 8e2644f, b8d2189, edce6fa and 6939ef4, onto the unoplatform#25804 IME design this branch takes from servicing/6.8 (unoplatform#25984). - TextCompositionChanged for text the platform applied (WebAssembly, Skia Android) waits for the platform's text sync, and isn't raised for an update the TextBox refused. The Changed and no-commit Ended ranges are clamped to the text. Skia Android reports where its composing region starts. - A composition ends when the hidden input is replaced or detached. - An edit a BeforeTextChanging handler or a read-only TextBox refuses is written back to the input at once, ending the composition. Unlike master, this branch does the same for an edit MaxLength refuses or a TextChanging handler changes (see below). - The hidden input is read-only with the TextBox. - The caret goes back at once after a refused edit. 6.8 differences: - Master's TextBoxCore.IME.cs, .Input.cs and .cs changes go to TextBox.IME.skia.cs, TextBox.skia.cs and TextBox.cs; events are raised on the TextBox itself. There is no RichEditBox IME, partial commit or CompositionCanceled on 6.8, so those parts are left out. - Skia Android syncs through a new TextBox.UpdateTextFromNative, the 6.8 counterpart of master's IImeSessionHost.UpdateTextFromNative. It raises the held TextCompositionChanged, and compares the editable's \n line breaks as the TextBox's \r, as master's IsNativeEchoOfCurrentText does. - The read-only input follows TextBox.IsReadOnly through OnIsReadonlyChangedPartial; UpdateProperties, which only sets the enter key hint on 6.8, now also sets readOnly or re-enters the input. With this branch's port of unoplatform#26005 (be85699): - A refused platform sync puts the composition range back on the text that is there (unoplatform#26005), and raises TextCompositionChanged for that range only when it isn't the last range raised. The refused update's own range is never raised (unoplatform#26434). - While a composition holds text the TextBox refused past MaxLength (reconciled when it ends), the hidden input's selectionchange isn't reported: its offsets are in that text, not in the TextBox's. Without this, the input's caret replaced the one edce6fa restores at once. - ApplyNativeInput keeps unoplatform#26005's handling of a refused edit's pending selection. Like Android's own LengthFilter (and this branch before the catch-up), a composition edit the TextBox doesn't keep as the keyboard applied it (MaxLength, a TextChanging filter, as well as BeforeTextChanging and read-only) writes the TextBox's text back at once and ends the composition, on WebAssembly and on Skia Android. Master keeps a MaxLength or TextChanging refusal in the input until the composition ends, so a CJK conversion can bring it back within the limit. Gboard composes every Latin word, though, so the refused letters stayed in the input for the whole word: its suggestions were built on them, and Backspace deleted them before it reached the TextBox's text. A conversion past the limit is lost here, as with Android's LengthFilter. When_Browser_Ime_Composes_With_TextChanging_Filter (unoplatform#25804) and the two conversion tests of unoplatform#26434 now expect that, and When_Browser_Ime_Composes_Word_Past_MaxLength_Then_Input_Keeps_The_Limit covers the Gboard case. Adds tests for a refused Skia Android sync, \n line breaks in its sync, and a refused composition followed by another before the dispatcher runs.
Port of unoplatform#26435 (stacked on unoplatform#26434), commit 6d7709a. WebKit browsers commit a composition through input events of their own: deleteCompositionText, insertFromComposition, then compositionend. The removal of the preedit is now reported together with the insertion that follows it, and a preedit put back unchanged isn't reported again. For the orders where compositionend comes before the input event that applies the commit, the composition ends with that event, after the text change and TextCompositionChanged, or after the task when none comes. 6.8 differences: the browser's composition cancel is OnCompositionEnded here (master: OnCompositionCanceled), so When_Browser_Ime_Selected_Composition_Cancelled_Without_Input_Event expects the composition to end with its range, as every composition that ends without a commit does on 6.8.
Port of the review round of unoplatform#26434 (commits 0e475cdb9e and 73279a2cf1 there) onto this branch's write-back. - Narrower rule: the input or the native editable takes the TextBox's text back at once, ending the composition, only when the TextBox refused the edit or kept text of another length (MaxLength, a length limit). A change that keeps the length (an upper-case TextChanging filter) waits for the end of the composition again, as unoplatform#25804 made it, so an IME can still convert it: When_Browser_Ime_Composes_With_TextChanging_Filter is back to servicing/6.8's version. TextBox.MustReturnTextToNative holds the rule, and compares without allocating. - Skia Android's EndBatchEdit no longer reads ActiveTextBox again after the sync, which runs app handlers that may move focus or clear it (a null reference in the IME callback): it writes back only to the TextBox it synced, and only after the IME changed the text. The write-back is one batch for the listeners, so a TextCompositionEnded handler that sets the text again is written after it. - The comments no longer describe this as what Android's LengthFilter does, and the remaining ones about the end-of-composition reconciliation say which edits it still covers. - When_Browser_Ime_Composes_Past_MaxLength and When_Browser_Ime_Composition_Coerced_Shorter_Than_Its_Start check the input right after the update, and that the browser's late compositionend changes nothing. TextBox.UpdateTextFromNative already kept the TextBox's caret on a refused sync (the applied check of unoplatform#26005), unlike master's; When_IME_Platform_Sync_Refused_Then_Caret_Stays covers it here too. 6.8 has no RichEditBox IME, so the RichEditBox part doesn't apply.
A composition edit the TextBox refused stayed in the hidden input until the composition ended, unless a BeforeTextChanging handler or a read-only TextBox refused it: an edit MaxLength refused, or that a length limit put back, was left for the end of the composition, so that a CJK conversion could still bring it back within the limit. Gboard composes every Latin word, though, so the letters typed past MaxLength stayed in the input for the whole word: the keyboard built its suggestions on them, and Backspace deleted them before it reached the TextBox's text. This replaces that trade-off. When the TextBox keeps text of another length than the input's (MaxLength, a length limit), or refuses a change of the input's text and keeps its own previous text, its text goes back to the input at once and the composition ends, so the keyboard builds its next keystrokes and suggestions on the text the TextBox kept. The input now reports its value at the previous sync with each edit, so the same text reported again (a caret move inside the preedit) doesn't count as a refusal while a same-length filter keeps the two texts apart. Kana typed past a limit is cut at the limit rather than converted later. A change that keeps the length (an upper-case filter) still waits for the end of the composition, as unoplatform#25804 made it, so an IME can still convert it. ImeSessionCoordinator.MustReturnTextToNative holds the rule. RichEditBox gets the same rule, so an edit it refuses or cuts to its text limit is written back, and its CharacterCasing waits for the end of the composition. ApplyNativeInput no longer has to tell a refusal from a handler's put-back text, so its result and the text change count go. Tests: When_Browser_Ime_Converts_Past_MaxLength and When_Browser_Ime_Converts_Past_TextChanging_Limit become When_Browser_Ime_Kana_Composes_Past_MaxLength and When_Browser_Ime_Kana_Composes_Past_TextChanging_Limit; When_Browser_Ime_Composes_Word_Past_MaxLength_Then_Input_Keeps_The_Limit covers the Gboard case and Given_RichEditBox.When_Wasm_Composition_Past_MaxLength_Is_Written_Back the RichEditBox, with When_Wasm_Composition_Past_MaxLength_In_The_Middle_Keeps_The_Caret and When_Wasm_Composition_With_Upper_Casing_Stays_Open. When_Browser_Ime_Filtered_Composition_Reported_Again_Stays_Open, When_Browser_Ime_Same_Length_Replacement_Is_Refused and the table test When_Native_Text_Is_Compared_To_The_Kept_Text cover the rule's clauses. When_Browser_Ime_Composes_Past_MaxLength and When_Browser_Ime_Composition_Coerced_Shorter_Than_Its_Start now check the input right after the update, and that the browser's late compositionend changes nothing.
Skia Android's EndBatchEdit synced the IME's text to the host, but an edit the host refused (MaxLength, BeforeTextChanging) stayed in the editable, as a refusal raises no text change to write back, and a TextChanging handler's change wasn't written back either while the batch ended. The keyboard kept composing on text the host doesn't have. With the WebAssembly host's rule (ImeSessionCoordinator.MustReturnTextToNative, given the host's text read before the sync and the editable's text at the start of the batch), the editable now takes the host's text at once and drops its composing region, which ends the composition, as one change for the listeners: a TextCompositionEnded handler that sets the text again is written after it. The check runs only after the IME changed the text, as a RichEditBox's text costs the document, and only while the host it synced is still the active one, as the handlers that ran may have moved focus. UpdateEditableStateFromHost reads the host once for the same reason. A refused sync also put the host's caret where the IME left it in the refused text, which the editable then took back, so the next key landed one place late. The caret now stays where the edit started (When_IME_Platform_Sync_Refused_Then_Caret_Stays).
Port of the second review round of unoplatform#26434 (commits d6480af and 71c75a7 there). An upper-case TextChanging filter leaves the TextBox's text ("AB") different from the composition's ("ab") until the composition ends. The input reporting its text again unchanged (a caret move inside the preedit) then looked like a refusal, as the TextBox kept its previous text, and ended the composition. A refusal now also needs the input's text to have changed: the browser passes the input's value at the previous sync with each edit, and Skia Android compares with the editable's text at the start of the batch and reads the TextBox's text before the sync, instead of the editable's, for what the TextBox had. UpdateEditableSelectionAndText reads the active TextBox once, as the editable's listeners notified by Clear may change it. The selectionchange comment no longer names MaxLength, which no longer stays in a composition. Tests: When_Browser_Ime_Filtered_Composition_Reported_Again_Stays_Open, When_Browser_Ime_Same_Length_Replacement_Is_Refused and the table test When_Native_Text_Is_Compared_To_The_Kept_Text.
The browser passed the input's previous value with each edit, so the whole text crossed to .NET twice per keystroke, while the rule only needs to know whether the input's text changed. The browser now compares the input's value with the one at the previous sync or write (both written by the input, so their line breaks match) and passes the result, for TextBox and RichEditBox alike. An overload of MustReturnTextToNative takes it; Android keeps passing the editable's text from the start of the batch, compared only when the rule needs it. The table test checks both overloads with the same rows.
Port of unoplatform#26434's 0effe84. The browser passed the input's previous value with each edit, so the whole text crossed to .NET twice per keystroke, while the rule only needs to know whether the input's text changed. The browser now compares the input's value with the one at the previous sync or write (both written by the input, so their line breaks match) and passes the result. An overload of TextBox.MustReturnTextToNative takes it; Skia Android keeps passing the editable's text from the start of the batch, compared only when the rule needs it. The table test checks both overloads with the same rows.
MartinZikmund
left a comment
There was a problem hiding this comment.
@mikernet thanks a lot for this one, and for the very thorough write-up and fail-before evidence. Moving TextCompositionChanged after the text sync is right for WinUI parity: in dxaml/xcp/core/native/text/Controls/TextBoxBase.cpp, CTextBoxBase::TxNotify handles EN_CHANGE by running OnContentChanged (sync TextChanging, queued TextChanged) first, and only then SendTextCompositionEvent(CompositionChanged). Uno's async TextChanged gives the same TextChanging, then TextCompositionChanged, then TextChanged order. The focus-move guards, the compositionend on a replaced or detached input, the read-only input and the caret restore all look good to me.
A few things before this goes in:
- Ending the composition on a length difference hurts desktop CJK IMEs (inline). On Windows Chrome with Microsoft Pinyin, the preedit in the input is the raw pinyin, so with
MaxLength="4"the 5th letter ofzhangsannow commitszhanas Latin text, and the user can never type 张三 (2 chars). On master the preedit stays in the input and is reconciled when it ends, so 张三 fits.When_Browser_Ime_Kana_Composes_Past_MaxLengthpins the same trade-off for kana. I get why Gboard needs it, but can we keep it from breaking conversion IMEs? Some options: only write back once the text the TextBox kept is shorter than where the composition starts, or keep master's end-of-composition reconciliation when the length difference comes only fromMaxLengthor aTextChanginglimit. If you think the trade-off is right as it is, please say so in the PR body so we decide it on purpose. - Skia Android validation. This changes the event order on Skia Android and makes
EndBatchEditreset the editable and its composing region on a refusal. The only validation listed is the Android compile plus the fake extension on desktop. Could you run Gboard (Latin + Japanese) on a real Skia Android head, at least the MaxLength andBeforeTextChangingcases? I'm especially curious whether Gboard leaves its composition cleanly after theupdateSelection(..., -1, -1). - iOS Safari: is there any manual check that assigning
input.valuemid-composition ends the composition on WebKit? If WebKit keeps composing, the nextcompositionupdates are dropped as stale (the generation was bumped), so the rest of that word gets no composition events.
Not blocking, FYI: WinUI doesn't raise BeforeTextChanging during a composition at all (CTextBox::UpdateTextProperty, shouldRaiseBeforeTextChanging = !m_compositionInProgress). It defers it to the final EN_CHANGE. Uno raises it per update, which is why the BeforeTextChanging refusal path exists here. That divergence was there before this PR, so no need to fix it here; I just want us to be aware that part of this behavior depends on it.
On other open PRs: #26435 stacks cleanly on top of this one. #25174 (approved) conflicts with this PR in BrowserInvisibleTextBoxViewExtension.ts detachCore(), where both add lines at the top. It's trivial: keep both (the lastKeyDownEnter* resets and wasComposing).
Ending the composition whenever the control kept text of another length than the input's broke conversion IMEs, whose reading is longer than the text it converts to: with MaxLength="4", Microsoft Pinyin in Chrome committed "zhan" as Latin text instead of letting "zhangsan" convert to two characters, and kana past MaxLength was cut instead of converted. The host now tells whether it refused the edit (read-only, BeforeTextChanging) rather than keeping other text through a limit or a handler (MaxLength, TextChanging). Only a refusal, or a kept text that no longer reaches where the composition starts, goes back to the input at once. Any other difference waits for the composition to end, as on master: the browser reconciles it at compositionend, and Skia Android now writes it back in the batch edit that removes the composing region, since nothing synced the editable there. Outside a composition, Android writes any difference back at once. This gives up the Gboard MaxLength fix: the letters of a Latin word typed past MaxLength stay in the input until the word ends, as on master, since nothing tells them apart from a reading. The browser no longer passes whether the input's text changed, which only the old rule needed, and skips the check, and with it reading a RichEditBox's document, outside a composition.
During a composition that doesn't start the text, the write-back check read the host's whole text on every input event, which for a RichEditBox materializes the document. When the host didn't refuse the edit, only the kept text's length matters: the input's text reaches where its composition starts, so a kept text shorter than that differs from it. The host now exposes its text's length for that. The refusal's doc now says what each host refuses: a read-only TextBox refuses only in the browser, where ApplyNativeInput checks IsReadOnly.
Nothing covered the browser's write-back of a composition update a RichEditBox refuses, since the MaxLength cases now wait for the composition to end. A composition started right after protected text, which the document refuses, now checks that the input takes the document's text and caret back at once and the composition ends.
Nit ( On Edit: cc8cec1 fixes a regression the narrowing introduced. While a composition MaxLength refused goes on, the input holds the composition's text and the TextBox its own, so the input's caret no longer indexes the TextBox's text. A key composed in the middle of a full TextBox moved the TextBox's caret onto the input's position ( |
Since a composition MaxLength refuses keeps its text in the input until
it ends, the input and the TextBox hold different text meanwhile. The
input's selection changes still reached the TextBox, so a key composed
in the middle of a full TextBox moved the TextBox's caret onto the
input's positions ("abcd" with the caret at 2, composing "x": the caret
went to 3), and the reconciliation at the end of the composition kept
that caret. While the TextBox holds other text than the composition's,
the input's selection no longer reaches it; the composition's end
reconciles both.
This reverts a6f4690. unoplatform#26434 no longer ends a browser composition whose update MaxLength refuses: a conversion IME's reading can be longer than the text it converts to, so the difference waits for the composition to end. unoplatform#26005's original expectation holds again: the composition survives the refused update, and the next change from code is an outside change that ends it.
GitHub Issue: closes #26432
PR Type:
🐞 Bugfix
What changed? 🚀
This builds on #25804's IME design (the hidden input is the source of truth for composition text, and the TextBox follows it with
textAlreadyApplied) and fixes what is left of the bugs #24502 fixed under its earlier design. It supersedes #24502, which I'll close. #25804's own body lists the first one as a known follow-up.Each fix is its own commit, with its tests:
1.
TextCompositionChangedis raised once its text is inText(TextBox and RichEditBox, WebAssembly and Skia Android)The platform applies the composition itself and reports it before the text sync that follows it (the browser's input event, Android's
EndBatchEdit). The event was raised on that report, so its range pointed into text that wasn't there yet: a handler readingText.Substring(e.StartIndex, e.Length)threw, and one moving focus sent the rest of the keystroke to the next TextBox. The event now waits for the sync, afterTextChanging, as for text the TextBox applies itself. RichEditBox holds itsCompositionandConversionTargetChangedautomation events with it. An update whose text the control refused, and so isn't inText, isn't raised. This changes the order of the events on every platform-applied update, so on Skia Android too, not only on WebAssembly.On WebAssembly, a
TextCompositionStartedorTextCompositionEndedhandler that moves focus no longer gets the browser's text synced into the TextBox that took focus.The ranges of
TextCompositionChangedand of a composition ending without a commit (cancel, coercion, external change) are clamped to the text. A commit'sTextCompositionEndedkeeps the committed text's own range, since Skia Android raises it before syncing that text (the point morning4coffe-dev made on #24502).Skia Android now passes where its composing region starts, as the browser does, so a composition opened on an existing word is placed there.
Tests:
When_IME_Platform_Applied_Composition_Changed_After_Its_Text(TextBox) andWhen_Platform_Applied_Composition_Changed_After_Its_Text(RichEditBox), which replay Android's order with a fake extension on every Skia target; on WebAssemblyWhen_Browser_Ime_Changed_Handler_Reads_Composition,When_Browser_Ime_Composition_Repeats_Existing_Character,When_Browser_Ime_Composition_Extends_Existing_Text,When_Browser_Ime_Caret_Moved_Inside_Preedit_Repeating_Text,When_Browser_Ime_Composition_Preedit_Emptied,When_Browser_Ime_Composition_Coerced_Shorter_Than_Its_Start,When_Browser_Ime_Changed_Handler_Moves_Focus,When_Browser_Ime_Started_Handler_Moves_Focus,When_Browser_Ime_Ended_Handler_Moves_Focus(each with a single-line and a multi-line target), two WebKit commit orders this already fixes (When_Browser_Ime_WebKit_Commit_Equal_To_Preedit_Ends_At_Once,When_Browser_Ime_WebKit_Preedit_Removed_Before_Cancel) andGiven_RichEditBox.When_Wasm_Composition_Reopened_On_Existing_Text_Changed_Sees_The_Preedit.2. A composition ends when the hidden input is replaced or removed (WebAssembly)
The browser's
compositionendfor a replaced or removed input is ignored on purpose, so when the same TextBox was re-entered with another focus state (a tap after keyboard focus) or accessibility detached the input while the TextBox kept focus,IsComposingstayedtrueandTextCompositionEndednever came.focus()anddetachCore()now end it.Tests:
When_Browser_Ime_Same_TextBox_Refocused_During_Composition,When_Browser_Ime_Input_Detached_During_Composition.3. A composition edit the control refuses is written back at once (TextBox and RichEditBox, WebAssembly and Skia Android)
#25804 reconciles a control's edit made during a composition when the composition ends. Until then refused text stayed in the hidden input, and the keyboard kept composing on it: typing
a, then anxaBeforeTextChanginghandler rejects, thenbleftTextata.Now, when the control refuses the composition's edit outright (a
BeforeTextChangingcancel, a read-only RichEditBox or a document refusing protected text, and in the browser a read-only TextBox), or keeps text shorter than where the composition starts (aTextChanginghandler clearing the text), its text goes back to the input at once. The composition ends for the control too, and the caret is pushed back to the input, so the keyboard builds its next keystrokes and suggestions on the text the control kept.IImeSessionHost.UpdateTextFromNativeandTextBoxCore.ApplyNativeInputreport the refusal:MaxLengthrejects the whole text in Uno, so the text alone can't tell it from aBeforeTextChangingcancel.Any other difference (
MaxLength, aTextChanginglimit or filter,CharacterCasing) keeps #25804's reconciliation at the composition's end. Meanwhile the input's selection changes don't reach the control, since they index the composition's text, not the control's. A conversion IME's reading is longer than the text it converts to: withMaxLength="4", Microsoft Pinyin'szhangsanstill converts to 张三, and kana pastMaxLengthstill converts to kanji that fit. The trade-off is Gboard's Latin words: the letters typed pastMaxLengthstay in the input until the word ends, as on master.On Skia Android,
EndBatchEditleft a refused edit in the native editable, since a refusal raises no text change to write back, and nothing reconciled the editable when a composition ended. The editable now takes the host's text, as one change, after a refusal or a cut before the composition (and loses its composing region, which ends the composition there too), when the composing region goes away, and outside a composition. A refused sync there also left the host's caret where the IME put it in the refused text, so the next key landed one place late; it now stays where the edit started.Tests:
When_Browser_Ime_Composition_Rejected_By_BeforeTextChanging,When_Browser_Ime_Same_Length_Replacement_Is_Refused,When_Browser_Ime_Composition_Coerced_Shorter_Than_Its_Start,When_Browser_Ime_Filtered_Composition_Reported_Again_Stays_Open,When_Browser_Ime_Pinyin_Reading_Past_MaxLength_Converts_Within_It,When_Browser_Ime_Kana_Composes_Past_MaxLengthandWhen_Browser_Ime_Kana_Composes_Past_TextChanging_Limit(the reading stays in the input and converts within the limit),When_Browser_Ime_Composes_Past_MaxLength(now checks the input during and after the composition),When_Browser_Ime_Composes_Past_MaxLength_In_The_Middle_Keeps_The_Caret(the TextBox keeps its caret while the input holds the composition's longer text),Given_RichEditBox.When_Wasm_Composition_Refused_By_Protected_Text_Is_Written_Back(a composition starting right after protected text),When_Wasm_Composition_Past_MaxLength_Applies_At_Its_End,When_Wasm_Composition_Past_MaxLength_In_The_Middle_Keeps_The_CaretandWhen_Wasm_Composition_With_Upper_Casing_Stays_Open. On every Skia target there areWhen_IME_Platform_Sync_Refused_Then_Caret_StaysandWhen_Native_Text_Is_Compared_To_The_Kept_Text, a table of the rule's cases (refusal, cut before the start, limit, filter, line breaks, outside a composition). #25804'sWhen_Browser_Ime_Composes_With_TextChanging_Filterstill passes unchanged.I checked Skia Android with Gboard on an emulator (Google APIs API 31 image, Gboard 10.8), driven by taps, with the
MaxLengthandBeforeTextChangingcases above:MaxLength="4": the word ends on space, the editable takesabcdback, and one Backspace deletes thed.xrefused byBeforeTextChanging: the composition ends at once, and Gboard's next composition builds on the kept text (it doesn't re-sendaxafterupdateSelection(..., -1, -1)).MaxLength="4": the reading stays in Gboard's composition, and committing it writes the kept text back.The kana-to-kanji conversion itself couldn't be tried there: that Gboard has no Japanese conversion model.
On Skia Android a read-only TextBox doesn't refuse an IME edit (
UpdateTextFromNativehas noIsReadOnlycheck), as on master; that's left for a follow-up.4. The hidden input is read-only for a read-only TextBox (WebAssembly)
It stayed editable, so a mobile browser opened the soft keyboard and let the user type into it until each edit was reverted; WinUI doesn't show the touch keyboard for a read-only TextBox. The input now gets
readOnlyand followsIsReadOnly. A read-only RichEditBox already suppressed the soft keyboard (inputmode="none"); it getsreadOnlytoo, for consistency.Mobile browsers show or hide the keyboard when an element takes focus, not when
readOnlyflips on the focused one. So focus moving between a read-only and an editable TextBox now focuses a new input instead of reusing the focused one, andIsReadOnlychanging on the focused TextBox enters a new input as focus does (except during a composition, which keeps its input).A read-only input still takes focus, a caret and a selection, and still gets key events and copy; the browser only refuses edits to it. I checked that in Chrome 157 with trusted CDP input on a plain read-only input: focus,
ArrowLeftandShift+ArrowLeftmove the caret and the selection,keydown/keyupandcopyfire, and typing firesbeforeinputbut leaves the value unchanged. The runtime test uses synthetic key events, so it shows that the TextBox still handles the keys and the input follows its selection, not native copy.#25804's
When_Browser_Input_Edits_Read_Only_TextBoxsaid the input stays editable under a read-only TextBox; it now checks the input is read-only, and still that an edit reaching it anyway is refused.Re-applying the properties when
IsReadOnlychanges also re-applies the keyboard type, autocorrect and accessory view on Apple UIKit, which is harmless.Tests:
When_Browser_Read_Only_TextBox_Keeps_Keyboard_And_Selection,When_Browser_Focus_Moves_From_Read_Only_TextBox,When_Browser_Read_Only_Toggled_On_Focused_TextBox,When_Browser_Input_Edits_Read_Only_TextBox(updated),Given_RichEditBox.When_Wasm_Read_Only_Hidden_Input_Follows_IsReadOnly, andWhen_Browser_Ime_TextBox_Made_Read_Only_During_Composition(the composition still ends; that part already worked on master).5. The caret is restored at once after a refused input (WebAssembly)
After the TextBox refused a plain edit, the caret went back to where the edit started a dispatcher tick later, so a key typed in between landed where the refused edit left it ("abc" with the caret after "a": a refused "x" then "y" gave "abyc"). It is now restored while the refused edit is applied, and the restore a tick later is skipped on this path.
Test:
When_Browser_Input_Refused_Then_Next_Key_Follows_At_Once.6. More soft keyboard sequences as regression guards (test only)
#24502's soft keyboard tests that already pass on master and have no equivalent there, adapted to master's helpers:
When_Browser_Soft_Keyboard_Backspace_Has_No_Code_In_PasswordBox,When_Browser_Ime_Caret_Moved_During_Composition,When_Browser_Ime_Composition_Ends_On_Replaced_Input,When_Browser_Ime_Multiline_Line_Break_During_Composition,When_Browser_Multiline_Selection_Follows_Native,When_Browser_Ime_Text_Set_By_TextCompositionEnded_Handler,When_Browser_Ime_Text_Cleared_During_Composition.Not in this PR: the rest of #24502's WebKit/iOS commit ordering, which I'm proposing separately in #26435 (stacked on this one).
Validation
Given_TextBox,Given_RichEditBox,Given_PasswordBox,Given_BrowserKeyboardInputSource,Given_AccessibleTextBoxandGiven_ImeSessionCoordinator*: 1392 pass, 30 inconclusive. The one failure,When_Touch_LongPress_Drag_Release_Does_Not_Open_Flyout_iOS, fails the same way without these changes.Given_TextBox,Given_RichEditBox,Given_PasswordBoxandGiven_ImeSessionCoordinator*: 1420 pass, one inconclusive; the one failure is the same iOS touch test.When_Browser_Ime_Started_Handler_Moves_Focus/When_Browser_Ime_Ended_Handler_Moves_Focus, where the reused input is emptied for the newly focused TextBox before the stale sync, so only the multi-line rows (a new textarea) show the bug;When_Browser_Ime_Filtered_Composition_Reported_Again_Stays_OpenandWhen_Wasm_Composition_With_Upper_Casing_Stays_Open(both pass on master), and theMaxLength, limit and pinyin tests, each covered by a mutation below;When_Wasm_Composition_Refused_By_Protected_Text_Is_Written_Back, which I checked with the mutation below rather than on master.When_Native_Text_Is_Compared_To_The_Kept_Textcalls the rule directly, as a table of its cases, so it has no fail-before (it doesn't compile on master).When_Browser_Ime_TextBox_Made_Read_Only_During_Compositionwithout itsreadOnlychecks.ApplyNativeInputcounting every edit that leftTextunchanged as a refusal (how the rule treated a kept text before the narrowing),When_Browser_Ime_Pinyin_Reading_Past_MaxLength_Converts_Within_It, bothWhen_Browser_Ime_Kana_Composes_*andWhen_Browser_Ime_Composes_Past_MaxLengthfail, andWhen_Browser_Ime_Composition_Rejected_By_BeforeTextChangingstill passes.When_Wasm_Composition_Past_MaxLength_Applies_At_Its_EndandWhen_Wasm_Composition_Past_MaxLength_In_The_Middle_Keeps_The_Caretfail (RichEditBox clips withClampInsertToMaxLengthinstead of refusing).When_Wasm_Composition_Refused_By_Protected_Text_Is_Written_Backfails.When_Browser_Ime_Composes_Past_MaxLength_In_The_Middle_Keeps_The_Caretfails on the narrowing alone (308f529): the input's caret moves the TextBox's.When_IME_Platform_Sync_Refused_Then_Caret_Staysfails.IsReadOnlychange,When_Browser_Focus_Moves_From_Read_Only_TextBoxandWhen_Browser_Read_Only_Toggled_On_Focused_TextBoxfail.input.valueduring a composition doesn't cancel it on iOS (macOS cancels it on the selection change). After fix 3 the value is assigned mid-composition only for a refusal or a cut before the composition.PR Checklist ✅
Screenshots Compare Test Runresults.