summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Yigit Boyar <yboyar@google.com> 2016-01-19 18:56:20 -0800
committer Yigit Boyar <yboyar@google.com> 2016-01-25 10:39:29 -0800
commitd62d5e9accc76952d737f9c58a97f898807713e5 (patch)
tree05212d6a9289c2c3a3b978877b856dd3c2c97ba1
parent7487f90581358b7b7d5116320465d37b3c34a0f5 (diff)
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
-rw-r--r--core/java/android/view/View.java27
-rw-r--r--core/java/android/view/ViewParent.java4
-rw-r--r--core/java/android/view/ViewRootImpl.java21
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,
* <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();
}
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:
* <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>
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;
}