Index: content/public/android/java/src/org/chromium/content/browser/input/ImeAdapter.java |
diff --git a/content/public/android/java/src/org/chromium/content/browser/input/ImeAdapter.java b/content/public/android/java/src/org/chromium/content/browser/input/ImeAdapter.java |
index d85273be9f59e92ddf388eeab157d6da9d7be89a..f86c405349582b6c8bf5e71578d54d9c56b25bd3 100644 |
--- a/content/public/android/java/src/org/chromium/content/browser/input/ImeAdapter.java |
+++ b/content/public/android/java/src/org/chromium/content/browser/input/ImeAdapter.java |
@@ -124,6 +124,10 @@ public class ImeAdapter { |
private final Handler mHandler; |
private DelayedDismissInput mDismissInput = null; |
private int mTextInputType; |
+ private String mLastComposeText; |
+ |
+ @VisibleForTesting |
+ int mLastComposeKeyCode; |
@VisibleForTesting |
boolean mIsShowWithoutHideOutstanding = false; |
@@ -317,6 +321,94 @@ public class ImeAdapter { |
else return COMPOSITION_KEY_CODE; |
} |
+ private int androidKeyCodeForCharacter(char chr) { |
+ // This is currently only called for letters due to the nature of |
+ // composition on Android. |
+ switch (chr) { |
+ case 'A': |
+ case 'a': |
+ return KeyEvent.KEYCODE_A; |
+ case 'B': |
+ case 'b': |
+ return KeyEvent.KEYCODE_B; |
+ case 'C': |
+ case 'c': |
+ return KeyEvent.KEYCODE_C; |
+ case 'D': |
+ case 'd': |
+ return KeyEvent.KEYCODE_D; |
+ case 'E': |
+ case 'e': |
+ return KeyEvent.KEYCODE_E; |
+ case 'F': |
+ case 'f': |
+ return KeyEvent.KEYCODE_F; |
+ case 'G': |
+ case 'g': |
+ return KeyEvent.KEYCODE_G; |
+ case 'H': |
+ case 'h': |
+ return KeyEvent.KEYCODE_H; |
+ case 'I': |
+ case 'i': |
+ return KeyEvent.KEYCODE_I; |
+ case 'J': |
+ case 'j': |
+ return KeyEvent.KEYCODE_J; |
+ case 'K': |
+ case 'k': |
+ return KeyEvent.KEYCODE_K; |
+ case 'L': |
+ case 'l': |
+ return KeyEvent.KEYCODE_L; |
+ case 'M': |
+ case 'm': |
+ return KeyEvent.KEYCODE_M; |
+ case 'N': |
+ case 'n': |
+ return KeyEvent.KEYCODE_N; |
+ case 'O': |
+ case 'o': |
+ return KeyEvent.KEYCODE_O; |
+ case 'P': |
+ case 'p': |
+ return KeyEvent.KEYCODE_P; |
+ case 'Q': |
+ case 'q': |
+ return KeyEvent.KEYCODE_Q; |
+ case 'R': |
+ case 'r': |
+ return KeyEvent.KEYCODE_R; |
+ case 'S': |
+ case 's': |
+ return KeyEvent.KEYCODE_S; |
+ case 'T': |
+ case 't': |
+ return KeyEvent.KEYCODE_T; |
+ case 'U': |
+ case 'u': |
+ return KeyEvent.KEYCODE_U; |
+ case 'V': |
+ case 'v': |
+ return KeyEvent.KEYCODE_V; |
+ case 'W': |
+ case 'w': |
+ return KeyEvent.KEYCODE_W; |
+ case 'X': |
+ case 'x': |
+ return KeyEvent.KEYCODE_X; |
+ case 'Y': |
+ case 'y': |
+ return KeyEvent.KEYCODE_Y; |
+ case 'Z': |
+ case 'z': |
+ return KeyEvent.KEYCODE_Z; |
+ |
+ default: |
+ return 0; |
+ } |
+ } |
+ |
void sendKeyEventWithKeyCode(int keyCode, int flags) { |
long eventTime = SystemClock.uptimeMillis(); |
translateAndSendNativeEvents(new KeyEvent(eventTime, eventTime, |
@@ -346,6 +438,18 @@ public class ImeAdapter { |
sendKeyEventWithKeyCode(keyCode, |
KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE); |
} else { |
+ if (mLastComposeText == null) { |
+ if (textStr.length() == 1) |
+ keyCode = androidKeyCodeForCharacter(textStr.charAt(0)); |
aurimas (slooooooooow)
2014/07/07 17:05:20
Android already has tools to convert characters to
bcwhite
2014/07/08 18:56:03
A little convoluted what with creating the event a
jdduke (slow)
2014/07/08 19:53:54
Hmm, should we be using that function even though
|
+ } else { |
+ if (textStr.length() == mLastComposeText.length() + 1) |
+ keyCode = androidKeyCodeForCharacter(textStr.charAt(textStr.length() - 1)); |
+ else if (textStr.length() == mLastComposeText.length() - 1) |
+ keyCode = KeyEvent.KEYCODE_DEL; |
+ } |
guohui
2014/07/04 21:56:13
we can get more accurate results if you check both
|
+ mLastComposeText = textStr; |
+ mLastComposeKeyCode = keyCode; |
+ |
nativeSendSyntheticKeyEvent(mNativeImeAdapterAndroid, sEventTypeRawKeyDown, |
timeStampMs, keyCode, 0); |
if (isCommit) { |
@@ -362,6 +466,7 @@ public class ImeAdapter { |
void finishComposingText() { |
if (mNativeImeAdapterAndroid == 0) return; |
+ mLastComposeText = null; |
nativeFinishComposingText(mNativeImeAdapterAndroid); |
} |
@@ -553,6 +658,7 @@ public class ImeAdapter { |
@CalledByNative |
private void cancelComposition() { |
if (mInputConnection != null) mInputConnection.restartInput(); |
+ mLastComposeText = null; |
} |
@CalledByNative |