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.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
8 import android.content.res.Configuration; | 8 import android.content.res.Configuration; |
9 import android.graphics.Rect; | 9 import android.graphics.Rect; |
10 import android.os.Build; | 10 import android.os.Build; |
(...skipping 13 matching lines...) Expand all Loading... |
24 import android.view.inputmethod.EditorInfo; | 24 import android.view.inputmethod.EditorInfo; |
25 import android.view.inputmethod.ExtractedText; | 25 import android.view.inputmethod.ExtractedText; |
26 import android.view.inputmethod.InputConnection; | 26 import android.view.inputmethod.InputConnection; |
27 import android.view.inputmethod.InputMethodManager; | 27 import android.view.inputmethod.InputMethodManager; |
28 | 28 |
29 import org.chromium.base.Log; | 29 import org.chromium.base.Log; |
30 import org.chromium.base.TraceEvent; | 30 import org.chromium.base.TraceEvent; |
31 import org.chromium.base.VisibleForTesting; | 31 import org.chromium.base.VisibleForTesting; |
32 import org.chromium.base.annotations.CalledByNative; | 32 import org.chromium.base.annotations.CalledByNative; |
33 import org.chromium.base.annotations.JNINamespace; | 33 import org.chromium.base.annotations.JNINamespace; |
34 import org.chromium.blink_public.web.WebFocusType; | |
35 import org.chromium.blink_public.web.WebInputEventModifier; | 34 import org.chromium.blink_public.web.WebInputEventModifier; |
36 import org.chromium.blink_public.web.WebInputEventType; | 35 import org.chromium.blink_public.web.WebInputEventType; |
37 import org.chromium.blink_public.web.WebTextInputMode; | 36 import org.chromium.blink_public.web.WebTextInputMode; |
38 import org.chromium.content.browser.ViewUtils; | 37 import org.chromium.content.browser.ViewUtils; |
39 import org.chromium.content.browser.picker.InputDialogContainer; | 38 import org.chromium.content.browser.picker.InputDialogContainer; |
40 import org.chromium.content_public.browser.ImeEventObserver; | 39 import org.chromium.content_public.browser.ImeEventObserver; |
41 import org.chromium.content_public.browser.WebContents; | 40 import org.chromium.content_public.browser.WebContents; |
42 import org.chromium.ui.base.ime.TextInputType; | 41 import org.chromium.ui.base.ime.TextInputType; |
43 | 42 |
44 import java.lang.ref.WeakReference; | 43 import java.lang.ref.WeakReference; |
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 case android.R.id.paste: | 626 case android.R.id.paste: |
628 mWebContents.paste(); | 627 mWebContents.paste(); |
629 return true; | 628 return true; |
630 default: | 629 default: |
631 return false; | 630 return false; |
632 } | 631 } |
633 } | 632 } |
634 | 633 |
635 boolean performEditorAction(int actionCode) { | 634 boolean performEditorAction(int actionCode) { |
636 if (!isValid()) return false; | 635 if (!isValid()) return false; |
637 switch (actionCode) { | 636 if (actionCode == EditorInfo.IME_ACTION_NEXT) { |
638 case EditorInfo.IME_ACTION_NEXT: | 637 sendSyntheticKeyPress(KeyEvent.KEYCODE_TAB, |
639 advanceFocusInForm(WebFocusType.FORWARD); | 638 KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE |
640 break; | 639 | KeyEvent.FLAG_EDITOR_ACTION); |
641 case EditorInfo.IME_ACTION_PREVIOUS: | 640 } else { |
642 advanceFocusInForm(WebFocusType.BACKWARD); | 641 sendSyntheticKeyPress(KeyEvent.KEYCODE_ENTER, |
643 break; | 642 KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE |
644 default: | 643 | KeyEvent.FLAG_EDITOR_ACTION); |
645 sendSyntheticKeyPress(KeyEvent.KEYCODE_ENTER, | |
646 KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_M
ODE | |
647 | KeyEvent.FLAG_EDITOR_ACTION); | |
648 break; | |
649 } | 644 } |
650 return true; | 645 return true; |
651 } | 646 } |
652 | 647 |
653 /** | |
654 * Advances the focus to next input field in the current form. | |
655 * | |
656 * @param focusType indicates whether to advance forward or backward directi
on. | |
657 */ | |
658 private void advanceFocusInForm(int focusType) { | |
659 if (mNativeImeAdapterAndroid == 0) return; | |
660 nativeAdvanceFocusInForm(mNativeImeAdapterAndroid, focusType); | |
661 } | |
662 | |
663 void notifyUserAction() { | 648 void notifyUserAction() { |
664 mInputMethodManagerWrapper.notifyUserAction(); | 649 mInputMethodManagerWrapper.notifyUserAction(); |
665 } | 650 } |
666 | 651 |
667 @VisibleForTesting | 652 @VisibleForTesting |
668 protected void sendSyntheticKeyPress(int keyCode, int flags) { | 653 protected void sendSyntheticKeyPress(int keyCode, int flags) { |
669 long eventTime = SystemClock.uptimeMillis(); | 654 long eventTime = SystemClock.uptimeMillis(); |
670 sendKeyEvent(new KeyEvent(eventTime, eventTime, | 655 sendKeyEvent(new KeyEvent(eventTime, eventTime, |
671 KeyEvent.ACTION_DOWN, keyCode, 0, 0, | 656 KeyEvent.ACTION_DOWN, keyCode, 0, 0, |
672 KeyCharacterMap.VIRTUAL_KEYBOARD, 0, | 657 KeyCharacterMap.VIRTUAL_KEYBOARD, 0, |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
928 private native void nativeSetEditableSelectionOffsets(long nativeImeAdapterA
ndroid, | 913 private native void nativeSetEditableSelectionOffsets(long nativeImeAdapterA
ndroid, |
929 int start, int end); | 914 int start, int end); |
930 private native void nativeSetComposingRegion(long nativeImeAdapterAndroid, i
nt start, int end); | 915 private native void nativeSetComposingRegion(long nativeImeAdapterAndroid, i
nt start, int end); |
931 private native void nativeDeleteSurroundingText(long nativeImeAdapterAndroid
, | 916 private native void nativeDeleteSurroundingText(long nativeImeAdapterAndroid
, |
932 int before, int after); | 917 int before, int after); |
933 private native void nativeDeleteSurroundingTextInCodePoints( | 918 private native void nativeDeleteSurroundingTextInCodePoints( |
934 long nativeImeAdapterAndroid, int before, int after); | 919 long nativeImeAdapterAndroid, int before, int after); |
935 private native boolean nativeRequestTextInputStateUpdate(long nativeImeAdapt
erAndroid); | 920 private native boolean nativeRequestTextInputStateUpdate(long nativeImeAdapt
erAndroid); |
936 private native void nativeRequestCursorUpdate(long nativeImeAdapterAndroid, | 921 private native void nativeRequestCursorUpdate(long nativeImeAdapterAndroid, |
937 boolean immediateRequest, boolean monitorRequest); | 922 boolean immediateRequest, boolean monitorRequest); |
938 private native void nativeAdvanceFocusInForm(long nativeImeAdapterAndroid, i
nt focusType); | |
939 } | 923 } |
OLD | NEW |