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

Commit 0cf35488 authored by Gavin Williams's avatar Gavin Williams
Browse files

a11y: Ignore cursor area size when hovering panel

The users have the option to ignore curser movement up to a large
radius. However the panel's buttons are so close together that a large
ignore radius makes interacting with the panel difficult.

So only when hovering the panel, ignore the user's selected cursor area
and size and always trigger clicks using the default slop.

Also rename to `isPanelHovered()` to clarify what is hovered.

Bug: b/398257159
Test: AutoclickTypePanelTest
Flag: com.android.server.accessibility.enable_autoclick_indicator
Change-Id: If76197b8dec5076a5f34ea0fb60e75ba4857ec9b
parent b95b3b96
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -303,10 +303,10 @@ public class AutoclickController extends BaseEventStreamTransformation {

    private boolean isPaused() {
        return Flags.enableAutoclickIndicator() && mAutoclickTypePanel.isPaused()
                && !isHovered();
                && !isPanelHovered();
    }

    private boolean isHovered() {
    private boolean isPanelHovered() {
        return Flags.enableAutoclickIndicator() && mAutoclickTypePanel.isHovered();
    }

@@ -809,7 +809,7 @@ public class AutoclickController extends BaseEventStreamTransformation {
            }
            mLastMotionEvent = MotionEvent.obtain(event);
            mEventPolicyFlags = policyFlags;
            mHoveredState = isHovered();
            mHoveredState = isPanelHovered();

            if (useAsAnchor) {
                final int pointerIndex = mLastMotionEvent.getActionIndex();
@@ -849,8 +849,11 @@ public class AutoclickController extends BaseEventStreamTransformation {
            float deltaX = mAnchorCoords.x - event.getX(pointerIndex);
            float deltaY = mAnchorCoords.y - event.getY(pointerIndex);
            double delta = Math.hypot(deltaX, deltaY);
            // If the panel is hovered, use the default slop so it's easier to click the closely
            // spaced buttons.
            double slop =
                    ((Flags.enableAutoclickIndicator() && mIgnoreMinorCursorMovement)
                    ((Flags.enableAutoclickIndicator() && mIgnoreMinorCursorMovement
                            && !isPanelHovered())
                            ? mMovementSlop
                            : DEFAULT_MOVEMENT_SLOP);
            return delta > slop;
+37 −0
Original line number Diff line number Diff line
@@ -776,6 +776,43 @@ public class AutoclickControllerTest {
                MotionEvent.BUTTON_PRIMARY);
    }

    @Test
    @EnableFlags(com.android.server.accessibility.Flags.FLAG_ENABLE_AUTOCLICK_INDICATOR)
    public void hoverOnAutoclickPanel_useDefaultCursorArea() {
        MotionEventCaptor motionEventCaptor = new MotionEventCaptor();
        mController.setNext(motionEventCaptor);

        injectFakeMouseActionHoverMoveEvent();
        // Set delay to zero so click is scheduled to run immediately.
        mController.mClickScheduler.updateDelay(0);

        // Set an extra large cursor area size and enable ignore minor cursor movement.
        int customSize = 250;
        Settings.Secure.putIntForUser(mTestableContext.getContentResolver(),
                Settings.Secure.ACCESSIBILITY_AUTOCLICK_CURSOR_AREA_SIZE,
                customSize,
                mTestableContext.getUserId());
        mController.onChangeForTesting(/* selfChange= */ true,
                Settings.Secure.getUriFor(
                        Settings.Secure.ACCESSIBILITY_AUTOCLICK_CURSOR_AREA_SIZE));
        enableIgnoreMinorCursorMovement();

        // Set mouse to hover panel.
        AutoclickTypePanel mockAutoclickTypePanel = mock(AutoclickTypePanel.class);
        when(mockAutoclickTypePanel.isHovered()).thenReturn(true);
        mController.mAutoclickTypePanel = mockAutoclickTypePanel;

        // Send a hover move event that's within than the cursor area size. Normally because
        // ignoreMinorCursorMovement is enabled this wouldn't trigger a click. But since the panel
        // is hovered a click is expected.
        injectFakeMouseMoveEvent(/* x= */ 30f, /* y= */ 0, MotionEvent.ACTION_HOVER_MOVE);
        mTestableLooper.processAllMessages();

        // Verify the expected left click.
        assertThat(motionEventCaptor.eventCount).isEqualTo(
                getNumEventsExpectedFromClick(/* numClicks= */ 1));
    }

    @Test
    @EnableFlags(com.android.server.accessibility.Flags.FLAG_ENABLE_AUTOCLICK_INDICATOR)
    public void sendClick_updateLastCursorAndScrollAtThatLocation() {