static private final boolean AUTO_REDRAW_HACK = false;
// true means redraw the screen all-the-time. Only with AUTO_REDRAW_HACK
private boolean mAutoRedraw;
+ private int mRootLayer; // C++ pointer to the root layer
+ private boolean mLayersHaveAnimations;
+ private EvaluateLayersAnimations mEvaluateThread;
static final String LOGTAG = "webview";
static final int SHOW_FULLSCREEN = 29;
static final int HIDE_FULLSCREEN = 30;
static final int DOM_FOCUS_CHANGED = 31;
+ static final int IMMEDIATE_REPAINT_MSG_ID = 32;
+ static final int SET_ROOT_LAYER_MSG_ID = 33;
static final String[] HandlerDebugString = {
"REMEMBER_PASSWORD", // = 1;
"DO_MOTION_UP", // = 28;
"SHOW_FULLSCREEN", // = 29;
"HIDE_FULLSCREEN", // = 30;
- "DOM_FOCUS_CHANGED" // = 31;
+ "DOM_FOCUS_CHANGED", // = 31;
+ "IMMEDIATE_REPAINT_MSG_ID", // = 32;
+ "SET_ROOT_LAYER_MSG_ID" // = 33;
};
// If the site doesn't use the viewport meta tag to specify the viewport,
if (AUTO_REDRAW_HACK && mAutoRedraw) {
invalidate();
}
+ mWebViewCore.signalRepaintDone();
}
@Override
}
}
+ private void drawLayers(Canvas canvas) {
+ if (mRootLayer != 0) {
+ float scrollY = Math.max(mScrollY - getTitleHeight(), 0);
+ nativeDrawLayers(mRootLayer, mScrollX, scrollY,
+ mActualScale, canvas);
+ }
+ }
+
private void drawCoreAndCursorRing(Canvas canvas, int color,
boolean drawCursorRing) {
if (mDrawHistory) {
canvas.scale(mActualScale, mActualScale);
canvas.drawPicture(mHistoryPicture);
+ drawLayers(canvas);
return;
}
mWebViewCore.drawContentPicture(canvas, color, animateZoom,
animateScroll);
+ drawLayers(canvas);
+
if (mNativeClass == 0) return;
if (mShiftIsPressed && !animateZoom) {
if (mTouchSelection || mExtendSelection) {
}
/*
+ * This class runs the layers animations in their own thread,
+ * so that we do not slow down the UI.
+ */
+ private class EvaluateLayersAnimations extends Thread {
+ boolean mRunning = true;
+ // delay corresponds to 40fps, no need to go faster.
+ int mDelay = 25; // in ms
+ public void run() {
+ while (mRunning) {
+ if (mLayersHaveAnimations && mRootLayer != 0) {
+ // updates is a C++ pointer to a Vector of AnimationValues
+ int updates = nativeEvaluateLayersAnimations(mRootLayer);
+ if (updates == 0) {
+ mRunning = false;
+ }
+ Message.obtain(mPrivateHandler,
+ WebView.IMMEDIATE_REPAINT_MSG_ID,
+ updates, 0).sendToTarget();
+ } else {
+ mRunning = false;
+ }
+ try {
+ Thread.currentThread().sleep(mDelay);
+ } catch (InterruptedException e) {
+ mRunning = false;
+ }
+ }
+ }
+ public void cancel() {
+ mRunning = false;
+ }
+ }
+
+ /*
* This class requests an Adapter for the WebTextView which shows past
* entries stored in the database. It is a Runnable so that it can be done
* in its own thread, without slowing down the UI.
// exclude INVAL_RECT_MSG_ID since it is frequently output
if (DebugFlags.WEB_VIEW && msg.what != INVAL_RECT_MSG_ID) {
Log.v(LOGTAG, msg.what < REMEMBER_PASSWORD || msg.what
- > DOM_FOCUS_CHANGED ? Integer.toString(msg.what)
+ > SET_ROOT_LAYER_MSG_ID ? Integer.toString(msg.what)
: HandlerDebugString[msg.what - REMEMBER_PASSWORD]);
}
if (mWebViewCore == null) {
}
break;
}
+ case IMMEDIATE_REPAINT_MSG_ID: {
+ int updates = msg.arg1;
+ if (updates != 0) {
+ // updates is a C++ pointer to a Vector of
+ // AnimationValues that we apply to the layers.
+ // The Vector is deallocated in nativeUpdateLayers().
+ nativeUpdateLayers(mRootLayer, updates);
+ }
+ invalidate();
+ break;
+ }
+ case SET_ROOT_LAYER_MSG_ID: {
+ int oldLayer = mRootLayer;
+ mRootLayer = msg.arg1;
+ if (oldLayer > 0) {
+ nativeDestroyLayer(oldLayer);
+ }
+ if (mRootLayer == 0) {
+ mLayersHaveAnimations = false;
+ }
+ if (mEvaluateThread != null) {
+ mEvaluateThread.cancel();
+ mEvaluateThread = null;
+ }
+ if (nativeLayersHaveAnimations(mRootLayer)) {
+ mLayersHaveAnimations = true;
+ mEvaluateThread = new EvaluateLayersAnimations();
+ mEvaluateThread.start();
+ }
+ invalidate();
+ break;
+ }
case REQUEST_FORM_DATA:
AutoCompleteAdapter adapter = (AutoCompleteAdapter) msg.obj;
if (mWebTextView.isSameTextField(msg.arg1)) {
private native void nativeDebugDump();
private native void nativeDestroy();
private native void nativeDrawCursorRing(Canvas content);
+ private native void nativeDestroyLayer(int layer);
+ private native int nativeEvaluateLayersAnimations(int layer);
+ private native boolean nativeLayersHaveAnimations(int layer);
+ private native void nativeUpdateLayers(int layer, int updates);
+ private native void nativeDrawLayers(int layer,
+ float scrollX, float scrollY,
+ float scale, Canvas canvas);
private native void nativeDrawMatches(Canvas canvas);
private native void nativeDrawSelectionPointer(Canvas content,
float scale, int x, int y, boolean extendSelection);