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 109c8b8021d70a2f401804e823d5cc5c92c5242e..96727638b4a739f5d1815d1faf71f20993e4f276 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; |
@@ -17,7 +16,6 @@ import android.view.KeyCharacterMap; |
import android.view.KeyEvent; |
import android.view.View; |
import android.view.inputmethod.BaseInputConnection; |
-import android.view.inputmethod.EditorInfo; |
import org.chromium.base.Log; |
import org.chromium.base.VisibleForTesting; |
@@ -104,12 +102,13 @@ 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; |
private int mTextInputFlags; |
private String mLastComposeText; |
+ private final Object mLock = new Object(); |
aelias_OOO_until_Jul13
2015/09/30 00:10:04
This lock doesn't seem to protect against anything
Changwan Ryu
2016/01/19 07:31:53
Removed.
|
@VisibleForTesting |
int mLastSyntheticKeyCode; |
@@ -129,16 +128,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. |
@@ -161,11 +150,17 @@ 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) { |
- mInputConnection = inputConnection; |
+ void setInputConnection(ChromiumBaseInputConnection inputConnection) { |
+ synchronized (mLock) { |
+ mInputConnection = inputConnection; |
+ } |
mLastComposeText = null; |
} |
+ boolean checkInputConnection(ChromiumBaseInputConnection inputConnection) { |
aelias_OOO_until_Jul13
2015/09/30 00:10:04
This method is unused, please delete.
Changwan Ryu
2016/01/19 07:31:53
Removed
|
+ return mInputConnection == inputConnection; |
+ } |
+ |
/** |
* Should be used only by AdapterInputConnection. |
* @return The input type of currently focused element. |
@@ -226,7 +221,7 @@ public class ImeAdapter { |
attach(nativeImeAdapter, textInputType, textInputFlags, true); |
if (mTextInputType != TextInputType.NONE) { |
- mInputMethodManagerWrapper.restartInput(mViewEmbedder.getAttachedView()); |
+ restartInput(); |
if (showIfNeeded) { |
showSoftKeyboard(); |
} |
@@ -312,8 +307,8 @@ public class ImeAdapter { |
public boolean dispatchKeyEvent(KeyEvent event) { |
Log.d(TAG, "dispatchKeyEvent: action [%d], keycode [%d]", event.getAction(), |
event.getKeyCode()); |
- if (mInputConnection != null) { |
- return mInputConnection.sendKeyEvent(event); |
+ synchronized (mLock) { |
+ if (mInputConnection != null) return mInputConnection.dispatchKeyEvent(event); |
} |
return translateAndSendNativeEvents(event); |
} |
@@ -392,17 +387,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++ |
@@ -488,10 +481,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) { |
@@ -569,7 +563,26 @@ public class ImeAdapter { |
@CalledByNative |
private void focusedNodeChanged(boolean isEditable) { |
Log.d(TAG, "focusedNodeChanged"); |
- if (mInputConnection != null && isEditable) mInputConnection.restartInput(); |
+ if (isEditable) restartInput(); |
+ } |
+ |
+ /** |
+ * Restart input connection. You should call this function whenever you need to call |
+ * InputMethodManager#restartInput(). |
+ */ |
+ public void restartInput() { |
+ synchronized (mLock) { |
+ if (mInputConnection != null) mInputConnection.restartInput(); |
+ } |
+ } |
+ |
+ /** |
+ * 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 |
@@ -595,7 +608,7 @@ public class ImeAdapter { |
@CalledByNative |
private void cancelComposition() { |
Log.d(TAG, "cancelComposition"); |
- if (mInputConnection != null) mInputConnection.restartInput(); |
+ restartInput(); |
mLastComposeText = null; |
} |
@@ -609,32 +622,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, int scanCode, |
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); |
} |