Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Side by Side Diff: content/public/android/java/src/org/chromium/content/browser/input/ImeAdapter.java

Issue 2121953002: Do not calculate composition bounds until IME requests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 19 matching lines...) Expand all
50 * the ViewEmbedder implementor) to hold a strong reference to it for the requir ed 51 * the ViewEmbedder implementor) to hold a strong reference to it for the requir ed
51 * lifetime of the object. 52 * lifetime of the object.
52 */ 53 */
53 @JNINamespace("content") 54 @JNINamespace("content")
54 public class ImeAdapter { 55 public class ImeAdapter {
55 private static final String TAG = "cr_Ime"; 56 private static final String TAG = "cr_Ime";
56 private static final boolean DEBUG_LOGS = false; 57 private static final boolean DEBUG_LOGS = false;
57 58
58 private static final int COMPOSITION_KEY_CODE = 229; 59 private static final int COMPOSITION_KEY_CODE = 229;
59 60
61 private static final int DISABLE_CURSOR_UPDATE = 0;
62
60 /** 63 /**
61 * Interface for the delegate that needs to be notified of IME changes. 64 * Interface for the delegate that needs to be notified of IME changes.
62 */ 65 */
63 public interface ImeAdapterDelegate { 66 public interface ImeAdapterDelegate {
64 /** 67 /**
65 * Called to notify the delegate about synthetic/real key events before sending to renderer. 68 * Called to notify the delegate about synthetic/real key events before sending to renderer.
66 */ 69 */
67 void onImeEvent(); 70 void onImeEvent();
68 71
69 /** 72 /**
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 setInputConnection(null); 189 setInputConnection(null);
187 if (DEBUG_LOGS) Log.w(TAG, "onCreateInputConnection returns null."); 190 if (DEBUG_LOGS) Log.w(TAG, "onCreateInputConnection returns null.");
188 return null; 191 return null;
189 } 192 }
190 if (mInputConnectionFactory == null) return null; 193 if (mInputConnectionFactory == null) return null;
191 setInputConnection(mInputConnectionFactory.initializeAndGet( 194 setInputConnection(mInputConnectionFactory.initializeAndGet(
192 mViewEmbedder.getAttachedView(), this, mTextInputType, mTextInpu tFlags, 195 mViewEmbedder.getAttachedView(), this, mTextInputType, mTextInpu tFlags,
193 mLastSelectionStart, mLastSelectionEnd, outAttrs)); 196 mLastSelectionStart, mLastSelectionEnd, outAttrs));
194 if (DEBUG_LOGS) Log.w(TAG, "onCreateInputConnection: " + mInputConnectio n); 197 if (DEBUG_LOGS) Log.w(TAG, "onCreateInputConnection: " + mInputConnectio n);
195 if (mCursorAnchorInfoController != null) { 198 if (mCursorAnchorInfoController != null) {
196 mCursorAnchorInfoController.resetMonitoringState(); 199 onRequestCursorUpdates(DISABLE_CURSOR_UPDATE);
Changwan Ryu 2016/07/07 01:05:36 How about just calling mCursorAnchorInfoController
Seigo Nonaka 2016/07/07 13:38:26 Sure fixed.
197 } 200 }
198 return mInputConnection; 201 return mInputConnection;
199 } 202 }
200 203
201 private void setInputConnection(ChromiumBaseInputConnection inputConnection) { 204 private void setInputConnection(ChromiumBaseInputConnection inputConnection) {
202 if (mInputConnection == inputConnection) return; 205 if (mInputConnection == inputConnection) return;
203 // The previous input connection might be waiting for state update. 206 // The previous input connection might be waiting for state update.
204 if (mInputConnection != null) mInputConnection.unblockOnUiThread(); 207 if (mInputConnection != null) mInputConnection.unblockOnUiThread();
205 mInputConnection = inputConnection; 208 mInputConnection = inputConnection;
206 } 209 }
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 if (mNativeImeAdapterAndroid == 0) return false; 657 if (mNativeImeAdapterAndroid == 0) return false;
655 // You won't get state update anyways. 658 // You won't get state update anyways.
656 if (mInputConnection == null) return false; 659 if (mInputConnection == null) return false;
657 return nativeRequestTextInputStateUpdate(mNativeImeAdapterAndroid); 660 return nativeRequestTextInputStateUpdate(mNativeImeAdapterAndroid);
658 } 661 }
659 662
660 /** 663 /**
661 * Notified when IME requested Chrome to change the cursor update mode. 664 * Notified when IME requested Chrome to change the cursor update mode.
662 */ 665 */
663 public boolean onRequestCursorUpdates(int cursorUpdateMode) { 666 public boolean onRequestCursorUpdates(int cursorUpdateMode) {
667 final boolean immediateRequest =
668 (cursorUpdateMode & InputConnection.CURSOR_UPDATE_IMMEDIATE) != 0;
669 final boolean monitorRequest =
670 (cursorUpdateMode & InputConnection.CURSOR_UPDATE_MONITOR) != 0;
671
672 if (mNativeImeAdapterAndroid != 0) {
673 nativeRequestCursorUpdate(mNativeImeAdapterAndroid, immediateRequest , monitorRequest);
674 }
664 if (mCursorAnchorInfoController == null) return false; 675 if (mCursorAnchorInfoController == null) return false;
665 return mCursorAnchorInfoController.onRequestCursorUpdates(cursorUpdateMo de, 676 return mCursorAnchorInfoController.onRequestCursorUpdates(immediateReque st, monitorRequest,
666 mViewEmbedder.getAttachedView()); 677 mViewEmbedder.getAttachedView());
667 } 678 }
668 679
669 /** 680 /**
670 * Notified when a frame has been produced by the renderer and all the assoc iated metadata. 681 * Notified when a frame has been produced by the renderer and all the assoc iated metadata.
671 * @param renderCoordinates coordinate information to convert CSS (document) coordinates to 682 * @param renderCoordinates coordinate information to convert CSS (document) coordinates to
672 * View-local Physical (screen) coordinates 683 * View-local Physical (screen) coordinates
673 * @param hasInsertionMarker Whether the insertion marker is visible or not. 684 * @param hasInsertionMarker Whether the insertion marker is visible or not.
674 * @param insertionMarkerHorizontal X coordinates (in view-local DIP pixels) of the insertion 685 * @param insertionMarkerHorizontal X coordinates (in view-local DIP pixels) of the insertion
675 * marker if it exists. Will be ignored oth erwise. 686 * marker if it exists. Will be ignored oth erwise.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 722
712 @CalledByNative 723 @CalledByNative
713 private void cancelComposition() { 724 private void cancelComposition() {
714 if (DEBUG_LOGS) Log.w(TAG, "cancelComposition"); 725 if (DEBUG_LOGS) Log.w(TAG, "cancelComposition");
715 if (mInputConnection != null) restartInput(); 726 if (mInputConnection != null) restartInput();
716 } 727 }
717 728
718 @CalledByNative 729 @CalledByNative
719 private void setCharacterBounds(float[] characterBounds) { 730 private void setCharacterBounds(float[] characterBounds) {
720 if (mCursorAnchorInfoController == null) return; 731 if (mCursorAnchorInfoController == null) return;
721 mCursorAnchorInfoController.setCompositionCharacterBounds(characterBound s); 732 mCursorAnchorInfoController.setCompositionCharacterBounds(characterBound s,
733 mViewEmbedder.getAttachedView());
722 } 734 }
723 735
724 @CalledByNative 736 @CalledByNative
725 private void detach() { 737 private void detach() {
726 if (DEBUG_LOGS) Log.w(TAG, "detach"); 738 if (DEBUG_LOGS) Log.w(TAG, "detach");
727 mNativeImeAdapterAndroid = 0; 739 mNativeImeAdapterAndroid = 0;
728 if (mCursorAnchorInfoController != null) { 740 if (mCursorAnchorInfoController != null) {
729 mCursorAnchorInfoController.focusedNodeChanged(false); 741 mCursorAnchorInfoController.focusedNodeChanged(false);
730 } 742 }
731 } 743 }
(...skipping 11 matching lines...) Expand all
743 private native void nativeCommitText(long nativeImeAdapterAndroid, String te xtStr); 755 private native void nativeCommitText(long nativeImeAdapterAndroid, String te xtStr);
744 private native void nativeFinishComposingText(long nativeImeAdapterAndroid); 756 private native void nativeFinishComposingText(long nativeImeAdapterAndroid);
745 private native void nativeAttachImeAdapter(long nativeImeAdapterAndroid); 757 private native void nativeAttachImeAdapter(long nativeImeAdapterAndroid);
746 private native void nativeSetEditableSelectionOffsets(long nativeImeAdapterA ndroid, 758 private native void nativeSetEditableSelectionOffsets(long nativeImeAdapterA ndroid,
747 int start, int end); 759 int start, int end);
748 private native void nativeSetComposingRegion(long nativeImeAdapterAndroid, i nt start, int end); 760 private native void nativeSetComposingRegion(long nativeImeAdapterAndroid, i nt start, int end);
749 private native void nativeDeleteSurroundingText(long nativeImeAdapterAndroid , 761 private native void nativeDeleteSurroundingText(long nativeImeAdapterAndroid ,
750 int before, int after); 762 int before, int after);
751 private native void nativeResetImeAdapter(long nativeImeAdapterAndroid); 763 private native void nativeResetImeAdapter(long nativeImeAdapterAndroid);
752 private native boolean nativeRequestTextInputStateUpdate(long nativeImeAdapt erAndroid); 764 private native boolean nativeRequestTextInputStateUpdate(long nativeImeAdapt erAndroid);
765 private native void nativeRequestCursorUpdate(long nativeImeAdapterAndroid,
766 boolean immediateRequest, boolean monitorRequest);
753 private native boolean nativeIsImeThreadEnabled(long nativeImeAdapterAndroid ); 767 private native boolean nativeIsImeThreadEnabled(long nativeImeAdapterAndroid );
754 } 768 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698