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

Commit 2a86bad9 authored by Phil Weaver's avatar Phil Weaver Committed by Android (Google) Code Review
Browse files

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

parents 8e3a8a70 6c617f0a
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;
                    }
                }