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.Editable; | |
11 import android.text.Selection; | |
12 import android.text.SpannableString; | 10 import android.text.SpannableString; |
13 import android.text.style.BackgroundColorSpan; | 11 import android.text.style.BackgroundColorSpan; |
14 import android.text.style.CharacterStyle; | 12 import android.text.style.CharacterStyle; |
15 import android.text.style.UnderlineSpan; | 13 import android.text.style.UnderlineSpan; |
16 import android.view.KeyCharacterMap; | 14 import android.view.KeyCharacterMap; |
17 import android.view.KeyEvent; | 15 import android.view.KeyEvent; |
18 import android.view.View; | 16 import android.view.View; |
19 import android.view.inputmethod.BaseInputConnection; | 17 import android.view.inputmethod.BaseInputConnection; |
20 import android.view.inputmethod.EditorInfo; | 18 import android.view.inputmethod.EditorInfo; |
21 | 19 |
| 20 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; |
| 27 import org.chromium.content.common.ContentSwitches; |
28 import org.chromium.ui.base.ime.TextInputType; | 28 import org.chromium.ui.base.ime.TextInputType; |
29 import org.chromium.ui.picker.InputDialogContainer; | 29 import org.chromium.ui.picker.InputDialogContainer; |
30 | 30 |
31 /** | 31 /** |
32 * Adapts and plumbs android IME service onto the chrome text input API. | 32 * Adapts and plumbs android IME service onto the chrome text input API. |
33 * ImeAdapter provides an interface in both ways native <-> java: | 33 * ImeAdapter provides an interface in both ways native <-> java: |
34 * 1. InputConnectionAdapter notifies native code of text composition state and | 34 * 1. InputConnectionAdapter notifies native code of text composition state and |
35 * dispatch key events from java -> WebKit. | 35 * dispatch key events from java -> WebKit. |
36 * 2. Native ImeAdapter notifies java side to clear composition text. | 36 * 2. Native ImeAdapter notifies java side to clear composition text. |
37 * | 37 * |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 * @return Object that should be called for all keyboard show and hide r
equests. | 83 * @return Object that should be called for all keyboard show and hide r
equests. |
84 */ | 84 */ |
85 ResultReceiver getNewShowKeyboardReceiver(); | 85 ResultReceiver getNewShowKeyboardReceiver(); |
86 } | 86 } |
87 | 87 |
88 static char[] sSingleCharArray = new char[1]; | 88 static char[] sSingleCharArray = new char[1]; |
89 static KeyCharacterMap sKeyCharacterMap; | 89 static KeyCharacterMap sKeyCharacterMap; |
90 | 90 |
91 private long mNativeImeAdapterAndroid; | 91 private long mNativeImeAdapterAndroid; |
92 private InputMethodManagerWrapper mInputMethodManagerWrapper; | 92 private InputMethodManagerWrapper mInputMethodManagerWrapper; |
93 private AdapterInputConnection mInputConnection; | 93 private ChromiumBaseInputConnection mInputConnection; |
94 private AdapterInputConnectionFactory mInputConnectionFactory; | 94 private ChromiumBaseInputConnection.Factory mInputConnectionFactory; |
| 95 |
95 private final ImeAdapterDelegate mViewEmbedder; | 96 private final ImeAdapterDelegate mViewEmbedder; |
96 | 97 |
97 // This holds the state of editable text (e.g. contents of <input>, contente
ditable) of | |
98 // a focused element. | |
99 // Every time the user, IME, javascript (Blink), autofill etc. modifies the
content, the new | |
100 // state must be reflected to this to keep consistency. | |
101 private final Editable mEditable; | |
102 | |
103 private int mTextInputType = TextInputType.NONE; | 98 private int mTextInputType = TextInputType.NONE; |
104 private int mTextInputFlags; | 99 private int mTextInputFlags; |
105 | 100 |
106 // Keep the current configuration to detect the change when onConfigurationC
hanged() is called. | 101 // Keep the current configuration to detect the change when onConfigurationC
hanged() is called. |
107 private Configuration mCurrentConfig; | 102 private Configuration mCurrentConfig; |
108 | 103 |
109 /** | 104 /** |
110 * @param wrapper InputMethodManagerWrapper that should receive all the call
directed to | 105 * @param wrapper InputMethodManagerWrapper that should receive all the call
directed to |
111 * InputMethodManager. | 106 * InputMethodManager. |
112 * @param embedder The view that is used for callbacks from ImeAdapter. | 107 * @param embedder The view that is used for callbacks from ImeAdapter. |
113 */ | 108 */ |
114 public ImeAdapter(InputMethodManagerWrapper wrapper, ImeAdapterDelegate embe
dder) { | 109 public ImeAdapter(InputMethodManagerWrapper wrapper, ImeAdapterDelegate embe
dder) { |
115 mInputMethodManagerWrapper = wrapper; | 110 mInputMethodManagerWrapper = wrapper; |
116 mViewEmbedder = embedder; | 111 mViewEmbedder = embedder; |
117 mInputConnectionFactory = new AdapterInputConnectionFactory(); | 112 if (CommandLine.getInstance().hasSwitch(ContentSwitches.USE_IME_THREAD))
{ |
118 mEditable = Editable.Factory.getInstance().newEditable(""); | 113 mInputConnectionFactory = new ChromiumInputConnectionFactory(); |
119 Selection.setSelection(mEditable, 0); | 114 } else { |
| 115 mInputConnectionFactory = new AdapterInputConnection.Factory(); |
| 116 } |
120 // Deep copy newConfig so that we can notice the difference. | 117 // Deep copy newConfig so that we can notice the difference. |
121 mCurrentConfig = new Configuration( | 118 mCurrentConfig = new Configuration( |
122 mViewEmbedder.getAttachedView().getResources().getConfiguration(
)); | 119 mViewEmbedder.getAttachedView().getResources().getConfiguration(
)); |
123 } | 120 } |
124 | 121 |
125 /** | 122 /** |
126 * Default factory for AdapterInputConnection classes. | |
127 */ | |
128 static class AdapterInputConnectionFactory { | |
129 AdapterInputConnection get(View view, ImeAdapter imeAdapter, int initial
SelStart, | |
130 int initialSelEnd, EditorInfo outAttrs) { | |
131 return new AdapterInputConnection( | |
132 view, imeAdapter, initialSelStart, initialSelEnd, outAttrs); | |
133 } | |
134 } | |
135 | |
136 /** | |
137 * @see View#onCreateInputConnection(EditorInfo) | 123 * @see View#onCreateInputConnection(EditorInfo) |
138 */ | 124 */ |
139 public AdapterInputConnection onCreateInputConnection(EditorInfo outAttrs) { | 125 public ChromiumBaseInputConnection onCreateInputConnection(EditorInfo outAtt
rs) { |
140 // Without this line, some third-party IMEs will try to compose text eve
n when | 126 // Without this line, some third-party IMEs will try to compose text eve
n when |
141 // not on an editable node. Even when we return null here, key events ca
n still go through | 127 // not on an editable node. Even when we return null here, key events ca
n still go |
142 // ImeAdapter#dispatchKeyEvent(). | 128 // through ImeAdapter#dispatchKeyEvent(). |
143 if (mTextInputType == TextInputType.NONE) { | 129 if (mTextInputType == TextInputType.NONE) { |
144 mInputConnection = null; | 130 mInputConnection = null; |
145 Log.d(TAG, "onCreateInputConnection returns null."); | 131 Log.d(TAG, "onCreateInputConnection: null"); |
146 return null; | 132 return null; |
147 } | 133 } |
148 | |
149 if (!isTextInputType(mTextInputType)) { | |
150 // Although onCheckIsTextEditor will return false in this case, the
EditorInfo | |
151 // is still used by the InputMethodService. Need to make sure the IM
E doesn't | |
152 // enter fullscreen mode. | |
153 outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_FULLSCREEN; | |
154 } | |
155 int initialSelStart = Selection.getSelectionStart(mEditable); | |
156 int initialSelEnd = outAttrs.initialSelEnd = Selection.getSelectionEnd(m
Editable); | |
157 mInputConnection = mInputConnectionFactory.get( | 134 mInputConnection = mInputConnectionFactory.get( |
158 mViewEmbedder.getAttachedView(), this, initialSelStart, initialS
elEnd, outAttrs); | 135 mViewEmbedder.getAttachedView(), this, mTextInputType, mTextInpu
tFlags, outAttrs); |
159 Log.d(TAG, "onCreateInputConnection"); | 136 Log.d(TAG, "onCreateInputConnection: ", mInputConnection); |
160 return mInputConnection; | 137 return mInputConnection; |
161 } | 138 } |
162 | 139 |
163 /** | 140 /** |
164 * Overrides the InputMethodManagerWrapper that ImeAdapter uses to make call
s to | 141 * Overrides the InputMethodManagerWrapper that ImeAdapter uses to make call
s to |
165 * InputMethodManager. | 142 * InputMethodManager. |
166 * @param immw InputMethodManagerWrapper that should be used to call InputMe
thodManager. | 143 * @param immw InputMethodManagerWrapper that should be used to call InputMe
thodManager. |
167 */ | 144 */ |
168 @VisibleForTesting | 145 @VisibleForTesting |
169 public void setInputMethodManagerWrapperForTest(InputMethodManagerWrapper im
mw) { | 146 public void setInputMethodManagerWrapperForTest(InputMethodManagerWrapper im
mw) { |
170 mInputMethodManagerWrapper = immw; | 147 mInputMethodManagerWrapper = immw; |
171 } | 148 } |
172 | 149 |
173 @VisibleForTesting | 150 @VisibleForTesting |
174 void setInputConnectionFactory(AdapterInputConnectionFactory factory) { | 151 void setInputConnectionFactory(ChromiumBaseInputConnection.Factory factory)
{ |
175 mInputConnectionFactory = factory; | 152 mInputConnectionFactory = factory; |
176 } | 153 } |
177 | 154 |
178 /** | 155 /** |
179 * Set the current active InputConnection when a new InputConnection is cons
tructed. | |
180 * @param inputConnection The input connection that is currently used with I
ME. | |
181 */ | |
182 void setInputConnection(AdapterInputConnection inputConnection) { | |
183 mInputConnection = inputConnection; | |
184 } | |
185 | |
186 /** | |
187 * Get the current input connection for testing purposes. | 156 * Get the current input connection for testing purposes. |
188 */ | 157 */ |
189 @VisibleForTesting | 158 @VisibleForTesting |
190 public AdapterInputConnection getInputConnectionForTest() { | 159 public ChromiumBaseInputConnection getInputConnectionForTest() { |
191 return mInputConnection; | 160 return mInputConnection; |
192 } | 161 } |
193 | 162 |
194 /** | |
195 * @return The Editable instance that will be shared across AdapterInputConn
ection instances. | |
196 */ | |
197 Editable getEditable() { | |
198 return mEditable; | |
199 } | |
200 | |
201 /** | |
202 * Should be used only by AdapterInputConnection. | |
203 * @return The input type of currently focused element. | |
204 */ | |
205 int getTextInputType() { | |
206 return mTextInputType; | |
207 } | |
208 | |
209 /** | |
210 * Should be used only by AdapterInputConnection. | |
211 * @return The input flags of the currently focused element. | |
212 */ | |
213 int getTextInputFlags() { | |
214 return mTextInputFlags; | |
215 } | |
216 | |
217 private static int getModifiers(int metaState) { | 163 private static int getModifiers(int metaState) { |
218 int modifiers = 0; | 164 int modifiers = 0; |
219 if ((metaState & KeyEvent.META_SHIFT_ON) != 0) { | 165 if ((metaState & KeyEvent.META_SHIFT_ON) != 0) { |
220 modifiers |= WebInputEventModifier.ShiftKey; | 166 modifiers |= WebInputEventModifier.ShiftKey; |
221 } | 167 } |
222 if ((metaState & KeyEvent.META_ALT_ON) != 0) { | 168 if ((metaState & KeyEvent.META_ALT_ON) != 0) { |
223 modifiers |= WebInputEventModifier.AltKey; | 169 modifiers |= WebInputEventModifier.AltKey; |
224 } | 170 } |
225 if ((metaState & KeyEvent.META_CTRL_ON) != 0) { | 171 if ((metaState & KeyEvent.META_CTRL_ON) != 0) { |
226 modifiers |= WebInputEventModifier.ControlKey; | 172 modifiers |= WebInputEventModifier.ControlKey; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 * is no selection. | 217 * is no selection. |
272 * @param compositionStart The character offset of the composition start, or
-1 if there is no | 218 * @param compositionStart The character offset of the composition start, or
-1 if there is no |
273 * composition. | 219 * composition. |
274 * @param compositionEnd The character offset of the composition end, or -1
if there is no | 220 * @param compositionEnd The character offset of the composition end, or -1
if there is no |
275 * selection. | 221 * selection. |
276 * @param isNonImeChange True when the update was caused by non-IME (e.g. Ja
vascript). | 222 * @param isNonImeChange True when the update was caused by non-IME (e.g. Ja
vascript). |
277 */ | 223 */ |
278 public void updateState(String text, int selectionStart, int selectionEnd, i
nt compositionStart, | 224 public void updateState(String text, int selectionStart, int selectionEnd, i
nt compositionStart, |
279 int compositionEnd, boolean isNonImeChange) { | 225 int compositionEnd, boolean isNonImeChange) { |
280 if (mInputConnection == null) return; | 226 if (mInputConnection == null) return; |
281 mInputConnection.updateState(text, selectionStart, selectionEnd, composi
tionStart, | 227 boolean singleLine = mTextInputType != TextInputType.TEXT_AREA |
282 compositionEnd, isNonImeChange); | 228 && mTextInputType != TextInputType.CONTENT_EDITABLE; |
| 229 mInputConnection.updateStateOnUiThread(text, selectionStart, selectionEn
d, compositionStart, |
| 230 compositionEnd, singleLine, isNonImeChange); |
283 } | 231 } |
284 | 232 |
285 /** | 233 /** |
286 * Attaches the imeAdapter to its native counterpart. This is needed to star
t forwarding | 234 * Attaches the imeAdapter to its native counterpart. This is needed to star
t forwarding |
287 * keyboard events to WebKit. | 235 * keyboard events to WebKit. |
288 * @param nativeImeAdapter The pointer to the native ImeAdapter object. | 236 * @param nativeImeAdapter The pointer to the native ImeAdapter object. |
289 */ | 237 */ |
290 public void attach(long nativeImeAdapter) { | 238 public void attach(long nativeImeAdapter) { |
291 if (mNativeImeAdapterAndroid == nativeImeAdapter) return; | 239 if (mNativeImeAdapterAndroid == nativeImeAdapter) return; |
292 if (mNativeImeAdapterAndroid != 0) { | 240 if (mNativeImeAdapterAndroid != 0) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 Log.d(TAG, "onViewFocusChanged: gainFocus [%b]", gainFocus); | 307 Log.d(TAG, "onViewFocusChanged: gainFocus [%b]", gainFocus); |
360 if (!gainFocus) hideKeyboard(); | 308 if (!gainFocus) hideKeyboard(); |
361 } | 309 } |
362 | 310 |
363 /** | 311 /** |
364 * Move cursor to the end of the current selection. | 312 * Move cursor to the end of the current selection. |
365 */ | 313 */ |
366 public void moveCursorToSelectionEnd() { | 314 public void moveCursorToSelectionEnd() { |
367 Log.d(TAG, "movecursorToEnd"); | 315 Log.d(TAG, "movecursorToEnd"); |
368 if (mInputConnection != null) { | 316 if (mInputConnection != null) { |
369 int selectionEnd = Selection.getSelectionEnd(mEditable); | 317 mInputConnection.moveCursorToSelectionEndOnUiThread(); |
370 mInputConnection.setSelection(selectionEnd, selectionEnd); | |
371 } | 318 } |
372 } | 319 } |
373 | 320 |
374 @VisibleForTesting | 321 @VisibleForTesting |
375 void setInputTypeForTest(int textInputType) { | 322 void setInputTypeForTest(int textInputType) { |
376 mTextInputType = textInputType; | 323 mTextInputType = textInputType; |
377 } | 324 } |
378 | 325 |
379 private static boolean isTextInputType(int type) { | 326 private static boolean isTextInputType(int type) { |
380 return type != TextInputType.NONE && !InputDialogContainer.isDialogInput
Type(type); | 327 return type != TextInputType.NONE && !InputDialogContainer.isDialogInput
Type(type); |
381 } | 328 } |
382 | 329 |
383 public boolean hasTextInputType() { | 330 public boolean hasTextInputType() { |
384 return isTextInputType(mTextInputType); | 331 return isTextInputType(mTextInputType); |
385 } | 332 } |
386 | 333 |
387 public boolean dispatchKeyEvent(KeyEvent event) { | 334 public boolean dispatchKeyEvent(KeyEvent event) { |
388 Log.d(TAG, "dispatchKeyEvent: action [%d], keycode [%d]", event.getActio
n(), | 335 Log.d(TAG, "dispatchKeyEvent: action [%d], keycode [%d]", event.getActio
n(), |
389 event.getKeyCode()); | 336 event.getKeyCode()); |
390 if (mInputConnection != null) { | 337 if (mInputConnection != null) return mInputConnection.sendKeyEventOnUiTh
read(event); |
391 return mInputConnection.sendKeyEvent(event); | |
392 } | |
393 return sendKeyEvent(event); | 338 return sendKeyEvent(event); |
394 } | 339 } |
395 | 340 |
396 /** | 341 /** |
397 * Update selection to input method manager. | 342 * Update selection to input method manager. |
398 * | 343 * |
399 * @param selectionStart The selection start. | 344 * @param selectionStart The selection start. |
400 * @param selectionEnd The selection end. | 345 * @param selectionEnd The selection end. |
401 * @param compositionStart The composition start. | 346 * @param compositionStart The composition start. |
402 * @param compositionEnd The composition end. | 347 * @param compositionEnd The composition end. |
403 */ | 348 */ |
404 void updateSelection( | 349 void updateSelection( |
405 int selectionStart, int selectionEnd, int compositionStart, int comp
ositionEnd) { | 350 int selectionStart, int selectionEnd, int compositionStart, int comp
ositionEnd) { |
406 mInputMethodManagerWrapper.updateSelection(mViewEmbedder.getAttachedView
(), selectionStart, | 351 mInputMethodManagerWrapper.updateSelection(mViewEmbedder.getAttachedView
(), selectionStart, |
407 selectionEnd, compositionStart, compositionEnd); | 352 selectionEnd, compositionStart, compositionEnd); |
408 } | 353 } |
409 | 354 |
410 /** | 355 /** |
411 * Restart input (finish composition and change EditorInfo, such as input ty
pe). | 356 * Restart input (finish composition and change EditorInfo, such as input ty
pe). |
412 */ | 357 */ |
413 void restartInput() { | 358 void restartInput() { |
414 mInputMethodManagerWrapper.restartInput(mViewEmbedder.getAttachedView())
; | 359 mInputMethodManagerWrapper.restartInput(mViewEmbedder.getAttachedView())
; |
415 if (mInputConnection != null) mInputConnection.onRestartInput(); | 360 if (mInputConnection != null) mInputConnection.onRestartInputOnUiThread(
); |
416 } | 361 } |
417 | 362 |
418 /** | 363 /** |
419 * @see BaseInputConnection#performContextMenuAction(int) | 364 * @see BaseInputConnection#performContextMenuAction(int) |
420 */ | 365 */ |
421 boolean performContextMenuAction(int id) { | 366 boolean performContextMenuAction(int id) { |
422 Log.d(TAG, "performContextMenuAction: id [%d]", id); | 367 Log.d(TAG, "performContextMenuAction: id [%d]", id); |
423 return mViewEmbedder.performContextMenuAction(id); | 368 return mViewEmbedder.performContextMenuAction(id); |
424 } | 369 } |
425 | 370 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 timestampMs, COMPOSITION_KEY_CODE, 0, 0); | 419 timestampMs, COMPOSITION_KEY_CODE, 0, 0); |
475 | 420 |
476 nativeSetComposingText(mNativeImeAdapterAndroid, text, text.toString(),
newCursorPosition); | 421 nativeSetComposingText(mNativeImeAdapterAndroid, text, text.toString(),
newCursorPosition); |
477 | 422 |
478 nativeSendSyntheticKeyEvent(mNativeImeAdapterAndroid, WebInputEventType.
KeyUp, | 423 nativeSendSyntheticKeyEvent(mNativeImeAdapterAndroid, WebInputEventType.
KeyUp, |
479 timestampMs, COMPOSITION_KEY_CODE, 0, 0); | 424 timestampMs, COMPOSITION_KEY_CODE, 0, 0); |
480 return true; | 425 return true; |
481 } | 426 } |
482 | 427 |
483 @VisibleForTesting | 428 @VisibleForTesting |
484 void finishComposingText() { | 429 boolean finishComposingText() { |
485 if (mNativeImeAdapterAndroid == 0) return; | 430 if (mNativeImeAdapterAndroid == 0) return false; |
486 nativeFinishComposingText(mNativeImeAdapterAndroid); | 431 nativeFinishComposingText(mNativeImeAdapterAndroid); |
| 432 return true; |
487 } | 433 } |
488 | 434 |
489 boolean sendKeyEvent(KeyEvent event) { | 435 boolean sendKeyEvent(KeyEvent event) { |
490 if (mNativeImeAdapterAndroid == 0) return false; | 436 if (mNativeImeAdapterAndroid == 0) return false; |
491 | 437 |
492 int action = event.getAction(); | 438 int action = event.getAction(); |
493 if (action != KeyEvent.ACTION_DOWN && action != KeyEvent.ACTION_UP) { | 439 if (action != KeyEvent.ACTION_DOWN && action != KeyEvent.ACTION_UP) { |
494 // action == KeyEvent.ACTION_MULTIPLE | 440 // action == KeyEvent.ACTION_MULTIPLE |
495 // TODO(bulach): confirm the actual behavior. Apparently: | 441 // TODO(bulach): confirm the actual behavior. Apparently: |
496 // If event.getKeyCode() == KEYCODE_UNKNOWN, we can send a | 442 // If event.getKeyCode() == KEYCODE_UNKNOWN, we can send a |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 nativeSetEditableSelectionOffsets(mNativeImeAdapterAndroid, start, end); | 485 nativeSetEditableSelectionOffsets(mNativeImeAdapterAndroid, start, end); |
540 return true; | 486 return true; |
541 } | 487 } |
542 | 488 |
543 /** | 489 /** |
544 * Send a request to the native counterpart to set composing region to given
indices. | 490 * Send a request to the native counterpart to set composing region to given
indices. |
545 * @param start The start of the composition. | 491 * @param start The start of the composition. |
546 * @param end The end of the composition. | 492 * @param end The end of the composition. |
547 * @return Whether the native counterpart of ImeAdapter received the call. | 493 * @return Whether the native counterpart of ImeAdapter received the call. |
548 */ | 494 */ |
549 boolean setComposingRegion(CharSequence text, int start, int end) { | 495 boolean setComposingRegion(int start, int end) { |
550 if (mNativeImeAdapterAndroid == 0) return false; | 496 if (mNativeImeAdapterAndroid == 0) return false; |
551 nativeSetComposingRegion(mNativeImeAdapterAndroid, start, end); | 497 nativeSetComposingRegion(mNativeImeAdapterAndroid, start, end); |
552 return true; | 498 return true; |
553 } | 499 } |
554 | 500 |
555 @CalledByNative | 501 @CalledByNative |
556 private void focusedNodeChanged(boolean isEditable) { | 502 private void focusedNodeChanged(boolean isEditable) { |
557 Log.d(TAG, "focusedNodeChanged: isEditable [%b]", isEditable); | 503 Log.d(TAG, "focusedNodeChanged: isEditable [%b]", isEditable); |
558 if (mTextInputType != TextInputType.NONE && mInputConnection != null &&
isEditable) { | 504 if (mTextInputType != TextInputType.NONE && mInputConnection != null &&
isEditable) { |
559 restartInput(); | 505 restartInput(); |
560 } | 506 } |
561 } | 507 } |
562 | 508 |
| 509 /** |
| 510 * Send a request to the native counterpart to give the latest text input st
ate update. |
| 511 */ |
| 512 boolean requestTextInputStateUpdate() { |
| 513 if (mNativeImeAdapterAndroid == 0) return false; |
| 514 nativeRequestTextInputStateUpdate(mNativeImeAdapterAndroid); |
| 515 return true; |
| 516 } |
| 517 |
563 @CalledByNative | 518 @CalledByNative |
564 private void populateUnderlinesFromSpans(CharSequence text, long underlines)
{ | 519 private void populateUnderlinesFromSpans(CharSequence text, long underlines)
{ |
565 Log.d(TAG, "populateUnderlinesFromSpans: text [%s], underlines [%d]", te
xt, underlines); | 520 Log.d(TAG, "populateUnderlinesFromSpans: text [%s], underlines [%d]", te
xt, underlines); |
566 if (!(text instanceof SpannableString)) return; | 521 if (!(text instanceof SpannableString)) return; |
567 | 522 |
568 SpannableString spannableString = ((SpannableString) text); | 523 SpannableString spannableString = ((SpannableString) text); |
569 CharacterStyle spans[] = | 524 CharacterStyle spans[] = |
570 spannableString.getSpans(0, text.length(), CharacterStyle.class)
; | 525 spannableString.getSpans(0, text.length(), CharacterStyle.class)
; |
571 for (CharacterStyle span : spans) { | 526 for (CharacterStyle span : spans) { |
572 if (span instanceof BackgroundColorSpan) { | 527 if (span instanceof BackgroundColorSpan) { |
(...skipping 14 matching lines...) Expand all Loading... |
587 } | 542 } |
588 | 543 |
589 @CalledByNative | 544 @CalledByNative |
590 private void detach() { | 545 private void detach() { |
591 Log.d(TAG, "detach"); | 546 Log.d(TAG, "detach"); |
592 mNativeImeAdapterAndroid = 0; | 547 mNativeImeAdapterAndroid = 0; |
593 } | 548 } |
594 | 549 |
595 private native boolean nativeSendSyntheticKeyEvent(long nativeImeAdapterAndr
oid, | 550 private native boolean nativeSendSyntheticKeyEvent(long nativeImeAdapterAndr
oid, |
596 int eventType, long timestampMs, int keyCode, int modifiers, int uni
codeChar); | 551 int eventType, long timestampMs, int keyCode, int modifiers, int uni
codeChar); |
597 | |
598 private native boolean nativeSendKeyEvent(long nativeImeAdapterAndroid, KeyE
vent event, | 552 private native boolean nativeSendKeyEvent(long nativeImeAdapterAndroid, KeyE
vent event, |
599 int action, int modifiers, long timestampMs, int keyCode, int scanCo
de, | 553 int action, int modifiers, long timestampMs, int keyCode, int scanCo
de, |
600 boolean isSystemKey, int unicodeChar); | 554 boolean isSystemKey, int unicodeChar); |
601 | |
602 private static native void nativeAppendUnderlineSpan(long underlinePtr, int
start, int end); | 555 private static native void nativeAppendUnderlineSpan(long underlinePtr, int
start, int end); |
603 | |
604 private static native void nativeAppendBackgroundColorSpan(long underlinePtr
, int start, | 556 private static native void nativeAppendBackgroundColorSpan(long underlinePtr
, int start, |
605 int end, int backgroundColor); | 557 int end, int backgroundColor); |
606 | |
607 private native void nativeSetComposingText(long nativeImeAdapterAndroid, Cha
rSequence text, | 558 private native void nativeSetComposingText(long nativeImeAdapterAndroid, Cha
rSequence text, |
608 String textStr, int newCursorPosition); | 559 String textStr, int newCursorPosition); |
609 | |
610 private native void nativeCommitText(long nativeImeAdapterAndroid, String te
xtStr); | 560 private native void nativeCommitText(long nativeImeAdapterAndroid, String te
xtStr); |
611 | |
612 private native void nativeFinishComposingText(long nativeImeAdapterAndroid); | 561 private native void nativeFinishComposingText(long nativeImeAdapterAndroid); |
613 | |
614 private native void nativeAttachImeAdapter(long nativeImeAdapterAndroid); | 562 private native void nativeAttachImeAdapter(long nativeImeAdapterAndroid); |
615 | |
616 private native void nativeSetEditableSelectionOffsets(long nativeImeAdapterA
ndroid, | 563 private native void nativeSetEditableSelectionOffsets(long nativeImeAdapterA
ndroid, |
617 int start, int end); | 564 int start, int end); |
618 | |
619 private native void nativeSetComposingRegion(long nativeImeAdapterAndroid, i
nt start, int end); | 565 private native void nativeSetComposingRegion(long nativeImeAdapterAndroid, i
nt start, int end); |
620 | |
621 private native void nativeDeleteSurroundingText(long nativeImeAdapterAndroid
, | 566 private native void nativeDeleteSurroundingText(long nativeImeAdapterAndroid
, |
622 int before, int after); | 567 int before, int after); |
623 | |
624 private native void nativeResetImeAdapter(long nativeImeAdapterAndroid); | 568 private native void nativeResetImeAdapter(long nativeImeAdapterAndroid); |
| 569 private native void nativeRequestTextInputStateUpdate(long nativeImeAdapterA
ndroid); |
625 } | 570 } |
OLD | NEW |