| 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.os.Handler; | 7 import android.os.Handler; |
| 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; | 10 import android.text.Editable; |
| 11 import android.text.SpannableString; | 11 import android.text.SpannableString; |
| 12 import android.text.style.BackgroundColorSpan; | 12 import android.text.style.BackgroundColorSpan; |
| 13 import android.text.style.CharacterStyle; | 13 import android.text.style.CharacterStyle; |
| 14 import android.text.style.UnderlineSpan; | 14 import android.text.style.UnderlineSpan; |
| 15 import android.view.KeyCharacterMap; | 15 import android.view.KeyCharacterMap; |
| 16 import android.view.KeyEvent; | 16 import android.view.KeyEvent; |
| 17 import android.view.View; | 17 import android.view.View; |
| 18 import android.view.inputmethod.CursorAnchorInfo; |
| 18 import android.view.inputmethod.EditorInfo; | 19 import android.view.inputmethod.EditorInfo; |
| 20 import android.view.inputmethod.InputConnection; |
| 21 import android.view.inputmethod.InputMethodManager; |
| 19 | 22 |
| 20 import org.chromium.base.CalledByNative; | 23 import org.chromium.base.CalledByNative; |
| 21 import org.chromium.base.JNINamespace; | 24 import org.chromium.base.JNINamespace; |
| 22 import org.chromium.base.VisibleForTesting; | 25 import org.chromium.base.VisibleForTesting; |
| 23 import org.chromium.ui.base.ime.TextInputType; | 26 import org.chromium.ui.base.ime.TextInputType; |
| 24 import org.chromium.ui.picker.InputDialogContainer; | 27 import org.chromium.ui.picker.InputDialogContainer; |
| 25 | 28 |
| 26 import java.lang.CharSequence; | 29 import java.lang.CharSequence; |
| 27 | 30 |
| 28 /** | 31 /** |
| (...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 * @return Whether the native counterpart of ImeAdapter received the call. | 559 * @return Whether the native counterpart of ImeAdapter received the call. |
| 557 */ | 560 */ |
| 558 boolean setComposingRegion(CharSequence text, int start, int end) { | 561 boolean setComposingRegion(CharSequence text, int start, int end) { |
| 559 if (mNativeImeAdapterAndroid == 0) return false; | 562 if (mNativeImeAdapterAndroid == 0) return false; |
| 560 nativeSetComposingRegion(mNativeImeAdapterAndroid, start, end); | 563 nativeSetComposingRegion(mNativeImeAdapterAndroid, start, end); |
| 561 mLastComposeText = text != null ? text.toString() : null; | 564 mLastComposeText = text != null ? text.toString() : null; |
| 562 return true; | 565 return true; |
| 563 } | 566 } |
| 564 | 567 |
| 565 /** | 568 /** |
| 569 * Send a request to the native counterpart to call back |
| 570 * {@link InputMethodManager#updateCursorAnchorInfo(View, CursorAnchorInfo)}
when necessary. |
| 571 * @param cursorUpdateMode The flag passed to {@link InputConnection#request
CursorUpdates(int)}. |
| 572 * @return Whether the native counterpart of ImeAdapter received the call. |
| 573 */ |
| 574 boolean requestCursorUpdates(int cursorUpdateMode) { |
| 575 if (mNativeImeAdapterAndroid == 0) return false; |
| 576 return nativeRequestCursorUpdates(mNativeImeAdapterAndroid, cursorUpdate
Mode); |
| 577 } |
| 578 |
| 579 /** |
| 566 * Send a request to the native counterpart to unselect text. | 580 * Send a request to the native counterpart to unselect text. |
| 567 * @return Whether the native counterpart of ImeAdapter received the call. | 581 * @return Whether the native counterpart of ImeAdapter received the call. |
| 568 */ | 582 */ |
| 569 public boolean unselect() { | 583 public boolean unselect() { |
| 570 if (mNativeImeAdapterAndroid == 0) return false; | 584 if (mNativeImeAdapterAndroid == 0) return false; |
| 571 nativeUnselect(mNativeImeAdapterAndroid); | 585 nativeUnselect(mNativeImeAdapterAndroid); |
| 572 return true; | 586 return true; |
| 573 } | 587 } |
| 574 | 588 |
| 575 /** | 589 /** |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 sTextInputFlagSpellcheckOn = textInputFlagSpellcheckOn; | 654 sTextInputFlagSpellcheckOn = textInputFlagSpellcheckOn; |
| 641 sTextInputFlagSpellcheckOff = textInputFlagSpellcheckOff; | 655 sTextInputFlagSpellcheckOff = textInputFlagSpellcheckOff; |
| 642 } | 656 } |
| 643 | 657 |
| 644 @CalledByNative | 658 @CalledByNative |
| 645 private void focusedNodeChanged(boolean isEditable) { | 659 private void focusedNodeChanged(boolean isEditable) { |
| 646 if (mInputConnection != null && isEditable) mInputConnection.restartInpu
t(); | 660 if (mInputConnection != null && isEditable) mInputConnection.restartInpu
t(); |
| 647 } | 661 } |
| 648 | 662 |
| 649 @CalledByNative | 663 @CalledByNative |
| 664 private void updateCursorAnchorInfo(Object cursorAnchorInfo) { |
| 665 if (cursorAnchorInfo instanceof CursorAnchorInfo) { |
| 666 mInputMethodManagerWrapper.updateCursorAnchorInfo(mViewEmbedder.getA
ttachedView(), |
| 667 (CursorAnchorInfo) cursorAnchorInfo); |
| 668 } |
| 669 } |
| 670 |
| 671 @CalledByNative |
| 650 private void populateUnderlinesFromSpans(CharSequence text, long underlines)
{ | 672 private void populateUnderlinesFromSpans(CharSequence text, long underlines)
{ |
| 651 if (!(text instanceof SpannableString)) return; | 673 if (!(text instanceof SpannableString)) return; |
| 652 | 674 |
| 653 SpannableString spannableString = ((SpannableString) text); | 675 SpannableString spannableString = ((SpannableString) text); |
| 654 CharacterStyle spans[] = | 676 CharacterStyle spans[] = |
| 655 spannableString.getSpans(0, text.length(), CharacterStyle.class)
; | 677 spannableString.getSpans(0, text.length(), CharacterStyle.class)
; |
| 656 for (CharacterStyle span : spans) { | 678 for (CharacterStyle span : spans) { |
| 657 if (span instanceof BackgroundColorSpan) { | 679 if (span instanceof BackgroundColorSpan) { |
| 658 nativeAppendBackgroundColorSpan(underlines, spannableString.getS
panStart(span), | 680 nativeAppendBackgroundColorSpan(underlines, spannableString.getS
panStart(span), |
| 659 spannableString.getSpanEnd(span), | 681 spannableString.getSpanEnd(span), |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 private native void nativeAttachImeAdapter(long nativeImeAdapterAndroid); | 725 private native void nativeAttachImeAdapter(long nativeImeAdapterAndroid); |
| 704 | 726 |
| 705 private native void nativeSetEditableSelectionOffsets(long nativeImeAdapterA
ndroid, | 727 private native void nativeSetEditableSelectionOffsets(long nativeImeAdapterA
ndroid, |
| 706 int start, int end); | 728 int start, int end); |
| 707 | 729 |
| 708 private native void nativeSetComposingRegion(long nativeImeAdapterAndroid, i
nt start, int end); | 730 private native void nativeSetComposingRegion(long nativeImeAdapterAndroid, i
nt start, int end); |
| 709 | 731 |
| 710 private native void nativeDeleteSurroundingText(long nativeImeAdapterAndroid
, | 732 private native void nativeDeleteSurroundingText(long nativeImeAdapterAndroid
, |
| 711 int before, int after); | 733 int before, int after); |
| 712 | 734 |
| 735 private native boolean nativeRequestCursorUpdates(long nativeImeAdapterAndro
id, |
| 736 int cursorUpdateMode); |
| 737 |
| 713 private native void nativeUnselect(long nativeImeAdapterAndroid); | 738 private native void nativeUnselect(long nativeImeAdapterAndroid); |
| 714 private native void nativeSelectAll(long nativeImeAdapterAndroid); | 739 private native void nativeSelectAll(long nativeImeAdapterAndroid); |
| 715 private native void nativeCut(long nativeImeAdapterAndroid); | 740 private native void nativeCut(long nativeImeAdapterAndroid); |
| 716 private native void nativeCopy(long nativeImeAdapterAndroid); | 741 private native void nativeCopy(long nativeImeAdapterAndroid); |
| 717 private native void nativePaste(long nativeImeAdapterAndroid); | 742 private native void nativePaste(long nativeImeAdapterAndroid); |
| 718 private native void nativeResetImeAdapter(long nativeImeAdapterAndroid); | 743 private native void nativeResetImeAdapter(long nativeImeAdapterAndroid); |
| 719 } | 744 } |
| OLD | NEW |