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 955873fd787dd41f58152213b0ea23b3f5b6c139..9a9acb51389982d02b7412d1c7e04ec6746291bb 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 |
@@ -8,7 +8,6 @@ import android.content.res.Configuration; |
import android.os.Handler; |
import android.os.ResultReceiver; |
import android.os.SystemClock; |
-import android.text.Editable; |
import android.text.SpannableString; |
import android.text.style.BackgroundColorSpan; |
import android.text.style.CharacterStyle; |
@@ -16,7 +15,7 @@ import android.text.style.UnderlineSpan; |
import android.view.KeyCharacterMap; |
import android.view.KeyEvent; |
import android.view.View; |
-import android.view.inputmethod.EditorInfo; |
+import android.view.inputmethod.BaseInputConnection; |
import org.chromium.base.VisibleForTesting; |
import org.chromium.base.annotations.CalledByNative; |
@@ -101,7 +100,7 @@ public class ImeAdapter { |
private long mNativeImeAdapterAndroid; |
private InputMethodManagerWrapper mInputMethodManagerWrapper; |
- private AdapterInputConnection mInputConnection; |
+ public ChromiumBaseInputConnection mInputConnection; |
private final ImeAdapterDelegate mViewEmbedder; |
private final Handler mHandler; |
private int mTextInputType; |
@@ -126,16 +125,6 @@ public class ImeAdapter { |
} |
/** |
- * Default factory for AdapterInputConnection classes. |
- */ |
- public static class AdapterInputConnectionFactory { |
- public AdapterInputConnection get(View view, ImeAdapter imeAdapter, |
- Editable editable, EditorInfo outAttrs) { |
- return new AdapterInputConnection(view, imeAdapter, editable, outAttrs); |
- } |
- } |
- |
- /** |
* Overrides the InputMethodManagerWrapper that ImeAdapter uses to make calls to |
* InputMethodManager. |
* @param immw InputMethodManagerWrapper that should be used to call InputMethodManager. |
@@ -158,7 +147,7 @@ public class ImeAdapter { |
* Set the current active InputConnection when a new InputConnection is constructed. |
* @param inputConnection The input connection that is currently used with IME. |
*/ |
- void setInputConnection(AdapterInputConnection inputConnection) { |
+ void setInputConnection(ChromiumBaseInputConnection inputConnection) { |
mInputConnection = inputConnection; |
mLastComposeText = null; |
} |
@@ -221,7 +210,7 @@ public class ImeAdapter { |
attach(nativeImeAdapter, textInputType, textInputFlags, true); |
if (mTextInputType != TextInputType.NONE) { |
- mInputMethodManagerWrapper.restartInput(mViewEmbedder.getAttachedView()); |
+ if (mInputConnection != null) mInputConnection.restartInput(); |
if (showIfNeeded) { |
showKeyboard(); |
} |
@@ -385,17 +374,15 @@ public class ImeAdapter { |
return null; |
} |
- void sendKeyEventWithKeyCode(int keyCode, int flags) { |
+ boolean sendKeyEventWithKeyCode(int keyCode, int flags) { |
long eventTime = SystemClock.uptimeMillis(); |
mLastSyntheticKeyCode = keyCode; |
- translateAndSendNativeEvents(new KeyEvent(eventTime, eventTime, |
- KeyEvent.ACTION_DOWN, keyCode, 0, 0, |
- KeyCharacterMap.VIRTUAL_KEYBOARD, 0, |
- flags)); |
- translateAndSendNativeEvents(new KeyEvent(SystemClock.uptimeMillis(), eventTime, |
- KeyEvent.ACTION_UP, keyCode, 0, 0, |
- KeyCharacterMap.VIRTUAL_KEYBOARD, 0, |
- flags)); |
+ boolean result = translateAndSendNativeEvents(new KeyEvent(eventTime, eventTime, |
+ KeyEvent.ACTION_DOWN, keyCode, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, flags)); |
+ if (!result) return false; |
+ result = translateAndSendNativeEvents(new KeyEvent(SystemClock.uptimeMillis(), eventTime, |
+ KeyEvent.ACTION_UP, keyCode, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, flags)); |
+ return result; |
} |
// Calls from Java to C++ |
@@ -482,10 +469,11 @@ public class ImeAdapter { |
} |
@VisibleForTesting |
- protected void finishComposingText() { |
+ protected boolean finishComposingText() { |
mLastComposeText = null; |
- if (mNativeImeAdapterAndroid == 0) return; |
+ if (mNativeImeAdapterAndroid == 0) return false; |
nativeFinishComposingText(mNativeImeAdapterAndroid); |
+ return true; |
} |
boolean translateAndSendNativeEvents(KeyEvent event) { |
@@ -560,11 +548,20 @@ public class ImeAdapter { |
return true; |
} |
- // Calls from C++ to Java |
+ /** |
+ * Send a request to the native counterpart to give the latest text input state update. |
+ */ |
+ boolean requestTextInputStateUpdate() { |
+ if (mNativeImeAdapterAndroid == 0) return false; |
+ nativeRequestTextInputStateUpdate(mNativeImeAdapterAndroid); |
+ return true; |
+ } |
@CalledByNative |
private void focusedNodeChanged(boolean isEditable) { |
- if (mInputConnection != null && isEditable) mInputConnection.restartInput(); |
+ if (mInputConnection != null && isEditable) { |
+ mInputConnection.restartInput(); |
+ } |
} |
@CalledByNative |
@@ -588,7 +585,7 @@ public class ImeAdapter { |
@CalledByNative |
private void cancelComposition() { |
- if (mInputConnection != null) mInputConnection.restartInput(); |
+ mInputMethodManagerWrapper.restartInput(mViewEmbedder.getAttachedView()); |
mLastComposeText = null; |
} |
@@ -601,32 +598,22 @@ public class ImeAdapter { |
private native boolean nativeSendSyntheticKeyEvent(long nativeImeAdapterAndroid, |
int eventType, long timestampMs, int keyCode, int modifiers, int unicodeChar); |
- |
private native boolean nativeSendKeyEvent(long nativeImeAdapterAndroid, KeyEvent event, |
int action, int modifiers, long timestampMs, int keyCode, boolean isSystemKey, |
int unicodeChar); |
- |
private static native void nativeAppendUnderlineSpan(long underlinePtr, int start, int end); |
- |
private static native void nativeAppendBackgroundColorSpan(long underlinePtr, int start, |
int end, int backgroundColor); |
- |
private native void nativeSetComposingText(long nativeImeAdapterAndroid, CharSequence text, |
String textStr, int newCursorPosition); |
- |
private native void nativeCommitText(long nativeImeAdapterAndroid, String textStr); |
- |
private native void nativeFinishComposingText(long nativeImeAdapterAndroid); |
- |
private native void nativeAttachImeAdapter(long nativeImeAdapterAndroid); |
- |
private native void nativeSetEditableSelectionOffsets(long nativeImeAdapterAndroid, |
int start, int end); |
- |
private native void nativeSetComposingRegion(long nativeImeAdapterAndroid, int start, int end); |
- |
private native void nativeDeleteSurroundingText(long nativeImeAdapterAndroid, |
int before, int after); |
- |
private native void nativeResetImeAdapter(long nativeImeAdapterAndroid); |
+ private native void nativeRequestTextInputStateUpdate(long nativeImeAdapterAndroid); |
} |