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

Commit 769ed21c authored by Grace Kloba's avatar Grace Kloba
Browse files
When the same page is loaded, updateRestoreState
will be false when we finish the first layout. As
we are still in the same page, we don't want to
update the current zoom/scroll. But in some cases,
like a site switch from mobile to full site and
keeps the same url, we do want to update the zoom
range as the viewport spec changed. Otherwise, user
can't zoom in the full site as the WebView thought
it is still a mobile non-scalable page.
parent 965f4a6b
Loading
Loading
Loading
Loading
+43 −27
Original line number Original line Diff line number Diff line
@@ -467,6 +467,7 @@ public class WebView extends AbsoluteLayout
    static final int UPDATE_TEXT_ENTRY_MSG_ID           = 15;
    static final int UPDATE_TEXT_ENTRY_MSG_ID           = 15;
    static final int WEBCORE_INITIALIZED_MSG_ID         = 16;
    static final int WEBCORE_INITIALIZED_MSG_ID         = 16;
    static final int UPDATE_TEXTFIELD_TEXT_MSG_ID       = 17;
    static final int UPDATE_TEXTFIELD_TEXT_MSG_ID       = 17;
    static final int UPDATE_ZOOM_RANGE                  = 18;
    static final int MOVE_OUT_OF_PLUGIN                 = 19;
    static final int MOVE_OUT_OF_PLUGIN                 = 19;
    static final int CLEAR_TEXT_ENTRY                   = 20;
    static final int CLEAR_TEXT_ENTRY                   = 20;
    static final int UPDATE_TEXT_SELECTION_MSG_ID       = 21;
    static final int UPDATE_TEXT_SELECTION_MSG_ID       = 21;
@@ -497,7 +498,7 @@ public class WebView extends AbsoluteLayout
        "UPDATE_TEXT_ENTRY_MSG_ID", //       = 15;
        "UPDATE_TEXT_ENTRY_MSG_ID", //       = 15;
        "WEBCORE_INITIALIZED_MSG_ID", //     = 16;
        "WEBCORE_INITIALIZED_MSG_ID", //     = 16;
        "UPDATE_TEXTFIELD_TEXT_MSG_ID", //   = 17;
        "UPDATE_TEXTFIELD_TEXT_MSG_ID", //   = 17;
        "18", //        = 18;
        "UPDATE_ZOOM_RANGE", //              = 18;
        "MOVE_OUT_OF_PLUGIN", //             = 19;
        "MOVE_OUT_OF_PLUGIN", //             = 19;
        "CLEAR_TEXT_ENTRY", //               = 20;
        "CLEAR_TEXT_ENTRY", //               = 20;
        "UPDATE_TEXT_SELECTION_MSG_ID", //   = 21;
        "UPDATE_TEXT_SELECTION_MSG_ID", //   = 21;
