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 75bb44fae0d3d228394b0e9bef71477c02904a08..3dc27066450a87dbbfa3f95d4d8ef8b0e38ac0d5 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 |
@@ -26,6 +26,7 @@ import org.chromium.base.annotations.CalledByNative; |
import org.chromium.base.annotations.JNINamespace; |
import org.chromium.blink_public.web.WebInputEventModifier; |
import org.chromium.blink_public.web.WebInputEventType; |
+import org.chromium.content.browser.RenderCoordinates; |
import org.chromium.ui.base.ime.TextInputType; |
import org.chromium.ui.picker.InputDialogContainer; |
@@ -101,6 +102,14 @@ public class ImeAdapter { |
// Every time the user, IME, javascript (Blink), autofill etc. modifies the content, the new |
// state must be reflected to this to keep consistency. |
private final Editable mEditable; |
+ // This holds the information necessary for constructing CursorAnchorInfo, and notifies to |
+ // InputMethodManager on appropriate timing, depending on how IME requested the information |
+ // via InputConnection. The update request is per InputConnection, hence for each time it is |
+ // re-created, the monitoring status will be reset. |
+ private final CursorAnchorInfoController mCursorAnchorInfoController; |
+ |
+ @VisibleForTesting |
+ int mLastSyntheticKeyCode; |
aelias_OOO_until_Jul13
2016/02/26 08:25:33
Looks like you accidentally reintroduced this dele
kinaba
2016/03/01 08:46:46
Ooops, removed.
|
private int mTextInputType = TextInputType.NONE; |
private int mTextInputFlags; |
@@ -122,6 +131,29 @@ public class ImeAdapter { |
// Deep copy newConfig so that we can notice the difference. |
mCurrentConfig = new Configuration( |
mViewEmbedder.getAttachedView().getResources().getConfiguration()); |
+ mCursorAnchorInfoController = CursorAnchorInfoController.create(wrapper, |
+ new CursorAnchorInfoController.ComposingTextDelegate() { |
aelias_OOO_until_Jul13
2016/02/26 08:25:33
It's a bit odd to be new'ing this object just to i
kinaba
2016/03/01 08:46:46
Done.
|
+ @Override |
+ public CharSequence getText() { |
+ return mEditable; |
+ } |
+ @Override |
+ public int getSelectionStart() { |
+ return Selection.getSelectionStart(mEditable); |
+ } |
+ @Override |
+ public int getSelectionEnd() { |
+ return Selection.getSelectionEnd(mEditable); |
+ } |
+ @Override |
+ public int getComposingTextStart() { |
+ return BaseInputConnection.getComposingSpanStart(mEditable); |
aelias_OOO_until_Jul13
2016/02/26 08:25:33
The refactoring https://codereview.chromium.org/12
kinaba
2016/03/01 08:46:46
Done.
|
+ } |
+ @Override |
+ public int getComposingTextEnd() { |
+ return BaseInputConnection.getComposingSpanEnd(mEditable); |
+ } |
+ }); |
} |
/** |
@@ -162,6 +194,9 @@ public class ImeAdapter { |
int initialSelEnd = outAttrs.initialSelEnd = Selection.getSelectionEnd(mEditable); |
mInputConnection = mInputConnectionFactory.get( |
mViewEmbedder.getAttachedView(), this, initialSelStart, initialSelEnd, outAttrs); |
+ if (mCursorAnchorInfoController != null) { |
+ mCursorAnchorInfoController.resetMonitoringState(); |
+ } |
if (DEBUG_LOGS) Log.w(TAG, "onCreateInputConnection"); |
return mInputConnection; |
} |
@@ -174,6 +209,9 @@ public class ImeAdapter { |
@VisibleForTesting |
public void setInputMethodManagerWrapperForTest(InputMethodManagerWrapper immw) { |
mInputMethodManagerWrapper = immw; |
+ if (mCursorAnchorInfoController != null) { |
+ mCursorAnchorInfoController.setInputMethodManagerWrapper(immw); |
+ } |
} |
@VisibleForTesting |
@@ -285,9 +323,13 @@ public class ImeAdapter { |
*/ |
public void updateState(String text, int selectionStart, int selectionEnd, int compositionStart, |
int compositionEnd, boolean isNonImeChange) { |
- if (mInputConnection == null) return; |
- mInputConnection.updateState(text, selectionStart, selectionEnd, compositionStart, |
- compositionEnd, isNonImeChange); |
+ if (mInputConnection != null) { |
+ mInputConnection.updateState(text, selectionStart, selectionEnd, compositionStart, |
+ compositionEnd, isNonImeChange); |
+ } |
+ if (mCursorAnchorInfoController != null) { |
+ mCursorAnchorInfoController.invalidateLastCursorAnchorInfo(); |
+ } |
} |
/** |
@@ -562,11 +604,44 @@ public class ImeAdapter { |
@CalledByNative |
private void focusedNodeChanged(boolean isEditable) { |
if (DEBUG_LOGS) Log.w(TAG, "focusedNodeChanged: isEditable [%b]", isEditable); |
+ |
+ // Update controller before the connection is restarted. |
+ if (mCursorAnchorInfoController != null) { |
+ mCursorAnchorInfoController.focusedNodeChanged(isEditable); |
+ } |
+ |
if (mTextInputType != TextInputType.NONE && mInputConnection != null && isEditable) { |
restartInput(); |
} |
} |
+ public boolean onRequestCursorUpdates(int cursorUpdateMode) { |
+ if (mCursorAnchorInfoController == null) return false; |
+ return mCursorAnchorInfoController.onRequestCursorUpdates(cursorUpdateMode, |
+ mViewEmbedder.getAttachedView()); |
+ } |
+ |
+ /** |
+ * Notify the location of composing characters to the IME if it explicitly requested them. |
+ * @param renderCoordinates coordinate information to convert CSS (document) coordinates to |
+ * View-local Physical (screen) coordinates |
+ * @param hasInsertionMarker Whether the insertion marker is visible or not. |
+ * @param insertionMarkerHorizontal X coordinates (in view-local DIP pixels) of the insertion |
+ * marker if it exists. Will be ignored otherwise. |
+ * @param insertionMarkerTop Y coordinates (in view-local DIP pixels) of the top of the |
+ * insertion marker if it exists. Will be ignored otherwise. |
+ * @param insertionMarkerBottom Y coordinates (in view-local DIP pixels) of the bottom of |
+ * the insertion marker if it exists. Will be ignored otherwise. |
+ */ |
+ public void onUpdateFrameInfo(RenderCoordinates renderCoordinates, boolean hasInsertionMarker, |
+ boolean isInsertionMarkerVisible, float insertionMarkerHorizontal, |
+ float insertionMarkerTop, float insertionMarkerBottom) { |
+ if (mCursorAnchorInfoController == null) return; |
+ mCursorAnchorInfoController.onUpdateFrameInfo(renderCoordinates, hasInsertionMarker, |
+ isInsertionMarkerVisible, insertionMarkerHorizontal, insertionMarkerTop, |
+ insertionMarkerBottom, mViewEmbedder.getAttachedView()); |
+ } |
+ |
@CalledByNative |
private void populateUnderlinesFromSpans(CharSequence text, long underlines) { |
if (DEBUG_LOGS) { |
@@ -596,9 +671,19 @@ public class ImeAdapter { |
} |
@CalledByNative |
+ private void setCharacterBounds(float[] characterBounds) { |
+ if (mCursorAnchorInfoController == null) return; |
+ mCursorAnchorInfoController.setCompositionCharacterBounds(characterBounds); |
+ } |
+ |
+ @CalledByNative |
private void detach() { |
if (DEBUG_LOGS) Log.w(TAG, "detach"); |
mNativeImeAdapterAndroid = 0; |
+ mTextInputType = 0; |
aelias_OOO_until_Jul13
2016/02/26 08:25:33
Another deleted line accidentally reintroduced?
kinaba
2016/03/01 08:46:46
Ouch. Sorry for my carelessness.. Done,.
|
+ if (mCursorAnchorInfoController != null) { |
+ mCursorAnchorInfoController.focusedNodeChanged(false); |
+ } |
} |
private native boolean nativeSendSyntheticKeyEvent(long nativeImeAdapterAndroid, |