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

Commit 4398c63e authored by Nicolas Roard's avatar Nicolas Roard Committed by Android (Google) Code Review
Browse files

Merge "Revert "Update to ToT RemoteCompose"" into main

parents ea7e81e8 4bb0b39e
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.internal.widget.remotecompose.player.accessibility.platform;
package com.android.internal.widget.remotecompose.accessibility;

import android.graphics.Rect;
import android.view.View;
@@ -22,7 +22,6 @@ import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;

import com.android.internal.widget.remotecompose.core.operations.RootContentBehavior;
import com.android.internal.widget.remotecompose.core.semantics.ScrollableComponent;
import com.android.internal.widget.remotecompose.player.accessibility.BaseSemanticNodeApplier;

import java.util.List;

+1 −1
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.internal.widget.remotecompose.player.accessibility;
package com.android.internal.widget.remotecompose.accessibility;

import android.graphics.Rect;
import android.util.Log;
+56 −26
Original line number Diff line number Diff line
@@ -13,9 +13,8 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.internal.widget.remotecompose.player.accessibility;
package com.android.internal.widget.remotecompose.accessibility;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.graphics.PointF;
import android.os.Bundle;
@@ -23,7 +22,7 @@ import android.view.accessibility.AccessibilityNodeInfo;

import com.android.internal.widget.remotecompose.core.CoreDocument;
import com.android.internal.widget.remotecompose.core.Operation;
import com.android.internal.widget.remotecompose.core.RemoteContextActions;
import com.android.internal.widget.remotecompose.core.RemoteContext;
import com.android.internal.widget.remotecompose.core.operations.layout.ClickModifierOperation;
import com.android.internal.widget.remotecompose.core.operations.layout.Component;
import com.android.internal.widget.remotecompose.core.operations.layout.LayoutComponent;
@@ -33,6 +32,7 @@ import com.android.internal.widget.remotecompose.core.operations.layout.modifier
import com.android.internal.widget.remotecompose.core.semantics.AccessibilitySemantics;
import com.android.internal.widget.remotecompose.core.semantics.AccessibleComponent;
import com.android.internal.widget.remotecompose.core.semantics.CoreSemantics;
import com.android.internal.widget.remotecompose.core.semantics.ScrollableComponent;
import com.android.internal.widget.remotecompose.core.semantics.ScrollableComponent.ScrollDirection;

import java.util.ArrayList;
@@ -49,12 +49,11 @@ import java.util.stream.Stream;
 */
public class CoreDocumentAccessibility implements RemoteComposeDocumentAccessibility {
    private final CoreDocument mDocument;
    private final RemoteContextActions mRemoteContextActions;
    private final RemoteContext mRemoteContext;

    public CoreDocumentAccessibility(
            CoreDocument document, RemoteContextActions mRemoteContextActions) {
    public CoreDocumentAccessibility(CoreDocument document, RemoteContext remoteContext) {
        this.mDocument = document;
        this.mRemoteContextActions = mRemoteContextActions;
        this.mRemoteContext = remoteContext;
    }

    @Nullable
@@ -99,14 +98,6 @@ public class CoreDocumentAccessibility implements RemoteComposeDocumentAccessibi
        return result;
    }

