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

Commit 170d2ee7 authored by Shimeng (Simon) Wang's avatar Shimeng (Simon) Wang Committed by Android (Google) Code Review
Browse files

Merge "Stabilize reflow, aka, the fit-to-screen option in settings."

parents 5afb316c c55886ae
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -1483,6 +1483,10 @@ public class WebSettings {
        return mAcceptLanguage;
        return mAcceptLanguage;
    }
    }


    /* package */ boolean isNarrowColumnLayout() {
        return getLayoutAlgorithm() == LayoutAlgorithm.NARROW_COLUMNS;
    }

    /**
    /**
     * Tell the WebView whether it needs to set a node to have focus when
     * Tell the WebView whether it needs to set a node to have focus when
     * {@link WebView#requestFocus(int, android.graphics.Rect)} is called.
     * {@link WebView#requestFocus(int, android.graphics.Rect)} is called.
+29 −11
Original line number Original line Diff line number Diff line
@@ -348,7 +348,8 @@ class ZoomManager {
        mZoomCenterY = mWebView.getViewHeight() * .5f;
        mZoomCenterY = mWebView.getViewHeight() * .5f;
        mAnchorX = mWebView.viewToContentX((int) mZoomCenterX + mWebView.getScrollX());
        mAnchorX = mWebView.viewToContentX((int) mZoomCenterX + mWebView.getScrollX());
        mAnchorY = mWebView.viewToContentY((int) mZoomCenterY + mWebView.getScrollY());
        mAnchorY = mWebView.viewToContentY((int) mZoomCenterY + mWebView.getScrollY());
        return startZoomAnimation(mActualScale * zoomMultiplier, true);
        return startZoomAnimation(mActualScale * zoomMultiplier, 
            !mWebView.getSettings().getUseFixedViewport());
    }
    }


    /**
    /**
@@ -460,7 +461,7 @@ class ZoomManager {
            mInZoomOverview = !exceedsMinScaleIncrement(scale, getZoomOverviewScale());
            mInZoomOverview = !exceedsMinScaleIncrement(scale, getZoomOverviewScale());
        }
        }


        if (reflowText) {
        if (reflowText && !mWebView.getSettings().getUseFixedViewport()) {
            mTextWrapScale = scale;
            mTextWrapScale = scale;
        }
        }


@@ -519,7 +520,7 @@ class ZoomManager {
     *
     *
     * (2) HTML/OTHER: If the taps occur outside a plugin then the following
     * (2) HTML/OTHER: If the taps occur outside a plugin then the following
     * heuristic is used.
     * heuristic is used.
     *   A. If the current scale is not the same as the text wrap scale and the
     *   A. If the current text wrap scale differs from newly calculated and the
     *      layout algorithm specifies the use of NARROW_COLUMNS, then fit to
     *      layout algorithm specifies the use of NARROW_COLUMNS, then fit to
     *      column by reflowing the text.
     *      column by reflowing the text.
     *   B. If the page is not in overview mode then change to overview mode.
     *   B. If the page is not in overview mode then change to overview mode.
@@ -553,8 +554,15 @@ class ZoomManager {
            return;
            return;
        }
        }


        if (settings.getLayoutAlgorithm() == WebSettings.LayoutAlgorithm.NARROW_COLUMNS
        final float newTextWrapScale;
                && willScaleTriggerZoom(mTextWrapScale)) {
        if (settings.getUseFixedViewport()) {
            newTextWrapScale = Math.max(mActualScale, getReadingLevelScale());
        } else {
            newTextWrapScale = mActualScale;
        }
        if (settings.isNarrowColumnLayout()
                && exceedsMinScaleIncrement(mTextWrapScale, newTextWrapScale)) {
            mTextWrapScale = newTextWrapScale;
            refreshZoomScale(true);
            refreshZoomScale(true);
        } else if (!mInZoomOverview) {
        } else if (!mInZoomOverview) {
            zoomToOverview();
            zoomToOverview();
@@ -584,7 +592,8 @@ class ZoomManager {
        if (scrollY < mWebView.getTitleHeight()) {
        if (scrollY < mWebView.getTitleHeight()) {
            mWebView.updateScrollCoordinates(mWebView.getScrollX(), 0);
            mWebView.updateScrollCoordinates(mWebView.getScrollX(), 0);
        }
        }
        startZoomAnimation(getZoomOverviewScale(), true);
        startZoomAnimation(getZoomOverviewScale(), 
            !mWebView.getSettings().getUseFixedViewport());
    }
    }


    private void zoomToReadingLevel() {
    private void zoomToReadingLevel() {
@@ -603,7 +612,8 @@ class ZoomManager {
                mZoomCenterX = 0;
                mZoomCenterX = 0;
            }
            }
        }
        }
        startZoomAnimation(readingScale, true);
        startZoomAnimation(readingScale,
            !mWebView.getSettings().getUseFixedViewport());
    }
    }


    public void updateMultiTouchSupport(Context context) {
    public void updateMultiTouchSupport(Context context) {
@@ -683,11 +693,12 @@ class ZoomManager {
                mAnchorX = mWebView.viewToContentX((int) mZoomCenterX + mWebView.getScrollX());
                mAnchorX = mWebView.viewToContentX((int) mZoomCenterX + mWebView.getScrollX());
                mAnchorY = mWebView.viewToContentY((int) mZoomCenterY + mWebView.getScrollY());
                mAnchorY = mWebView.viewToContentY((int) mZoomCenterY + mWebView.getScrollY());
                // don't reflow when zoom in; when zoom out, do reflow if the
                // don't reflow when zoom in; when zoom out, do reflow if the
                // new scale is almost minimum scale;
                // new scale is almost minimum scale.
                boolean reflowNow = !canZoomOut() || (mActualScale <= 0.8 * mTextWrapScale);
                boolean reflowNow = !canZoomOut() || (mActualScale <= 0.8 * mTextWrapScale);
                // force zoom after mPreviewZoomOnly is set to false so that the
                // force zoom after mPreviewZoomOnly is set to false so that the
                // new view size will be passed to the WebKit
                // new view size will be passed to the WebKit
                refreshZoomScale(reflowNow);
                refreshZoomScale(reflowNow &&
                    !mWebView.getSettings().getUseFixedViewport());
                // call invalidate() to draw without zoom filter
                // call invalidate() to draw without zoom filter
                mWebView.invalidate();
                mWebView.invalidate();
            }
            }
@@ -730,7 +741,8 @@ class ZoomManager {
        // cause its child View to reposition itself through ViewManager's
        // cause its child View to reposition itself through ViewManager's
        // scaleAll(), we need to post a Runnable to ensure requestLayout().
        // scaleAll(), we need to post a Runnable to ensure requestLayout().
        // Additionally, only update the text wrap scale if the width changed.
        // Additionally, only update the text wrap scale if the width changed.
        mWebView.post(new PostScale(w != ow));
        mWebView.post(new PostScale(w != ow &&
            !mWebView.getSettings().getUseFixedViewport()));
    }
    }


    private class PostScale implements Runnable {
    private class PostScale implements Runnable {
@@ -808,7 +820,8 @@ class ZoomManager {
        if (!mWebView.drawHistory() && (mInitialZoomOverview || (mInZoomOverview
        if (!mWebView.drawHistory() && (mInitialZoomOverview || (mInZoomOverview
                && Math.abs((viewWidth * mInvActualScale) - mZoomOverviewWidth) > 1))) {
                && Math.abs((viewWidth * mInvActualScale) - mZoomOverviewWidth) > 1))) {
            mInitialZoomOverview = false;
            mInitialZoomOverview = false;
            setZoomScale(zoomOverviewScale, !willScaleTriggerZoom(mTextWrapScale));
            setZoomScale(zoomOverviewScale, !willScaleTriggerZoom(mTextWrapScale) &&
                !mWebView.getSettings().getUseFixedViewport());
        }
        }
    }
    }


@@ -855,6 +868,11 @@ class ZoomManager {
                    scale = Math.max(viewState.mTextWrapScale, scale);
                    scale = Math.max(viewState.mTextWrapScale, scale);
                    mInitialZoomOverview = !exceedsMinScaleIncrement(scale, getZoomOverviewScale());
                    mInitialZoomOverview = !exceedsMinScaleIncrement(scale, getZoomOverviewScale());
                }
                }
                if (settings.isNarrowColumnLayout() && settings.getUseFixedViewport()) {
                    // When first layout, reflow using the reading level scale to avoid
                    // reflow when double tapped.
                    mTextWrapScale = getReadingLevelScale();
                }
                reflowText = exceedsMinScaleIncrement(mTextWrapScale, scale);
                reflowText = exceedsMinScaleIncrement(mTextWrapScale, scale);
            }
            }
            setZoomScale(scale, reflowText);
            setZoomScale(scale, reflowText);