зеркало из https://github.com/mozilla/gecko-dev.git
Bug 805162 - i. Refactor DebugGeckoInputConnection to be smaller by using reflection; r=cpeterson
This commit is contained in:
Родитель
175924643e
Коммит
5d6c93b431
|
@ -26,6 +26,9 @@ import android.view.inputmethod.ExtractedTextRequest;
|
||||||
import android.view.inputmethod.InputConnection;
|
import android.view.inputmethod.InputConnection;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationHandler;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Proxy;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
|
||||||
|
@ -553,260 +556,77 @@ class GeckoInputConnection
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static final class DebugGeckoInputConnection extends GeckoInputConnection {
|
final class DebugGeckoInputConnection
|
||||||
public DebugGeckoInputConnection(View targetView) {
|
extends GeckoInputConnection
|
||||||
super(targetView);
|
implements InvocationHandler {
|
||||||
GeckoApp.assertOnUiThread();
|
|
||||||
|
private InputConnection mProxy;
|
||||||
|
|
||||||
|
private DebugGeckoInputConnection(View targetView,
|
||||||
|
GeckoEditableClient editable) {
|
||||||
|
super(targetView, editable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static InputConnectionHandler create(View targetView,
|
||||||
public boolean beginBatchEdit() {
|
GeckoEditableClient editable) {
|
||||||
Log.d(LOGTAG, "IME: beginBatchEdit: mBatchEditCount " + mBatchEditCount
|
final Class[] PROXY_INTERFACES = { InputConnection.class,
|
||||||
+ " -> " + (mBatchEditCount+1));
|
InputConnectionHandler.class,
|
||||||
GeckoApp.assertOnUiThread();
|
GeckoEditableListener.class };
|
||||||
return super.beginBatchEdit();
|
DebugGeckoInputConnection dgic =
|
||||||
|
new DebugGeckoInputConnection(targetView, editable);
|
||||||
|
dgic.mProxy = (InputConnection)Proxy.newProxyInstance(
|
||||||
|
GeckoInputConnection.class.getClassLoader(),
|
||||||
|
PROXY_INTERFACES, dgic);
|
||||||
|
editable.setListener((GeckoEditableListener)dgic.mProxy);
|
||||||
|
return (InputConnectionHandler)dgic.mProxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private static StringBuilder debugAppend(StringBuilder sb, Object obj) {
|
||||||
public boolean endBatchEdit() {
|
if (obj == null) {
|
||||||
Log.d(LOGTAG, "IME: endBatchEdit: mBatchEditCount " + mBatchEditCount
|
sb.append("null");
|
||||||
+ " -> " + (mBatchEditCount-1));
|
} else if (obj instanceof GeckoEditable) {
|
||||||
GeckoApp.assertOnUiThread();
|
sb.append("GeckoEditable");
|
||||||
if (mBatchEditCount <= 0) {
|
} else if (Proxy.isProxyClass(obj.getClass())) {
|
||||||
throw new IllegalStateException("Expected positive mBatchEditCount, but got "
|
debugAppend(sb, Proxy.getInvocationHandler(obj));
|
||||||
+ mBatchEditCount);
|
} else if (obj instanceof CharSequence) {
|
||||||
|
sb.append("\"").append(obj.toString().replace('\n', '\u21b2')).append("\"");
|
||||||
|
} else if (obj.getClass().isArray()) {
|
||||||
|
Class cls = obj.getClass();
|
||||||
|
sb.append(cls.getComponentType().getSimpleName()).append("[")
|
||||||
|
.append(java.lang.reflect.Array.getLength(obj)).append("]");
|
||||||
|
} else {
|
||||||
|
sb.append(obj.toString());
|
||||||
}
|
}
|
||||||
return super.endBatchEdit();
|
return sb;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public Object invoke(Object proxy, Method method, Object[] args)
|
||||||
public boolean commitCompletion(CompletionInfo text) {
|
throws Throwable {
|
||||||
Log.d(LOGTAG, "IME: commitCompletion");
|
|
||||||
GeckoApp.assertOnUiThread();
|
GeckoApp.assertOnUiThread();
|
||||||
return super.commitCompletion(text);
|
Object ret = method.invoke(this, args);
|
||||||
}
|
if (ret == this) {
|
||||||
|
ret = mProxy;
|
||||||
@Override
|
|
||||||
public boolean commitText(CharSequence text, int newCursorPosition) {
|
|
||||||
Log.d(LOGTAG, String.format("IME: commitText(\"%s\", %d)", text, newCursorPosition));
|
|
||||||
GeckoApp.assertOnUiThread();
|
|
||||||
return super.commitText(text, newCursorPosition);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean deleteSurroundingText(int leftLength, int rightLength) {
|
|
||||||
Log.d(LOGTAG, "IME: deleteSurroundingText(leftLen=" + leftLength + ", rightLen="
|
|
||||||
+ rightLength + ")");
|
|
||||||
GeckoApp.assertOnUiThread();
|
|
||||||
return super.deleteSurroundingText(leftLength, rightLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean finishComposingText() {
|
|
||||||
Log.d(LOGTAG, "IME: finishComposingText");
|
|
||||||
// finishComposingText will post itself to the ui thread,
|
|
||||||
// no need to assert it.
|
|
||||||
return super.finishComposingText();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Editable getEditable() {
|
|
||||||
Editable editable = super.getEditable();
|
|
||||||
Log.d(LOGTAG, "IME: getEditable -> " + prettyPrintString(editable));
|
|
||||||
// FIXME: Uncomment assert after bug 780543 is fixed. //GeckoApp.assertOnUiThread();
|
|
||||||
return editable;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean performContextMenuAction(int id) {
|
|
||||||
Log.d(LOGTAG, "IME: performContextMenuAction");
|
|
||||||
GeckoApp.assertOnUiThread();
|
|
||||||
return super.performContextMenuAction(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ExtractedText getExtractedText(ExtractedTextRequest req, int flags) {
|
|
||||||
Log.d(LOGTAG, "IME: getExtractedText");
|
|
||||||
GeckoApp.assertOnUiThread();
|
|
||||||
ExtractedText extract = super.getExtractedText(req, flags);
|
|
||||||
if (extract != null)
|
|
||||||
Log.d(LOGTAG, String.format(
|
|
||||||
". . . getExtractedText: extract.text=\"%s\", selStart=%d, selEnd=%d",
|
|
||||||
extract.text, extract.selectionStart, extract.selectionEnd));
|
|
||||||
return extract;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CharSequence getTextAfterCursor(int length, int flags) {
|
|
||||||
Log.d(LOGTAG, "IME: getTextAfterCursor(length=" + length + ", flags=" + flags + ")");
|
|
||||||
GeckoApp.assertOnUiThread();
|
|
||||||
CharSequence s = super.getTextAfterCursor(length, flags);
|
|
||||||
Log.d(LOGTAG, ". . . getTextAfterCursor returns \"" + s + "\"");
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CharSequence getTextBeforeCursor(int length, int flags) {
|
|
||||||
Log.d(LOGTAG, "IME: getTextBeforeCursor");
|
|
||||||
GeckoApp.assertOnUiThread();
|
|
||||||
CharSequence s = super.getTextBeforeCursor(length, flags);
|
|
||||||
Log.d(LOGTAG, ". . . getTextBeforeCursor returns \"" + s + "\"");
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean setComposingText(CharSequence text, int newCursorPosition) {
|
|
||||||
Log.d(LOGTAG, String.format("IME: setComposingText(\"%s\", %d)", text, newCursorPosition));
|
|
||||||
GeckoApp.assertOnUiThread();
|
|
||||||
return super.setComposingText(text, newCursorPosition);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean setComposingRegion(int start, int end) {
|
|
||||||
Log.d(LOGTAG, "IME: setComposingRegion(start=" + start + ", end=" + end + ")");
|
|
||||||
GeckoApp.assertOnUiThread();
|
|
||||||
return super.setComposingRegion(start, end);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean setSelection(int start, int end) {
|
|
||||||
Log.d(LOGTAG, "IME: setSelection(start=" + start + ", end=" + end + ")");
|
|
||||||
GeckoApp.assertOnUiThread();
|
|
||||||
return super.setSelection(start, end);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getComposingText() {
|
|
||||||
Log.d(LOGTAG, "IME: getComposingText");
|
|
||||||
GeckoApp.assertOnUiThread();
|
|
||||||
String s = super.getComposingText();
|
|
||||||
Log.d(LOGTAG, ". . . getComposingText: Composing text = \"" + s + "\"");
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onKeyDel() {
|
|
||||||
Log.d(LOGTAG, "IME: onKeyDel");
|
|
||||||
GeckoApp.assertOnUiThread();
|
|
||||||
return super.onKeyDel();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void notifyTextChange(String text, int start, int oldEnd, int newEnd) {
|
|
||||||
// notifyTextChange() call is posted to UI thread from notifyIMEChange().
|
|
||||||
GeckoApp.assertOnUiThread();
|
|
||||||
String msg = String.format("IME: >notifyTextChange(%s, start=%d, oldEnd=%d, newEnd=%d)",
|
|
||||||
prettyPrintString(text), start, oldEnd, newEnd);
|
|
||||||
Log.d(LOGTAG, msg);
|
|
||||||
if (start < 0 || oldEnd < start || newEnd < start || newEnd > text.length()) {
|
|
||||||
throw new IllegalArgumentException("BUG! " + msg);
|
|
||||||
}
|
}
|
||||||
super.notifyTextChange(text, start, oldEnd, newEnd);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
StringBuilder log = new StringBuilder(method.getName());
|
||||||
protected void notifySelectionChange(int start, int end) {
|
log.append("(");
|
||||||
// notifySelectionChange() call is posted to UI thread from notifyIMEChange().
|
for (Object arg : args) {
|
||||||
// FIXME: Uncomment assert after bug 780543 is fixed.
|
debugAppend(log, arg).append(", ");
|
||||||
//GeckoApp.assertOnUiThread();
|
|
||||||
Log.d(LOGTAG, String.format("IME: >notifySelectionChange(start=%d, end=%d)", start, end));
|
|
||||||
super.notifySelectionChange(start, end);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void resetCompositionState() {
|
|
||||||
Log.d(LOGTAG, "IME: resetCompositionState");
|
|
||||||
GeckoApp.assertOnUiThread();
|
|
||||||
if (hasCompositionString()) {
|
|
||||||
Log.d(LOGTAG, "resetCompositionState() is abandoning an active composition string");
|
|
||||||
}
|
}
|
||||||
super.resetCompositionState();
|
if (args.length > 0) {
|
||||||
}
|
log.setLength(log.length() - 2);
|
||||||
|
}
|
||||||
|
if (method.getReturnType().equals(Void.TYPE)) {
|
||||||
|
log.append(")");
|
||||||
|
} else {
|
||||||
|
debugAppend(log.append(") = "), ret);
|
||||||
|
}
|
||||||
|
Log.d(LOGTAG, log.toString());
|
||||||
|
|
||||||
@Override
|
return ret;
|
||||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
||||||
Log.d(LOGTAG, String.format("IME: onTextChanged(\"%s\" start=%d, before=%d, count=%d)",
|
|
||||||
s, start, before, count));
|
|
||||||
GeckoApp.assertOnUiThread();
|
|
||||||
super.onTextChanged(s, start, before, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterTextChanged(Editable s) {
|
|
||||||
Log.d(LOGTAG, "IME: afterTextChanged(\"" + s + "\")");
|
|
||||||
GeckoApp.assertOnUiThread();
|
|
||||||
super.afterTextChanged(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
||||||
Log.d(LOGTAG, String.format("IME: beforeTextChanged(\"%s\", start=%d, count=%d, after=%d)",
|
|
||||||
s, start, count, after));
|
|
||||||
GeckoApp.assertOnUiThread();
|
|
||||||
super.beforeTextChanged(s, start, count, after);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
|
|
||||||
Log.d(LOGTAG, "IME: onCreateInputConnection called");
|
|
||||||
GeckoApp.assertOnUiThread();
|
|
||||||
return super.onCreateInputConnection(outAttrs);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
|
|
||||||
Log.d(LOGTAG, "IME: onKeyPreIme(keyCode=" + keyCode + ", event=" + event + ")");
|
|
||||||
GeckoApp.assertOnUiThread();
|
|
||||||
return super.onKeyPreIme(keyCode, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
||||||
Log.d(LOGTAG, "IME: onKeyDown(keyCode=" + keyCode + ", event=" + event + ")");
|
|
||||||
GeckoApp.assertOnUiThread();
|
|
||||||
return super.onKeyDown(keyCode, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
|
||||||
Log.d(LOGTAG, "IME: onKeyUp(keyCode=" + keyCode + ", event=" + event + ")");
|
|
||||||
GeckoApp.assertOnUiThread();
|
|
||||||
return super.onKeyUp(keyCode, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
|
|
||||||
Log.d(LOGTAG, "IME: onKeyMultiple(keyCode=" + keyCode + ", repeatCount=" + repeatCount
|
|
||||||
+ ", event=" + event + ")");
|
|
||||||
GeckoApp.assertOnUiThread();
|
|
||||||
return super.onKeyMultiple(keyCode, repeatCount, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
|
|
||||||
Log.d(LOGTAG, "IME: onKeyLongPress(keyCode=" + keyCode + ", event=" + event + ")");
|
|
||||||
GeckoApp.assertOnUiThread();
|
|
||||||
return super.onKeyLongPress(keyCode, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void notifyIME(int type, int state) {
|
|
||||||
Log.d(LOGTAG, "IME: >notifyIME(type=" + type + ", state=" + state + ")");
|
|
||||||
GeckoApp.assertOnGeckoThread();
|
|
||||||
super.notifyIME(type, state);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void notifyIMEEnabled(int state, String typeHint, String modeHint, String actionHint) {
|
|
||||||
Log.d(LOGTAG, "IME: >notifyIMEEnabled(state=" + state + ", typeHint=\"" + typeHint
|
|
||||||
+ "\", modeHint=\"" + modeHint + "\", actionHint=\""
|
|
||||||
+ actionHint + "\"");
|
|
||||||
GeckoApp.assertOnGeckoThread();
|
|
||||||
if (state < IME_STATE_DISABLED || state > IME_STATE_PLUGIN)
|
|
||||||
throw new IllegalArgumentException("Unexpected IMEState=" + state);
|
|
||||||
super.notifyIMEEnabled(state, typeHint, modeHint, actionHint);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче