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

Commit 14bcc0e7 authored by Shimeng (Simon) Wang's avatar Shimeng (Simon) Wang
Browse files

Use website preferred width as the fixed viewport.

This preferred width will be set between the default viewport width and
the max fixed viewport width.  The default viewport width serves as the
minimum fixed viewport width, so it's lowered to 980.

This change will make the shirt.woot.com/blog site works better, since it's using
1080 as the preferred width, so user needs not to scroll in overview mode.

issue: 3003933
Change-Id: Ie3eed44a54d277f5bc5f63cd394d463012a80d80
parent a8f99bbb
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -178,6 +178,7 @@ public class WebSettings {
    private boolean         mUseDoubleTree = false;
    private boolean         mUseWideViewport = false;
    private boolean         mUseFixedViewport = false;
    private int             mMaxFixedViewportWidth = WebView.DEFAULT_VIEWPORT_WIDTH;
    private boolean         mSupportMultipleWindows = false;
    private boolean         mShrinksStandaloneImagesToFit = false;
    private long            mMaximumDecodedImageSize = 0; // 0 means default
@@ -324,8 +325,9 @@ public class WebSettings {

        // Detect tablet device for fixed viewport mode.
        final DisplayMetrics metrics = context.getResources().getDisplayMetrics();
        mUseFixedViewport = (metrics.density == 1.0f 
            && (metrics.widthPixels >= 800 ||metrics.heightPixels >= 800));
        final int landscapeWidth = Math.max(metrics.widthPixels, metrics.heightPixels);
        mUseFixedViewport = (metrics.density == 1.0f && landscapeWidth >= 800);
        mMaxFixedViewportWidth = (int) (landscapeWidth * 1.25);

        if (sLockForLocaleSettings == null) {
            sLockForLocaleSettings = new Object();
@@ -1515,6 +1517,13 @@ public class WebSettings {
        return mUseFixedViewport;
    }

    /**
     * Returns maximum fixed viewport width.
     */
    /* package */ int getMaxFixedViewportWidth() {
        return mMaxFixedViewportWidth;
    }

    /**
     * Returns whether private browsing is enabled.
     */
+1 −1
Original line number Diff line number Diff line
@@ -667,7 +667,7 @@ public class WebView extends AbsoluteLayout

    // 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 = 1040;
    static final int DEFAULT_VIEWPORT_WIDTH = 980;

    // 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
+8 −1
Original line number Diff line number Diff line
@@ -1706,7 +1706,7 @@ final class WebViewCore {
                }
            } else if (mViewportWidth > 0) {
                if (mSettings.getUseFixedViewport()) {
                    // Use website specified viewport width.
                    // Use website specified or desired fixed viewport width.
                    width = mViewportWidth;
                } else {
                    width = Math.max(w, mViewportWidth);
@@ -1827,6 +1827,13 @@ final class WebViewCore {
            }
            if (mInitialViewState != null) {
                draw.mViewState = mInitialViewState;
                if (mViewportWidth == -1 && mSettings.getUseFixedViewport() &&
                    mSettings.getUseWideViewPort()) {
                    // Use website's initial preferred width as the fixed viewport width.
                    mViewportWidth = Math.min(mSettings.getMaxFixedViewportWidth(),
                        draw.mMinPrefWidth);
                    draw.mViewState.mViewportWidth = mViewportWidth;
                }
                mInitialViewState = null;
            }
            if (DebugFlags.WEB_VIEW_CORE) Log.v(LOGTAG, "webkitDraw NEW_PICTURE_MSG_ID");