Fix TextView#getEditorAndHandwritingBounds used wrong matrix

In ag/28386190, the TextView's local visible bounds is comptued by
1. find the global visible bounds of the TextView in view root's
coordinates.
2. transform the global visible bounds to TextView's coordinates

The issue is that in step 2, we used matrix returned from
View#transformMatrixToLocal which maps *screen coordinates* to
the view's coordinates. The correct matrix should be one that
maps view root's coordinates to view's coordinates.

Bug: 361208016
Test: atest TextViewWithTransformationHandwritingTest
Flag: com.android.text.flags.handwriting_gesture_with_transformation
Change-Id: Ie8cfeb86235bdd14b97d69574c634a293a11f1e6
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 523ff38..7b4ea41 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -27377,6 +27377,29 @@
     }
 
     /**
+     * Modifiers the input matrix such that it maps root view's coordinates to view-local
+     * coordinates.
+     *
+     * @param matrix input matrix to modify
+     * @hide
+     */
+    public void transformMatrixRootToLocal(@NonNull Matrix matrix) {
+        final ViewParent parent = mParent;
+        if (parent instanceof final View vp) {
+            vp.transformMatrixRootToLocal(matrix);
+            matrix.postTranslate(vp.mScrollX, vp.mScrollY);
+        }
+        // This method is different from transformMatrixToLocal that it doesn't perform any
+        // transformation for ViewRootImpl
+
+        matrix.postTranslate(-mLeft, -mTop);
+
+        if (!hasIdentityMatrix()) {
+            matrix.postConcat(getInverseMatrix());
+        }
+    }
+
+    /**
      * @hide
      */
     @ViewDebug.ExportedProperty(category = "layout", indexMapping = {
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index a346a67..a4b28ad 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -14375,7 +14375,7 @@
 
         Matrix matrix = mTempMatrix;
         matrix.reset();
-        transformMatrixToLocal(matrix);
+        transformMatrixRootToLocal(matrix);
         editorBounds.set(rect);
         // When the view has transformations like scaleX/scaleY computing the global visible
         // rectangle will already apply the transformations. The getLocalVisibleRect only offsets