Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4b69e790 authored by Amanda Lin Dietz's avatar Amanda Lin Dietz Committed by Android (Google) Code Review
Browse files

Merge changes from topic "request-rectangle-with-source-api" into main

* changes:
  [A11y Focus API] Update Magnification to use requestRectangleOnScreen API with source
  [A11y Focus API] Add new requestRectangleOnScreen API with a parameter for source
parents caefa535 02908b5f
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -54439,6 +54439,7 @@ package android.view {
    method public void requestPointerCapture();
    method public boolean requestRectangleOnScreen(android.graphics.Rect);
    method public boolean requestRectangleOnScreen(android.graphics.Rect, boolean);
    method @FlaggedApi("android.view.accessibility.request_rectangle_with_source") public boolean requestRectangleOnScreen(@NonNull android.graphics.Rect, boolean, int);
    method public final void requestUnbufferedDispatch(android.view.MotionEvent);
    method public final void requestUnbufferedDispatch(int);
    method @NonNull public final <T extends android.view.View> T requireViewById(@IdRes int);
@@ -54763,6 +54764,10 @@ package android.view {
    field protected static final int[] PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET;
    field protected static final int[] PRESSED_STATE_SET;
    field protected static final int[] PRESSED_WINDOW_FOCUSED_STATE_SET;
    field @FlaggedApi("android.view.accessibility.request_rectangle_with_source") public static final int RECTANGLE_ON_SCREEN_REQUEST_SOURCE_INPUT_FOCUS = 3; // 0x3
    field @FlaggedApi("android.view.accessibility.request_rectangle_with_source") public static final int RECTANGLE_ON_SCREEN_REQUEST_SOURCE_SCROLL_ONLY = 1; // 0x1
    field @FlaggedApi("android.view.accessibility.request_rectangle_with_source") public static final int RECTANGLE_ON_SCREEN_REQUEST_SOURCE_TEXT_CURSOR = 2; // 0x2
    field @FlaggedApi("android.view.accessibility.request_rectangle_with_source") public static final int RECTANGLE_ON_SCREEN_REQUEST_SOURCE_UNDEFINED = 0; // 0x0
    field @FlaggedApi("android.view.flags.toolkit_set_frame_rate_read_only") public static final float REQUESTED_FRAME_RATE_CATEGORY_DEFAULT = (0.0f/0.0f);
    field @FlaggedApi("android.view.flags.toolkit_set_frame_rate_read_only") public static final float REQUESTED_FRAME_RATE_CATEGORY_HIGH = -4.0f;
    field @FlaggedApi("android.view.flags.toolkit_set_frame_rate_read_only") public static final float REQUESTED_FRAME_RATE_CATEGORY_LOW = -2.0f;
@@ -55316,6 +55321,7 @@ package android.view {
    method public void recomputeViewAttributes(android.view.View);
    method public void requestChildFocus(android.view.View, android.view.View);
    method public boolean requestChildRectangleOnScreen(@NonNull android.view.View, android.graphics.Rect, boolean);
    method @FlaggedApi("android.view.accessibility.request_rectangle_with_source") public default boolean requestChildRectangleOnScreen(@NonNull android.view.View, @NonNull android.graphics.Rect, boolean, int);
    method public void requestDisallowInterceptTouchEvent(boolean);
    method public void requestFitSystemWindows();
    method public void requestLayout();
+1 −1
Original line number Diff line number Diff line
@@ -229,7 +229,7 @@ interface IWindowSession {
    /**
     * Notifies that a rectangle on the screen has been requested.
     */
    oneway void onRectangleOnScreenRequested(IBinder token, in Rect rectangle);
    oneway void onRectangleOnScreenRequested(IBinder token, in Rect rectangle, int source);

    IWindowId getWindowId(IBinder window);

+89 −2
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
import static android.view.accessibility.AccessibilityEvent.CONTENT_CHANGE_TYPE_UNDEFINED;
import static android.view.accessibility.Flags.a11ySequentialFocusStartingPoint;
import static android.view.accessibility.Flags.FLAG_DEPRECATE_ACCESSIBILITY_ANNOUNCEMENT_APIS;
import static android.view.accessibility.Flags.FLAG_REQUEST_RECTANGLE_WITH_SOURCE;
import static android.view.accessibility.Flags.FLAG_SUPPLEMENTAL_DESCRIPTION;
import static android.view.accessibility.Flags.removeChildHoverCheckForTouchExploration;
import static android.view.accessibility.Flags.supplementalDescription;
@@ -5853,6 +5854,50 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
    private int mSizeBasedFrameRateCategoryAndReason;
    /**
     * @hide
     */
    @IntDef(prefix = { "RECTANGLE_ON_SCREEN_REQUEST_SOURCE_" }, value = {
            RECTANGLE_ON_SCREEN_REQUEST_SOURCE_UNDEFINED,
            RECTANGLE_ON_SCREEN_REQUEST_SOURCE_SCROLL_ONLY,
            RECTANGLE_ON_SCREEN_REQUEST_SOURCE_TEXT_CURSOR,
            RECTANGLE_ON_SCREEN_REQUEST_SOURCE_INPUT_FOCUS,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface RectangleOnScreenRequestSource {}
    /**
     * Represents that the user interaction that is requesting a rectangle on screen is
     * doing so via the original {@link #requestRectangleOnScreen(Rect)} or
     * {@link #requestRectangleOnScreen(Rect, boolean)} APIs that do not define the source.
     * RECTANGLE_ON_SCREEN_REQUEST_SOURCE_UNDEFINED should be reserved for backward
     * compatibility and should only be provided from calls to the original API.
     */
    @FlaggedApi(FLAG_REQUEST_RECTANGLE_WITH_SOURCE)
    public static final int RECTANGLE_ON_SCREEN_REQUEST_SOURCE_UNDEFINED = 0x00000000;
    /**
     * Represents that the user interaction that is requesting a rectangle on screen is doing so
     * only to scroll the View on screen, and the rectangle is not associated with a text cursor or
     * keyboard focus.
     */
    @FlaggedApi(FLAG_REQUEST_RECTANGLE_WITH_SOURCE)
    public static final int RECTANGLE_ON_SCREEN_REQUEST_SOURCE_SCROLL_ONLY = 0x00000001;
    /**
     * Represents that the user interaction that is requesting a rectangle on screen is
     * doing so because the View contains a text cursor (caret).
     */
    @FlaggedApi(FLAG_REQUEST_RECTANGLE_WITH_SOURCE)
    public static final int RECTANGLE_ON_SCREEN_REQUEST_SOURCE_TEXT_CURSOR = 0x00000002;
    /**
     * Represents that the user interaction that is requesting a rectangle on screen is
     * doing so because the View has input/keyboard focus.
     */
    @FlaggedApi(FLAG_REQUEST_RECTANGLE_WITH_SOURCE)
    public static final int RECTANGLE_ON_SCREEN_REQUEST_SOURCE_INPUT_FOCUS = 0x00000003;
    /**
     * Simple constructor to use when creating a view from code.
     *
@@ -8530,6 +8575,42 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     * @return Whether any parent scrolled.
     */
    public boolean requestRectangleOnScreen(Rect rectangle, boolean immediate) {
        return requestRectangleOnScreen(rectangle, immediate,
                RECTANGLE_ON_SCREEN_REQUEST_SOURCE_UNDEFINED);
    }
    /**
     * Request that a rectangle of this view be visible on the screen,
     * scrolling if necessary just enough.
     *
     * <p>A View should call this if it maintains some notion of which part
     * of its content is interesting.  For example, a text editing view
     * should call this when its cursor moves.
     * <p>The Rectangle passed into this method should be in the View's content coordinate space.
     * It should not be affected by which part of the View is currently visible or its scroll
     * position.
     * <p>When <code>immediate</code> is set to true, scrolling will not be
     * animated.
     * <p> The <code>source</code> parameter is used to differentiate behaviors of certain
     * system features, like focus-following with display magnification, based on user
     * preferences and the source of requests to show content on-screen. Callers are
     * encouraged to provide one of the following request sources, when applicable,
     * instead of using {@link #requestRectangleOnScreen(Rect)} or
     * {@link #requestRectangleOnScreen(Rect, boolean)}:
     * <ol>
     *   <li>{@link #RECTANGLE_ON_SCREEN_REQUEST_SOURCE_SCROLL_ONLY}</li>
     *   <li>{@link #RECTANGLE_ON_SCREEN_REQUEST_SOURCE_TEXT_CURSOR}</li>
     *   <li>{@link #RECTANGLE_ON_SCREEN_REQUEST_SOURCE_INPUT_FOCUS}</li>
     * </ol>
     *
     * @param rectangle The rectangle in the View's content coordinate space
     * @param immediate True to forbid animated scrolling, false otherwise
     * @param source The type of user interaction that requested this rectangle
     * @return Whether any parent scrolled.
     */
    @FlaggedApi(FLAG_REQUEST_RECTANGLE_WITH_SOURCE)
    public boolean requestRectangleOnScreen(@NonNull Rect rectangle, boolean immediate,
            @RectangleOnScreenRequestSource int source) {
        if (mParent == null) {
            return false;
        }
@@ -8544,8 +8625,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        while (parent != null) {
            rectangle.set((int) position.left, (int) position.top,
                    (int) position.right, (int) position.bottom);
            scrolled |= parent.requestChildRectangleOnScreen(child, rectangle, immediate);
            scrolled |= parent.requestChildRectangleOnScreen(child, rectangle, immediate, source);
            if (!(parent instanceof View)) {
                break;
@@ -8775,6 +8855,13 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
                    viewRoot.getHandwritingInitiator().onEditorFocused(this);
                }
            }
            if (android.view.accessibility.Flags.requestRectangleWithSource()) {
                final Rect r = mAttachInfo.mTmpInvalRect;
                getLocalVisibleRect(r);
                requestRectangleOnScreen(r, false,
                        RECTANGLE_ON_SCREEN_REQUEST_SOURCE_INPUT_FOCUS);
            }
        }
        invalidate(true);
+36 −3
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

package android.view;

import static android.view.accessibility.Flags.FLAG_REQUEST_RECTANGLE_WITH_SOURCE;

import android.annotation.FlaggedApi;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.graphics.Matrix;
@@ -322,8 +325,8 @@ public interface ViewParent {
     * positioned onto the screen.  {@link ViewGroup}s overriding this can trust
     * that:
     * <ul>
     *   <li>child will be a direct child of this group</li>
     *   <li>rectangle will be in the child's content coordinates</li>
     *   <li>{@code child} will be a direct child of this group</li>
     *   <li>{@code rectangle} will be in the child's content coordinates</li>
     * </ul>
     *
     * <p>{@link ViewGroup}s overriding this should uphold the contract:</p>
@@ -331,7 +334,7 @@ public interface ViewParent {
     *   <li>nothing will change if the rectangle is already visible</li>
     *   <li>the view port will be scrolled only just enough to make the
     *       rectangle visible</li>
     * <ul>
     * </ul>
     *
     * @param child The direct child making the request.
     * @param rectangle The rectangle in the child's coordinates the child
@@ -343,6 +346,36 @@ public interface ViewParent {
    public boolean requestChildRectangleOnScreen(@NonNull View child, Rect rectangle,
            boolean immediate);

    /**
     * Called when a child of this group wants a particular rectangle to be
     * positioned onto the screen.  {@link ViewGroup}s overriding this can trust
     * that:
     * <ul>
     *   <li>{@code child} will be a direct child of this group</li>
     *   <li>{@code rectangle} will be in the child's content coordinates</li>
     * </ul>
     *
     * <p>{@link ViewGroup}s overriding this should uphold the contract:</p>
     * <ul>
     *   <li>nothing will change if the rectangle is already visible</li>
     *   <li>the view port will be scrolled only just enough to make the
     *       rectangle visible</li>
     * </ul>
     *
     * @param child The direct child making the request.
     * @param rectangle The rectangle in the child's coordinates the child
     *        wishes to be on the screen.
     * @param immediate True to forbid animated or delayed scrolling,
     *        false otherwise
     * @param source The parameter for the source of this request.
     * @return Whether the group scrolled to handle the operation
     */
    @FlaggedApi(FLAG_REQUEST_RECTANGLE_WITH_SOURCE)
    default boolean requestChildRectangleOnScreen(@NonNull View child, @NonNull Rect rectangle,
            boolean immediate, @View.RectangleOnScreenRequestSource int source) {
        return requestChildRectangleOnScreen(child, rectangle, immediate);
    }

    /**
     * Called by a child to request from its parent to send an {@link AccessibilityEvent}.
     * The child has already populated a record for itself in the event and is delegating
+8 −1
Original line number Diff line number Diff line
@@ -11358,6 +11358,13 @@ public final class ViewRootImpl implements ViewParent,
    @Override
    public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) {
        return requestChildRectangleOnScreen(child, rectangle, immediate,
                View.RECTANGLE_ON_SCREEN_REQUEST_SOURCE_UNDEFINED);
    }
    @Override
    public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate,
            @View.RectangleOnScreenRequestSource int source) {
        if (rectangle == null) {
            return scrollToRectOrFocus(null, immediate);
        }
@@ -11368,7 +11375,7 @@ public final class ViewRootImpl implements ViewParent,
        mTempRect.offset(0, -mCurScrollY);
        mTempRect.offset(mAttachInfo.mWindowLeft, mAttachInfo.mWindowTop);
        try {
            mWindowSession.onRectangleOnScreenRequested(mWindow, mTempRect);
            mWindowSession.onRectangleOnScreenRequested(mWindow, mTempRect, source);
        } catch (RemoteException re) {
            /* ignore */
        }
Loading