Bug 1633621 - Synchronize Java text and Gecko text at force when getting focus. r=geckoview-reviewers,agi
If client script wants to commit composition string per input, it sometimes
use the following script.
```
let input = document.getElementById('input');
input.addEventListener('input', () => {
input.blur();
input.focus();
});
```
Since `blur` will commit composition string, this script can commit text. But
since Gecko has an optimization for this situation, focus won't be lost
completely.
Although GeckoView synchronizes Java text and selection with Gecko text when
getting focus, this sample may be failed due to timing issue. `blur` tries to
commit string, but result is never returned since focus is lost as temporary
(although text is finally committed in Gecko.). Then, GeckoView are waiting
for result that is never returned forever, So this synchronization is failed.
When getting focus again, we should synchronize it at force.
Differential Revision: https://phabricator.services.mozilla.com/D80147
This commit is contained in:
@@ -849,4 +849,27 @@ class TextInputDelegateTest : BaseSessionTest() {
|
||||
finishComposingText(ic)
|
||||
assertText("commit abc", ic, "bar")
|
||||
}
|
||||
|
||||
@WithDisplay(width = 512, height = 512) // Child process updates require having a display.
|
||||
@Test fun inputConnection_bug1633621() {
|
||||
// no way on designmode.
|
||||
assumeThat("Not in designmode", id, not(equalTo("#designmode")))
|
||||
|
||||
setupContent("")
|
||||
val ic = mainSession.textInput.onCreateInputConnection(EditorInfo())!!
|
||||
|
||||
mainSession.evaluateJS("""
|
||||
document.querySelector('$id').addEventListener('input', () => {
|
||||
document.querySelector('$id').blur();
|
||||
document.querySelector('$id').focus();
|
||||
})
|
||||
""")
|
||||
|
||||
setComposingText(ic, "b", 1)
|
||||
setComposingText(ic, "a", 1)
|
||||
pressKey(ic, KeyEvent.KEYCODE_R)
|
||||
|
||||
assertText("Can set composition string after calling blur and focus",
|
||||
ic, "bar")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -776,6 +776,10 @@ void GeckoEditableSupport::FlushIMEChanges(FlushChangesFlag aFlags) {
|
||||
}
|
||||
|
||||
void GeckoEditableSupport::FlushIMEText(FlushChangesFlag aFlags) {
|
||||
NS_WARNING_ASSERTION(
|
||||
!mIMEDelaySynchronizeReply || !mIMEActiveCompositionCount,
|
||||
"Cannot synchronize Java text with Gecko text");
|
||||
|
||||
// Notify Java of the newly focused content
|
||||
mIMETextChanges.Clear();
|
||||
mIMESelectionChanged = true;
|
||||
@@ -1265,6 +1269,9 @@ nsresult GeckoEditableSupport::NotifyIME(
|
||||
}
|
||||
mDispatcher = dispatcher;
|
||||
mIMEKeyEvents.Clear();
|
||||
|
||||
mIMEDelaySynchronizeReply = false;
|
||||
mIMEActiveCompositionCount = 0;
|
||||
FlushIMEText();
|
||||
|
||||
// IME will call requestCursorUpdates after getting context.
|
||||
|
||||
Reference in New Issue
Block a user