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; |
34 import org.chromium.blink_public.web.WebInputEventModifier; | 35 import org.chromium.blink_public.web.WebInputEventModifier; |
35 import org.chromium.blink_public.web.WebInputEventType; | 36 import org.chromium.blink_public.web.WebInputEventType; |
36 import org.chromium.blink_public.web.WebTextInputMode; | 37 import org.chromium.blink_public.web.WebTextInputMode; |
37 import org.chromium.content.browser.ViewUtils; | 38 import org.chromium.content.browser.ViewUtils; |
38 import org.chromium.content.browser.picker.InputDialogContainer; | 39 import org.chromium.content.browser.picker.InputDialogContainer; |
39 import org.chromium.content_public.browser.ImeEventObserver; | 40 import org.chromium.content_public.browser.ImeEventObserver; |
40 import org.chromium.content_public.browser.WebContents; | 41 import org.chromium.content_public.browser.WebContents; |
41 import org.chromium.ui.base.ime.TextInputType; | 42 import org.chromium.ui.base.ime.TextInputType; |
42 | 43 |
43 import java.lang.ref.WeakReference; | 44 import java.lang.ref.WeakReference; |
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 case android.R.id.paste: | 627 case android.R.id.paste: |
627 mWebContents.paste(); | 628 mWebContents.paste(); |
628 return true; | 629 return true; |
629 default: | 630 default: |
630 return false; | 631 return false; |
631 } | 632 } |
632 } | 633 } |
633 | 634 |
634 boolean performEditorAction(int actionCode) { | 635 boolean performEditorAction(int actionCode) { |
635 if (!isValid()) return false; | 636 if (!isValid()) return false; |
636 if (actionCode == EditorInfo.IME_ACTION_NEXT) { | 637 switch (actionCode) { |
637 sendSyntheticKeyPress(KeyEvent.KEYCODE_TAB, | 638 case EditorInfo.IME_ACTION_NEXT: |
638 KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE | 639 advanceFocusInForm(WebFocusType.FORWARD); |
639 | KeyEvent.FLAG_EDITOR_ACTION); | 640 break; |
640 } else { | 641 case EditorInfo.IME_ACTION_PREVIOUS: |
641 sendSyntheticKeyPress(KeyEvent.KEYCODE_ENTER, | 642 advanceFocusInForm(WebFocusType.BACKWARD); |
642 KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE | 643 break; |
643 | KeyEvent.FLAG_EDITOR_ACTION); | 644 default: |
| 645 sendSyntheticKeyPress(KeyEvent.KEYCODE_ENTER, |
| 646 KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_M
ODE |
| 647 | KeyEvent.FLAG_EDITOR_ACTION); |
| 648 break; |
644 } | 649 } |
645 return true; | 650 return true; |
646 } | 651 } |
647 | 652 |
| 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 |
648 void notifyUserAction() { | 663 void notifyUserAction() { |
649 mInputMethodManagerWrapper.notifyUserAction(); | 664 mInputMethodManagerWrapper.notifyUserAction(); |
650 } | 665 } |
651 | 666 |
652 @VisibleForTesting | 667 @VisibleForTesting |
653 protected void sendSyntheticKeyPress(int keyCode, int flags) { | 668 protected void sendSyntheticKeyPress(int keyCode, int flags) { |
654 long eventTime = SystemClock.uptimeMillis(); | 669 long eventTime = SystemClock.uptimeMillis(); |
655 sendKeyEvent(new KeyEvent(eventTime, eventTime, | 670 sendKeyEvent(new KeyEvent(eventTime, eventTime, |
656 KeyEvent.ACTION_DOWN, keyCode, 0, 0, | 671 KeyEvent.ACTION_DOWN, keyCode, 0, 0, |
657 KeyCharacterMap.VIRTUAL_KEYBOARD, 0, | 672 KeyCharacterMap.VIRTUAL_KEYBOARD, 0, |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
913 private native void nativeSetEditableSelectionOffsets(long nativeImeAdapterA
ndroid, | 928 private native void nativeSetEditableSelectionOffsets(long nativeImeAdapterA
ndroid, |
914 int start, int end); | 929 int start, int end); |
915 private native void nativeSetComposingRegion(long nativeImeAdapterAndroid, i
nt start, int end); | 930 private native void nativeSetComposingRegion(long nativeImeAdapterAndroid, i
nt start, int end); |
916 private native void nativeDeleteSurroundingText(long nativeImeAdapterAndroid
, | 931 private native void nativeDeleteSurroundingText(long nativeImeAdapterAndroid
, |
917 int before, int after); | 932 int before, int after); |
918 private native void nativeDeleteSurroundingTextInCodePoints( | 933 private native void nativeDeleteSurroundingTextInCodePoints( |
919 long nativeImeAdapterAndroid, int before, int after); | 934 long nativeImeAdapterAndroid, int before, int after); |
920 private native boolean nativeRequestTextInputStateUpdate(long nativeImeAdapt
erAndroid); | 935 private native boolean nativeRequestTextInputStateUpdate(long nativeImeAdapt
erAndroid); |
921 private native void nativeRequestCursorUpdate(long nativeImeAdapterAndroid, | 936 private native void nativeRequestCursorUpdate(long nativeImeAdapterAndroid, |
922 boolean immediateRequest, boolean monitorRequest); | 937 boolean immediateRequest, boolean monitorRequest); |
| 938 private native void nativeAdvanceFocusInForm(long nativeImeAdapterAndroid, i
nt focusType); |
923 } | 939 } |
OLD | NEW |