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 12 matching lines...) Expand all Loading... |
23 import android.view.inputmethod.BaseInputConnection; | 23 import android.view.inputmethod.BaseInputConnection; |
24 import android.view.inputmethod.EditorInfo; | 24 import android.view.inputmethod.EditorInfo; |
25 import android.view.inputmethod.InputConnection; | 25 import android.view.inputmethod.InputConnection; |
26 import android.view.inputmethod.InputMethodManager; | 26 import android.view.inputmethod.InputMethodManager; |
27 | 27 |
28 import org.chromium.base.Log; | 28 import org.chromium.base.Log; |
29 import org.chromium.base.TraceEvent; | 29 import org.chromium.base.TraceEvent; |
30 import org.chromium.base.VisibleForTesting; | 30 import org.chromium.base.VisibleForTesting; |
31 import org.chromium.base.annotations.CalledByNative; | 31 import org.chromium.base.annotations.CalledByNative; |
32 import org.chromium.base.annotations.JNINamespace; | 32 import org.chromium.base.annotations.JNINamespace; |
| 33 import org.chromium.blink_public.web.WebFocusType; |
33 import org.chromium.blink_public.web.WebInputEventModifier; | 34 import org.chromium.blink_public.web.WebInputEventModifier; |
34 import org.chromium.blink_public.web.WebInputEventType; | 35 import org.chromium.blink_public.web.WebInputEventType; |
35 import org.chromium.blink_public.web.WebTextInputMode; | 36 import org.chromium.blink_public.web.WebTextInputMode; |
36 import org.chromium.content.browser.ViewUtils; | 37 import org.chromium.content.browser.ViewUtils; |
37 import org.chromium.content.browser.picker.InputDialogContainer; | 38 import org.chromium.content.browser.picker.InputDialogContainer; |
38 import org.chromium.content_public.browser.ImeEventObserver; | 39 import org.chromium.content_public.browser.ImeEventObserver; |
39 import org.chromium.content_public.browser.WebContents; | 40 import org.chromium.content_public.browser.WebContents; |
40 import org.chromium.ui.base.ime.TextInputType; | 41 import org.chromium.ui.base.ime.TextInputType; |
41 | 42 |
42 import java.lang.ref.WeakReference; | 43 import java.lang.ref.WeakReference; |
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 case android.R.id.paste: | 614 case android.R.id.paste: |
614 mWebContents.paste(); | 615 mWebContents.paste(); |
615 return true; | 616 return true; |
616 default: | 617 default: |
617 return false; | 618 return false; |
618 } | 619 } |
619 } | 620 } |
620 | 621 |
621 boolean performEditorAction(int actionCode) { | 622 boolean performEditorAction(int actionCode) { |
622 if (!isValid()) return false; | 623 if (!isValid()) return false; |
623 if (actionCode == EditorInfo.IME_ACTION_NEXT) { | 624 switch (actionCode) { |
624 sendSyntheticKeyPress(KeyEvent.KEYCODE_TAB, | 625 case EditorInfo.IME_ACTION_NEXT: |
625 KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE | 626 advanceFocusInForm(WebFocusType.FORWARD); |
626 | KeyEvent.FLAG_EDITOR_ACTION); | 627 break; |
627 } else { | 628 case EditorInfo.IME_ACTION_PREVIOUS: |
628 sendSyntheticKeyPress(KeyEvent.KEYCODE_ENTER, | 629 advanceFocusInForm(WebFocusType.BACKWARD); |
629 KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE | 630 break; |
630 | KeyEvent.FLAG_EDITOR_ACTION); | 631 default: |
| 632 sendSyntheticKeyPress(KeyEvent.KEYCODE_ENTER, |
| 633 KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_M
ODE |
| 634 | KeyEvent.FLAG_EDITOR_ACTION); |
| 635 break; |
631 } | 636 } |
632 return true; | 637 return true; |
633 } | 638 } |
634 | 639 |
| 640 /** |
| 641 * Advances the focus to next input field in the current form. |
| 642 * |
| 643 * @param focusType indicates whether to advance forward or backward directi
on. |
| 644 */ |
| 645 private void advanceFocusInForm(int focusType) { |
| 646 if (mNativeImeAdapterAndroid == 0) return; |
| 647 nativeAdvanceFocusInForm(mNativeImeAdapterAndroid, focusType); |
| 648 } |
| 649 |
635 void notifyUserAction() { | 650 void notifyUserAction() { |
636 mInputMethodManagerWrapper.notifyUserAction(); | 651 mInputMethodManagerWrapper.notifyUserAction(); |
637 } | 652 } |
638 | 653 |
639 @VisibleForTesting | 654 @VisibleForTesting |
640 protected void sendSyntheticKeyPress(int keyCode, int flags) { | 655 protected void sendSyntheticKeyPress(int keyCode, int flags) { |
641 long eventTime = SystemClock.uptimeMillis(); | 656 long eventTime = SystemClock.uptimeMillis(); |
642 sendKeyEvent(new KeyEvent(eventTime, eventTime, | 657 sendKeyEvent(new KeyEvent(eventTime, eventTime, |
643 KeyEvent.ACTION_DOWN, keyCode, 0, 0, | 658 KeyEvent.ACTION_DOWN, keyCode, 0, 0, |
644 KeyCharacterMap.VIRTUAL_KEYBOARD, 0, | 659 KeyCharacterMap.VIRTUAL_KEYBOARD, 0, |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
900 private native void nativeSetEditableSelectionOffsets(long nativeImeAdapterA
ndroid, | 915 private native void nativeSetEditableSelectionOffsets(long nativeImeAdapterA
ndroid, |
901 int start, int end); | 916 int start, int end); |
902 private native void nativeSetComposingRegion(long nativeImeAdapterAndroid, i
nt start, int end); | 917 private native void nativeSetComposingRegion(long nativeImeAdapterAndroid, i
nt start, int end); |
903 private native void nativeDeleteSurroundingText(long nativeImeAdapterAndroid
, | 918 private native void nativeDeleteSurroundingText(long nativeImeAdapterAndroid
, |
904 int before, int after); | 919 int before, int after); |
905 private native void nativeDeleteSurroundingTextInCodePoints( | 920 private native void nativeDeleteSurroundingTextInCodePoints( |
906 long nativeImeAdapterAndroid, int before, int after); | 921 long nativeImeAdapterAndroid, int before, int after); |
907 private native boolean nativeRequestTextInputStateUpdate(long nativeImeAdapt
erAndroid); | 922 private native boolean nativeRequestTextInputStateUpdate(long nativeImeAdapt
erAndroid); |
908 private native void nativeRequestCursorUpdate(long nativeImeAdapterAndroid, | 923 private native void nativeRequestCursorUpdate(long nativeImeAdapterAndroid, |
909 boolean immediateRequest, boolean monitorRequest); | 924 boolean immediateRequest, boolean monitorRequest); |
| 925 private native void nativeAdvanceFocusInForm(long nativeImeAdapterAndroid, i
nt focusType); |
910 } | 926 } |
OLD | NEW |