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

Commit a87898b6 authored by Yongshun Liu's avatar Yongshun Liu
Browse files

a11y: Show magnification mode switch button on mouse move

This change enables the magnification mode switch button to appear
when the user moves the mouse, creating behavior consistent with
existing touch interactions.

It adds the necessary logic to MagnificationGestureHandler and
MagnificationController to detect mouse hover events and trigger the UI.

Additionally, this change includes unit tests for the new functionality
and improves existing related tests:
  - Added tests to verify onMouseMove is called correctly.
  - Added negative test cases to prevent regressions.

Bug: 424272057
Flag: EXEMPT bugfix
Test: atest MagnificationGestureHandlerTest
Test: atest MagnificationControllerTest
Change-Id: I53dfd21dac4f8684a473aa9e60d3b58192065e3e
parent b0a75b7e
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -394,6 +394,11 @@ public class MagnificationController implements MagnificationConnectionManager.C
        handleUserInteractionChanged(displayId, mode);
    }

    @Override
    public void onMouseMove(int displayId, int mode) {
        handleUserInteractionChanged(displayId, mode);
    }

    @Override
    public void onPanMagnificationStart(int displayId,
            @MagnificationController.PanDirection int direction) {
+11 −0
Original line number Diff line number Diff line
@@ -90,6 +90,14 @@ public abstract class MagnificationGestureHandler extends BaseEventStreamTransfo
         * @param mode The magnification mode
         */
        void onTouchInteractionEnd(int displayId, int mode);

        /**
         * Called when the pointer moves by a user.
         *
         * @param displayId The logical display id
         * @param mode The magnification mode
         */
        void onMouseMove(int displayId, int mode);
    }

    private final AccessibilityTraceManager mTrace;
@@ -160,6 +168,9 @@ public abstract class MagnificationGestureHandler extends BaseEventStreamTransfo
            case SOURCE_MOUSE:
            case SOURCE_STYLUS: {
                if (magnificationShortcutExists()) {
                    if (event.getAction() == MotionEvent.ACTION_HOVER_MOVE) {
                        mCallback.onMouseMove(mDisplayId, getMode());
                    }
                    handleMouseOrStylusEvent(event, rawEvent, policyFlags);
                }
            }
+40 −0
Original line number Diff line number Diff line
@@ -2112,6 +2112,46 @@ public class MagnificationControllerTest {
                eq(TEST_DISPLAY));
    }

    @Test
    public void onMouseMove_whenNotMagnifying_notShowMagnificationButton() {
        mMagnificationController.onMouseMove(TEST_DISPLAY, MODE_FULLSCREEN);

        verify(mMagnificationConnectionManager, never()).showMagnificationButton(
                eq(TEST_DISPLAY), eq(MODE_FULLSCREEN));
    }

    @Test
    public void onMouseMove_fullscreenAndCapabilitiesAll_showMagnificationButton()
            throws RemoteException {
        setMagnificationEnabled(MODE_FULLSCREEN);

        reset(mMagnificationConnectionManager);
        mMagnificationController.onMouseMove(TEST_DISPLAY, MODE_FULLSCREEN);

        verify(mMagnificationConnectionManager).showMagnificationButton(eq(TEST_DISPLAY),
                eq(MODE_FULLSCREEN));
        // Never call removeMagnificationSettingsPanel if it is allowed to show the settings panel
        // in current capability and mode, and the magnification is activated.
        verify(mMagnificationConnectionManager, never()).removeMagnificationSettingsPanel(
                eq(TEST_DISPLAY));
    }

    @Test
    public void onMouseMove_windowModeAndCapabilitiesAll_showMagnificationButton()
            throws RemoteException {
        setMagnificationEnabled(MODE_WINDOW);

        reset(mMagnificationConnectionManager);
        mMagnificationController.onMouseMove(TEST_DISPLAY, MODE_WINDOW);

        verify(mMagnificationConnectionManager).showMagnificationButton(eq(TEST_DISPLAY),
                eq(MODE_WINDOW));
        // Never call removeMagnificationSettingsPanel if it is allowed to show the settings panel
        // in current capability and mode, and the magnification is activated.
        verify(mMagnificationConnectionManager, never()).removeMagnificationSettingsPanel(
                eq(TEST_DISPLAY));
    }

    @Test
    public void enableWindowMode_showMagnificationButton()
            throws RemoteException {
+29 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import static android.view.MotionEvent.ACTION_HOVER_MOVE;
import static android.view.MotionEvent.ACTION_UP;

import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.testng.AssertJUnit.assertTrue;

@@ -157,6 +158,34 @@ public class MagnificationGestureHandlerTest {
        }
    }

    @Test
    public void onMotionEvent_withHoverMoveEventFromMouse_shouldInvokeOnMouseMoveCallback() {
        final MotionEvent mouseEvent = MotionEvent.obtain(0, 0, ACTION_HOVER_MOVE, 0, 0, 0);
        mouseEvent.setSource(InputDevice.SOURCE_MOUSE);

        mMgh.onMotionEvent(mouseEvent, mouseEvent, /* policyFlags= */ 0);

        try {
            verify(mCallback).onMouseMove(eq(DISPLAY_0), eq(mMgh.getMode()));
        } finally {
            mouseEvent.recycle();
        }
    }

    @Test
    public void onMotionEvent_withMouseDownEventFromMouse_shouldNotInvokeOnMouseMove() {
        final MotionEvent mouseEvent = MotionEvent.obtain(0, 0, ACTION_DOWN, 0, 0, 0);
        mouseEvent.setSource(InputDevice.SOURCE_MOUSE);

        mMgh.onMotionEvent(mouseEvent, mouseEvent, /* policyFlags= */ 0);

        try {
            verify(mCallback, never()).onMouseMove(eq(DISPLAY_0), eq(mMgh.getMode()));
        } finally {
            mouseEvent.recycle();
        }
    }

    private static class TestMagnificationGestureHandler extends MagnificationGestureHandler {

        boolean mIsInternalMethodCalled = false;