I'm trying to get the caret/selection bounds for a text field in KeyboardController. In KeyboardController::OnTextInputStateChanged, there's a TextInputClient which I can use to get the caret bounds. The TextInputClient grabs the bounds from a cached map in TextInputManager::GetSelectionRegion. However, from some logging, it appears that this cached map is getting updated (in TextInputManager::SelectionBoundsChanged) -after- I query the bounds in KeyboardController::OnTextInputStateChanged. So the values I'm getting are stale & inconsistent.
For example, I went to a website and:
1. Clicked on a textbox
2. Clicked somewhere else to defocus the textbox
3. Clicked on the same textbox again.
I got two wildly different values for the caret bounds in step 1 & 3. Here's a trace: https://pastebin.com/qxQHF4aa
For the trace:
- "** got caret bound" is where I log the result of getting the caret bound, and it's a different value the second time.
- "Changing selection region map" happens after "** got caret bound".
So it seems like the focus event is being triggered before the selection update. Is this intentional? If so, is it possible to change this behaviour so that the selection region is updated before it's queried? Are there any other workarounds?
Comment 1 by shend@chromium.org
, Mar 22 2018Status: Assigned (was: Available)