summaryrefslogtreecommitdiffstats
path: root/core/java/android/webkit
diff options
context:
space:
mode:
authorPatrick Scott <phanna@android.com>2009-07-17 16:38:07 -0400
committerPatrick Scott <phanna@android.com>2009-07-20 09:31:56 -0400
commitfb6aecb70392516427908c3148c0350840f6bc04 (patch)
treec65c28326f4943f396b70fb60b22561cc0858a57 /core/java/android/webkit
parent4a06b68c82fc011d8cd780ed7f0393d1d0617a07 (diff)
downloadframeworks_base-fb6aecb70392516427908c3148c0350840f6bc04.zip
frameworks_base-fb6aecb70392516427908c3148c0350840f6bc04.tar.gz
frameworks_base-fb6aecb70392516427908c3148c0350840f6bc04.tar.bz2
Added hooks from jni to create and manage SurfaceViews for plugins.
A subclass of SurfaceView is created in order to appear like a normal SurfaceView to jni but can be managed in Java easily. This class implements the SurfaceHolder.Callback interface in order to notify the native PluginSurface when the surface changes.
Diffstat (limited to 'core/java/android/webkit')
-rw-r--r--core/java/android/webkit/WebViewCore.java72
1 files changed, 72 insertions, 0 deletions
diff --git a/core/java/android/webkit/WebViewCore.java b/core/java/android/webkit/WebViewCore.java
index 20f7239..99ceec2 100644
--- a/core/java/android/webkit/WebViewCore.java
+++ b/core/java/android/webkit/WebViewCore.java
@@ -32,6 +32,8 @@ import android.os.Process;
import android.util.Log;
import android.util.SparseBooleanArray;
import android.view.KeyEvent;
+import android.view.SurfaceHolder;
+import android.view.SurfaceView;
import java.util.ArrayList;
@@ -1826,6 +1828,76 @@ final class WebViewCore {
}
}
+ // This class looks like a SurfaceView to native code. In java, we can
+ // assume the passed in SurfaceView is this class so we can talk to the
+ // ViewManager through the ChildView.
+ private class SurfaceViewProxy extends SurfaceView
+ implements SurfaceHolder.Callback {
+ private final ViewManager.ChildView mChildView;
+ private int mPointer;
+ SurfaceViewProxy(Context context, ViewManager.ChildView childView,
+ int pointer) {
+ super(context);
+ setWillNotDraw(false); // this prevents the black box artifact
+ getHolder().addCallback(this);
+ mChildView = childView;
+ mChildView.mView = this;
+ mPointer = pointer;
+ }
+ void destroy() {
+ mPointer = 0;
+ mChildView.removeView();
+ }
+ void attach(int x, int y, int width, int height) {
+ mChildView.attachView(x, y, width, height);
+ }
+
+ // SurfaceHolder.Callback methods
+ public void surfaceCreated(SurfaceHolder holder) {
+ if (mPointer != 0) {
+ nativeSurfaceChanged(mPointer, 0, 0, 0, 0);
+ }
+ }
+ public void surfaceChanged(SurfaceHolder holder, int format, int width,
+ int height) {
+ if (mPointer != 0) {
+ nativeSurfaceChanged(mPointer, 1, format, width, height);
+ }
+ }
+ public void surfaceDestroyed(SurfaceHolder holder) {
+ if (mPointer != 0) {
+ nativeSurfaceChanged(mPointer, 2, 0, 0, 0);
+ }
+ }
+ }
+
+ // PluginWidget functions for mainting SurfaceViews for the Surface drawing
+ // model.
+ private SurfaceView createSurface(int nativePointer) {
+ if (mWebView == null) {
+ return null;
+ }
+ return new SurfaceViewProxy(mContext,
+ mWebView.mViewManager.createView(), nativePointer);
+ }
+
+ private void destroySurface(SurfaceView surface) {
+ SurfaceViewProxy proxy = (SurfaceViewProxy) surface;
+ proxy.destroy();
+ }
+
+ private void attachSurface(SurfaceView surface, int x, int y,
+ int width, int height) {
+ SurfaceViewProxy proxy = (SurfaceViewProxy) surface;
+ proxy.attach(x, y, width, height);
+ }
+
+ // Callback for the SurfaceHolder.Callback. Called for all the surface
+ // callbacks. The state parameter is one of Created(0), Changed(1),
+ // Destroyed(2).
+ private native void nativeSurfaceChanged(int pointer, int state, int format,
+ int width, int height);
+
private native void nativePause();
private native void nativeResume();
private native void nativeFreeMemory();