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:
Makoto Kato
2020-07-06 16:26:08 +00:00
parent 3aa6ac1714
commit cb5c64d241
2 changed files with 30 additions and 0 deletions

View File

@@ -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")
}
}

View File

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