Merge "Pause WebKit drawing when WebView loses window focus."

This commit is contained in:
Adam Powell
2011-09-12 18:15:37 -07:00
committed by Android (Google) Code Review
3 changed files with 23 additions and 4 deletions

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -2107,6 +2107,10 @@ public final class WebViewCore {
}
}
static boolean isUpdatePicturePaused(WebViewCore core) {
return core != null ? core.mDrawIsPaused : false;
}
//////////////////////////////////////////////////////////////////////////
private void restoreState(int index) {