    /**
     * Performs the given accessibility action on the specified component.
     *
     * @param component The component on which to perform the action.
     * @param action The accessibility action to perform.
     * @param arguments Optional arguments for the action.
     * @return True if the action was successfully performed, false otherwise.
     */
    public boolean performAction(Component component, int action, Bundle arguments) {
        boolean needsRepaint = true;

@@ -114,11 +105,11 @@ public class CoreDocumentAccessibility implements RemoteComposeDocumentAccessibi
            if (isClickAction(action)) {
                return performClick(component);
            } else if (isScrollForwardAction(action)) {
                return scrollDirection(component, ScrollDirection.FORWARD);
                return scrollDirection(mRemoteContext, component, ScrollDirection.FORWARD);
            } else if (isScrollBackwardAction(action)) {
                return scrollDirection(component, ScrollDirection.BACKWARD);
                return scrollDirection(mRemoteContext, component, ScrollDirection.BACKWARD);
            } else if (isShowOnScreenAction(action)) {
                return showOnScreen(component);
                return showOnScreen(mRemoteContext, component);
            } else {
                needsRepaint = false;
                return false;
@@ -150,30 +141,68 @@ public class CoreDocumentAccessibility implements RemoteComposeDocumentAccessibi
        return action == AccessibilityNodeInfo.ACTION_CLICK;
    }

    private boolean showOnScreen(Component component) {
        return mRemoteContextActions.showOnScreen(component);
    private boolean showOnScreen(RemoteContext context, Component component) {
        ScrollableComponent scrollable = findScrollable(component);

        if (scrollable != null) {
            return scrollable.showOnScreen(context, component);
        }

        return false;
    }

    @Nullable
    private static ScrollableComponent findScrollable(Component component) {
        Component parent = component.getParent();

        while (parent != null) {
            ScrollableComponent scrollable = parent.selfOrModifier(ScrollableComponent.class);

            if (scrollable != null) {
                return scrollable;
            } else {
                parent = parent.getParent();
            }
        }

        return null;
    }

    /**
     * scroll content by the given offset
     *
     * @param context
     * @param component
     * @param pixels
     * @return
     */
    public int scrollByOffset(@NonNull Component component, int pixels) {
        return mRemoteContextActions.scrollByOffset(component, pixels);
    public int scrollByOffset(RemoteContext context, Component component, int pixels) {
        ScrollableComponent scrollable = component.selfOrModifier(ScrollableComponent.class);

        if (scrollable != null) {
            return scrollable.scrollByOffset(context, pixels);
        }

        return 0;
    }

    /**
     * scroll content in a given direction
     *
     * @param context
     * @param component
     * @param direction
     * @return
     */
    public boolean scrollDirection(@NonNull Component component, ScrollDirection direction) {
        return mRemoteContextActions.scrollDirection(component, direction);
    public boolean scrollDirection(
            RemoteContext context, Component component, ScrollDirection direction) {
        ScrollableComponent scrollable = component.selfOrModifier(ScrollableComponent.class);

        if (scrollable != null) {
            return scrollable.scrollDirection(context, direction);
        }

        return false;
    }

    /**
@@ -182,8 +211,9 @@ public class CoreDocumentAccessibility implements RemoteComposeDocumentAccessibi
     * @param component
     * @return
     */
    public boolean performClick(@NonNull Component component) {
        return mRemoteContextActions.performClick(mDocument, component, "");
    public boolean performClick(Component component) {
        mDocument.performClick(mRemoteContext, component.getComponentId(), "");
        return true;
    }

    @Nullable
+4 −25
Original line number Diff line number Diff line
@@ -13,15 +13,13 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.internal.widget.remotecompose.player.accessibility.platform;
package com.android.internal.widget.remotecompose.accessibility;

import android.annotation.NonNull;
import android.view.View;

import com.android.internal.widget.remotecompose.core.CoreDocument;
import com.android.internal.widget.remotecompose.core.RemoteContextActions;
import com.android.internal.widget.remotecompose.player.accessibility.CoreDocumentAccessibility;
import com.android.internal.widget.remotecompose.player.accessibility.RemoteComposeAccessibilityRegistrar;
import com.android.internal.widget.remotecompose.core.RemoteContextAware;

/**
 * Trivial wrapper for calling setAccessibilityDelegate on a View. This exists primarily because the
@@ -30,39 +28,20 @@ import com.android.internal.widget.remotecompose.player.accessibility.RemoteComp
 */
public class PlatformRemoteComposeAccessibilityRegistrar
        implements RemoteComposeAccessibilityRegistrar {

    /**
     * return helper
     *
     * @param player
     * @param coreDocument
     * @return
     */
    public PlatformRemoteComposeTouchHelper forRemoteComposePlayer(
            View player, @NonNull CoreDocument coreDocument) {
        return new PlatformRemoteComposeTouchHelper(
                player,
                new CoreDocumentAccessibility(coreDocument, ((RemoteContextActions) player)),
                new CoreDocumentAccessibility(
                        coreDocument, ((RemoteContextAware) player).getRemoteContext()),
                new AndroidPlatformSemanticNodeApplier(player));
    }

    /**
     * set delegate
     *
     * @param remoteComposePlayer The View representing the remote compose player.
     * @param document The CoreDocument containing the accessibility information for the UI
     *     elements.
     */
    public void setAccessibilityDelegate(View remoteComposePlayer, CoreDocument document) {
        remoteComposePlayer.setAccessibilityDelegate(
                forRemoteComposePlayer(remoteComposePlayer, document));
    }

    /**
     * clear delegate
     *
     * @param remoteComposePlayer The View representing the remote compose player.
     */
    public void clearAccessibilityDelegate(View remoteComposePlayer) {
        remoteComposePlayer.setAccessibilityDelegate(null);
    }
+6 −15
Original line number Diff line number Diff line
@@ -13,9 +13,9 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.internal.widget.remotecompose.player.accessibility.platform;
package com.android.internal.widget.remotecompose.accessibility;

import static com.android.internal.widget.remotecompose.player.accessibility.RemoteComposeDocumentAccessibility.RootId;
import static com.android.internal.widget.remotecompose.accessibility.RemoteComposeDocumentAccessibility.RootId;

import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -28,13 +28,10 @@ import android.view.accessibility.AccessibilityNodeInfo;

import com.android.internal.widget.ExploreByTouchHelper;
import com.android.internal.widget.remotecompose.core.CoreDocument;
import com.android.internal.widget.remotecompose.core.RemoteContextActions;
import com.android.internal.widget.remotecompose.core.RemoteContextAware;
import com.android.internal.widget.remotecompose.core.operations.layout.Component;
import com.android.internal.widget.remotecompose.core.semantics.AccessibilitySemantics;
import com.android.internal.widget.remotecompose.core.semantics.AccessibleComponent.Mode;
import com.android.internal.widget.remotecompose.player.accessibility.CoreDocumentAccessibility;
import com.android.internal.widget.remotecompose.player.accessibility.RemoteComposeDocumentAccessibility;
import com.android.internal.widget.remotecompose.player.accessibility.SemanticNodeApplier;

import java.util.List;

@@ -54,14 +51,12 @@ public class PlatformRemoteComposeTouchHelper extends ExploreByTouchHelper {
        this.mHost = host;
    }

    /**
     * access the helper
     */
    public static PlatformRemoteComposeTouchHelper forRemoteComposePlayer(
            View player, @NonNull CoreDocument coreDocument) {
        return new PlatformRemoteComposeTouchHelper(
                player,
                new CoreDocumentAccessibility(coreDocument, ((RemoteContextActions) player)),
                new CoreDocumentAccessibility(
                        coreDocument, ((RemoteContextAware) player).getRemoteContext()),
                new AndroidPlatformSemanticNodeApplier(player));
    }

@@ -106,9 +101,6 @@ public class PlatformRemoteComposeTouchHelper extends ExploreByTouchHelper {
        }
    }

    /**
     * returns the list of visible children
     */
    @SuppressWarnings("JdkImmutableCollections")
    public List<Integer> getVisibleChildVirtualViews() {
        Component rootComponent = mRemoteDocA11y.findComponentById(RootId);
@@ -153,8 +145,7 @@ public class PlatformRemoteComposeTouchHelper extends ExploreByTouchHelper {
    }

    @Override
    protected void onPopulateEventForVirtualView(
            int virtualViewId, @NonNull AccessibilityEvent event) {}
    protected void onPopulateEventForVirtualView(int virtualViewId, AccessibilityEvent event) {}

    @Override
    protected boolean onPerformActionForVirtualView(
Loading