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

Commit 369aca27 authored by Derek Sollenberger's avatar Derek Sollenberger
Browse files

Consolidate common zoom code and tighten access to some ZoomManager variables.

This is a single CL in a series of CL's that is focused on moving the
zoom logic from WebView to ZoomManager.

Change-Id: I741fc34d5dd481b89f6e0b33503834c33f4fe69e
http://b/2671604
parent 293c360f
Loading
Loading
Loading
Loading
+4 −13
Original line number Diff line number Diff line
@@ -3322,8 +3322,7 @@ public class WebView extends AbsoluteLayout
            if (!animateScroll) {
                extras = DRAW_EXTRAS_FIND;
            }
        } else if (mShiftIsPressed
                && !nativePageShouldHandleShiftAndArrows()) {
        } else if (mShiftIsPressed && !nativePageShouldHandleShiftAndArrows()) {
            if (!mZoomManager.isZoomAnimating()) {
                extras = DRAW_EXTRAS_SELECTION;
                nativeSetSelectionRegion(mTouchSelection || mExtendSelection);
@@ -4454,7 +4453,7 @@ public class WebView extends AbsoluteLayout
        if (mZoomManager.supportsMultiTouchZoom() && ev.getPointerCount() > 1) {

            // if the page disallows zoom, then skip multi-pointer action
            if (mZoomManager.mMinZoomScale >= mZoomManager.mMaxZoomScale) {
            if (mZoomManager.isZoomScaleFixed()) {
                return true;
            }

@@ -5604,11 +5603,7 @@ public class WebView extends AbsoluteLayout
        int viewHeight = getViewHeightWithTitle();
        float scale = Math.min((float) viewWidth / view.width,
                (float) viewHeight / view.height);
        if (scale < mZoomManager.mMinZoomScale) {
            scale = mZoomManager.mMinZoomScale;
        } else if (scale > mZoomManager.mMaxZoomScale) {
            scale = mZoomManager.mMaxZoomScale;
        }
        scale = mZoomManager.computeScaleWithLimits(scale);
        if (!mZoomManager.willScaleTriggerZoom(scale)) {
            if (contentToViewX(view.x) >= mScrollX
                    && contentToViewX(view.x + view.width) <= mScrollX
@@ -5633,11 +5628,7 @@ public class WebView extends AbsoluteLayout
        int viewHeight = getViewHeightWithTitle();
        float scale = Math.min((float) viewWidth / docWidth, (float) viewHeight
                / docHeight);
        if (scale < mZoomManager.mMinZoomScale) {
            scale = mZoomManager.mMinZoomScale;
        } else if (scale > mZoomManager.mMaxZoomScale) {
            scale = mZoomManager.mMaxZoomScale;
        }
        scale = mZoomManager.computeScaleWithLimits(scale);
        if (!mZoomManager.willScaleTriggerZoom(scale)) {
            pinScrollTo(contentToViewX(docX + docWidth / 2) - viewWidth / 2,
                    contentToViewY(docY + docHeight / 2) - viewHeight / 2,
+1 −2
Original line number Diff line number Diff line
@@ -36,8 +36,7 @@ class ZoomControlEmbedded implements ZoomControlBase {
    }

    public void show() {
        if (!getControls().isVisible()
                && mZoomManager.mMinZoomScale < mZoomManager.mMaxZoomScale) {
        if (!getControls().isVisible() && !mZoomManager.isZoomScaleFixed()) {

            mZoomButtonsController.setVisible(true);

+16 −4
Original line number Diff line number Diff line
@@ -65,11 +65,11 @@ class ZoomManager {
    static float DEFAULT_MIN_ZOOM_SCALE;

    // actual scale limits, which can be set through a webpage viewport meta tag
    float mMaxZoomScale;
    float mMinZoomScale;
    private float mMaxZoomScale;
    private float mMinZoomScale;

    // locks the minimum ZoomScale to the value currently set in mMinZoomScale
    boolean mMinZoomScaleFixed = true;
    private boolean mMinZoomScaleFixed = true;

    // while in the zoom overview mode, the page's width is fully fit to the
    // current window. The page is alive, in another words, you can click to
@@ -128,7 +128,6 @@ class ZoomManager {

    // use the framework's ScaleGestureDetector to handle multi-touch
    private ScaleGestureDetector mScaleDetector;

    private boolean mPinchToZoomAnimating = false;

    public ZoomManager(WebView webView, CallbackProxy callbackProxy) {
@@ -177,6 +176,19 @@ class ZoomManager {
        mInitialScale = scaleInPercent * 0.01f;
    }

    public float computeScaleWithLimits(float scale) {
        if (scale < mMinZoomScale) {
            scale = mMinZoomScale;
        } else if (scale > mMaxZoomScale) {
            scale = mMaxZoomScale;
        }
        return scale;
    }

    public boolean isZoomScaleFixed() {
        return mMinZoomScale >= mMaxZoomScale;
    }

    public static final boolean exceedsMinScaleIncrement(float scaleA, float scaleB) {
        return Math.abs(scaleA - scaleB) >= MINIMUM_SCALE_INCREMENT;
    }