From d62d5e9accc76952d737f9c58a97f898807713e5 Mon Sep 17 00:00:00 2001 From: Yigit Boyar Date: Tue, 19 Jan 2016 18:56:20 -0800 Subject: 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 --- core/java/android/view/View.java | 27 ++++++++++++--------------- core/java/android/view/ViewParent.java | 4 ++-- core/java/android/view/ViewRootImpl.java | 21 ++++++++++++--------- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 0b8018b22f1b..19fe1749156f 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -5736,8 +5736,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback, *

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. + *

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, *

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. - * + *

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. *

When immediate 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(); } diff --git a/core/java/android/view/ViewParent.java b/core/java/android/view/ViewParent.java index e9b123b5b9be..1962be86ffb1 100644 --- a/core/java/android/view/ViewParent.java +++ b/core/java/android/view/ViewParent.java @@ -266,14 +266,14 @@ public interface ViewParent { * intercept touch events. */ public void requestDisallowInterceptTouchEvent(boolean disallowIntercept); - + /** * Called when a child of this group wants a particular rectangle to be * positioned onto the screen. {@link ViewGroup}s overriding this can trust * that: *

* *

{@link ViewGroup}s overriding this should uphold the contract:

diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index 9c19bf14a8bd..bcd4d2d09858 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -6693,16 +6693,19 @@ 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); - try { - mWindowSession.onRectangleOnScreenRequested(mWindow, mTempRect); - } catch (RemoteException re) { - /* ignore */ - } + mTempRect.set(rectangle); + mTempRect.offset(0, -mCurScrollY); + mTempRect.offset(mAttachInfo.mWindowLeft, mAttachInfo.mWindowTop); + try { + mWindowSession.onRectangleOnScreenRequested(mWindow, mTempRect); + } catch (RemoteException re) { + /* ignore */ } return scrolled; } -- cgit v1.2.3-59-g8ed1b