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

Commit 37c2e3e5 authored by Huahui Wu's avatar Huahui Wu Committed by Android (Google) Code Review
Browse files

Merge "b/4075349 Make the pinch to zoom more responsive after limits." into honeycomb-mr1

parents 6167a390 ff6f4c2e
Loading
Loading
Loading
Loading
+29 −14
Original line number Diff line number Diff line
@@ -360,6 +360,10 @@ class ZoomManager {
        return scale;
    }

    public final boolean isScaleOverLimits(float scale) {
        return scale <= mMinZoomScale || scale >= mMaxZoomScale;
    }

    public final boolean isZoomScaleFixed() {
        return mMinZoomScale >= mMaxZoomScale;
    }
@@ -749,12 +753,9 @@ class ZoomManager {
            return true;
        }

        public boolean onScale(ScaleGestureDetector detector) {
            // Prevent scaling beyond overview scale.
            float scale = Math.max(
                    computeScaleWithLimits(detector.getScaleFactor() * mActualScale),
                    getZoomOverviewScale());

            // If the user moves the fingers but keeps the same distance between them,
            // we should do panning only.
        public boolean isPanningOnly(ScaleGestureDetector detector) {
            float prevFocusX = mFocusX;
            float prevFocusY = mFocusY;
            mFocusX = detector.getFocusX();
@@ -768,15 +769,20 @@ class ZoomManager {
                mFocusMovementSum -= mFocusMovementQueue.remove();
            }
            float deltaSpan = Math.abs(detector.getCurrentSpan() - detector.getPreviousSpan());

            // If the user moves the fingers but keeps the same distance between them,
            // we should do panning only.
            if (mFocusMovementSum > deltaSpan) {
                mFocusMovementSum = 0;
                mFocusMovementQueue.clear();
                return true;
            return mFocusMovementSum > deltaSpan;
        }

        public boolean handleScale(ScaleGestureDetector detector) {
            float scale = detector.getScaleFactor() * mActualScale;

            // if scale is limited by any reason, don't zoom but do ask
            // the detector to update the event.
            boolean isScaleLimited =
                    isScaleOverLimits(scale) || scale < getZoomOverviewScale();

            // Prevent scaling beyond overview scale.
            scale = Math.max(computeScaleWithLimits(scale), getZoomOverviewScale());

            if (mPinchToZoomAnimating || willScaleTriggerZoom(scale)) {
                mPinchToZoomAnimating = true;
                // limit the scale change per step
@@ -788,13 +794,22 @@ class ZoomManager {
                scale = computeScaleWithLimits(scale);
                // if the scale change is too small, regard it as jitter and skip it.
                if (Math.abs(scale - mActualScale) < MINIMUM_SCALE_WITHOUT_JITTER) {
                    return false;
                    return isScaleLimited;
                }
                setZoomCenter(detector.getFocusX(), detector.getFocusY());
                setZoomScale(scale, false);
                mWebView.invalidate();
                return true;
            }
            return isScaleLimited;
        }

        public boolean onScale(ScaleGestureDetector detector) {
            if (isPanningOnly(detector) || handleScale(detector)) {
                mFocusMovementSum = 0;
                mFocusMovementQueue.clear();
                return true;
            }
            return false;
        }