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

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

A method refactoring and a simple rounding fix.

issue: 3382398
Change-Id: I3b43c6e4954b5040a266da60c9a97314f1a5b91f
parent 10d63fad
Loading
Loading
Loading
Loading
+32 −26
Original line number Diff line number Diff line
@@ -1814,7 +1814,34 @@ final class WebViewCore {
            Log.w(LOGTAG, "skip viewSizeChanged as w is 0");
            return;
        }
        int width = w;
        int width = calculateWindowWidth(w, textwrapWidth);
        int height = h;
        if (width != w) {
            float heightWidthRatio = data.mHeightWidthRatio;
            float ratio = (heightWidthRatio > 0) ? heightWidthRatio : (float) h / w;
            height = Math.round(ratio * width);
        }
        nativeSetSize(width, height, textwrapWidth, scale, w,
                data.mActualViewHeight > 0 ? data.mActualViewHeight : h,
                data.mAnchorX, data.mAnchorY, data.mIgnoreHeight);
        // Remember the current width and height
        boolean needInvalidate = (mCurrentViewWidth == 0);
        mCurrentViewWidth = w;
        mCurrentViewHeight = h;
        mCurrentViewScale = scale;
        if (needInvalidate) {
            // ensure {@link #webkitDraw} is called as we were blocking in
            // {@link #contentDraw} when mCurrentViewWidth is 0
            if (DebugFlags.WEB_VIEW_CORE) Log.v(LOGTAG, "viewSizeChanged");
            contentDraw();
        }
        mEventHub.sendMessage(Message.obtain(null,
                EventHub.UPDATE_CACHE_AND_TEXT_ENTRY));
    }

    // Calculate width to be used in webkit window.
    private int calculateWindowWidth(int viewWidth, int textwrapWidth) {
        int width = viewWidth;
        if (mSettings.getUseWideViewPort()) {
            if (mViewportWidth == -1) {
                if (mSettings.getLayoutAlgorithm() ==
@@ -1833,7 +1860,7 @@ final class WebViewCore {
                     * In the worse case, the native width will be adjusted when
                     * next zoom or screen orientation change happens.
                     */
                    width = Math.min(WebView.sMaxViewportWidth, Math.max(w,
                    width = Math.min(WebView.sMaxViewportWidth, Math.max(viewWidth,
                            Math.max(WebView.DEFAULT_VIEWPORT_WIDTH,
                                    nativeGetContentMinPrefWidth())));
                }
@@ -1842,7 +1869,7 @@ final class WebViewCore {
                    // Use website specified or desired fixed viewport width.
                    width = mViewportWidth;
                } else {
                    width = Math.max(w, mViewportWidth);
                    width = Math.max(viewWidth, mViewportWidth);
                }
            } else if (mSettings.getUseFixedViewport()) {
                width = mWebView.getViewWidth();
@@ -1850,28 +1877,7 @@ final class WebViewCore {
                width = textwrapWidth;
            }
        }
        int height = h;
        if (width != w) {
            float heightWidthRatio = data.mHeightWidthRatio;
            float ratio = (heightWidthRatio > 0) ? heightWidthRatio : (float) h / w;
            height = Math.round(ratio * width);
        }
        nativeSetSize(width, height, textwrapWidth, scale, w,
                data.mActualViewHeight > 0 ? data.mActualViewHeight : h,
                data.mAnchorX, data.mAnchorY, data.mIgnoreHeight);
        // Remember the current width and height
        boolean needInvalidate = (mCurrentViewWidth == 0);
        mCurrentViewWidth = w;
        mCurrentViewHeight = h;
        mCurrentViewScale = scale;
        if (needInvalidate) {
            // ensure {@link #webkitDraw} is called as we were blocking in
            // {@link #contentDraw} when mCurrentViewWidth is 0
            if (DebugFlags.WEB_VIEW_CORE) Log.v(LOGTAG, "viewSizeChanged");
            contentDraw();
        }
        mEventHub.sendMessage(Message.obtain(null,
                EventHub.UPDATE_CACHE_AND_TEXT_ENTRY));
        return width;
    }

    private void sendUpdateTextEntry() {
@@ -2370,7 +2376,7 @@ final class WebViewCore {
                // to syncing an incorrect height.
                data.mHeight = mCurrentViewHeight == 0 ?
                        Math.round(mWebView.getViewHeight() / data.mScale)
                        : mCurrentViewHeight * data.mWidth / viewportWidth;
                        : Math.round((float) mCurrentViewHeight * data.mWidth / viewportWidth);
                data.mTextWrapWidth = Math.round(webViewWidth
                        / mInitialViewState.mTextWrapScale);
                data.mIgnoreHeight = false;