OSDN Git Service

Show selection handles at the correct position for view transformation
authorSeigo Nonaka <nona@google.com>
Thu, 18 Feb 2016 08:53:54 +0000 (17:53 +0900)
committerSeigo Nonaka <nona@google.com>
Wed, 24 Feb 2016 03:56:36 +0000 (12:56 +0900)
The selection handles are implemented based on PopupWindow hence it is
necessary to calculate the transformed location from the TextView's
local coordinates.

This CL only addresses the selection handle locations. Many
functionalities (e.g. selection handle moving direction, handle angle)
doesn't work on transformed view since many components are calculated
on the TextView's local coordinates.

Bug: 24902578
Change-Id: Iaa5fd2812969d097e3bf3219a818ffbc67aaef54

core/java/android/view/View.java
core/java/android/widget/Editor.java

index 70a0e01..fdebecf 100644 (file)
@@ -18916,7 +18916,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
         transformFromViewToWindowSpace(outLocation);
     }
 
-    void transformFromViewToWindowSpace(@Size(2) int[] inOutLocation) {
+    /** @hide */
+    public void transformFromViewToWindowSpace(@Size(2) int[] inOutLocation) {
         if (inOutLocation == null || inOutLocation.length < 2) {
             throw new IllegalArgumentException("inOutLocation must be an array of two integers");
         }
index b2ef687..881e5cd 100644 (file)
@@ -4131,13 +4131,15 @@ public class Editor {
                 }
 
                 if (isVisible()) {
-                    final int positionX = parentPositionX + mPositionX;
-                    final int positionY = parentPositionY + mPositionY;
+                    // Transform to the window coordinates to follow the view tranformation.
+                    final int[] pts = { mPositionX + mHotspotX + getHorizontalOffset(), mPositionY};
+                    mTextView.transformFromViewToWindowSpace(pts);
+                    pts[0] -= mHotspotX + getHorizontalOffset();
+
                     if (isShowing()) {
-                        mContainer.update(positionX, positionY, -1, -1);
+                        mContainer.update(pts[0], pts[1], -1, -1);
                     } else {
-                        mContainer.showAtLocation(mTextView, Gravity.NO_GRAVITY,
-                                positionX, positionY);
+                        mContainer.showAtLocation(mTextView, Gravity.NO_GRAVITY, pts[0], pts[1]);
                     }
                 } else {
                     if (isShowing()) {