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

Commit 0b47dde9 authored by Yuki Awano's avatar Yuki Awano
Browse files

Fix magnification offset min and max calculation

- Magnification offset is in screen coordinate. It needs to take care
  about left and top of magnification bounds when calculating min and
  max.

Bug: 77152978
Test: None
Change-Id: I5ee7835c88eed080d9b22901977b0b5f76737703
parent 3c2956e0
Loading
Loading
Loading
Loading
+20 −4
Original line number Diff line number Diff line
@@ -650,12 +650,14 @@ public class MagnificationController implements Handler.Callback {
                            + ", nonNormOffsetY = " + nonNormOffsetY + ")");
        }
        boolean changed = false;
        final float offsetX = MathUtils.constrain(nonNormOffsetX, getMinOffsetXLocked(), 0);
        final float offsetX = MathUtils.constrain(
            nonNormOffsetX, getMinOffsetXLocked(), getMaxOffsetXLocked());
        if (Float.compare(mCurrentMagnificationSpec.offsetX, offsetX) != 0) {
            mCurrentMagnificationSpec.offsetX = offsetX;
            changed = true;
        }
        final float offsetY = MathUtils.constrain(nonNormOffsetY, getMinOffsetYLocked(), 0);
        final float offsetY = MathUtils.constrain(
            nonNormOffsetY, getMinOffsetYLocked(), getMaxOffsetYLocked());
        if (Float.compare(mCurrentMagnificationSpec.offsetY, offsetY) != 0) {
            mCurrentMagnificationSpec.offsetY = offsetY;
            changed = true;
@@ -665,12 +667,26 @@ public class MagnificationController implements Handler.Callback {

    private float getMinOffsetXLocked() {
        final float viewportWidth = mMagnificationBounds.width();
        return viewportWidth - viewportWidth * mCurrentMagnificationSpec.scale;
        final float viewportLeft = mMagnificationBounds.left;
        return (viewportLeft + viewportWidth) -
            (viewportLeft + viewportWidth) * mCurrentMagnificationSpec.scale;
    }

    private float getMaxOffsetXLocked() {
        return mMagnificationBounds.left -
            mMagnificationBounds.left * mCurrentMagnificationSpec.scale;
    }

    private float getMinOffsetYLocked() {
        final float viewportHeight = mMagnificationBounds.height();
        return viewportHeight - viewportHeight * mCurrentMagnificationSpec.scale;
        final float viewportTop = mMagnificationBounds.top;
        return (viewportTop + viewportHeight) -
            (viewportTop + viewportHeight) * mCurrentMagnificationSpec.scale;
    }

    private float getMaxOffsetYLocked() {
        return mMagnificationBounds.top -
            mMagnificationBounds.top * mCurrentMagnificationSpec.scale;
    }

    /**