| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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.SystemClock; | 7 import android.os.SystemClock; |
| 8 import android.text.Editable; | 8 import android.text.Editable; |
| 9 import android.text.InputType; | 9 import android.text.InputType; |
| 10 import android.text.Selection; | 10 import android.text.Selection; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 | EditorInfo.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT; | 70 | EditorInfo.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT; |
| 71 | 71 |
| 72 int inputType = imeAdapter.getTextInputType(); | 72 int inputType = imeAdapter.getTextInputType(); |
| 73 int inputFlags = imeAdapter.getTextInputFlags(); | 73 int inputFlags = imeAdapter.getTextInputFlags(); |
| 74 if ((inputFlags & WebTextInputFlags.AutocompleteOff) != 0) { | 74 if ((inputFlags & WebTextInputFlags.AutocompleteOff) != 0) { |
| 75 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS; | 75 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS; |
| 76 } | 76 } |
| 77 | 77 |
| 78 if (inputType == TextInputType.TEXT) { | 78 if (inputType == TextInputType.TEXT) { |
| 79 // Normal text field | 79 // Normal text field |
| 80 outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO; | |
| 81 if ((inputFlags & WebTextInputFlags.AutocorrectOff) == 0) { | 80 if ((inputFlags & WebTextInputFlags.AutocorrectOff) == 0) { |
| 82 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT; | 81 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT; |
| 83 } | 82 } |
| 84 } else if (inputType == TextInputType.TEXT_AREA | 83 } else if (inputType == TextInputType.TEXT_AREA |
| 85 || inputType == TextInputType.CONTENT_EDITABLE) { | 84 || inputType == TextInputType.CONTENT_EDITABLE) { |
| 86 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE; | 85 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE; |
| 87 if ((inputFlags & WebTextInputFlags.AutocorrectOff) == 0) { | 86 if ((inputFlags & WebTextInputFlags.AutocorrectOff) == 0) { |
| 88 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT; | 87 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT; |
| 89 } | 88 } |
| 90 outAttrs.imeOptions |= EditorInfo.IME_ACTION_NONE; | |
| 91 mSingleLine = false; | 89 mSingleLine = false; |
| 92 } else if (inputType == TextInputType.PASSWORD) { | 90 } else if (inputType == TextInputType.PASSWORD) { |
| 93 // Password | 91 // Password |
| 94 outAttrs.inputType = InputType.TYPE_CLASS_TEXT | 92 outAttrs.inputType = InputType.TYPE_CLASS_TEXT |
| 95 | InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD; | 93 | InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD; |
| 96 outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO; | |
| 97 } else if (inputType == TextInputType.SEARCH) { | 94 } else if (inputType == TextInputType.SEARCH) { |
| 98 // Search | 95 // Search |
| 99 outAttrs.imeOptions |= EditorInfo.IME_ACTION_SEARCH; | 96 outAttrs.imeOptions |= EditorInfo.IME_ACTION_SEARCH; |
| 100 } else if (inputType == TextInputType.URL) { | 97 } else if (inputType == TextInputType.URL) { |
| 101 // Url | 98 // Url |
| 102 outAttrs.inputType = InputType.TYPE_CLASS_TEXT | 99 outAttrs.inputType = InputType.TYPE_CLASS_TEXT |
| 103 | InputType.TYPE_TEXT_VARIATION_URI; | 100 | InputType.TYPE_TEXT_VARIATION_URI; |
| 104 outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO; | |
| 105 } else if (inputType == TextInputType.EMAIL) { | 101 } else if (inputType == TextInputType.EMAIL) { |
| 106 // Email | 102 // Email |
| 107 outAttrs.inputType = InputType.TYPE_CLASS_TEXT | 103 outAttrs.inputType = InputType.TYPE_CLASS_TEXT |
| 108 | InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS; | 104 | InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS; |
| 109 outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO; | |
| 110 } else if (inputType == TextInputType.TELEPHONE) { | 105 } else if (inputType == TextInputType.TELEPHONE) { |
| 111 // Telephone | 106 // Telephone |
| 112 // Number and telephone do not have both a Tab key and an | 107 // Number and telephone do not have both a Tab key and an |
| 113 // action in default OSK, so set the action to NEXT | 108 // action in default OSK, so set the action to NEXT |
| 114 outAttrs.inputType = InputType.TYPE_CLASS_PHONE; | 109 outAttrs.inputType = InputType.TYPE_CLASS_PHONE; |
| 115 outAttrs.imeOptions |= EditorInfo.IME_ACTION_NEXT; | |
| 116 } else if (inputType == TextInputType.NUMBER) { | 110 } else if (inputType == TextInputType.NUMBER) { |
| 117 // Number | 111 // Number |
| 118 outAttrs.inputType = InputType.TYPE_CLASS_NUMBER | 112 outAttrs.inputType = InputType.TYPE_CLASS_NUMBER |
| 119 | InputType.TYPE_NUMBER_VARIATION_NORMAL | 113 | InputType.TYPE_NUMBER_VARIATION_NORMAL |
| 120 | InputType.TYPE_NUMBER_FLAG_DECIMAL; | 114 | InputType.TYPE_NUMBER_FLAG_DECIMAL; |
| 115 } |
| 116 |
| 117 boolean haveNextInput = false; |
| 118 if ((inputFlags & WebTextInputFlags.HaveNextFocusableElement) != 0) { |
| 121 outAttrs.imeOptions |= EditorInfo.IME_ACTION_NEXT; | 119 outAttrs.imeOptions |= EditorInfo.IME_ACTION_NEXT; |
| 120 haveNextInput = true; |
| 121 } |
| 122 if ((inputFlags & WebTextInputFlags.HavePreviousFocusableElement) != 0)
{ |
| 123 outAttrs.imeOptions |= EditorInfo.IME_ACTION_PREVIOUS; |
| 124 } |
| 125 if (mSingleLine && (inputFlags & WebTextInputFlags.ListeningToKeyboardEv
ents) == 0) { |
| 126 // TODO(AKV) Find an option to remove Enter Key from IME |
| 127 if (!haveNextInput) outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO; |
| 122 } | 128 } |
| 123 | 129 |
| 124 // Handling of autocapitalize. Blink will send the flag taking into acco
unt the element's | 130 // Handling of autocapitalize. Blink will send the flag taking into acco
unt the element's |
| 125 // type. This is not using AutocapitalizeNone because Android does not a
utocapitalize by | 131 // type. This is not using AutocapitalizeNone because Android does not a
utocapitalize by |
| 126 // default and there is no way to express no capitalization. | 132 // default and there is no way to express no capitalization. |
| 127 // Autocapitalize is meant as a hint to the virtual keyboard. | 133 // Autocapitalize is meant as a hint to the virtual keyboard. |
| 128 if ((inputFlags & WebTextInputFlags.AutocapitalizeCharacters) != 0) { | 134 if ((inputFlags & WebTextInputFlags.AutocapitalizeCharacters) != 0) { |
| 129 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS; | 135 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS; |
| 130 } else if ((inputFlags & WebTextInputFlags.AutocapitalizeWords) != 0) { | 136 } else if ((inputFlags & WebTextInputFlags.AutocapitalizeWords) != 0) { |
| 131 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_WORDS; | 137 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_WORDS; |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 return mImeAdapter.checkCompositionQueueAndCallNative(text, newCursorPos
ition, | 280 return mImeAdapter.checkCompositionQueueAndCallNative(text, newCursorPos
ition, |
| 275 text.length() > 0); | 281 text.length() > 0); |
| 276 } | 282 } |
| 277 | 283 |
| 278 /** | 284 /** |
| 279 * @see BaseInputConnection#performEditorAction(int) | 285 * @see BaseInputConnection#performEditorAction(int) |
| 280 */ | 286 */ |
| 281 @Override | 287 @Override |
| 282 public boolean performEditorAction(int actionCode) { | 288 public boolean performEditorAction(int actionCode) { |
| 283 if (DEBUG) Log.w(TAG, "performEditorAction [" + actionCode + "]"); | 289 if (DEBUG) Log.w(TAG, "performEditorAction [" + actionCode + "]"); |
| 284 if (actionCode == EditorInfo.IME_ACTION_NEXT) { | 290 switch (actionCode) { |
| 285 restartInput(); | 291 case EditorInfo.IME_ACTION_NEXT: |
| 286 // Send TAB key event | 292 restartInput(); |
| 287 long timeStampMs = SystemClock.uptimeMillis(); | 293 mImeAdapter.advanceFocusToNextFormControl(true); |
| 288 mImeAdapter.sendSyntheticKeyEvent( | 294 break; |
| 289 WebInputEventType.RawKeyDown, timeStampMs, KeyEvent.KEYCODE_
TAB, 0, 0); | 295 case EditorInfo.IME_ACTION_PREVIOUS: |
| 290 } else { | 296 restartInput(); |
| 291 mImeAdapter.sendKeyEventWithKeyCode(KeyEvent.KEYCODE_ENTER, | 297 mImeAdapter.advanceFocusToNextFormControl(false); |
| 292 KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE | 298 break; |
| 293 | KeyEvent.FLAG_EDITOR_ACTION); | 299 default: |
| 300 mImeAdapter.sendKeyEventWithKeyCode( |
| 301 KeyEvent.KEYCODE_ENTER, KeyEvent.FLAG_SOFT_KEYBOARD |
| 302 | KeyEvent.FLAG_KEEP_TOUCH_MODE | KeyEvent.FLAG_
EDITOR_ACTION); |
| 303 break; |
| 294 } | 304 } |
| 295 return true; | 305 return true; |
| 296 } | 306 } |
| 297 | 307 |
| 298 /** | 308 /** |
| 299 * @see BaseInputConnection#performContextMenuAction(int) | 309 * @see BaseInputConnection#performContextMenuAction(int) |
| 300 */ | 310 */ |
| 301 @Override | 311 @Override |
| 302 public boolean performContextMenuAction(int id) { | 312 public boolean performContextMenuAction(int id) { |
| 303 if (DEBUG) Log.w(TAG, "performContextMenuAction [" + id + "]"); | 313 if (DEBUG) Log.w(TAG, "performContextMenuAction [" + id + "]"); |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 @VisibleForTesting | 632 @VisibleForTesting |
| 623 ImeState getImeStateForTesting() { | 633 ImeState getImeStateForTesting() { |
| 624 String text = mEditable.toString(); | 634 String text = mEditable.toString(); |
| 625 int selectionStart = Selection.getSelectionStart(mEditable); | 635 int selectionStart = Selection.getSelectionStart(mEditable); |
| 626 int selectionEnd = Selection.getSelectionEnd(mEditable); | 636 int selectionEnd = Selection.getSelectionEnd(mEditable); |
| 627 int compositionStart = getComposingSpanStart(mEditable); | 637 int compositionStart = getComposingSpanStart(mEditable); |
| 628 int compositionEnd = getComposingSpanEnd(mEditable); | 638 int compositionEnd = getComposingSpanEnd(mEditable); |
| 629 return new ImeState(text, selectionStart, selectionEnd, compositionStart
, compositionEnd); | 639 return new ImeState(text, selectionStart, selectionEnd, compositionStart
, compositionEnd); |
| 630 } | 640 } |
| 631 } | 641 } |
| OLD | NEW |