From ee6c6ae5b2111bbb602dbc8030ba3c8eb014cc6e Mon Sep 17 00:00:00 2001 From: Svetoslav Ganov Date: Mon, 10 Sep 2012 19:56:06 -0700 Subject: [PATCH] Fixing implementation of View.requestRectangleOnScreen(Rect, boolean). 1. The implementation was not taking into account the transformation matrices if the views. 2. The rectangle that was passed as an argument to ViewParent.requestChildRectangleOnScreen was modified by some implementations - now care is taken to prevent it. 3. The scroll of child was used when a rectangle of its coordinate system was mapped to one in the parent system. However, the scroll shows how much a parent has scrolled its descendants, so the scroll of the parent has to be used not the child. bug:7139556 Change-Id: I5b09eb7f105047e95282f74308968d5465831c84 --- core/java/android/view/View.java | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 236adaba9cb4b..7567d88d63d91 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -39,7 +39,6 @@ import android.graphics.Region; import android.graphics.Shader; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; -import android.hardware.display.DisplayManager; import android.hardware.display.DisplayManagerGlobal; import android.os.Bundle; import android.os.Handler; @@ -4275,25 +4274,42 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * @return Whether any parent scrolled. */ public boolean requestRectangleOnScreen(Rect rectangle, boolean immediate) { + if (mAttachInfo == null) { + return false; + } + View child = this; + + RectF position = mAttachInfo.mTmpTransformRect; + position.set(rectangle); + ViewParent parent = mParent; boolean scrolled = false; while (parent != null) { + rectangle.set((int) position.left, (int) position.top, + (int) position.right, (int) position.bottom); + scrolled |= parent.requestChildRectangleOnScreen(child, rectangle, immediate); - // offset rect so next call has the rectangle in the - // coordinate system of its direct child. - rectangle.offset(child.getLeft(), child.getTop()); - rectangle.offset(-child.getScrollX(), -child.getScrollY()); + if (!child.hasIdentityMatrix()) { + child.getMatrix().mapRect(position); + } + + position.offset(child.mLeft, child.mTop); if (!(parent instanceof View)) { break; } - child = (View) parent; + View parentView = (View) parent; + + position.offset(-parentView.getScrollX(), -parentView.getScrollY()); + + child = parentView; parent = child.getParent(); } + return scrolled; }