Skip to content

Commit 843e04d

Browse files
jreckAndroid (Google) Code Review
authored andcommitted
Merge "Pause drawing when not visible" into ics-mr1
2 parents 2375d16 + 5f1c549 commit 843e04d

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

core/java/android/webkit/WebView.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3254,6 +3254,26 @@ public void onPause() {
32543254
if (mHTML5VideoViewProxy != null) {
32553255
mHTML5VideoViewProxy.pauseAndDispatch();
32563256
}
3257+
if (mNativeClass != 0) {
3258+
nativeSetPauseDrawing(mNativeClass, true);
3259+
}
3260+
}
3261+
}
3262+
3263+
@Override
3264+
protected void onWindowVisibilityChanged(int visibility) {
3265+
super.onWindowVisibilityChanged(visibility);
3266+
updateDrawingState();
3267+
}
3268+
3269+
void updateDrawingState() {
3270+
if (mNativeClass == 0 || mIsPaused) return;
3271+
if (getWindowVisibility() != VISIBLE) {
3272+
nativeSetPauseDrawing(mNativeClass, true);
3273+
} else if (getVisibility() != VISIBLE) {
3274+
nativeSetPauseDrawing(mNativeClass, true);
3275+
} else {
3276+
nativeSetPauseDrawing(mNativeClass, false);
32573277
}
32583278
}
32593279

@@ -3265,6 +3285,9 @@ public void onResume() {
32653285
if (mIsPaused) {
32663286
mIsPaused = false;
32673287
mWebViewCore.sendMessage(EventHub.ON_RESUME);
3288+
if (mNativeClass != 0) {
3289+
nativeSetPauseDrawing(mNativeClass, false);
3290+
}
32683291
}
32693292
}
32703293

@@ -5599,6 +5622,7 @@ protected void onVisibilityChanged(View changedView, int visibility) {
55995622
if (visibility != View.VISIBLE && mZoomManager != null) {
56005623
mZoomManager.dismissZoomPicker();
56015624
}
5625+
updateDrawingState();
56025626
}
56035627

56045628
/**
@@ -8403,6 +8427,9 @@ public void handleMessage(Message msg) {
84038427
setNewPicture(mDelaySetPicture, true);
84048428
mDelaySetPicture = null;
84058429
}
8430+
if (mIsPaused) {
8431+
nativeSetPauseDrawing(mNativeClass, true);
8432+
}
84068433
break;
84078434
case UPDATE_TEXTFIELD_TEXT_MSG_ID:
84088435
// Make sure that the textfield is currently focused
@@ -9581,4 +9608,5 @@ private native int nativeScrollableLayer(int x, int y, Rect scrollRect,
95819608
* See {@link ComponentCallbacks2} for the trim levels and descriptions
95829609
*/
95839610
private static native void nativeOnTrimMemory(int level);
9611+
private static native void nativeSetPauseDrawing(int instance, boolean pause);
95849612
}

0 commit comments

Comments
 (0)