Remove the web text view if the key cannot be handled

Also add some debugging to WebTextView
Requires companion change in external/webkit
This commit is contained in:
Cary Clark
2009-06-25 10:49:32 -04:00
parent 215b72cbf7
commit 243ea06d2b
4 changed files with 43 additions and 3 deletions

View File

@@ -42,6 +42,7 @@ class DebugFlags {
public static final boolean WEB_BACK_FORWARD_LIST = false;
public static final boolean WEB_SETTINGS = false;
public static final boolean WEB_SYNC_MANAGER = false;
public static final boolean WEB_TEXT_VIEW = false;
public static final boolean WEB_VIEW = false;
public static final boolean WEB_VIEW_CORE = false;

View File

@@ -24,6 +24,7 @@ import android.text.Selection;
import android.text.Spannable;
import android.text.TextUtils;
import android.text.method.MovementMethod;
import android.util.Log;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.view.KeyCharacterMap;
@@ -45,6 +46,8 @@ import java.util.ArrayList;
*/
/* package */ class WebTextView extends AutoCompleteTextView {
static final String LOGTAG = "webtextview";
private WebView mWebView;
private boolean mSingle;
private int mWidthSpec;
@@ -82,6 +85,7 @@ import java.util.ArrayList;
setImeOptions(EditorInfo.IME_ACTION_NONE);
// Allow webkit's drawing to show through
setWillNotDraw(true);
setCursorVisible(false);
}
@Override
@@ -268,6 +272,10 @@ import java.util.ArrayList;
@Override
protected void onSelectionChanged(int selStart, int selEnd) {
if (mWebView != null) {
if (DebugFlags.WEB_TEXT_VIEW) {
Log.v(LOGTAG, "onSelectionChanged selStart=" + selStart
+ " selEnd=" + selEnd);
}
mWebView.setSelection(selStart, selEnd);
}
}
@@ -313,6 +321,10 @@ import java.util.ArrayList;
} else {
// This corrects the selection which may have been affected by the
// trackball or auto-correct.
if (DebugFlags.WEB_TEXT_VIEW) {
Log.v(LOGTAG, "onTextChanged start=" + start
+ " start + before=" + (start + before));
}
mWebView.setSelection(start, start + before);
}
if (!cannotUseKeyEvents) {
@@ -542,6 +554,10 @@ import java.util.ArrayList;
} else if (start > length) {
start = length;
}
if (DebugFlags.WEB_TEXT_VIEW) {
Log.v(LOGTAG, "setText start=" + start
+ " end=" + end);
}
Selection.setSelection(span, start, end);
}

View File

@@ -459,6 +459,8 @@ public class WebView extends AbsoluteLayout
static final int UPDATE_TEXTFIELD_TEXT_MSG_ID = 17;
static final int DID_FIRST_LAYOUT_MSG_ID = 18;
static final int MOVE_OUT_OF_PLUGIN = 19;
static final int CLEAR_TEXT_ENTRY = 20;
static final int UPDATE_CLIPBOARD = 22;
static final int LONG_PRESS_CENTER = 23;
static final int PREVENT_TOUCH_ID = 24;
@@ -486,7 +488,7 @@ public class WebView extends AbsoluteLayout
"UPDATE_TEXTFIELD_TEXT_MSG_ID", // = 17;
"DID_FIRST_LAYOUT_MSG_ID", // = 18;
"MOVE_OUT_OF_PLUGIN", // = 19;
"20",
"CLEAR_TEXT_ENTRY", // = 20;
"21", // = 21;
"UPDATE_CLIPBOARD", // = 22;
"LONG_PRESS_CENTER", // = 23;
@@ -3108,6 +3110,9 @@ public class WebView extends AbsoluteLayout
mWebTextView.setInPassword(nativeFocusCandidateIsPassword());
if (null == text) {
mWebTextView.setText("", 0, 0);
if (DebugFlags.WEB_VIEW) {
Log.v(LOGTAG, "rebuildWebTextView null == text");
}
} else {
// Change to true to enable the old style behavior, where
// entering a textfield/textarea always set the selection to the
@@ -3122,8 +3127,14 @@ public class WebView extends AbsoluteLayout
} else if (isTextField) {
int length = text.length();
mWebTextView.setText(text, length, length);
if (DebugFlags.WEB_VIEW) {
Log.v(LOGTAG, "rebuildWebTextView length=" + length);
}
} else {
mWebTextView.setText(text, 0, 0);
if (DebugFlags.WEB_VIEW) {
Log.v(LOGTAG, "rebuildWebTextView !isTextField");
}
}
}
mWebTextView.requestFocus();
@@ -4847,6 +4858,9 @@ public class WebView extends AbsoluteLayout
}
rebuildWebTextView();
break;
case CLEAR_TEXT_ENTRY:
clearTextEntry();
break;
case INVAL_RECT_MSG_ID: {
Rect r = (Rect)msg.obj;
if (r == null) {

View File

@@ -720,9 +720,11 @@ final class WebViewCore {
@Override
public void handleMessage(Message msg) {
if (DebugFlags.WEB_VIEW_CORE) {
Log.v(LOGTAG, msg.what < LOAD_URL || msg.what
Log.v(LOGTAG, (msg.what < LOAD_URL || msg.what
> FREE_MEMORY ? Integer.toString(msg.what)
: HandlerDebugString[msg.what - LOAD_URL]);
: HandlerDebugString[msg.what - LOAD_URL])
+ " arg1=" + msg.arg1 + " arg2=" + msg.arg2
+ " obj=" + msg.obj);
}
switch (msg.what) {
case WEBKIT_DRAW:
@@ -1749,6 +1751,13 @@ final class WebViewCore {
}
}
// called by JNI
private void clearTextEntry() {
if (mWebView == null) return;
Message.obtain(mWebView.mPrivateHandler,
WebView.CLEAR_TEXT_ENTRY).sendToTarget();
}
// these must be in document space (i.e. not scaled/zoomed).
private native void nativeSetScrollOffset(int gen, int dx, int dy);