| 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; |
| 21 | 22 |
| 22 import org.chromium.base.Log; | 23 import org.chromium.base.Log; |
| 23 import org.chromium.base.VisibleForTesting; | 24 import org.chromium.base.VisibleForTesting; |
| 24 import org.chromium.base.annotations.CalledByNative; | 25 import org.chromium.base.annotations.CalledByNative; |
| 25 import org.chromium.base.annotations.JNINamespace; | 26 import org.chromium.base.annotations.JNINamespace; |
| 26 import org.chromium.blink_public.web.WebInputEventModifier; | 27 import org.chromium.blink_public.web.WebInputEventModifier; |
| 27 import org.chromium.blink_public.web.WebInputEventType; | 28 import org.chromium.blink_public.web.WebInputEventType; |
| 28 import org.chromium.content.browser.RenderCoordinates; | 29 import org.chromium.content.browser.RenderCoordinates; |
| 29 import org.chromium.ui.base.ime.TextInputType; | 30 import org.chromium.ui.base.ime.TextInputType; |
| 30 import org.chromium.ui.picker.InputDialogContainer; | 31 import org.chromium.ui.picker.InputDialogContainer; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 if (mTextInputType == TextInputType.NONE) { | 186 if (mTextInputType == TextInputType.NONE) { |
| 186 setInputConnection(null); | 187 setInputConnection(null); |
| 187 if (DEBUG_LOGS) Log.w(TAG, "onCreateInputConnection returns null."); | 188 if (DEBUG_LOGS) Log.w(TAG, "onCreateInputConnection returns null."); |
| 188 return null; | 189 return null; |
| 189 } | 190 } |
| 190 if (mInputConnectionFactory == null) return null; | 191 if (mInputConnectionFactory == null) return null; |
| 191 setInputConnection(mInputConnectionFactory.initializeAndGet( | 192 setInputConnection(mInputConnectionFactory.initializeAndGet( |
| 192 mViewEmbedder.getAttachedView(), this, mTextInputType, mTextInpu
tFlags, | 193 mViewEmbedder.getAttachedView(), this, mTextInputType, mTextInpu
tFlags, |
| 193 mLastSelectionStart, mLastSelectionEnd, outAttrs)); | 194 mLastSelectionStart, mLastSelectionEnd, outAttrs)); |
| 194 if (DEBUG_LOGS) Log.w(TAG, "onCreateInputConnection: " + mInputConnectio
n); | 195 if (DEBUG_LOGS) Log.w(TAG, "onCreateInputConnection: " + mInputConnectio
n); |
| 196 |
| 195 if (mCursorAnchorInfoController != null) { | 197 if (mCursorAnchorInfoController != null) { |
| 196 mCursorAnchorInfoController.resetMonitoringState(); | 198 mCursorAnchorInfoController.onRequestCursorUpdates( |
| 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 */); |
| 197 } | 205 } |
| 198 return mInputConnection; | 206 return mInputConnection; |
| 199 } | 207 } |
| 200 | 208 |
| 201 private void setInputConnection(ChromiumBaseInputConnection inputConnection)
{ | 209 private void setInputConnection(ChromiumBaseInputConnection inputConnection)
{ |
| 202 if (mInputConnection == inputConnection) return; | 210 if (mInputConnection == inputConnection) return; |
| 203 // The previous input connection might be waiting for state update. | 211 // The previous input connection might be waiting for state update. |
| 204 if (mInputConnection != null) mInputConnection.unblockOnUiThread(); | 212 if (mInputConnection != null) mInputConnection.unblockOnUiThread(); |
| 205 mInputConnection = inputConnection; | 213 mInputConnection = inputConnection; |
| 206 } | 214 } |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 if (mNativeImeAdapterAndroid == 0) return false; | 675 if (mNativeImeAdapterAndroid == 0) return false; |
| 668 // You won't get state update anyways. | 676 // You won't get state update anyways. |
| 669 if (mInputConnection == null) return false; | 677 if (mInputConnection == null) return false; |
| 670 return nativeRequestTextInputStateUpdate(mNativeImeAdapterAndroid); | 678 return nativeRequestTextInputStateUpdate(mNativeImeAdapterAndroid); |
| 671 } | 679 } |
| 672 | 680 |
| 673 /** | 681 /** |
| 674 * Notified when IME requested Chrome to change the cursor update mode. | 682 * Notified when IME requested Chrome to change the cursor update mode. |
| 675 */ | 683 */ |
| 676 public boolean onRequestCursorUpdates(int cursorUpdateMode) { | 684 public boolean onRequestCursorUpdates(int cursorUpdateMode) { |
| 685 final boolean immediateRequest = |
| 686 (cursorUpdateMode & InputConnection.CURSOR_UPDATE_IMMEDIATE) !=
0; |
| 687 final boolean monitorRequest = |
| 688 (cursorUpdateMode & InputConnection.CURSOR_UPDATE_MONITOR) != 0; |
| 689 |
| 690 if (mNativeImeAdapterAndroid != 0) { |
| 691 nativeRequestCursorUpdate(mNativeImeAdapterAndroid, immediateRequest
, monitorRequest); |
| 692 } |
| 677 if (mCursorAnchorInfoController == null) return false; | 693 if (mCursorAnchorInfoController == null) return false; |
| 678 return mCursorAnchorInfoController.onRequestCursorUpdates(cursorUpdateMo
de, | 694 return mCursorAnchorInfoController.onRequestCursorUpdates(immediateReque
st, monitorRequest, |
| 679 mViewEmbedder.getAttachedView()); | 695 mViewEmbedder.getAttachedView()); |
| 680 } | 696 } |
| 681 | 697 |
| 682 /** | 698 /** |
| 683 * Notified when a frame has been produced by the renderer and all the assoc
iated metadata. | 699 * Notified when a frame has been produced by the renderer and all the assoc
iated metadata. |
| 684 * @param renderCoordinates coordinate information to convert CSS (document)
coordinates to | 700 * @param renderCoordinates coordinate information to convert CSS (document)
coordinates to |
| 685 * View-local Physical (screen) coordinates | 701 * View-local Physical (screen) coordinates |
| 686 * @param hasInsertionMarker Whether the insertion marker is visible or not. | 702 * @param hasInsertionMarker Whether the insertion marker is visible or not. |
| 687 * @param insertionMarkerHorizontal X coordinates (in view-local DIP pixels)
of the insertion | 703 * @param insertionMarkerHorizontal X coordinates (in view-local DIP pixels)
of the insertion |
| 688 * marker if it exists. Will be ignored oth
erwise. | 704 * marker if it exists. Will be ignored oth
erwise. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 724 | 740 |
| 725 @CalledByNative | 741 @CalledByNative |
| 726 private void cancelComposition() { | 742 private void cancelComposition() { |
| 727 if (DEBUG_LOGS) Log.w(TAG, "cancelComposition"); | 743 if (DEBUG_LOGS) Log.w(TAG, "cancelComposition"); |
| 728 if (mInputConnection != null) restartInput(); | 744 if (mInputConnection != null) restartInput(); |
| 729 } | 745 } |
| 730 | 746 |
| 731 @CalledByNative | 747 @CalledByNative |
| 732 private void setCharacterBounds(float[] characterBounds) { | 748 private void setCharacterBounds(float[] characterBounds) { |
| 733 if (mCursorAnchorInfoController == null) return; | 749 if (mCursorAnchorInfoController == null) return; |
| 734 mCursorAnchorInfoController.setCompositionCharacterBounds(characterBound
s); | 750 mCursorAnchorInfoController.setCompositionCharacterBounds(characterBound
s, |
| 751 mViewEmbedder.getAttachedView()); |
| 735 } | 752 } |
| 736 | 753 |
| 737 @CalledByNative | 754 @CalledByNative |
| 738 private void detach() { | 755 private void detach() { |
| 739 if (DEBUG_LOGS) Log.w(TAG, "detach"); | 756 if (DEBUG_LOGS) Log.w(TAG, "detach"); |
| 740 mNativeImeAdapterAndroid = 0; | 757 mNativeImeAdapterAndroid = 0; |
| 741 if (mCursorAnchorInfoController != null) { | 758 if (mCursorAnchorInfoController != null) { |
| 742 mCursorAnchorInfoController.focusedNodeChanged(false); | 759 mCursorAnchorInfoController.focusedNodeChanged(false); |
| 743 } | 760 } |
| 744 } | 761 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 756 private native void nativeCommitText(long nativeImeAdapterAndroid, String te
xtStr); | 773 private native void nativeCommitText(long nativeImeAdapterAndroid, String te
xtStr); |
| 757 private native void nativeFinishComposingText(long nativeImeAdapterAndroid); | 774 private native void nativeFinishComposingText(long nativeImeAdapterAndroid); |
| 758 private native void nativeAttachImeAdapter(long nativeImeAdapterAndroid); | 775 private native void nativeAttachImeAdapter(long nativeImeAdapterAndroid); |
| 759 private native void nativeSetEditableSelectionOffsets(long nativeImeAdapterA
ndroid, | 776 private native void nativeSetEditableSelectionOffsets(long nativeImeAdapterA
ndroid, |
| 760 int start, int end); | 777 int start, int end); |
| 761 private native void nativeSetComposingRegion(long nativeImeAdapterAndroid, i
nt start, int end); | 778 private native void nativeSetComposingRegion(long nativeImeAdapterAndroid, i
nt start, int end); |
| 762 private native void nativeDeleteSurroundingText(long nativeImeAdapterAndroid
, | 779 private native void nativeDeleteSurroundingText(long nativeImeAdapterAndroid
, |
| 763 int before, int after); | 780 int before, int after); |
| 764 private native void nativeResetImeAdapter(long nativeImeAdapterAndroid); | 781 private native void nativeResetImeAdapter(long nativeImeAdapterAndroid); |
| 765 private native boolean nativeRequestTextInputStateUpdate(long nativeImeAdapt
erAndroid); | 782 private native boolean nativeRequestTextInputStateUpdate(long nativeImeAdapt
erAndroid); |
| 783 private native void nativeRequestCursorUpdate(long nativeImeAdapterAndroid, |
| 784 boolean immediateRequest, boolean monitorRequest); |
| 766 private native boolean nativeIsImeThreadEnabled(long nativeImeAdapterAndroid
); | 785 private native boolean nativeIsImeThreadEnabled(long nativeImeAdapterAndroid
); |
| 767 } | 786 } |
| OLD | NEW |