From 83e725da7aad97409d96eed784a076f6d4841b54 Mon Sep 17 00:00:00 2001 From: Adrian Roos Date: Fri, 8 Jan 2016 16:49:17 +0100 Subject: [PATCH] Apply transformations while offsetting focused rects Change-Id: Id6ebf8d50bd74f52fb76cf12bf14ccc0dcf7e34b --- core/java/android/view/ViewGroup.java | 50 ++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java index cd93dab0c48bc..121b590d1cb8a 100644 --- a/core/java/android/view/ViewGroup.java +++ b/core/java/android/view/ViewGroup.java @@ -5359,6 +5359,9 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager void offsetRectBetweenParentAndChild(View descendant, Rect rect, boolean offsetFromChildToParent, boolean clipToBounds) { + final RectF rectF = mAttachInfo != null ? mAttachInfo.mTmpTransformRect1 : new RectF(); + final Matrix inverse = mAttachInfo != null ? mAttachInfo.mTmpMatrix : new Matrix(); + // already in the same coord system :) if (descendant == this) { return; @@ -5372,8 +5375,16 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager && (theParent != this)) { if (offsetFromChildToParent) { - rect.offset(descendant.mLeft - descendant.mScrollX, - descendant.mTop - descendant.mScrollY); + rect.offset(-descendant.mScrollX, -descendant.mScrollY); + + if (!descendant.hasIdentityMatrix()) { + rectF.set(rect); + descendant.getMatrix().mapRect(rectF); + rectF.roundOut(rect); + } + + rect.offset(descendant.mLeft, descendant.mTop); + if (clipToBounds) { View p = (View) theParent; boolean intersected = rect.intersect(0, 0, p.mRight - p.mLeft, @@ -5391,8 +5402,16 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager rect.setEmpty(); } } - rect.offset(descendant.mScrollX - descendant.mLeft, - descendant.mScrollY - descendant.mTop); + rect.offset(-descendant.mLeft, -descendant.mTop); + + if (!descendant.hasIdentityMatrix()) { + descendant.getMatrix().invert(inverse); + rectF.set(rect); + inverse.mapRect(rectF); + rectF.roundOut(rect); + } + + rect.offset(descendant.mScrollX, descendant.mScrollY); } descendant = (View) theParent; @@ -5403,11 +5422,26 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager // to get into our coordinate space if (theParent == this) { if (offsetFromChildToParent) { - rect.offset(descendant.mLeft - descendant.mScrollX, - descendant.mTop - descendant.mScrollY); + rect.offset(-descendant.mScrollX, -descendant.mScrollY); + + if (!descendant.hasIdentityMatrix()) { + rectF.set(rect); + descendant.getMatrix().mapRect(rectF); + rectF.roundOut(rect); + } + + rect.offset(descendant.mLeft, descendant.mTop); } else { - rect.offset(descendant.mScrollX - descendant.mLeft, - descendant.mScrollY - descendant.mTop); + rect.offset(-descendant.mLeft, -descendant.mTop); + + if (!descendant.hasIdentityMatrix()) { + descendant.getMatrix().invert(inverse); + rectF.set(rect); + inverse.mapRect(rectF); + rectF.roundOut(rect); + } + + rect.offset(descendant.mScrollX, descendant.mScrollY); } } else { throw new IllegalArgumentException("parameter must be a descendant of this view");