From 487b4db166ce724892b11d829b2f8217785c9d7d Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Wed, 6 Apr 2022 11:26:18 -0700 Subject: [PATCH] Fix touchable region calculation in NavigationBarController This is a follow up CL to my previous CL [1], which aimed to automatically adjust InputMethodService.Insets so that the tap events on the navigation bar region can be sent to the IME. What I forgot was that View#get{Left,Top,Right,Bottom}() returns values in the window local coordinates, not in the screen coordinates. As a result, in some cases the keyboard area could become untouchable unless the IME specified ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION to InputMethodService.Insets#touchableInsets. With this CL, touchable region should be correctly calculated. [1]: I3e7e1f83554444131e2765dc159617bb9e2337c7 ff7b453ca8e23b4ef75ba2c3f5becaf511cb07d3 Fix: 226566506 Test: manually verified with the IME mentioned in the bug. Change-Id: I0fe54efac80dd0d55f4ba37cfa7d7188b642abb0 --- .../NavigationBarController.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/core/java/android/inputmethodservice/NavigationBarController.java b/core/java/android/inputmethodservice/NavigationBarController.java index bd6c4e1a0c09e..dc38db2134f40 100644 --- a/core/java/android/inputmethodservice/NavigationBarController.java +++ b/core/java/android/inputmethodservice/NavigationBarController.java @@ -259,23 +259,22 @@ final class NavigationBarController { switch (originalInsets.touchableInsets) { case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME: if (inputFrame.getVisibility() == View.VISIBLE) { - touchableRegion = new Region(inputFrame.getLeft(), - inputFrame.getTop(), inputFrame.getRight(), - inputFrame.getBottom()); + inputFrame.getBoundsOnScreen(mTempRect); + touchableRegion = new Region(mTempRect); } break; case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: if (inputFrame.getVisibility() == View.VISIBLE) { - touchableRegion = new Region(inputFrame.getLeft(), - originalInsets.contentTopInsets, inputFrame.getRight(), - inputFrame.getBottom()); + inputFrame.getBoundsOnScreen(mTempRect); + mTempRect.top = originalInsets.contentTopInsets; + touchableRegion = new Region(mTempRect); } break; case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: if (inputFrame.getVisibility() == View.VISIBLE) { - touchableRegion = new Region(inputFrame.getLeft(), - originalInsets.visibleTopInsets, inputFrame.getRight(), - inputFrame.getBottom()); + inputFrame.getBoundsOnScreen(mTempRect); + mTempRect.top = originalInsets.visibleTopInsets; + touchableRegion = new Region(mTempRect); } break; case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION: @@ -283,6 +282,7 @@ final class NavigationBarController { touchableRegion.set(originalInsets.touchableRegion); break; } + // Hereafter "mTempRect" means a navigation bar rect. mTempRect.set(decor.getLeft(), decor.getBottom() - systemInsets.bottom, decor.getRight(), decor.getBottom()); if (touchableRegion == null) {