The user may see flickering of autocomplete text if onDraw() is called inside keyboard app's batch edited IME operations.
For example, consider the following sequence of events:
1) beginBatchEdit() 2) commitText() 3) onDraw() 4) endBatchEdit() 5) onDraw()
With current implementation, onDraw() at step 3) and onDraw() at step 5) may see different getText() because we remove span at beginBatchEdit() and does not add a new one until endBatchEdit().
In order to ensure that span is added at the end of every IME operation, even including beginBatchEdit(), the current internal calls to beginBatchEdit() and endBatchEdit() have been separated out as onBeginImeCommand() and onEndImeCommand(), respectively. And then beginBatchEdit() and endBatchEdit() will simply increment / decrement batch edit count inside these new IME command guards.
And we remove / add span in the IME command guards even when they are not the outermost ones, to ensure that onDraw() can see the span when necessary.
Note that notification is not affected thanks to the count guard.
Change-Id: Ia1f044dd3c2669658dd363e4375f841c9c448f37 Reviewed-on: https://chromium-review.googlesource.com/568914
880dcbe Avoid flicker in the new omnibox inline autocomplete
.../SpannableAutocompleteEditTextModel.java | 82 ++++++++++++++--------
.../browser/omnibox/AutocompleteEditTextTest.java | 16 +++++
2 files changed, 68 insertions(+), 30 deletions(-)