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