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; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 | 85 |
86 /** | 86 /** |
87 * @return Object that should be called for all keyboard show and hide r equests. | 87 * @return Object that should be called for all keyboard show and hide r equests. |
88 */ | 88 */ |
89 ResultReceiver getNewShowKeyboardReceiver(); | 89 ResultReceiver getNewShowKeyboardReceiver(); |
90 } | 90 } |
91 | 91 |
92 static char[] sSingleCharArray = new char[1]; | 92 static char[] sSingleCharArray = new char[1]; |
93 static KeyCharacterMap sKeyCharacterMap; | 93 static KeyCharacterMap sKeyCharacterMap; |
94 | 94 |
95 private long mNativeImeAdapterAndroid; | 95 private final long mNativeImeAdapterAndroid; |
96 private InputMethodManagerWrapper mInputMethodManagerWrapper; | 96 private InputMethodManagerWrapper mInputMethodManagerWrapper; |
97 private ChromiumBaseInputConnection mInputConnection; | 97 private ChromiumBaseInputConnection mInputConnection; |
98 private ChromiumBaseInputConnection.Factory mInputConnectionFactory; | 98 private ChromiumBaseInputConnection.Factory mInputConnectionFactory; |
99 | 99 |
100 private final ImeAdapterDelegate mViewEmbedder; | 100 private final ImeAdapterDelegate mViewEmbedder; |
101 // This holds the information necessary for constructing CursorAnchorInfo, a nd notifies to | 101 // This holds the information necessary for constructing CursorAnchorInfo, a nd notifies to |
102 // InputMethodManager on appropriate timing, depending on how IME requested the information | 102 // InputMethodManager on appropriate timing, depending on how IME requested the information |
103 // via InputConnection. The update request is per InputConnection, hence for each time it is | 103 // via InputConnection. The update request is per InputConnection, hence for each time it is |
104 // re-created, the monitoring status will be reset. | 104 // re-created, the monitoring status will be reset. |
105 private final CursorAnchorInfoController mCursorAnchorInfoController; | 105 private final CursorAnchorInfoController mCursorAnchorInfoController; |
106 | 106 |
107 private int mTextInputType = TextInputType.NONE; | 107 private int mTextInputType = TextInputType.NONE; |
108 private int mTextInputFlags; | 108 private int mTextInputFlags; |
109 private int mTextInputMode = WebTextInputMode.kDefault; | 109 private int mTextInputMode = WebTextInputMode.kDefault; |
110 | 110 |
111 // Keep the current configuration to detect the change when onConfigurationC hanged() is called. | 111 // Keep the current configuration to detect the change when onConfigurationC hanged() is called. |
112 private Configuration mCurrentConfig; | 112 private Configuration mCurrentConfig; |
113 | 113 |
114 private int mLastSelectionStart; | 114 private int mLastSelectionStart; |
115 private int mLastSelectionEnd; | 115 private int mLastSelectionEnd; |
116 private String mLastText; | 116 private String mLastText; |
117 private int mLastCompositionStart; | 117 private int mLastCompositionStart; |
118 private int mLastCompositionEnd; | 118 private int mLastCompositionEnd; |
119 private boolean mRestartInputOnNextStateUpdate; | 119 private boolean mRestartInputOnNextStateUpdate; |
120 private boolean mIsConnected; | |
120 | 121 |
121 /** | 122 /** |
122 * @param wrapper InputMethodManagerWrapper that should receive all the call directed to | 123 * @param wrapper InputMethodManagerWrapper that should receive all the call directed to |
123 * InputMethodManager. | 124 * InputMethodManager. |
124 * @param embedder The view that is used for callbacks from ImeAdapter. | 125 * @param embedder The view that is used for callbacks from ImeAdapter. |
125 */ | 126 */ |
126 public ImeAdapter(InputMethodManagerWrapper wrapper, ImeAdapterDelegate embe dder) { | 127 public ImeAdapter(InputMethodManagerWrapper wrapper, ImeAdapterDelegate embe dder) { |
127 mInputMethodManagerWrapper = wrapper; | 128 mInputMethodManagerWrapper = wrapper; |
128 mViewEmbedder = embedder; | 129 mViewEmbedder = embedder; |
129 // Deep copy newConfig so that we can notice the difference. | 130 // Deep copy newConfig so that we can notice the difference. |
(...skipping 20 matching lines...) Expand all Loading... | |
150 return mLastCompositionStart; | 151 return mLastCompositionStart; |
151 } | 152 } |
152 @Override | 153 @Override |
153 public int getComposingTextEnd() { | 154 public int getComposingTextEnd() { |
154 return mLastCompositionEnd; | 155 return mLastCompositionEnd; |
155 } | 156 } |
156 }); | 157 }); |
157 } else { | 158 } else { |
158 mCursorAnchorInfoController = null; | 159 mCursorAnchorInfoController = null; |
159 } | 160 } |
161 mNativeImeAdapterAndroid = nativeInit(); | |
162 } | |
163 | |
164 public long getNativePointer() { | |
165 return mNativeImeAdapterAndroid; | |
160 } | 166 } |
161 | 167 |
162 private void createInputConnectionFactory() { | 168 private void createInputConnectionFactory() { |
163 if (mInputConnectionFactory != null) return; | 169 if (mInputConnectionFactory != null) return; |
164 mInputConnectionFactory = new ThreadedInputConnectionFactory(mInputMetho dManagerWrapper); | 170 mInputConnectionFactory = new ThreadedInputConnectionFactory(mInputMetho dManagerWrapper); |
165 } | 171 } |
166 | 172 |
167 /** | 173 /** |
168 * @see View#onCreateInputConnection(EditorInfo) | 174 * @see View#onCreateInputConnection(EditorInfo) |
169 */ | 175 */ |
(...skipping 13 matching lines...) Expand all Loading... | |
183 setInputConnection(mInputConnectionFactory.initializeAndGet(mViewEmbedde r.getAttachedView(), | 189 setInputConnection(mInputConnectionFactory.initializeAndGet(mViewEmbedde r.getAttachedView(), |
184 this, mTextInputType, mTextInputFlags, mTextInputMode, mLastSele ctionStart, | 190 this, mTextInputType, mTextInputFlags, mTextInputMode, mLastSele ctionStart, |
185 mLastSelectionEnd, outAttrs)); | 191 mLastSelectionEnd, outAttrs)); |
186 if (DEBUG_LOGS) Log.i(TAG, "onCreateInputConnection: " + mInputConnectio n); | 192 if (DEBUG_LOGS) Log.i(TAG, "onCreateInputConnection: " + mInputConnectio n); |
187 | 193 |
188 if (mCursorAnchorInfoController != null) { | 194 if (mCursorAnchorInfoController != null) { |
189 mCursorAnchorInfoController.onRequestCursorUpdates( | 195 mCursorAnchorInfoController.onRequestCursorUpdates( |
190 false /* not an immediate request */, false /* disable monit oring */, | 196 false /* not an immediate request */, false /* disable monit oring */, |
191 mViewEmbedder.getAttachedView()); | 197 mViewEmbedder.getAttachedView()); |
192 } | 198 } |
193 if (mNativeImeAdapterAndroid != 0) { | 199 if (mIsConnected) { |
194 nativeRequestCursorUpdate(mNativeImeAdapterAndroid, | 200 nativeRequestCursorUpdate(mNativeImeAdapterAndroid, |
195 false /* not an immediate request */, false /* disable monit oring */); | 201 false /* not an immediate request */, false /* disable monit oring */); |
196 } | 202 } |
197 return mInputConnection; | 203 return mInputConnection; |
198 } | 204 } |
199 | 205 |
200 private void setInputConnection(ChromiumBaseInputConnection inputConnection) { | 206 private void setInputConnection(ChromiumBaseInputConnection inputConnection) { |
201 if (mInputConnection == inputConnection) return; | 207 if (mInputConnection == inputConnection) return; |
202 // The previous input connection might be waiting for state update. | 208 // The previous input connection might be waiting for state update. |
203 if (mInputConnection != null) mInputConnection.unblockOnUiThread(); | 209 if (mInputConnection != null) mInputConnection.unblockOnUiThread(); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
318 } | 324 } |
319 | 325 |
320 if (mInputConnection == null) return; | 326 if (mInputConnection == null) return; |
321 boolean singleLine = mTextInputType != TextInputType.TEXT_AREA | 327 boolean singleLine = mTextInputType != TextInputType.TEXT_AREA |
322 && mTextInputType != TextInputType.CONTENT_EDITABLE; | 328 && mTextInputType != TextInputType.CONTENT_EDITABLE; |
323 mInputConnection.updateStateOnUiThread(text, selectionStart, selectionEn d, compositionStart, | 329 mInputConnection.updateStateOnUiThread(text, selectionStart, selectionEn d, compositionStart, |
324 compositionEnd, singleLine, replyToRequest); | 330 compositionEnd, singleLine, replyToRequest); |
325 } | 331 } |
326 | 332 |
327 /** | 333 /** |
328 * Attaches the imeAdapter to its native counterpart. This is needed to star t forwarding | |
329 * keyboard events to WebKit. | |
330 * @param nativeImeAdapter The pointer to the native ImeAdapter object. | |
331 */ | |
332 public void attach(long nativeImeAdapter) { | |
333 if (DEBUG_LOGS) Log.i(TAG, "attach"); | |
334 if (mNativeImeAdapterAndroid == nativeImeAdapter) return; | |
335 if (mNativeImeAdapterAndroid != 0) { | |
336 nativeResetImeAdapter(mNativeImeAdapterAndroid); | |
337 } | |
338 if (nativeImeAdapter != 0) { | |
339 nativeAttachImeAdapter(nativeImeAdapter); | |
340 } | |
341 mNativeImeAdapterAndroid = nativeImeAdapter; | |
342 if (nativeImeAdapter != 0) { | |
343 createInputConnectionFactory(); | |
344 } | |
345 resetAndHideKeyboard(); | |
346 } | |
347 | |
348 /** | |
349 * Show soft keyboard only if it is the current keyboard configuration. | 334 * Show soft keyboard only if it is the current keyboard configuration. |
350 */ | 335 */ |
351 private void showSoftKeyboard() { | 336 private void showSoftKeyboard() { |
352 if (DEBUG_LOGS) Log.i(TAG, "showSoftKeyboard"); | 337 if (DEBUG_LOGS) Log.i(TAG, "showSoftKeyboard"); |
353 mInputMethodManagerWrapper.showSoftInput( | 338 mInputMethodManagerWrapper.showSoftInput( |
354 mViewEmbedder.getAttachedView(), 0, mViewEmbedder.getNewShowKeyb oardReceiver()); | 339 mViewEmbedder.getAttachedView(), 0, mViewEmbedder.getNewShowKeyb oardReceiver()); |
355 if (mViewEmbedder.getAttachedView().getResources().getConfiguration().ke yboard | 340 if (mViewEmbedder.getAttachedView().getResources().getConfiguration().ke yboard |
356 != Configuration.KEYBOARD_NOKEYS) { | 341 != Configuration.KEYBOARD_NOKEYS) { |
357 mViewEmbedder.onKeyboardBoundsUnchanged(); | 342 mViewEmbedder.onKeyboardBoundsUnchanged(); |
358 } | 343 } |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
478 public void resetAndHideKeyboard() { | 463 public void resetAndHideKeyboard() { |
479 if (DEBUG_LOGS) Log.i(TAG, "resetAndHideKeyboard"); | 464 if (DEBUG_LOGS) Log.i(TAG, "resetAndHideKeyboard"); |
480 mTextInputType = TextInputType.NONE; | 465 mTextInputType = TextInputType.NONE; |
481 mTextInputFlags = 0; | 466 mTextInputFlags = 0; |
482 mTextInputMode = WebTextInputMode.kDefault; | 467 mTextInputMode = WebTextInputMode.kDefault; |
483 mRestartInputOnNextStateUpdate = false; | 468 mRestartInputOnNextStateUpdate = false; |
484 // This will trigger unblocking if necessary. | 469 // This will trigger unblocking if necessary. |
485 hideKeyboard(); | 470 hideKeyboard(); |
486 } | 471 } |
487 | 472 |
473 public void destroy() { | |
474 resetAndHideKeyboard(); | |
475 nativeDestroy(mNativeImeAdapterAndroid); | |
Changwan Ryu
2017/03/17 23:47:19
Could you also set mNativeImeAdapterAndroid to 0 h
Jinsuk Kim
2017/03/19 23:44:20
I believe the intention of |mNativeImeAdapterAndro
Changwan Ryu
2017/03/20 18:23:00
ImeAdapter#destroy() -> ImeAdapter#finishComposing
Jinsuk Kim
2017/03/21 00:09:11
Added back the checking against mNativeImeAdapterA
| |
476 if (mCursorAnchorInfoController != null) { | |
477 mCursorAnchorInfoController.focusedNodeChanged(false); | |
478 } | |
479 } | |
480 | |
488 /** | 481 /** |
489 * Update selection to input method manager. | 482 * Update selection to input method manager. |
490 * | 483 * |
491 * @param selectionStart The selection start. | 484 * @param selectionStart The selection start. |
492 * @param selectionEnd The selection end. | 485 * @param selectionEnd The selection end. |
493 * @param compositionStart The composition start. | 486 * @param compositionStart The composition start. |
494 * @param compositionEnd The composition end. | 487 * @param compositionEnd The composition end. |
495 */ | 488 */ |
496 void updateSelection( | 489 void updateSelection( |
497 int selectionStart, int selectionEnd, int compositionStart, int comp ositionEnd) { | 490 int selectionStart, int selectionEnd, int compositionStart, int comp ositionEnd) { |
(...skipping 12 matching lines...) Expand all Loading... | |
510 | 503 |
511 /** | 504 /** |
512 * @see BaseInputConnection#performContextMenuAction(int) | 505 * @see BaseInputConnection#performContextMenuAction(int) |
513 */ | 506 */ |
514 boolean performContextMenuAction(int id) { | 507 boolean performContextMenuAction(int id) { |
515 if (DEBUG_LOGS) Log.i(TAG, "performContextMenuAction: id [%d]", id); | 508 if (DEBUG_LOGS) Log.i(TAG, "performContextMenuAction: id [%d]", id); |
516 return mViewEmbedder.performContextMenuAction(id); | 509 return mViewEmbedder.performContextMenuAction(id); |
517 } | 510 } |
518 | 511 |
519 boolean performEditorAction(int actionCode) { | 512 boolean performEditorAction(int actionCode) { |
520 if (mNativeImeAdapterAndroid == 0) return false; | 513 if (!mIsConnected) return false; |
Changwan Ryu
2017/03/17 23:47:19
I prefer to keep all these native pointer checks f
Jinsuk Kim
2017/03/19 23:44:20
mIsConnected is equivalent to the native pointer i
| |
521 if (actionCode == EditorInfo.IME_ACTION_NEXT) { | 514 if (actionCode == EditorInfo.IME_ACTION_NEXT) { |
522 sendSyntheticKeyPress(KeyEvent.KEYCODE_TAB, | 515 sendSyntheticKeyPress(KeyEvent.KEYCODE_TAB, |
523 KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE | 516 KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE |
524 | KeyEvent.FLAG_EDITOR_ACTION); | 517 | KeyEvent.FLAG_EDITOR_ACTION); |
525 } else { | 518 } else { |
526 sendSyntheticKeyPress(KeyEvent.KEYCODE_ENTER, | 519 sendSyntheticKeyPress(KeyEvent.KEYCODE_ENTER, |
527 KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE | 520 KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE |
528 | KeyEvent.FLAG_EDITOR_ACTION); | 521 | KeyEvent.FLAG_EDITOR_ACTION); |
529 } | 522 } |
530 return true; | 523 return true; |
(...skipping 11 matching lines...) Expand all Loading... | |
542 KeyCharacterMap.VIRTUAL_KEYBOARD, 0, | 535 KeyCharacterMap.VIRTUAL_KEYBOARD, 0, |
543 flags)); | 536 flags)); |
544 sendKeyEvent(new KeyEvent(eventTime, eventTime, | 537 sendKeyEvent(new KeyEvent(eventTime, eventTime, |
545 KeyEvent.ACTION_UP, keyCode, 0, 0, | 538 KeyEvent.ACTION_UP, keyCode, 0, 0, |
546 KeyCharacterMap.VIRTUAL_KEYBOARD, 0, | 539 KeyCharacterMap.VIRTUAL_KEYBOARD, 0, |
547 flags)); | 540 flags)); |
548 } | 541 } |
549 | 542 |
550 boolean sendCompositionToNative( | 543 boolean sendCompositionToNative( |
551 CharSequence text, int newCursorPosition, boolean isCommit, int unic odeFromKeyEvent) { | 544 CharSequence text, int newCursorPosition, boolean isCommit, int unic odeFromKeyEvent) { |
552 if (mNativeImeAdapterAndroid == 0) return false; | 545 if (!mIsConnected) return false; |
553 | 546 |
554 // One WebView app detects Enter in JS by looking at KeyDown (http://crb ug/577967). | 547 // One WebView app detects Enter in JS by looking at KeyDown (http://crb ug/577967). |
555 if (TextUtils.equals(text, "\n")) { | 548 if (TextUtils.equals(text, "\n")) { |
556 sendSyntheticKeyPress(KeyEvent.KEYCODE_ENTER, | 549 sendSyntheticKeyPress(KeyEvent.KEYCODE_ENTER, |
557 KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE) ; | 550 KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE) ; |
558 return true; | 551 return true; |
559 } | 552 } |
560 | 553 |
561 mViewEmbedder.onImeEvent(); | 554 mViewEmbedder.onImeEvent(); |
562 long timestampMs = SystemClock.uptimeMillis(); | 555 long timestampMs = SystemClock.uptimeMillis(); |
563 nativeSendKeyEvent(mNativeImeAdapterAndroid, null, WebInputEventType.Raw KeyDown, 0, | 556 nativeSendKeyEvent(mNativeImeAdapterAndroid, null, WebInputEventType.Raw KeyDown, 0, |
564 timestampMs, COMPOSITION_KEY_CODE, 0, false, unicodeFromKeyEvent ); | 557 timestampMs, COMPOSITION_KEY_CODE, 0, false, unicodeFromKeyEvent ); |
565 | 558 |
566 if (isCommit) { | 559 if (isCommit) { |
567 nativeCommitText(mNativeImeAdapterAndroid, text, text.toString(), ne wCursorPosition); | 560 nativeCommitText(mNativeImeAdapterAndroid, text, text.toString(), ne wCursorPosition); |
568 } else { | 561 } else { |
569 nativeSetComposingText( | 562 nativeSetComposingText( |
570 mNativeImeAdapterAndroid, text, text.toString(), newCursorPo sition); | 563 mNativeImeAdapterAndroid, text, text.toString(), newCursorPo sition); |
571 } | 564 } |
572 | 565 |
573 nativeSendKeyEvent(mNativeImeAdapterAndroid, null, WebInputEventType.Key Up, 0, timestampMs, | 566 nativeSendKeyEvent(mNativeImeAdapterAndroid, null, WebInputEventType.Key Up, 0, timestampMs, |
574 COMPOSITION_KEY_CODE, 0, false, unicodeFromKeyEvent); | 567 COMPOSITION_KEY_CODE, 0, false, unicodeFromKeyEvent); |
575 return true; | 568 return true; |
576 } | 569 } |
577 | 570 |
578 @VisibleForTesting | 571 @VisibleForTesting |
579 boolean finishComposingText() { | 572 boolean finishComposingText() { |
580 if (mNativeImeAdapterAndroid == 0) return false; | 573 if (!mIsConnected) return false; |
581 nativeFinishComposingText(mNativeImeAdapterAndroid); | 574 nativeFinishComposingText(mNativeImeAdapterAndroid); |
582 return true; | 575 return true; |
583 } | 576 } |
584 | 577 |
585 boolean sendKeyEvent(KeyEvent event) { | 578 boolean sendKeyEvent(KeyEvent event) { |
586 if (mNativeImeAdapterAndroid == 0) return false; | 579 if (!mIsConnected) return false; |
587 | 580 |
588 int action = event.getAction(); | 581 int action = event.getAction(); |
589 int type; | 582 int type; |
590 if (action == KeyEvent.ACTION_DOWN) { | 583 if (action == KeyEvent.ACTION_DOWN) { |
591 type = WebInputEventType.KeyDown; | 584 type = WebInputEventType.KeyDown; |
592 } else if (action == KeyEvent.ACTION_UP) { | 585 } else if (action == KeyEvent.ACTION_UP) { |
593 type = WebInputEventType.KeyUp; | 586 type = WebInputEventType.KeyUp; |
594 } else { | 587 } else { |
595 // In theory, KeyEvent.ACTION_MULTIPLE is a valid value, but in prac tice | 588 // In theory, KeyEvent.ACTION_MULTIPLE is a valid value, but in prac tice |
596 // this seems to have been quietly deprecated and we've never observ ed | 589 // this seems to have been quietly deprecated and we've never observ ed |
(...skipping 11 matching lines...) Expand all Loading... | |
608 /** | 601 /** |
609 * Send a request to the native counterpart to delete a given range of chara cters. | 602 * Send a request to the native counterpart to delete a given range of chara cters. |
610 * @param beforeLength Number of characters to extend the selection by befor e the existing | 603 * @param beforeLength Number of characters to extend the selection by befor e the existing |
611 * selection. | 604 * selection. |
612 * @param afterLength Number of characters to extend the selection by after the existing | 605 * @param afterLength Number of characters to extend the selection by after the existing |
613 * selection. | 606 * selection. |
614 * @return Whether the native counterpart of ImeAdapter received the call. | 607 * @return Whether the native counterpart of ImeAdapter received the call. |
615 */ | 608 */ |
616 boolean deleteSurroundingText(int beforeLength, int afterLength) { | 609 boolean deleteSurroundingText(int beforeLength, int afterLength) { |
617 mViewEmbedder.onImeEvent(); | 610 mViewEmbedder.onImeEvent(); |
618 if (mNativeImeAdapterAndroid == 0) return false; | 611 if (!mIsConnected) return false; |
619 nativeSendKeyEvent(mNativeImeAdapterAndroid, null, WebInputEventType.Raw KeyDown, 0, | 612 nativeSendKeyEvent(mNativeImeAdapterAndroid, null, WebInputEventType.Raw KeyDown, 0, |
620 SystemClock.uptimeMillis(), COMPOSITION_KEY_CODE, 0, false, 0); | 613 SystemClock.uptimeMillis(), COMPOSITION_KEY_CODE, 0, false, 0); |
621 nativeDeleteSurroundingText(mNativeImeAdapterAndroid, beforeLength, afte rLength); | 614 nativeDeleteSurroundingText(mNativeImeAdapterAndroid, beforeLength, afte rLength); |
622 nativeSendKeyEvent(mNativeImeAdapterAndroid, null, WebInputEventType.Key Up, 0, | 615 nativeSendKeyEvent(mNativeImeAdapterAndroid, null, WebInputEventType.Key Up, 0, |
623 SystemClock.uptimeMillis(), COMPOSITION_KEY_CODE, 0, false, 0); | 616 SystemClock.uptimeMillis(), COMPOSITION_KEY_CODE, 0, false, 0); |
624 return true; | 617 return true; |
625 } | 618 } |
626 | 619 |
627 /** | 620 /** |
628 * Send a request to the native counterpart to delete a given range of chara cters. | 621 * Send a request to the native counterpart to delete a given range of chara cters. |
629 * @param beforeLength Number of code points to extend the selection by befo re the existing | 622 * @param beforeLength Number of code points to extend the selection by befo re the existing |
630 * selection. | 623 * selection. |
631 * @param afterLength Number of code points to extend the selection by after the existing | 624 * @param afterLength Number of code points to extend the selection by after the existing |
632 * selection. | 625 * selection. |
633 * @return Whether the native counterpart of ImeAdapter received the call. | 626 * @return Whether the native counterpart of ImeAdapter received the call. |
634 */ | 627 */ |
635 boolean deleteSurroundingTextInCodePoints(int beforeLength, int afterLength) { | 628 boolean deleteSurroundingTextInCodePoints(int beforeLength, int afterLength) { |
636 mViewEmbedder.onImeEvent(); | 629 mViewEmbedder.onImeEvent(); |
637 if (mNativeImeAdapterAndroid == 0) return false; | 630 if (!mIsConnected) return false; |
638 nativeSendKeyEvent(mNativeImeAdapterAndroid, null, WebInputEventType.Raw KeyDown, 0, | 631 nativeSendKeyEvent(mNativeImeAdapterAndroid, null, WebInputEventType.Raw KeyDown, 0, |
639 SystemClock.uptimeMillis(), COMPOSITION_KEY_CODE, 0, false, 0); | 632 SystemClock.uptimeMillis(), COMPOSITION_KEY_CODE, 0, false, 0); |
640 nativeDeleteSurroundingTextInCodePoints( | 633 nativeDeleteSurroundingTextInCodePoints( |
641 mNativeImeAdapterAndroid, beforeLength, afterLength); | 634 mNativeImeAdapterAndroid, beforeLength, afterLength); |
642 nativeSendKeyEvent(mNativeImeAdapterAndroid, null, WebInputEventType.Key Up, 0, | 635 nativeSendKeyEvent(mNativeImeAdapterAndroid, null, WebInputEventType.Key Up, 0, |
643 SystemClock.uptimeMillis(), COMPOSITION_KEY_CODE, 0, false, 0); | 636 SystemClock.uptimeMillis(), COMPOSITION_KEY_CODE, 0, false, 0); |
644 return true; | 637 return true; |
645 } | 638 } |
646 | 639 |
647 /** | 640 /** |
648 * Send a request to the native counterpart to set the selection to given ra nge. | 641 * Send a request to the native counterpart to set the selection to given ra nge. |
649 * @param start Selection start index. | 642 * @param start Selection start index. |
650 * @param end Selection end index. | 643 * @param end Selection end index. |
651 * @return Whether the native counterpart of ImeAdapter received the call. | 644 * @return Whether the native counterpart of ImeAdapter received the call. |
652 */ | 645 */ |
653 boolean setEditableSelectionOffsets(int start, int end) { | 646 boolean setEditableSelectionOffsets(int start, int end) { |
654 if (mNativeImeAdapterAndroid == 0) return false; | 647 if (!mIsConnected) return false; |
655 nativeSetEditableSelectionOffsets(mNativeImeAdapterAndroid, start, end); | 648 nativeSetEditableSelectionOffsets(mNativeImeAdapterAndroid, start, end); |
656 return true; | 649 return true; |
657 } | 650 } |
658 | 651 |
659 /** | 652 /** |
660 * Send a request to the native counterpart to set composing region to given indices. | 653 * Send a request to the native counterpart to set composing region to given indices. |
661 * @param start The start of the composition. | 654 * @param start The start of the composition. |
662 * @param end The end of the composition. | 655 * @param end The end of the composition. |
663 * @return Whether the native counterpart of ImeAdapter received the call. | 656 * @return Whether the native counterpart of ImeAdapter received the call. |
664 */ | 657 */ |
665 boolean setComposingRegion(int start, int end) { | 658 boolean setComposingRegion(int start, int end) { |
666 if (mNativeImeAdapterAndroid == 0) return false; | 659 if (!mIsConnected) return false; |
667 if (start <= end) { | 660 if (start <= end) { |
668 nativeSetComposingRegion(mNativeImeAdapterAndroid, start, end); | 661 nativeSetComposingRegion(mNativeImeAdapterAndroid, start, end); |
669 } else { | 662 } else { |
670 nativeSetComposingRegion(mNativeImeAdapterAndroid, end, start); | 663 nativeSetComposingRegion(mNativeImeAdapterAndroid, end, start); |
671 } | 664 } |
672 return true; | 665 return true; |
673 } | 666 } |
674 | 667 |
675 @CalledByNative | 668 @CalledByNative |
676 private void focusedNodeChanged(boolean isEditable) { | 669 private void focusedNodeChanged(boolean isEditable) { |
677 if (DEBUG_LOGS) Log.i(TAG, "focusedNodeChanged: isEditable [%b]", isEdit able); | 670 if (DEBUG_LOGS) Log.i(TAG, "focusedNodeChanged: isEditable [%b]", isEdit able); |
678 | 671 |
679 // Update controller before the connection is restarted. | 672 // Update controller before the connection is restarted. |
680 if (mCursorAnchorInfoController != null) { | 673 if (mCursorAnchorInfoController != null) { |
681 mCursorAnchorInfoController.focusedNodeChanged(isEditable); | 674 mCursorAnchorInfoController.focusedNodeChanged(isEditable); |
682 } | 675 } |
683 | 676 |
684 if (mTextInputType != TextInputType.NONE && mInputConnection != null && isEditable) { | 677 if (mTextInputType != TextInputType.NONE && mInputConnection != null && isEditable) { |
685 mRestartInputOnNextStateUpdate = true; | 678 mRestartInputOnNextStateUpdate = true; |
686 } | 679 } |
687 } | 680 } |
688 | 681 |
689 /** | 682 /** |
690 * Send a request to the native counterpart to give the latest text input st ate update. | 683 * Send a request to the native counterpart to give the latest text input st ate update. |
691 */ | 684 */ |
692 boolean requestTextInputStateUpdate() { | 685 boolean requestTextInputStateUpdate() { |
693 if (mNativeImeAdapterAndroid == 0) return false; | 686 if (!mIsConnected) return false; |
694 // You won't get state update anyways. | 687 // You won't get state update anyways. |
695 if (mInputConnection == null) return false; | 688 if (mInputConnection == null) return false; |
696 return nativeRequestTextInputStateUpdate(mNativeImeAdapterAndroid); | 689 return nativeRequestTextInputStateUpdate(mNativeImeAdapterAndroid); |
697 } | 690 } |
698 | 691 |
699 /** | 692 /** |
700 * Notified when IME requested Chrome to change the cursor update mode. | 693 * Notified when IME requested Chrome to change the cursor update mode. |
701 */ | 694 */ |
702 public boolean onRequestCursorUpdates(int cursorUpdateMode) { | 695 public boolean onRequestCursorUpdates(int cursorUpdateMode) { |
703 final boolean immediateRequest = | 696 final boolean immediateRequest = |
704 (cursorUpdateMode & InputConnection.CURSOR_UPDATE_IMMEDIATE) != 0; | 697 (cursorUpdateMode & InputConnection.CURSOR_UPDATE_IMMEDIATE) != 0; |
705 final boolean monitorRequest = | 698 final boolean monitorRequest = |
706 (cursorUpdateMode & InputConnection.CURSOR_UPDATE_MONITOR) != 0; | 699 (cursorUpdateMode & InputConnection.CURSOR_UPDATE_MONITOR) != 0; |
707 | 700 |
708 if (mNativeImeAdapterAndroid != 0) { | 701 if (mIsConnected) { |
709 nativeRequestCursorUpdate(mNativeImeAdapterAndroid, immediateRequest , monitorRequest); | 702 nativeRequestCursorUpdate(mNativeImeAdapterAndroid, immediateRequest , monitorRequest); |
710 } | 703 } |
711 if (mCursorAnchorInfoController == null) return false; | 704 if (mCursorAnchorInfoController == null) return false; |
712 return mCursorAnchorInfoController.onRequestCursorUpdates(immediateReque st, monitorRequest, | 705 return mCursorAnchorInfoController.onRequestCursorUpdates(immediateReque st, monitorRequest, |
713 mViewEmbedder.getAttachedView()); | 706 mViewEmbedder.getAttachedView()); |
714 } | 707 } |
715 | 708 |
716 /** | 709 /** |
717 * Notified when a frame has been produced by the renderer and all the assoc iated metadata. | 710 * Notified when a frame has been produced by the renderer and all the assoc iated metadata. |
718 * @param renderCoordinates coordinate information to convert CSS (document) coordinates to | 711 * @param renderCoordinates coordinate information to convert CSS (document) coordinates to |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
763 } | 756 } |
764 | 757 |
765 @CalledByNative | 758 @CalledByNative |
766 private void setCharacterBounds(float[] characterBounds) { | 759 private void setCharacterBounds(float[] characterBounds) { |
767 if (mCursorAnchorInfoController == null) return; | 760 if (mCursorAnchorInfoController == null) return; |
768 mCursorAnchorInfoController.setCompositionCharacterBounds(characterBound s, | 761 mCursorAnchorInfoController.setCompositionCharacterBounds(characterBound s, |
769 mViewEmbedder.getAttachedView()); | 762 mViewEmbedder.getAttachedView()); |
770 } | 763 } |
771 | 764 |
772 @CalledByNative | 765 @CalledByNative |
773 private void detach() { | 766 private void onConnectedToRenderProcess(boolean connected) { |
774 if (DEBUG_LOGS) Log.i(TAG, "detach"); | 767 if (DEBUG_LOGS) Log.w(TAG, "onConnectedToRenderPrcess: " + connected); |
775 mNativeImeAdapterAndroid = 0; | 768 mIsConnected = connected; |
776 if (mCursorAnchorInfoController != null) { | 769 if (connected) { |
777 mCursorAnchorInfoController.focusedNodeChanged(false); | 770 createInputConnectionFactory(); |
771 resetAndHideKeyboard(); | |
772 } else { | |
773 if (mCursorAnchorInfoController != null) { | |
774 mCursorAnchorInfoController.focusedNodeChanged(false); | |
775 } | |
778 } | 776 } |
779 } | 777 } |
780 | 778 |
779 private native long nativeInit(); | |
780 private native void nativeDestroy(long nativeImeAdapterAndroid); | |
781 private native boolean nativeSendKeyEvent(long nativeImeAdapterAndroid, KeyE vent event, | 781 private native boolean nativeSendKeyEvent(long nativeImeAdapterAndroid, KeyE vent event, |
782 int type, int modifiers, long timestampMs, int keyCode, int scanCode , | 782 int type, int modifiers, long timestampMs, int keyCode, int scanCode , |
783 boolean isSystemKey, int unicodeChar); | 783 boolean isSystemKey, int unicodeChar); |
784 private static native void nativeAppendUnderlineSpan(long underlinePtr, int start, int end); | 784 private static native void nativeAppendUnderlineSpan(long underlinePtr, int start, int end); |
785 private static native void nativeAppendBackgroundColorSpan(long underlinePtr , int start, | 785 private static native void nativeAppendBackgroundColorSpan(long underlinePtr , int start, |
786 int end, int backgroundColor); | 786 int end, int backgroundColor); |
787 private native void nativeSetComposingText(long nativeImeAdapterAndroid, Cha rSequence text, | 787 private native void nativeSetComposingText(long nativeImeAdapterAndroid, Cha rSequence text, |
788 String textStr, int newCursorPosition); | 788 String textStr, int newCursorPosition); |
789 private native void nativeCommitText( | 789 private native void nativeCommitText( |
790 long nativeImeAdapterAndroid, CharSequence text, String textStr, int newCursorPosition); | 790 long nativeImeAdapterAndroid, CharSequence text, String textStr, int newCursorPosition); |
791 private native void nativeFinishComposingText(long nativeImeAdapterAndroid); | 791 private native void nativeFinishComposingText(long nativeImeAdapterAndroid); |
792 private native void nativeAttachImeAdapter(long nativeImeAdapterAndroid); | |
793 private native void nativeSetEditableSelectionOffsets(long nativeImeAdapterA ndroid, | 792 private native void nativeSetEditableSelectionOffsets(long nativeImeAdapterA ndroid, |
794 int start, int end); | 793 int start, int end); |
795 private native void nativeSetComposingRegion(long nativeImeAdapterAndroid, i nt start, int end); | 794 private native void nativeSetComposingRegion(long nativeImeAdapterAndroid, i nt start, int end); |
796 private native void nativeDeleteSurroundingText(long nativeImeAdapterAndroid , | 795 private native void nativeDeleteSurroundingText(long nativeImeAdapterAndroid , |
797 int before, int after); | 796 int before, int after); |
798 private native void nativeDeleteSurroundingTextInCodePoints( | 797 private native void nativeDeleteSurroundingTextInCodePoints( |
799 long nativeImeAdapterAndroid, int before, int after); | 798 long nativeImeAdapterAndroid, int before, int after); |
800 private native void nativeResetImeAdapter(long nativeImeAdapterAndroid); | |
801 private native boolean nativeRequestTextInputStateUpdate(long nativeImeAdapt erAndroid); | 799 private native boolean nativeRequestTextInputStateUpdate(long nativeImeAdapt erAndroid); |
802 private native void nativeRequestCursorUpdate(long nativeImeAdapterAndroid, | 800 private native void nativeRequestCursorUpdate(long nativeImeAdapterAndroid, |
803 boolean immediateRequest, boolean monitorRequest); | 801 boolean immediateRequest, boolean monitorRequest); |
804 } | 802 } |
OLD | NEW |