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.blink_public.web.WebInputEventModifier; | 26 import org.chromium.blink_public.web.WebInputEventModifier; |
24 import org.chromium.blink_public.web.WebInputEventType; | 27 import org.chromium.blink_public.web.WebInputEventType; |
25 import org.chromium.blink_public.web.WebTextInputFlags; | 28 import org.chromium.blink_public.web.WebTextInputFlags; |
26 import org.chromium.ui.base.ime.TextInputType; | 29 import org.chromium.ui.base.ime.TextInputType; |
27 import org.chromium.ui.picker.InputDialogContainer; | 30 import org.chromium.ui.picker.InputDialogContainer; |
28 | 31 |
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 * @return Whether the native counterpart of ImeAdapter received the call. | 556 * @return Whether the native counterpart of ImeAdapter received the call. |
554 */ | 557 */ |
555 boolean setComposingRegion(CharSequence text, int start, int end) { | 558 boolean setComposingRegion(CharSequence text, int start, int end) { |
556 if (mNativeImeAdapterAndroid == 0) return false; | 559 if (mNativeImeAdapterAndroid == 0) return false; |
557 nativeSetComposingRegion(mNativeImeAdapterAndroid, start, end); | 560 nativeSetComposingRegion(mNativeImeAdapterAndroid, start, end); |
558 mLastComposeText = text != null ? text.toString() : null; | 561 mLastComposeText = text != null ? text.toString() : null; |
559 return true; | 562 return true; |
560 } | 563 } |
561 | 564 |
562 /** | 565 /** |
| 566 * Send a request to the native counterpart to call back |
| 567 * {@link InputMethodManager#updateCursorAnchorInfo(View, CursorAnchorInfo)}
when necessary. |
| 568 * @param cursorUpdateMode The flag passed to {@link InputConnection#request
CursorUpdates(int)}. |
| 569 * @return Whether the native counterpart of ImeAdapter received the call. |
| 570 */ |
| 571 boolean requestCursorUpdates(int cursorUpdateMode) { |
| 572 if (mNativeImeAdapterAndroid == 0) return false; |
| 573 return nativeRequestCursorUpdates(mNativeImeAdapterAndroid, cursorUpdate
Mode); |
| 574 } |
| 575 |
| 576 /** |
563 * Send a request to the native counterpart to unselect text. | 577 * Send a request to the native counterpart to unselect text. |
564 * @return Whether the native counterpart of ImeAdapter received the call. | 578 * @return Whether the native counterpart of ImeAdapter received the call. |
565 */ | 579 */ |
566 public boolean unselect() { | 580 public boolean unselect() { |
567 if (mNativeImeAdapterAndroid == 0) return false; | 581 if (mNativeImeAdapterAndroid == 0) return false; |
568 nativeUnselect(mNativeImeAdapterAndroid); | 582 nativeUnselect(mNativeImeAdapterAndroid); |
569 return true; | 583 return true; |
570 } | 584 } |
571 | 585 |
572 /** | 586 /** |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 } | 624 } |
611 | 625 |
612 // Calls from C++ to Java | 626 // Calls from C++ to Java |
613 | 627 |
614 @CalledByNative | 628 @CalledByNative |
615 private void focusedNodeChanged(boolean isEditable) { | 629 private void focusedNodeChanged(boolean isEditable) { |
616 if (mInputConnection != null && isEditable) mInputConnection.restartInpu
t(); | 630 if (mInputConnection != null && isEditable) mInputConnection.restartInpu
t(); |
617 } | 631 } |
618 | 632 |
619 @CalledByNative | 633 @CalledByNative |
| 634 private void updateCursorAnchorInfo(Object cursorAnchorInfo) { |
| 635 if (cursorAnchorInfo instanceof CursorAnchorInfo) { |
| 636 mInputMethodManagerWrapper.updateCursorAnchorInfo(mViewEmbedder.getA
ttachedView(), |
| 637 (CursorAnchorInfo) cursorAnchorInfo); |
| 638 } |
| 639 } |
| 640 |
| 641 @CalledByNative |
620 private void populateUnderlinesFromSpans(CharSequence text, long underlines)
{ | 642 private void populateUnderlinesFromSpans(CharSequence text, long underlines)
{ |
621 if (!(text instanceof SpannableString)) return; | 643 if (!(text instanceof SpannableString)) return; |
622 | 644 |
623 SpannableString spannableString = ((SpannableString) text); | 645 SpannableString spannableString = ((SpannableString) text); |
624 CharacterStyle spans[] = | 646 CharacterStyle spans[] = |
625 spannableString.getSpans(0, text.length(), CharacterStyle.class)
; | 647 spannableString.getSpans(0, text.length(), CharacterStyle.class)
; |
626 for (CharacterStyle span : spans) { | 648 for (CharacterStyle span : spans) { |
627 if (span instanceof BackgroundColorSpan) { | 649 if (span instanceof BackgroundColorSpan) { |
628 nativeAppendBackgroundColorSpan(underlines, spannableString.getS
panStart(span), | 650 nativeAppendBackgroundColorSpan(underlines, spannableString.getS
panStart(span), |
629 spannableString.getSpanEnd(span), | 651 spannableString.getSpanEnd(span), |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 private native void nativeAttachImeAdapter(long nativeImeAdapterAndroid); | 695 private native void nativeAttachImeAdapter(long nativeImeAdapterAndroid); |
674 | 696 |
675 private native void nativeSetEditableSelectionOffsets(long nativeImeAdapterA
ndroid, | 697 private native void nativeSetEditableSelectionOffsets(long nativeImeAdapterA
ndroid, |
676 int start, int end); | 698 int start, int end); |
677 | 699 |
678 private native void nativeSetComposingRegion(long nativeImeAdapterAndroid, i
nt start, int end); | 700 private native void nativeSetComposingRegion(long nativeImeAdapterAndroid, i
nt start, int end); |
679 | 701 |
680 private native void nativeDeleteSurroundingText(long nativeImeAdapterAndroid
, | 702 private native void nativeDeleteSurroundingText(long nativeImeAdapterAndroid
, |
681 int before, int after); | 703 int before, int after); |
682 | 704 |
| 705 private native boolean nativeRequestCursorUpdates(long nativeImeAdapterAndro
id, |
| 706 int cursorUpdateMode); |
| 707 |
683 private native void nativeUnselect(long nativeImeAdapterAndroid); | 708 private native void nativeUnselect(long nativeImeAdapterAndroid); |
684 private native void nativeSelectAll(long nativeImeAdapterAndroid); | 709 private native void nativeSelectAll(long nativeImeAdapterAndroid); |
685 private native void nativeCut(long nativeImeAdapterAndroid); | 710 private native void nativeCut(long nativeImeAdapterAndroid); |
686 private native void nativeCopy(long nativeImeAdapterAndroid); | 711 private native void nativeCopy(long nativeImeAdapterAndroid); |
687 private native void nativePaste(long nativeImeAdapterAndroid); | 712 private native void nativePaste(long nativeImeAdapterAndroid); |
688 private native void nativeResetImeAdapter(long nativeImeAdapterAndroid); | 713 private native void nativeResetImeAdapter(long nativeImeAdapterAndroid); |
689 } | 714 } |
OLD | NEW |