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

Commit e00e8a78 authored by Adam Powell's avatar Adam Powell
Browse files

Pause WebKit drawing when WebView loses window focus.

This prevents animations and other live page content from consuming
too many resources while the user is interacting with a popup window.

Bug 5300522

Change-Id: I40fb6d16d56b540c431172052a1ae7fead7109be
parent aeb11675
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -643,10 +643,10 @@ public class WebSettings {

    /**
     * Set whether the WebView will enable smooth transition while panning or
     * zooming. If it is true, WebView will choose a solution to maximize the
     * performance. e.g. the WebView's content may not be updated during the
     * transition. If it is false, WebView will keep its fidelity. The default
     * value is false.
     * zooming or while the window hosting the WebView does not have focus.
     * If it is true, WebView will choose a solution to maximize the performance.
     * e.g. the WebView's content may not be updated during the transition.
     * If it is false, WebView will keep its fidelity. The default value is false.
     */
    public void setEnableSmoothTransition(boolean enable) {
        mEnableSmoothTransition = enable;
+15 −0
Original line number Diff line number Diff line
@@ -908,6 +908,9 @@ public class WebView extends AbsoluteLayout
    // used for serializing asynchronously handled touch events.
    private final TouchEventQueue mTouchEventQueue = new TouchEventQueue();

    // Used to track whether picture updating was paused due to a window focus change.
    private boolean mPictureUpdatePausedForFocusChange = false;

    // Used to notify listeners of a new picture.
    private PictureListener mPictureListener;
    /**
@@ -5570,8 +5573,20 @@ public class WebView extends AbsoluteLayout
        setActive(hasWindowFocus);
        if (hasWindowFocus) {
            JWebCoreJavaBridge.setActiveWebView(this);
            if (mPictureUpdatePausedForFocusChange) {
                WebViewCore.resumeUpdatePicture(mWebViewCore);
                nativeSetIsScrolling(false);
                mPictureUpdatePausedForFocusChange = false;
            }
        } else {
            JWebCoreJavaBridge.removeActiveWebView(this);
            final WebSettings settings = getSettings();
            if (settings != null && settings.enableSmoothTransition() &&
                    mWebViewCore != null && !WebViewCore.isUpdatePicturePaused(mWebViewCore)) {
                WebViewCore.pauseUpdatePicture(mWebViewCore);
                nativeSetIsScrolling(true);
                mPictureUpdatePausedForFocusChange = true;
            }
        }
        super.onWindowFocusChanged(hasWindowFocus);
    }
+4 −0
Original line number Diff line number Diff line
@@ -2107,6 +2107,10 @@ public final class WebViewCore {
        }
    }

    static boolean isUpdatePicturePaused(WebViewCore core) {
        return core != null ? core.mDrawIsPaused : false;
    }

    //////////////////////////////////////////////////////////////////////////

    private void restoreState(int index) {