@@ -5315,6 +5316,14 @@ public class WebView extends AbsoluteLayout
                case SPAWN_SCROLL_TO_MSG_ID:
                case SPAWN_SCROLL_TO_MSG_ID:
                    spawnContentScrollTo(msg.arg1, msg.arg2);
                    spawnContentScrollTo(msg.arg1, msg.arg2);
                    break;
                    break;
                case UPDATE_ZOOM_RANGE: {
                    WebViewCore.RestoreState restoreState
                            = (WebViewCore.RestoreState) msg.obj;
                    // mScrollX contains the new minPrefWidth
                    updateZoomRange(restoreState, getViewWidth(),
                            restoreState.mScrollX, false);
                    break;
                }
                case NEW_PICTURE_MSG_ID: {
                case NEW_PICTURE_MSG_ID: {
                    WebSettings settings = mWebViewCore.getSettings();
                    WebSettings settings = mWebViewCore.getSettings();
                    // called for new content
                    // called for new content
@@ -5326,32 +5335,8 @@ public class WebView extends AbsoluteLayout
                    WebViewCore.RestoreState restoreState = draw.mRestoreState;
                    WebViewCore.RestoreState restoreState = draw.mRestoreState;
                    if (restoreState != null) {
                    if (restoreState != null) {
                        mInZoomOverview = false;
                        mInZoomOverview = false;
                        if (restoreState.mMinScale == 0) {
                        updateZoomRange(restoreState, viewSize.x,
                            if (restoreState.mMobileSite) {
                                draw.mMinPrefWidth, true);
                                if (draw.mMinPrefWidth >
                                        Math.max(0, draw.mViewPoint.x)) {
                                    mMinZoomScale = (float) viewWidth
                                            / draw.mMinPrefWidth;
                                    mMinZoomScaleFixed = false;
                                    mInZoomOverview = useWideViewport &&
                                            settings.getLoadWithOverviewMode();
                                } else {
                                    mMinZoomScale = restoreState.mDefaultScale;
                                    mMinZoomScaleFixed = true;
                                }
                            } else {
                                mMinZoomScale = DEFAULT_MIN_ZOOM_SCALE;
                                mMinZoomScaleFixed = false;
                            }
                        } else {
                            mMinZoomScale = restoreState.mMinScale;
                            mMinZoomScaleFixed = true;
                        }
                        if (restoreState.mMaxScale == 0) {
                            mMaxZoomScale = DEFAULT_MAX_ZOOM_SCALE;
                        } else {
                            mMaxZoomScale = restoreState.mMaxScale;
                        }
                        if (mInitialScaleInPercent > 0) {
                        if (mInitialScaleInPercent > 0) {
                            setNewZoomScale(mInitialScaleInPercent / 100.0f,
                            setNewZoomScale(mInitialScaleInPercent / 100.0f,
                                    mInitialScaleInPercent != mTextWrapScale * 100,
                                    mInitialScaleInPercent != mTextWrapScale * 100,
@@ -5822,6 +5807,37 @@ public class WebView extends AbsoluteLayout
                new InvokeListBox(array, enabledArray, selectedArray));
                new InvokeListBox(array, enabledArray, selectedArray));
    }
    }


    private void updateZoomRange(WebViewCore.RestoreState restoreState,
            int viewWidth, int minPrefWidth, boolean updateZoomOverview) {
        if (restoreState.mMinScale == 0) {
            if (restoreState.mMobileSite) {
                if (minPrefWidth > Math.max(0, viewWidth)) {
                    mMinZoomScale = (float) viewWidth / minPrefWidth;
                    mMinZoomScaleFixed = false;
                    if (updateZoomOverview) {
                        WebSettings settings = getSettings();
                        mInZoomOverview = settings.getUseWideViewPort() &&
                                settings.getLoadWithOverviewMode();
                    }
                } else {
                    mMinZoomScale = restoreState.mDefaultScale;
                    mMinZoomScaleFixed = true;
                }
            } else {
                mMinZoomScale = DEFAULT_MIN_ZOOM_SCALE;
                mMinZoomScaleFixed = false;
            }
        } else {
            mMinZoomScale = restoreState.mMinScale;
            mMinZoomScaleFixed = true;
        }
        if (restoreState.mMaxScale == 0) {
            mMaxZoomScale = DEFAULT_MAX_ZOOM_SCALE;
        } else {
            mMaxZoomScale = restoreState.mMaxScale;
        }
    }

    /*
    /*
     * Request a dropdown menu for a listbox with single selection or a single
     * Request a dropdown menu for a listbox with single selection or a single
     * <select> element.
     * <select> element.
+13 −1
Original line number Original line Diff line number Diff line
@@ -1931,7 +1931,19 @@ final class WebViewCore {
        }
        }


        // if mViewportWidth is 0, it means device-width, always update.
        // if mViewportWidth is 0, it means device-width, always update.
        if (mViewportWidth != 0 && !updateRestoreState) return;
        if (mViewportWidth != 0 && !updateRestoreState) {
            RestoreState restoreState = new RestoreState();
            restoreState.mMinScale = mViewportMinimumScale / 100.0f;
            restoreState.mMaxScale = mViewportMaximumScale / 100.0f;
            restoreState.mDefaultScale = adjust;
            // as mViewportWidth is not 0, it is not mobile site.
            restoreState.mMobileSite = false;
            // for non-mobile site, we don't need minPrefWidth, set it as 0
            restoreState.mScrollX = 0;
            Message.obtain(mWebView.mPrivateHandler,
                    WebView.UPDATE_ZOOM_RANGE, restoreState).sendToTarget();
            return;
        }


        // now notify webview
        // now notify webview
        // webViewWidth refers to the width in the view system
        // webViewWidth refers to the width in the view system