OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.content.browser.input; | 5 package org.chromium.content.browser.input; |
6 | 6 |
7 import android.content.res.Configuration; | 7 import android.content.res.Configuration; |
8 import android.os.Build; | 8 import android.os.Build; |
9 import android.os.ResultReceiver; | 9 import android.os.ResultReceiver; |
10 import android.os.SystemClock; | 10 import android.os.SystemClock; |
11 import android.text.SpannableString; | 11 import android.text.SpannableString; |
12 import android.text.TextUtils; | 12 import android.text.TextUtils; |
13 import android.text.style.BackgroundColorSpan; | 13 import android.text.style.BackgroundColorSpan; |
14 import android.text.style.CharacterStyle; | 14 import android.text.style.CharacterStyle; |
15 import android.text.style.UnderlineSpan; | 15 import android.text.style.UnderlineSpan; |
16 import android.view.KeyCharacterMap; | 16 import android.view.KeyCharacterMap; |
17 import android.view.KeyEvent; | 17 import android.view.KeyEvent; |
18 import android.view.View; | 18 import android.view.View; |
19 import android.view.inputmethod.BaseInputConnection; | 19 import android.view.inputmethod.BaseInputConnection; |
20 import android.view.inputmethod.EditorInfo; | 20 import android.view.inputmethod.EditorInfo; |
21 import android.view.inputmethod.InputConnection; | |
22 | 21 |
23 import org.chromium.base.Log; | 22 import org.chromium.base.Log; |
24 import org.chromium.base.VisibleForTesting; | 23 import org.chromium.base.VisibleForTesting; |
25 import org.chromium.base.annotations.CalledByNative; | 24 import org.chromium.base.annotations.CalledByNative; |
26 import org.chromium.base.annotations.JNINamespace; | 25 import org.chromium.base.annotations.JNINamespace; |
27 import org.chromium.blink_public.web.WebInputEventModifier; | 26 import org.chromium.blink_public.web.WebInputEventModifier; |
28 import org.chromium.blink_public.web.WebInputEventType; | 27 import org.chromium.blink_public.web.WebInputEventType; |
29 import org.chromium.content.browser.RenderCoordinates; | 28 import org.chromium.content.browser.RenderCoordinates; |
30 import org.chromium.ui.base.ime.TextInputType; | 29 import org.chromium.ui.base.ime.TextInputType; |
31 import org.chromium.ui.picker.InputDialogContainer; | 30 import org.chromium.ui.picker.InputDialogContainer; |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 if (mTextInputType == TextInputType.NONE) { | 185 if (mTextInputType == TextInputType.NONE) { |
187 setInputConnection(null); | 186 setInputConnection(null); |
188 if (DEBUG_LOGS) Log.w(TAG, "onCreateInputConnection returns null."); | 187 if (DEBUG_LOGS) Log.w(TAG, "onCreateInputConnection returns null."); |
189 return null; | 188 return null; |
190 } | 189 } |
191 if (mInputConnectionFactory == null) return null; | 190 if (mInputConnectionFactory == null) return null; |
192 setInputConnection(mInputConnectionFactory.initializeAndGet( | 191 setInputConnection(mInputConnectionFactory.initializeAndGet( |
193 mViewEmbedder.getAttachedView(), this, mTextInputType, mTextInpu
tFlags, | 192 mViewEmbedder.getAttachedView(), this, mTextInputType, mTextInpu
tFlags, |
194 mLastSelectionStart, mLastSelectionEnd, outAttrs)); | 193 mLastSelectionStart, mLastSelectionEnd, outAttrs)); |
195 if (DEBUG_LOGS) Log.w(TAG, "onCreateInputConnection: " + mInputConnectio
n); | 194 if (DEBUG_LOGS) Log.w(TAG, "onCreateInputConnection: " + mInputConnectio
n); |
196 | |
197 if (mCursorAnchorInfoController != null) { | 195 if (mCursorAnchorInfoController != null) { |
198 mCursorAnchorInfoController.onRequestCursorUpdates( | 196 mCursorAnchorInfoController.resetMonitoringState(); |
199 false /* not an immediate request */, false /* disable monit
oring */, | |
200 mViewEmbedder.getAttachedView()); | |
201 } | |
202 if (mNativeImeAdapterAndroid != 0) { | |
203 nativeRequestCursorUpdate(mNativeImeAdapterAndroid, | |
204 false /* not an immediate request */, false /* disable monit
oring */); | |
205 } | 197 } |
206 return mInputConnection; | 198 return mInputConnection; |
207 } | 199 } |
208 | 200 |
209 private void setInputConnection(ChromiumBaseInputConnection inputConnection)
{ | 201 private void setInputConnection(ChromiumBaseInputConnection inputConnection)
{ |
210 if (mInputConnection == inputConnection) return; | 202 if (mInputConnection == inputConnection) return; |
211 // The previous input connection might be waiting for state update. | 203 // The previous input connection might be waiting for state update. |
212 if (mInputConnection != null) mInputConnection.unblockOnUiThread(); | 204 if (mInputConnection != null) mInputConnection.unblockOnUiThread(); |
213 mInputConnection = inputConnection; | 205 mInputConnection = inputConnection; |
214 } | 206 } |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 if (mNativeImeAdapterAndroid == 0) return false; | 654 if (mNativeImeAdapterAndroid == 0) return false; |
663 // You won't get state update anyways. | 655 // You won't get state update anyways. |
664 if (mInputConnection == null) return false; | 656 if (mInputConnection == null) return false; |
665 return nativeRequestTextInputStateUpdate(mNativeImeAdapterAndroid); | 657 return nativeRequestTextInputStateUpdate(mNativeImeAdapterAndroid); |
666 } | 658 } |
667 | 659 |
668 /** | 660 /** |
669 * Notified when IME requested Chrome to change the cursor update mode. | 661 * Notified when IME requested Chrome to change the cursor update mode. |
670 */ | 662 */ |
671 public boolean onRequestCursorUpdates(int cursorUpdateMode) { | 663 public boolean onRequestCursorUpdates(int cursorUpdateMode) { |
672 final boolean immediateRequest = | |
673 (cursorUpdateMode & InputConnection.CURSOR_UPDATE_IMMEDIATE) !=
0; | |
674 final boolean monitorRequest = | |
675 (cursorUpdateMode & InputConnection.CURSOR_UPDATE_MONITOR) != 0; | |
676 | |
677 if (mNativeImeAdapterAndroid != 0) { | |
678 nativeRequestCursorUpdate(mNativeImeAdapterAndroid, immediateRequest
, monitorRequest); | |
679 } | |
680 if (mCursorAnchorInfoController == null) return false; | 664 if (mCursorAnchorInfoController == null) return false; |
681 return mCursorAnchorInfoController.onRequestCursorUpdates(immediateReque
st, monitorRequest, | 665 return mCursorAnchorInfoController.onRequestCursorUpdates(cursorUpdateMo
de, |
682 mViewEmbedder.getAttachedView()); | 666 mViewEmbedder.getAttachedView()); |
683 } | 667 } |
684 | 668 |
685 /** | 669 /** |
686 * Notified when a frame has been produced by the renderer and all the assoc
iated metadata. | 670 * Notified when a frame has been produced by the renderer and all the assoc
iated metadata. |
687 * @param renderCoordinates coordinate information to convert CSS (document)
coordinates to | 671 * @param renderCoordinates coordinate information to convert CSS (document)
coordinates to |
688 * View-local Physical (screen) coordinates | 672 * View-local Physical (screen) coordinates |
689 * @param hasInsertionMarker Whether the insertion marker is visible or not. | 673 * @param hasInsertionMarker Whether the insertion marker is visible or not. |
690 * @param insertionMarkerHorizontal X coordinates (in view-local DIP pixels)
of the insertion | 674 * @param insertionMarkerHorizontal X coordinates (in view-local DIP pixels)
of the insertion |
691 * marker if it exists. Will be ignored oth
erwise. | 675 * marker if it exists. Will be ignored oth
erwise. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 | 711 |
728 @CalledByNative | 712 @CalledByNative |
729 private void cancelComposition() { | 713 private void cancelComposition() { |
730 if (DEBUG_LOGS) Log.w(TAG, "cancelComposition"); | 714 if (DEBUG_LOGS) Log.w(TAG, "cancelComposition"); |
731 if (mInputConnection != null) restartInput(); | 715 if (mInputConnection != null) restartInput(); |
732 } | 716 } |
733 | 717 |
734 @CalledByNative | 718 @CalledByNative |
735 private void setCharacterBounds(float[] characterBounds) { | 719 private void setCharacterBounds(float[] characterBounds) { |
736 if (mCursorAnchorInfoController == null) return; | 720 if (mCursorAnchorInfoController == null) return; |
737 mCursorAnchorInfoController.setCompositionCharacterBounds(characterBound
s, | 721 mCursorAnchorInfoController.setCompositionCharacterBounds(characterBound
s); |
738 mViewEmbedder.getAttachedView()); | |
739 } | 722 } |
740 | 723 |
741 @CalledByNative | 724 @CalledByNative |
742 private void detach() { | 725 private void detach() { |
743 if (DEBUG_LOGS) Log.w(TAG, "detach"); | 726 if (DEBUG_LOGS) Log.w(TAG, "detach"); |
744 mNativeImeAdapterAndroid = 0; | 727 mNativeImeAdapterAndroid = 0; |
745 if (mCursorAnchorInfoController != null) { | 728 if (mCursorAnchorInfoController != null) { |
746 mCursorAnchorInfoController.focusedNodeChanged(false); | 729 mCursorAnchorInfoController.focusedNodeChanged(false); |
747 } | 730 } |
748 } | 731 } |
(...skipping 11 matching lines...) Expand all Loading... |
760 private native void nativeCommitText(long nativeImeAdapterAndroid, String te
xtStr); | 743 private native void nativeCommitText(long nativeImeAdapterAndroid, String te
xtStr); |
761 private native void nativeFinishComposingText(long nativeImeAdapterAndroid); | 744 private native void nativeFinishComposingText(long nativeImeAdapterAndroid); |
762 private native void nativeAttachImeAdapter(long nativeImeAdapterAndroid); | 745 private native void nativeAttachImeAdapter(long nativeImeAdapterAndroid); |
763 private native void nativeSetEditableSelectionOffsets(long nativeImeAdapterA
ndroid, | 746 private native void nativeSetEditableSelectionOffsets(long nativeImeAdapterA
ndroid, |
764 int start, int end); | 747 int start, int end); |
765 private native void nativeSetComposingRegion(long nativeImeAdapterAndroid, i
nt start, int end); | 748 private native void nativeSetComposingRegion(long nativeImeAdapterAndroid, i
nt start, int end); |
766 private native void nativeDeleteSurroundingText(long nativeImeAdapterAndroid
, | 749 private native void nativeDeleteSurroundingText(long nativeImeAdapterAndroid
, |
767 int before, int after); | 750 int before, int after); |
768 private native void nativeResetImeAdapter(long nativeImeAdapterAndroid); | 751 private native void nativeResetImeAdapter(long nativeImeAdapterAndroid); |
769 private native boolean nativeRequestTextInputStateUpdate(long nativeImeAdapt
erAndroid); | 752 private native boolean nativeRequestTextInputStateUpdate(long nativeImeAdapt
erAndroid); |
770 private native void nativeRequestCursorUpdate(long nativeImeAdapterAndroid, | |
771 boolean immediateRequest, boolean monitorRequest); | |
772 private native boolean nativeIsImeThreadEnabled(long nativeImeAdapterAndroid
); | 753 private native boolean nativeIsImeThreadEnabled(long nativeImeAdapterAndroid
); |
773 } | 754 } |
OLD | NEW |