Index: content/public/android/java/src/org/chromium/content/browser/ImeAdapter.java |
diff --git a/content/public/android/java/src/org/chromium/content/browser/ImeAdapter.java b/content/public/android/java/src/org/chromium/content/browser/ImeAdapter.java |
index e5ddc2987ac770e604509d1ebe563f20667b9fd5..49572dfbb9df44934c10e30ab8ece6c77267fbec 100644 |
--- a/content/public/android/java/src/org/chromium/content/browser/ImeAdapter.java |
+++ b/content/public/android/java/src/org/chromium/content/browser/ImeAdapter.java |
@@ -280,7 +280,7 @@ class ImeAdapter { |
} |
} |
- private boolean checkCompositionQueueAndCallNative(String text, int newCursorPosition, |
+ boolean checkCompositionQueueAndCallNative(String text, int newCursorPosition, |
boolean isCommit) { |
if (mNativeImeAdapterAndroid == 0) { |
return false; |
@@ -461,20 +461,21 @@ class ImeAdapter { |
return true; |
} |
+ public static class AdapterInputConnectionFactory { |
+ public AdapterInputConnection get(View view, ImeAdapter imeAdapter, |
+ EditorInfo outAttrs) { |
+ return new AdapterInputConnection(view, imeAdapter, outAttrs); |
+ } |
+ } |
+ |
// This InputConnection is created by ContentView.onCreateInputConnection. |
// It then adapts android's IME to chrome's RenderWidgetHostView using the |
// native ImeAdapterAndroid via the outer class ImeAdapter. |
- static public class AdapterInputConnection extends BaseInputConnection { |
+ public static class AdapterInputConnection extends BaseInputConnection { |
private View mInternalView; |
private ImeAdapter mImeAdapter; |
private boolean mSingleLine; |
- // Factory function. |
- static public AdapterInputConnection getInstance(View view, ImeAdapter imeAdapter, |
- EditorInfo outAttrs) { |
- return new AdapterInputConnection(view, imeAdapter, outAttrs); |
- } |
- |
/** |
* Updates the AdapterInputConnection's internal representation of the text |
* being edited and its selection and composition properties. The resulting |
@@ -522,7 +523,6 @@ class ImeAdapter { |
} |
Selection.setSelection(editable, selectionStart, selectionEnd); |
super.setComposingRegion(compositionStart, compositionEnd); |
- |
if (textUnchanged || prevText.equals("")) { |
// updateSelection should be called when a manual selection change occurs. |
// Should not be called if text is being entered else issues can occur |
@@ -530,13 +530,6 @@ class ImeAdapter { |
getInputMethodManager().updateSelection(mInternalView, |
selectionStart, selectionEnd, compositionStart, compositionEnd); |
} |
- |
- // When WebKit changes the editable field, both the start and the end positions for |
- // the composition will be set to -1. In this case we have to call restart input |
- // for the IME to update its state. |
- if (textUnchanged && compositionStart == -1 && compositionEnd == -1) { |
- restartInput(); |
- } |
} |
@Override |
@@ -555,22 +548,17 @@ class ImeAdapter { |
@Override |
public boolean performEditorAction(int actionCode) { |
- switch (actionCode) { |
- case EditorInfo.IME_ACTION_NEXT: |
- restartInput(); |
- // Send TAB key event |
- long timeStampMs = System.currentTimeMillis(); |
- mImeAdapter.sendSyntheticKeyEvent( |
- sEventTypeRawKeyDown, timeStampMs, KeyEvent.KEYCODE_TAB, 0); |
- return true; |
- case EditorInfo.IME_ACTION_GO: |
- case EditorInfo.IME_ACTION_SEARCH: |
- mImeAdapter.dismissInput(true); |
- break; |
+ if (actionCode == EditorInfo.IME_ACTION_NEXT) { |
+ restartInput(); |
+ // Send TAB key event |
+ long timeStampMs = System.currentTimeMillis(); |
+ mImeAdapter.sendSyntheticKeyEvent( |
+ sEventTypeRawKeyDown, timeStampMs, KeyEvent.KEYCODE_TAB, 0); |
+ } else { |
+ mImeAdapter.sendKeyEventWithKeyCode(KeyEvent.KEYCODE_ENTER, |
+ KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE |
+ | KeyEvent.FLAG_EDITOR_ACTION); |
} |
- mImeAdapter.sendKeyEventWithKeyCode(KeyEvent.KEYCODE_ENTER, |
- KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE |
- | KeyEvent.FLAG_EDITOR_ACTION); |
return true; |
} |
@@ -685,7 +673,7 @@ class ImeAdapter { |
.getSystemService(Context.INPUT_METHOD_SERVICE); |
} |
- private AdapterInputConnection(View view, ImeAdapter imeAdapter, EditorInfo outAttrs) { |
+ protected AdapterInputConnection(View view, ImeAdapter imeAdapter, EditorInfo outAttrs) { |
super(view, true); |
mInternalView = view; |
mImeAdapter = imeAdapter; |
@@ -735,6 +723,16 @@ class ImeAdapter { |
| InputType.TYPE_NUMBER_VARIATION_NORMAL; |
outAttrs.imeOptions |= EditorInfo.IME_ACTION_NEXT; |
} |
+ |
+ Editable editable = getEditable(); |
+ int selectionStart = Selection.getSelectionStart(editable); |
+ int selectionEnd = Selection.getSelectionEnd(editable); |
+ if (selectionStart < 0 || selectionEnd < 0) { |
+ selectionStart = editable.length(); |
+ selectionEnd = selectionStart; |
+ } |
+ outAttrs.initialSelStart = selectionStart; |
+ outAttrs.initialSelEnd = selectionEnd; |
} |
} |