From: Philip P. Moltmann Date: Wed, 3 May 2017 00:32:07 +0000 (-0700) Subject: Fix left/top in ViewNode for suppressed parents X-Git-Tag: android-x86-9.0-r1~1044^2~942^2 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=e926aad53d9bb7255ce3f4e94dc3de38089349ea;p=android-x86%2Fframeworks-base.git Fix left/top in ViewNode for suppressed parents If parents of a view got suppressed in the autofill structure the left and top value are not relative to their direct parents anymore. They need to be relative to the next non-suppressed parent. This does not change any values for assist structures. Fixes: 36060132, 37444334 Test: CtsAutoFillServiceTestCases + new ones that check for the left and top parameters of view nodes. Change-Id: I914ad028c7ed2f93ce44210cbe1a2a710673cbbb --- diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index c250ca03565e..24eaf3441c9c 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -7304,7 +7304,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * fills in all data that can be inferred from the view itself. */ public void onProvideStructure(ViewStructure structure) { - onProvideStructureForAssistOrAutofill(structure, false); + onProvideStructureForAssistOrAutofill(structure, false, 0); } /** @@ -7318,6 +7318,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback, *
  • It must set fields such {@link ViewStructure#setText(CharSequence)}, * {@link ViewStructure#setAutofillOptions(CharSequence[])}, * or {@link ViewStructure#setWebDomain(String)}. + *
  • The {@code left} and {@code top} values set in + * {@link ViewStructure#setDimens(int, int, int, int, int, int)} need to be relative to the next + * {@link ViewGroup#isImportantForAutofill() included} parent in the structure. * * * @param structure Fill in with structured view data. The default implementation @@ -7326,12 +7329,12 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * * @see #AUTOFILL_FLAG_INCLUDE_NOT_IMPORTANT_VIEWS */ - public void onProvideAutofillStructure(ViewStructure structure, int flags) { - onProvideStructureForAssistOrAutofill(structure, true); + public void onProvideAutofillStructure(ViewStructure structure, @AutofillFlags int flags) { + onProvideStructureForAssistOrAutofill(structure, true, flags); } private void onProvideStructureForAssistOrAutofill(ViewStructure structure, - boolean forAutofill) { + boolean forAutofill, @AutofillFlags int flags) { final int id = mID; if (id != NO_ID && !isViewIdGenerated(id)) { String pkg, type, entry; @@ -7359,7 +7362,31 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } } - structure.setDimens(mLeft, mTop, mScrollX, mScrollY, mRight - mLeft, mBottom - mTop); + int ignoredParentLeft = 0; + int ignoredParentTop = 0; + if (forAutofill && (flags & AUTOFILL_FLAG_INCLUDE_NOT_IMPORTANT_VIEWS) == 0) { + View parentGroup = null; + + ViewParent viewParent = getParent(); + if (viewParent instanceof View) { + parentGroup = (View) viewParent; + } + + while (parentGroup != null && !parentGroup.isImportantForAutofill()) { + ignoredParentLeft += parentGroup.mLeft; + ignoredParentTop += parentGroup.mTop; + + viewParent = parentGroup.getParent(); + if (viewParent instanceof View) { + parentGroup = (View) viewParent; + } else { + break; + } + } + } + + structure.setDimens(ignoredParentLeft + mLeft, ignoredParentTop + mTop, mScrollX, mScrollY, + mRight - mLeft, mBottom - mTop); if (!forAutofill) { if (!hasIdentityMatrix()) { structure.setTransformation(getMatrix()); @@ -7445,10 +7472,15 @@ public class View implements Drawable.Callback, KeyEvent.Callback, *
  • Call {@link AutofillManager#cancel()} ()} when the autofill context * of the view structure changed and you want the current autofill interaction if such * to be cancelled. + *
  • The {@code left} and {@code top} values set in + * {@link ViewStructure#setDimens(int, int, int, int, int, int)} need to be relative to the next + * {@link ViewGroup#isImportantForAutofill() included} parent in the structure. * * * @param structure Fill in with structured view data. - * @param flags optional flags (currently {@code 0}). + * @param flags optional flags. + * + * @see #AUTOFILL_FLAG_INCLUDE_NOT_IMPORTANT_VIEWS */ public void onProvideAutofillVirtualStructure(ViewStructure structure, int flags) { } @@ -7771,7 +7803,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * {@link #onProvideVirtualStructure}. */ public void dispatchProvideStructure(ViewStructure structure) { - dispatchProvideStructureForAssistOrAutofill(structure, false); + dispatchProvideStructureForAssistOrAutofill(structure, false, 0); } /** @@ -7804,16 +7836,15 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ public void dispatchProvideAutofillStructure(@NonNull ViewStructure structure, @AutofillFlags int flags) { - dispatchProvideStructureForAssistOrAutofill(structure, true); + dispatchProvideStructureForAssistOrAutofill(structure, true, flags); } private void dispatchProvideStructureForAssistOrAutofill(ViewStructure structure, - boolean forAutofill) { + boolean forAutofill, @AutofillFlags int flags) { if (forAutofill) { structure.setAutofillId(getAutofillId()); - // NOTE: flags are not currently supported, hence 0 - onProvideAutofillStructure(structure, 0); - onProvideAutofillVirtualStructure(structure, 0); + onProvideAutofillStructure(structure, flags); + onProvideAutofillVirtualStructure(structure, flags); } else if (!isAssistBlocked()) { onProvideStructure(structure); onProvideVirtualStructure(structure);