Support view transformations when positioning floating CAB

Bug: 24088745

Use ViewGroup#getChildVisibleRect to transform the reported content
rect into the coordinate system of the root view. This allows the
floating CAB to be positioned correctly for views that may have a
scale (or other transforms) applied.

Change-Id: Ia6733a461b44070e7f6bab42f0b6fe2aed6870e5
This commit is contained in:
Justin Klaassen
2016-04-26 20:19:07 -07:00
parent 25459e135d
commit 6183b722de

View File

@@ -24,6 +24,8 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.ViewParent;
import com.android.internal.R;
import com.android.internal.util.Preconditions;
@@ -165,7 +167,17 @@ public class FloatingActionMode extends ActionMode {
checkToolbarInitialized();
mContentRectOnScreen.set(mContentRect);
mContentRectOnScreen.offset(mViewPositionOnScreen[0], mViewPositionOnScreen[1]);
// Offset the content rect into screen coordinates, taking into account any transformations
// that may be applied to the originating view or its ancestors.
final ViewParent parent = mOriginatingView.getParent();
if (parent instanceof ViewGroup) {
((ViewGroup) parent).getChildVisibleRect(
mOriginatingView, mContentRectOnScreen, null /* offset */);
mContentRectOnScreen.offset(mRootViewPositionOnScreen[0], mRootViewPositionOnScreen[1]);
} else {
mContentRectOnScreen.offset(mViewPositionOnScreen[0], mViewPositionOnScreen[1]);
}
if (isContentRectWithinBounds()) {
mFloatingToolbarVisibilityHelper.setOutOfBounds(false);