diff options
| author | Derek Sollenberger <djsollen@google.com> | 2010-03-16 10:39:48 -0400 |
|---|---|---|
| committer | Derek Sollenberger <djsollen@google.com> | 2010-03-16 13:47:04 -0400 |
| commit | 41df3f7e15b3d5f77dc7f255ec702e381eb93f35 (patch) | |
| tree | 33ddb304cce5cfd27d3422e031d8ca3f2e1576d0 /core/java/android/webkit/ViewManager.java | |
| parent | e118d6fbdef7e97e229351c2c76c5c7245ecd521 (diff) | |
Restrict plugins to a fixed size surface after exceeding a pixel threshold.
fixes bug: http://b/issue?id=2428737
Change-Id: I8d8f2c591ac8539a345e0167b05bec8539f34535
Diffstat (limited to 'core/java/android/webkit/ViewManager.java')
| -rw-r--r-- | core/java/android/webkit/ViewManager.java | 52 |
1 files changed, 41 insertions, 11 deletions
diff --git a/core/java/android/webkit/ViewManager.java b/core/java/android/webkit/ViewManager.java index 47e77918fd41..02f452b4d41a 100644 --- a/core/java/android/webkit/ViewManager.java +++ b/core/java/android/webkit/ViewManager.java @@ -16,6 +16,7 @@ package android.webkit; +import android.view.SurfaceView; import android.view.View; import android.widget.AbsoluteLayout; @@ -27,6 +28,9 @@ class ViewManager { private boolean mHidden; private boolean mReadyToDraw; + // Threshold at which a surface is prevented from further increasing in size + private static final int MAX_SURFACE_THRESHOLD = 1000000; + class ChildView { int x; int y; @@ -34,6 +38,11 @@ class ViewManager { int height; View mView; // generic view to show + /* set to true if the view is a surface and it has exceeded the pixel + threshold specified in MAX_SURFACE_THRESHOLD. + */ + boolean isFixedSize = false; + ChildView() { } @@ -49,15 +58,15 @@ class ViewManager { return; } setBounds(x, y, width, height); - final AbsoluteLayout.LayoutParams lp = - new AbsoluteLayout.LayoutParams(ctvD(width), ctvD(height), - ctvX(x), ctvY(y)); + mWebView.mPrivateHandler.post(new Runnable() { public void run() { // This method may be called multiple times. If the view is // already attached, just set the new LayoutParams, // otherwise attach the view and add it to the list of // children. + AbsoluteLayout.LayoutParams lp = computeLayout(ChildView.this); + if (mView.getParent() != null) { mView.setLayoutParams(lp); } else { @@ -67,7 +76,7 @@ class ViewManager { }); } - void attachViewOnUIThread(AbsoluteLayout.LayoutParams lp) { + private void attachViewOnUIThread(AbsoluteLayout.LayoutParams lp) { mWebView.addView(mView, lp); mChildren.add(this); if (!mReadyToDraw) { @@ -86,7 +95,7 @@ class ViewManager { }); } - void removeViewOnUIThread() { + private void removeViewOnUIThread() { mWebView.removeView(mView); mChildren.remove(this); } @@ -125,16 +134,37 @@ class ViewManager { return mWebView.contentToViewY(val); } - void scaleAll() { - for (ChildView v : mChildren) { - View view = v.mView; - AbsoluteLayout.LayoutParams lp = - (AbsoluteLayout.LayoutParams) view.getLayoutParams(); + /** + * This should only be called from the UI thread. + */ + private AbsoluteLayout.LayoutParams computeLayout(ChildView v) { + + // if the surface has exceed a predefined threshold then fix the size + // of the surface. + if (!v.isFixedSize && (v.width * v.height) > MAX_SURFACE_THRESHOLD + && v.mView instanceof SurfaceView) { + ((SurfaceView)v.mView).getHolder().setFixedSize(v.width, v.height); + v.isFixedSize = true; + } + + AbsoluteLayout.LayoutParams lp = + (AbsoluteLayout.LayoutParams) v.mView.getLayoutParams(); + + if (lp == null) + lp = new AbsoluteLayout.LayoutParams(ctvD(v.width), ctvD(v.height), + ctvX(v.x), ctvY(v.y)); + else { lp.width = ctvD(v.width); lp.height = ctvD(v.height); lp.x = ctvX(v.x); lp.y = ctvY(v.y); - view.setLayoutParams(lp); + } + return lp; + } + + void scaleAll() { + for (ChildView v : mChildren) { + v.mView.setLayoutParams(computeLayout(v)); } } |
