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

Commit d62d5e9a authored by Yigit Boyar's avatar Yigit Boyar
Browse files

Fix requestRectangleOnScreen

This CL fixes a bug in View#requestRectangleOnScreen where the
position was not being moved from child's coordinate space to
the parent's coordinate space properly.

I've also added more documentation to clarify the API.

Bug: 25787435
Change-Id: Id821fa178e04016f6fb830d0bd2abde046581465
parent 7487f905
Loading
Loading
Loading
Loading
+12 −15
Original line number Diff line number Diff line
@@ -5736,8 +5736,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     * <p>A View should call this if it maintains some notion of which part
     * of its content is interesting.  For example, a text editing view
     * should call this when its cursor moves.
     * <p>The Rectangle passed into this method should be in the View's content coordinate space.
     * It should not be affected by which part of the View is currently visible or its scroll
     * position.
     *
     * @param rectangle The rectangle.
     * @param rectangle The rectangle in the View's content coordinate space
     * @return Whether any parent scrolled.
     */
    public boolean requestRectangleOnScreen(Rect rectangle) {
@@ -5751,11 +5754,13 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     * <p>A View should call this if it maintains some notion of which part
     * of its content is interesting.  For example, a text editing view
     * should call this when its cursor moves.
     *
     * <p>The Rectangle passed into this method should be in the View's content coordinate space.
     * It should not be affected by which part of the View is currently visible or its scroll
     * position.
     * <p>When <code>immediate</code> is set to true, scrolling will not be
     * animated.
     *
     * @param rectangle The rectangle.
     * @param rectangle The rectangle in the View's content coordinate space
     * @param immediate True to forbid animated scrolling, false otherwise
     * @return Whether any parent scrolled.
     */
@@ -5775,24 +5780,16 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            rectangle.set((int) position.left, (int) position.top,
                    (int) position.right, (int) position.bottom);
            scrolled |= parent.requestChildRectangleOnScreen(child,
                    rectangle, immediate);
            if (!child.hasIdentityMatrix()) {
                child.getMatrix().mapRect(position);
            }
            position.offset(child.mLeft, child.mTop);
            scrolled |= parent.requestChildRectangleOnScreen(child, rectangle, immediate);
            if (!(parent instanceof View)) {
                break;
            }
            View parentView = (View) parent;
            position.offset(-parentView.getScrollX(), -parentView.getScrollY());
            // move it from child's content coordinate space to parent's content coordinate space
            position.offset(child.mLeft - child.getScrollX(), child.mTop -child.getScrollY());
            child = parentView;
            child = (View) parent;
            parent = child.getParent();
        }
+2 −2
Original line number Diff line number Diff line
@@ -273,7 +273,7 @@ public interface ViewParent {
     * that:
     * <ul>
     *   <li>child will be a direct child of this group</li>
     *   <li>rectangle will be in the child's coordinates</li>
     *   <li>rectangle will be in the child's content coordinates</li>
     * </ul>
     *
     * <p>{@link ViewGroup}s overriding this should uphold the contract:</p>
+12 −9
Original line number Diff line number Diff line
@@ -6693,8 +6693,12 @@ public final class ViewRootImpl implements ViewParent,

    @Override
    public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) {
        if (rectangle == null) {
            return scrollToRectOrFocus(null, immediate);
        }
        rectangle.offset(child.getLeft() - child.getScrollX(),
                child.getTop() - child.getScrollY());
        final boolean scrolled = scrollToRectOrFocus(rectangle, immediate);
        if (rectangle != null) {
        mTempRect.set(rectangle);
        mTempRect.offset(0, -mCurScrollY);
        mTempRect.offset(mAttachInfo.mWindowLeft, mAttachInfo.mWindowTop);
@@ -6703,7 +6707,6 @@ public final class ViewRootImpl implements ViewParent,
        } catch (RemoteException re) {
            /* ignore */
        }
        }
        return scrolled;
    }