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

Commit a4fa107f authored by Grace Kloba's avatar Grace Kloba
Browse files

Do not grow the viewport width to infinite to fit

the content. Limit the overview viewport width to
a level that if a site behaves badly, the WebView
still does reasonably.

Partially fix http://b/issue?id=2209659
maps.yahoo.com keeps growing due to a layout bug.
This prevents the browser to go insane.

Partially fix http://b/issue?id=2215387
caltrain.com has a super long   which caused
the page super wide. This prevents the browser to
become unusable.

This change will make sites like, caltrain.com/timetable.html
not fit all in the view. You have to scroll left
and right. And it is same as iPhone.
parent 188f40d7
Loading
Loading
Loading
Loading
+24 −3
Original line number Diff line number Diff line
@@ -504,6 +504,16 @@ public class WebView extends AbsoluteLayout
        "REQUEST_KEYBOARD" //                = 27;
    };

    // If the site doesn't use the viewport meta tag to specify the viewport,
    // use DEFAULT_VIEWPORT_WIDTH as the default viewport width
    static final int DEFAULT_VIEWPORT_WIDTH = 800;

    // normally we try to fit the content to the minimum preferred width
    // calculated by the Webkit. To avoid the bad behavior when some site's
    // minimum preferred width keeps growing when changing the viewport width or
    // the minimum preferred width is huge, an upper limit is needed.
    static int sMaxViewportWidth = DEFAULT_VIEWPORT_WIDTH;

    // default scale limit. Depending on the display density
    private static float DEFAULT_MAX_ZOOM_SCALE;
    private static float DEFAULT_MIN_ZOOM_SCALE;
@@ -523,7 +533,7 @@ public class WebView extends AbsoluteLayout

    // ideally mZoomOverviewWidth should be mContentWidth. But sites like espn,
    // engadget always have wider mContentWidth no matter what viewport size is.
    int mZoomOverviewWidth = WebViewCore.DEFAULT_VIEWPORT_WIDTH;
    int mZoomOverviewWidth = DEFAULT_VIEWPORT_WIDTH;
    float mLastScale;

    // default scale. Depending on the display density.
@@ -3732,6 +3742,14 @@ public class WebView extends AbsoluteLayout
            mZoomCenterY = getViewHeight() * .5f;
        }

        // adjust the max viewport width depending on the view dimensions. This
        // is to ensure the scaling is not going insane. So do not shrink it if
        // the view size is temporarily smaller, e.g. when soft keyboard is up.
        int newMaxViewportWidth = (int) (Math.max(w, h) / DEFAULT_MIN_ZOOM_SCALE);
        if (newMaxViewportWidth > sMaxViewportWidth) {
            sMaxViewportWidth = newMaxViewportWidth;
        }

        // update mMinZoomScale if the minimum zoom scale is not fixed
        if (!mMinZoomScaleFixed) {
            // when change from narrow screen to wide screen, the new viewWidth
@@ -5165,8 +5183,11 @@ public class WebView extends AbsoluteLayout
                        mPictureListener.onNewPicture(WebView.this, capturePicture());
                    }
                    if (useWideViewport) {
                        mZoomOverviewWidth = Math.max(draw.mMinPrefWidth,
                                draw.mViewPoint.x);
                        // limit mZoomOverviewWidth to sMaxViewportWidth so that
                        // if the page doesn't behave well, the WebView won't go
                        // insane.
                        mZoomOverviewWidth = Math.min(sMaxViewportWidth, Math
                                .max(draw.mMinPrefWidth, draw.mViewPoint.x));
                    }
                    if (!mMinZoomScaleFixed) {
                        mMinZoomScale = (float) viewWidth / mZoomOverviewWidth;
+5 −8
Original line number Diff line number Diff line
@@ -124,10 +124,6 @@ final class WebViewCore {
    private int mWebkitScrollX = 0;
    private int mWebkitScrollY = 0;

    // If the site doesn't use viewport meta tag to specify the viewport, use
    // DEFAULT_VIEWPORT_WIDTH as default viewport width
    static final int DEFAULT_VIEWPORT_WIDTH = 800;

    // The thread name used to identify the WebCore thread and for use in
    // debugging other classes that require operation within the WebCore thread.
    /* package */ static final String THREAD_NAME = "WebViewCoreThread";
@@ -1522,7 +1518,7 @@ final class WebViewCore {
            if (mViewportWidth == -1) {
                if (mSettings.getLayoutAlgorithm() ==
                        WebSettings.LayoutAlgorithm.NORMAL) {
                    width = DEFAULT_VIEWPORT_WIDTH;
                    width = WebView.DEFAULT_VIEWPORT_WIDTH;
                } else {
                    /*
                     * if a page's minimum preferred width is wider than the
@@ -1536,8 +1532,9 @@ final class WebViewCore {
                     * In the worse case, the native width will be adjusted when
                     * next zoom or screen orientation change happens.
                     */
                    width = Math.max(w, Math.max(DEFAULT_VIEWPORT_WIDTH,
                            nativeGetContentMinPrefWidth()));
                    width = Math.min(WebView.sMaxViewportWidth, Math.max(w,
                            Math.max(WebView.DEFAULT_VIEWPORT_WIDTH,
                                    nativeGetContentMinPrefWidth())));
                }
            } else {
                width = Math.max(w, mViewportWidth);
@@ -1637,7 +1634,7 @@ final class WebViewCore {
            draw.mViewPoint = new Point(mCurrentViewWidth, mCurrentViewHeight);
            if (mSettings.getUseWideViewPort()) {
                draw.mMinPrefWidth = Math.max(
                        mViewportWidth == -1 ? DEFAULT_VIEWPORT_WIDTH
                        mViewportWidth == -1 ? WebView.DEFAULT_VIEWPORT_WIDTH
                                : (mViewportWidth == 0 ? mCurrentViewWidth
                                        : mViewportWidth),
                        nativeGetContentMinPrefWidth());