Skip to content

Commit ee6c6ae

Browse files
committed
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
1 parent 36e614c commit ee6c6ae

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

core/java/android/view/View.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import android.graphics.Shader;
4040
import android.graphics.drawable.ColorDrawable;
4141
import android.graphics.drawable.Drawable;
42-
import android.hardware.display.DisplayManager;
4342
import android.hardware.display.DisplayManagerGlobal;
4443
import android.os.Bundle;
4544
import android.os.Handler;
@@ -4275,25 +4274,42 @@ public boolean requestRectangleOnScreen(Rect rectangle) {
42754274
* @return Whether any parent scrolled.
42764275
*/
42774276
public boolean requestRectangleOnScreen(Rect rectangle, boolean immediate) {
4277+
if (mAttachInfo == null) {
4278+
return false;
4279+
}
4280+
42784281
View child = this;
4282+
4283+
RectF position = mAttachInfo.mTmpTransformRect;
4284+
position.set(rectangle);
4285+
42794286
ViewParent parent = mParent;
42804287
boolean scrolled = false;
42814288
while (parent != null) {
4289+
rectangle.set((int) position.left, (int) position.top,
4290+
(int) position.right, (int) position.bottom);
4291+
42824292
scrolled |= parent.requestChildRectangleOnScreen(child,
42834293
rectangle, immediate);
42844294

4285-
// offset rect so next call has the rectangle in the
4286-
// coordinate system of its direct child.
4287-
rectangle.offset(child.getLeft(), child.getTop());
4288-
rectangle.offset(-child.getScrollX(), -child.getScrollY());
4295+
if (!child.hasIdentityMatrix()) {
4296+
child.getMatrix().mapRect(position);
4297+
}
4298+
4299+
position.offset(child.mLeft, child.mTop);
42894300

42904301
if (!(parent instanceof View)) {
42914302
break;
42924303
}
42934304

4294-
child = (View) parent;
4305+
View parentView = (View) parent;
4306+
4307+
position.offset(-parentView.getScrollX(), -parentView.getScrollY());
4308+
4309+
child = parentView;
42954310
parent = child.getParent();
42964311
}
4312+
42974313
return scrolled;
42984314
}
42994315

0 commit comments

Comments
 (0)