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.Handler; | 8 import android.os.Handler; |
9 import android.os.ResultReceiver; | 9 import android.os.ResultReceiver; |
10 import android.os.SystemClock; | 10 import android.os.SystemClock; |
11 import android.text.Editable; | 11 import android.text.Editable; |
12 import android.text.SpannableString; | 12 import android.text.SpannableString; |
13 import android.text.style.BackgroundColorSpan; | 13 import android.text.style.BackgroundColorSpan; |
14 import android.text.style.CharacterStyle; | 14 import android.text.style.CharacterStyle; |
15 import android.text.style.UnderlineSpan; | 15 import android.text.style.UnderlineSpan; |
16 import android.view.KeyCharacterMap; | 16 import android.view.KeyCharacterMap; |
17 import android.view.KeyEvent; | 17 import android.view.KeyEvent; |
18 import android.view.View; | 18 import android.view.View; |
| 19 import android.view.inputmethod.CursorAnchorInfo; |
19 import android.view.inputmethod.EditorInfo; | 20 import android.view.inputmethod.EditorInfo; |
| 21 import android.view.inputmethod.InputConnection; |
| 22 import android.view.inputmethod.InputMethodManager; |
20 | 23 |
21 import org.chromium.base.CalledByNative; | 24 import org.chromium.base.CalledByNative; |
22 import org.chromium.base.JNINamespace; | 25 import org.chromium.base.JNINamespace; |
23 import org.chromium.base.VisibleForTesting; | 26 import org.chromium.base.VisibleForTesting; |
24 import org.chromium.blink_public.web.WebInputEventModifier; | 27 import org.chromium.blink_public.web.WebInputEventModifier; |
25 import org.chromium.blink_public.web.WebInputEventType; | 28 import org.chromium.blink_public.web.WebInputEventType; |
26 import org.chromium.blink_public.web.WebTextInputFlags; | 29 import org.chromium.blink_public.web.WebTextInputFlags; |
27 import org.chromium.ui.base.ime.TextInputType; | 30 import org.chromium.ui.base.ime.TextInputType; |
28 import org.chromium.ui.picker.InputDialogContainer; | 31 import org.chromium.ui.picker.InputDialogContainer; |
29 | 32 |
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 * @return Whether the native counterpart of ImeAdapter received the call. | 562 * @return Whether the native counterpart of ImeAdapter received the call. |
560 */ | 563 */ |
561 boolean setComposingRegion(CharSequence text, int start, int end) { | 564 boolean setComposingRegion(CharSequence text, int start, int end) { |
562 if (mNativeImeAdapterAndroid == 0) return false; | 565 if (mNativeImeAdapterAndroid == 0) return false; |
563 nativeSetComposingRegion(mNativeImeAdapterAndroid, start, end); | 566 nativeSetComposingRegion(mNativeImeAdapterAndroid, start, end); |
564 mLastComposeText = text != null ? text.toString() : null; | 567 mLastComposeText = text != null ? text.toString() : null; |
565 return true; | 568 return true; |
566 } | 569 } |
567 | 570 |
568 /** | 571 /** |
| 572 * Send a request to the native counterpart to call back |
| 573 * {@link InputMethodManager#updateCursorAnchorInfo(View, CursorAnchorInfo)}
when necessary. |
| 574 * @param cursorUpdateMode The flag passed to {@link InputConnection#request
CursorUpdates(int)}. |
| 575 * @return Whether the native counterpart of ImeAdapter received the call. |
| 576 */ |
| 577 boolean requestCursorUpdates(int cursorUpdateMode) { |
| 578 if (mNativeImeAdapterAndroid == 0) return false; |
| 579 return nativeRequestCursorUpdates(mNativeImeAdapterAndroid, cursorUpdate
Mode); |
| 580 } |
| 581 |
| 582 /** |
569 * Send a request to the native counterpart to unselect text. | 583 * Send a request to the native counterpart to unselect text. |
570 * @return Whether the native counterpart of ImeAdapter received the call. | 584 * @return Whether the native counterpart of ImeAdapter received the call. |
571 */ | 585 */ |
572 public boolean unselect() { | 586 public boolean unselect() { |
573 if (mNativeImeAdapterAndroid == 0) return false; | 587 if (mNativeImeAdapterAndroid == 0) return false; |
574 nativeUnselect(mNativeImeAdapterAndroid); | 588 nativeUnselect(mNativeImeAdapterAndroid); |
575 return true; | 589 return true; |
576 } | 590 } |
577 | 591 |
578 /** | 592 /** |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 } | 630 } |
617 | 631 |
618 // Calls from C++ to Java | 632 // Calls from C++ to Java |
619 | 633 |
620 @CalledByNative | 634 @CalledByNative |
621 private void focusedNodeChanged(boolean isEditable) { | 635 private void focusedNodeChanged(boolean isEditable) { |
622 if (mInputConnection != null && isEditable) mInputConnection.restartInpu
t(); | 636 if (mInputConnection != null && isEditable) mInputConnection.restartInpu
t(); |
623 } | 637 } |
624 | 638 |
625 @CalledByNative | 639 @CalledByNative |
| 640 private void updateCursorAnchorInfo(Object cursorAnchorInfo) { |
| 641 if (cursorAnchorInfo instanceof CursorAnchorInfo) { |
| 642 mInputMethodManagerWrapper.updateCursorAnchorInfo(mViewEmbedder.getA
ttachedView(), |
| 643 (CursorAnchorInfo) cursorAnchorInfo); |
| 644 } |
| 645 } |
| 646 |
| 647 @CalledByNative |
626 private void populateUnderlinesFromSpans(CharSequence text, long underlines)
{ | 648 private void populateUnderlinesFromSpans(CharSequence text, long underlines)
{ |
627 if (!(text instanceof SpannableString)) return; | 649 if (!(text instanceof SpannableString)) return; |
628 | 650 |
629 SpannableString spannableString = ((SpannableString) text); | 651 SpannableString spannableString = ((SpannableString) text); |
630 CharacterStyle spans[] = | 652 CharacterStyle spans[] = |
631 spannableString.getSpans(0, text.length(), CharacterStyle.class)
; | 653 spannableString.getSpans(0, text.length(), CharacterStyle.class)
; |
632 for (CharacterStyle span : spans) { | 654 for (CharacterStyle span : spans) { |
633 if (span instanceof BackgroundColorSpan) { | 655 if (span instanceof BackgroundColorSpan) { |
634 nativeAppendBackgroundColorSpan(underlines, spannableString.getS
panStart(span), | 656 nativeAppendBackgroundColorSpan(underlines, spannableString.getS
panStart(span), |
635 spannableString.getSpanEnd(span), | 657 spannableString.getSpanEnd(span), |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 private native void nativeAttachImeAdapter(long nativeImeAdapterAndroid); | 701 private native void nativeAttachImeAdapter(long nativeImeAdapterAndroid); |
680 | 702 |
681 private native void nativeSetEditableSelectionOffsets(long nativeImeAdapterA
ndroid, | 703 private native void nativeSetEditableSelectionOffsets(long nativeImeAdapterA
ndroid, |
682 int start, int end); | 704 int start, int end); |
683 | 705 |
684 private native void nativeSetComposingRegion(long nativeImeAdapterAndroid, i
nt start, int end); | 706 private native void nativeSetComposingRegion(long nativeImeAdapterAndroid, i
nt start, int end); |
685 | 707 |
686 private native void nativeDeleteSurroundingText(long nativeImeAdapterAndroid
, | 708 private native void nativeDeleteSurroundingText(long nativeImeAdapterAndroid
, |
687 int before, int after); | 709 int before, int after); |
688 | 710 |
| 711 private native boolean nativeRequestCursorUpdates(long nativeImeAdapterAndro
id, |
| 712 int cursorUpdateMode); |
| 713 |
689 private native void nativeUnselect(long nativeImeAdapterAndroid); | 714 private native void nativeUnselect(long nativeImeAdapterAndroid); |
690 private native void nativeSelectAll(long nativeImeAdapterAndroid); | 715 private native void nativeSelectAll(long nativeImeAdapterAndroid); |
691 private native void nativeCut(long nativeImeAdapterAndroid); | 716 private native void nativeCut(long nativeImeAdapterAndroid); |
692 private native void nativeCopy(long nativeImeAdapterAndroid); | 717 private native void nativeCopy(long nativeImeAdapterAndroid); |
693 private native void nativePaste(long nativeImeAdapterAndroid); | 718 private native void nativePaste(long nativeImeAdapterAndroid); |
694 private native void nativeResetImeAdapter(long nativeImeAdapterAndroid); | 719 private native void nativeResetImeAdapter(long nativeImeAdapterAndroid); |
695 } | 720 } |
OLD | NEW |