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

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

Send actual view height to webkit for window.innerHeight.

Currently only fixed height is sent over to webkit, which is to
avoid relayout when url bar is being scrolled.
And this fixed height is used also as the visible height and shown up
as window.innerheight, which is not correct.

This change sends the actual view height as the screen height to
webkit, so window.innerheight is correct.  This may potentially
help fixed elments in a page's bottom.  The relayout is still avoided
as before.

issue: 3396895
Change-Id: I0426a7d6dc76a823d8d26943a92689f49026fba8
parent 23a8a459
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -557,6 +557,9 @@ public class WebView extends AbsoluteLayout
    // sending the same dimensions more than once.
    int mLastWidthSent;
    int mLastHeightSent;
    // Since view height sent to webkit could be fixed to avoid relayout, this
    // value records the last sent actual view height.
    int mLastActualHeightSent;

    private int mContentWidth;   // cache of value from WebViewCore
    private int mContentHeight;  // cache of value from WebViewCore
@@ -2573,6 +2576,7 @@ public class WebView extends AbsoluteLayout
        int mWidth;
        int mHeight;
        float mHeightWidthRatio;
        int mActualViewHeight;
        int mTextWrapWidth;
        int mAnchorX;
        int mAnchorY;
@@ -2594,6 +2598,7 @@ public class WebView extends AbsoluteLayout

        int viewWidth = getViewWidth();
        int newWidth = Math.round(viewWidth * mZoomManager.getInvScale());
        // This height could be fixed and be different from actual visible height.
        int viewHeight = getViewHeightWithTitle() - getTitleHeight();
        int newHeight = Math.round(viewHeight * mZoomManager.getInvScale());
        // Make the ratio more accurate than (newHeight / newWidth), since the
@@ -2611,12 +2616,16 @@ public class WebView extends AbsoluteLayout
            newHeight = 0;
            heightWidthRatio = 0;
        }
        // Actual visible height.
        int actualViewHeight = getViewHeight();
        // Avoid sending another message if the dimensions have not changed.
        if (newWidth != mLastWidthSent || newHeight != mLastHeightSent || force) {
        if (newWidth != mLastWidthSent || newHeight != mLastHeightSent || force ||
                actualViewHeight != mLastActualHeightSent) {
            ViewSizeData data = new ViewSizeData();
            data.mWidth = newWidth;
            data.mHeight = newHeight;
            data.mHeightWidthRatio = heightWidthRatio;
            data.mActualViewHeight = actualViewHeight;
            data.mTextWrapWidth = Math.round(viewWidth / mZoomManager.getTextWrapScale());
            data.mScale = mZoomManager.getScale();
            data.mIgnoreHeight = mZoomManager.isFixedLengthAnimationInProgress()
@@ -2626,6 +2635,7 @@ public class WebView extends AbsoluteLayout
            mWebViewCore.sendMessage(EventHub.VIEW_SIZE_CHANGED, data);
            mLastWidthSent = newWidth;
            mLastHeightSent = newHeight;
            mLastActualHeightSent = actualViewHeight;
            mZoomManager.clearDocumentAnchor();
            return true;
        }
+10 −11
Original line number Diff line number Diff line
@@ -1177,13 +1177,7 @@ final class WebViewCore {
                            break;

                        case VIEW_SIZE_CHANGED: {
                            WebView.ViewSizeData data =
                                    (WebView.ViewSizeData) msg.obj;
                            viewSizeChanged(data.mWidth, data.mHeight,
                                    data.mHeightWidthRatio,
                                    data.mTextWrapWidth, data.mScale,
                                    data.mAnchorX, data.mAnchorY,
                                    data.mIgnoreHeight);
                            viewSizeChanged((WebView.ViewSizeData) msg.obj);
                            break;
                        }
                        case SET_SCROLL_OFFSET:
@@ -1817,8 +1811,11 @@ final class WebViewCore {
    private float mCurrentViewScale = 1.0f;

    // notify webkit that our virtual view size changed size (after inv-zoom)
    private void viewSizeChanged(int w, int h, float heightWidthRatio, int textwrapWidth,
            float scale, int anchorX, int anchorY, boolean ignoreHeight) {
    private void viewSizeChanged(WebView.ViewSizeData data) {
        int w = data.mWidth;
        int h = data.mHeight;
        int textwrapWidth = data.mTextWrapWidth;
        float scale = data.mScale;
        if (DebugFlags.WEB_VIEW_CORE) {
            Log.v(LOGTAG, "viewSizeChanged w=" + w + "; h=" + h
                    + "; textwrapWidth=" + textwrapWidth + "; scale=" + scale);
@@ -1865,11 +1862,13 @@ final class WebViewCore {
        }
        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, h, anchorX, anchorY, ignoreHeight);
        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;