Add focusTransferTarget in WindowInfo
A transfer focus request was originally added on FocusRequest object. This meant when a host wanted to provide focus to an embedded window, it would request to transfer focus, but provide its own token as the focusedToken in the request. In FocusResolver, it would ensure that the focusedToken was current focus before allow the request to proceed. This worked in some cases, but created races where clients had to understand timing in order to properly transfer focus. The new code creates a persistent focusTransferTarget value on the WindowInfo object. The host will add the embedded token as part of its own WindowInfo#focusTransferTarget. When FocusResolver determines that a window should gain focus, it will check to see if there is any focusTransferTarget value set. If there is, it will attempt to give focus to that window, if possible. Otherwise, it will fallback to the previous window in the chain. This solves a few issues with embedded windows. 1. Apps can request focus to the embedded by requesting focus to the SV that hosts the embedded. However, if they request focus too early, it will drop the request since the host has not yet gained focus. With the current code, it will transfer focus to the embedded once the host could have gained focus. If the host wants to revoke, the focusTransferTarget can be set to null, which will give the host focus again. 2. This fixes the issue if another window becomes focus. When WM gives focus back to the host window, it should automatically give focus to the embedded if it was last requested. The app shouldn't be required to maintain the last state of the embedded focus to see if it needs to transfer it again. It's actually not even possible once focus can be given to embedded via touch since only WM and Input know about this. By adding focusTransferTarget to WindowInfo, the focusedToken value in FocusRequest can be removed, as well. Test: InputDispatcher_test Test: FocusResolver_test Test: WindowInfo_test Bug: 230340812 Change-Id: I252403184f7060c37c82353638ac6ee25a0979fc
Loading
Please register or sign in to comment