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.ResultReceiver; | 8 import android.os.ResultReceiver; |
9 import android.os.SystemClock; | 9 import android.os.SystemClock; |
10 import android.text.SpannableString; | 10 import android.text.SpannableString; |
11 import android.text.TextUtils; | 11 import android.text.TextUtils; |
12 import android.text.style.BackgroundColorSpan; | 12 import android.text.style.BackgroundColorSpan; |
13 import android.text.style.CharacterStyle; | 13 import android.text.style.CharacterStyle; |
14 import android.text.style.UnderlineSpan; | 14 import android.text.style.UnderlineSpan; |
15 import android.view.KeyCharacterMap; | 15 import android.view.KeyCharacterMap; |
16 import android.view.KeyEvent; | 16 import android.view.KeyEvent; |
17 import android.view.View; | 17 import android.view.View; |
18 import android.view.inputmethod.BaseInputConnection; | 18 import android.view.inputmethod.BaseInputConnection; |
19 import android.view.inputmethod.EditorInfo; | 19 import android.view.inputmethod.EditorInfo; |
20 | 20 |
21 import org.chromium.base.CommandLine; | |
22 import org.chromium.base.Log; | 21 import org.chromium.base.Log; |
23 import org.chromium.base.VisibleForTesting; | 22 import org.chromium.base.VisibleForTesting; |
24 import org.chromium.base.annotations.CalledByNative; | 23 import org.chromium.base.annotations.CalledByNative; |
25 import org.chromium.base.annotations.JNINamespace; | 24 import org.chromium.base.annotations.JNINamespace; |
26 import org.chromium.blink_public.web.WebInputEventModifier; | 25 import org.chromium.blink_public.web.WebInputEventModifier; |
27 import org.chromium.blink_public.web.WebInputEventType; | 26 import org.chromium.blink_public.web.WebInputEventType; |
28 import org.chromium.content.common.ContentSwitches; | |
29 import org.chromium.ui.base.ime.TextInputType; | 27 import org.chromium.ui.base.ime.TextInputType; |
30 import org.chromium.ui.picker.InputDialogContainer; | 28 import org.chromium.ui.picker.InputDialogContainer; |
31 | 29 |
32 /** | 30 /** |
33 * Adapts and plumbs android IME service onto the chrome text input API. | 31 * Adapts and plumbs android IME service onto the chrome text input API. |
34 * ImeAdapter provides an interface in both ways native <-> java: | 32 * ImeAdapter provides an interface in both ways native <-> java: |
35 * 1. InputConnectionAdapter notifies native code of text composition state and | 33 * 1. InputConnectionAdapter notifies native code of text composition state and |
36 * dispatch key events from java -> WebKit. | 34 * dispatch key events from java -> WebKit. |
37 * 2. Native ImeAdapter notifies java side to clear composition text. | 35 * 2. Native ImeAdapter notifies java side to clear composition text. |
38 * | 36 * |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 */ | 111 */ |
114 public ImeAdapter(InputMethodManagerWrapper wrapper, ImeAdapterDelegate embe
dder) { | 112 public ImeAdapter(InputMethodManagerWrapper wrapper, ImeAdapterDelegate embe
dder) { |
115 mInputMethodManagerWrapper = wrapper; | 113 mInputMethodManagerWrapper = wrapper; |
116 mViewEmbedder = embedder; | 114 mViewEmbedder = embedder; |
117 resetInputConnectionFactory(); | 115 resetInputConnectionFactory(); |
118 // Deep copy newConfig so that we can notice the difference. | 116 // Deep copy newConfig so that we can notice the difference. |
119 mCurrentConfig = new Configuration( | 117 mCurrentConfig = new Configuration( |
120 mViewEmbedder.getAttachedView().getResources().getConfiguration(
)); | 118 mViewEmbedder.getAttachedView().getResources().getConfiguration(
)); |
121 } | 119 } |
122 | 120 |
123 void resetInputConnectionFactory() { | 121 private boolean isImeThreadEnabled() { |
124 if (shouldUseImeThread()) { | 122 if (mNativeImeAdapterAndroid == 0) return false; |
| 123 return nativeIsImeThreadEnabled(mNativeImeAdapterAndroid); |
| 124 } |
| 125 |
| 126 private void resetInputConnectionFactory() { |
| 127 if (isImeThreadEnabled()) { |
125 mInputConnectionFactory = | 128 mInputConnectionFactory = |
126 new ThreadedInputConnectionFactory(mInputMethodManagerWrappe
r); | 129 new ThreadedInputConnectionFactory(mInputMethodManagerWrappe
r); |
127 } else { | 130 } else { |
128 mInputConnectionFactory = new ReplicaInputConnection.Factory(); | 131 mInputConnectionFactory = new ReplicaInputConnection.Factory(); |
129 } | 132 } |
130 } | 133 } |
131 | 134 |
132 private boolean shouldUseImeThread() { | |
133 if (CommandLine.getInstance().hasSwitch(ContentSwitches.DISABLE_IME_THRE
AD)) { | |
134 return false; | |
135 } | |
136 if (CommandLine.getInstance().hasSwitch(ContentSwitches.ENABLE_IME_THREA
D)) { | |
137 return true; | |
138 } | |
139 return false; | |
140 } | |
141 | |
142 /** | 135 /** |
143 * @see View#onCreateInputConnection(EditorInfo) | 136 * @see View#onCreateInputConnection(EditorInfo) |
144 */ | 137 */ |
145 public ChromiumBaseInputConnection onCreateInputConnection(EditorInfo outAtt
rs) { | 138 public ChromiumBaseInputConnection onCreateInputConnection(EditorInfo outAtt
rs) { |
146 // InputMethodService evaluates fullscreen mode even when the new input
connection is | 139 // InputMethodService evaluates fullscreen mode even when the new input
connection is |
147 // null. This makes sure IME doesn't enter fullscreen mode or open custo
m UI. | 140 // null. This makes sure IME doesn't enter fullscreen mode or open custo
m UI. |
148 outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_FULLSCREEN | EditorInfo.IME
_FLAG_NO_EXTRACT_UI; | 141 outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_FULLSCREEN | EditorInfo.IME
_FLAG_NO_EXTRACT_UI; |
149 // Without this line, some third-party IMEs will try to compose text eve
n when | 142 // Without this line, some third-party IMEs will try to compose text eve
n when |
150 // not on an editable node. Even when we return null here, key events ca
n still go | 143 // not on an editable node. Even when we return null here, key events ca
n still go |
151 // through ImeAdapter#dispatchKeyEvent(). | 144 // through ImeAdapter#dispatchKeyEvent(). |
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 private native void nativeCommitText(long nativeImeAdapterAndroid, String te
xtStr); | 611 private native void nativeCommitText(long nativeImeAdapterAndroid, String te
xtStr); |
619 private native void nativeFinishComposingText(long nativeImeAdapterAndroid); | 612 private native void nativeFinishComposingText(long nativeImeAdapterAndroid); |
620 private native void nativeAttachImeAdapter(long nativeImeAdapterAndroid); | 613 private native void nativeAttachImeAdapter(long nativeImeAdapterAndroid); |
621 private native void nativeSetEditableSelectionOffsets(long nativeImeAdapterA
ndroid, | 614 private native void nativeSetEditableSelectionOffsets(long nativeImeAdapterA
ndroid, |
622 int start, int end); | 615 int start, int end); |
623 private native void nativeSetComposingRegion(long nativeImeAdapterAndroid, i
nt start, int end); | 616 private native void nativeSetComposingRegion(long nativeImeAdapterAndroid, i
nt start, int end); |
624 private native void nativeDeleteSurroundingText(long nativeImeAdapterAndroid
, | 617 private native void nativeDeleteSurroundingText(long nativeImeAdapterAndroid
, |
625 int before, int after); | 618 int before, int after); |
626 private native void nativeResetImeAdapter(long nativeImeAdapterAndroid); | 619 private native void nativeResetImeAdapter(long nativeImeAdapterAndroid); |
627 private native boolean nativeRequestTextInputStateUpdate(long nativeImeAdapt
erAndroid); | 620 private native boolean nativeRequestTextInputStateUpdate(long nativeImeAdapt
erAndroid); |
| 621 private native boolean nativeIsImeThreadEnabled(long nativeImeAdapterAndroid
); |
628 } | 622 } |
OLD | NEW |