Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c89c9dd3 authored by Phil Weaver's avatar Phil Weaver Committed by android-build-merger
Browse files

Merge "Properly translate text locations to screen coords" into oc-dev

am: 2a86bad9

Change-Id: I268464c67b76de2a5c467a8cbb60b4dbee784b47
parents f306510b 2a86bad9
Loading
Loading
Loading
Loading
+23 −14
Original line number Diff line number Diff line
@@ -7237,44 +7237,53 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        RectF position = mAttachInfo.mTmpTransformRect;
        position.set(0, 0, mRight - mLeft, mBottom - mTop);
        mapRectFromViewToScreenCoords(position, clipToParent);
        outRect.set(Math.round(position.left), Math.round(position.top),
                Math.round(position.right), Math.round(position.bottom));
    }
    /**
     * Map a rectangle from view-relative coordinates to screen-relative coordinates
     *
     * @param rect The rectangle to be mapped
     * @param clipToParent Whether to clip child bounds to the parent ones.
     * @hide
     */
    public void mapRectFromViewToScreenCoords(RectF rect, boolean clipToParent) {
        if (!hasIdentityMatrix()) {
            getMatrix().mapRect(position);
            getMatrix().mapRect(rect);
        }
        position.offset(mLeft, mTop);
        rect.offset(mLeft, mTop);
        ViewParent parent = mParent;
        while (parent instanceof View) {
            View parentView = (View) parent;
            position.offset(-parentView.mScrollX, -parentView.mScrollY);
            rect.offset(-parentView.mScrollX, -parentView.mScrollY);
            if (clipToParent) {
                position.left = Math.max(position.left, 0);
                position.top = Math.max(position.top, 0);
                position.right = Math.min(position.right, parentView.getWidth());
                position.bottom = Math.min(position.bottom, parentView.getHeight());
                rect.left = Math.max(rect.left, 0);
                rect.top = Math.max(rect.top, 0);
                rect.right = Math.min(rect.right, parentView.getWidth());
                rect.bottom = Math.min(rect.bottom, parentView.getHeight());
            }
            if (!parentView.hasIdentityMatrix()) {
                parentView.getMatrix().mapRect(position);
                parentView.getMatrix().mapRect(rect);
            }
            position.offset(parentView.mLeft, parentView.mTop);
            rect.offset(parentView.mLeft, parentView.mTop);
            parent = parentView.mParent;
        }
        if (parent instanceof ViewRootImpl) {
            ViewRootImpl viewRootImpl = (ViewRootImpl) parent;
            position.offset(0, -viewRootImpl.mCurScrollY);
            rect.offset(0, -viewRootImpl.mCurScrollY);
        }
        position.offset(mAttachInfo.mWindowLeft, mAttachInfo.mWindowTop);
        outRect.set(Math.round(position.left), Math.round(position.top),
                Math.round(position.right), Math.round(position.bottom));
        rect.offset(mAttachInfo.mWindowLeft, mAttachInfo.mWindowTop);
    }
    /**
+1 −2
Original line number Diff line number Diff line
@@ -10400,14 +10400,13 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                    positionInfoStartIndex + positionInfoLength,
                    viewportToContentHorizontalOffset(), viewportToContentVerticalOffset());
            CursorAnchorInfo cursorAnchorInfo = builder.setMatrix(null).build();
            int[] locationOnScreen = getLocationOnScreen();
            for (int i = 0; i < positionInfoLength; i++) {
                int flags = cursorAnchorInfo.getCharacterBoundsFlags(positionInfoStartIndex + i);
                if ((flags & FLAG_HAS_VISIBLE_REGION) == FLAG_HAS_VISIBLE_REGION) {
                    RectF bounds = cursorAnchorInfo
                            .getCharacterBounds(positionInfoStartIndex + i);
                    if (bounds != null) {
                        bounds.offset(locationOnScreen[0], locationOnScreen[1]);
                        mapRectFromViewToScreenCoords(bounds, true);
                        boundingRects[i] = bounds;
                    }
                }