| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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.text.Editable; | 7 import android.text.Editable; |
| 8 import android.text.InputType; | 8 import android.text.InputType; |
| 9 import android.text.Selection; | 9 import android.text.Selection; |
| 10 import android.util.StringBuilderPrinter; | 10 import android.util.StringBuilderPrinter; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_WEB_
EDIT_TEXT; | 42 EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_WEB_
EDIT_TEXT; |
| 43 | 43 |
| 44 if ((inputFlags & WebTextInputFlags.AutocompleteOff) != 0) { | 44 if ((inputFlags & WebTextInputFlags.AutocompleteOff) != 0) { |
| 45 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS; | 45 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS; |
| 46 } | 46 } |
| 47 | 47 |
| 48 int imeAction = 0; | 48 int imeAction = 0; |
| 49 if (inputMode == WebTextInputMode.kDefault) { | 49 if (inputMode == WebTextInputMode.kDefault) { |
| 50 if (inputType == TextInputType.TEXT) { | 50 if (inputType == TextInputType.TEXT) { |
| 51 // Normal text field | 51 // Normal text field |
| 52 imeAction = EditorInfo.IME_ACTION_GO; | |
| 53 if ((inputFlags & WebTextInputFlags.AutocorrectOff) == 0) { | 52 if ((inputFlags & WebTextInputFlags.AutocorrectOff) == 0) { |
| 54 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT
; | 53 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT
; |
| 55 } | 54 } |
| 56 } else if (inputType == TextInputType.TEXT_AREA | 55 } else if (inputType == TextInputType.TEXT_AREA |
| 57 || inputType == TextInputType.CONTENT_EDITABLE) { | 56 || inputType == TextInputType.CONTENT_EDITABLE) { |
| 58 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE; | 57 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE; |
| 59 if ((inputFlags & WebTextInputFlags.AutocorrectOff) == 0) { | 58 if ((inputFlags & WebTextInputFlags.AutocorrectOff) == 0) { |
| 60 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT
; | 59 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT
; |
| 61 } | 60 } |
| 62 imeAction = EditorInfo.IME_ACTION_NONE; | |
| 63 } else if (inputType == TextInputType.PASSWORD) { | 61 } else if (inputType == TextInputType.PASSWORD) { |
| 64 outAttrs.inputType = | 62 outAttrs.inputType = |
| 65 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATIO
N_WEB_PASSWORD; | 63 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATIO
N_WEB_PASSWORD; |
| 66 imeAction = EditorInfo.IME_ACTION_GO; | |
| 67 } else if (inputType == TextInputType.SEARCH) { | 64 } else if (inputType == TextInputType.SEARCH) { |
| 68 imeAction = EditorInfo.IME_ACTION_SEARCH; | 65 imeAction = EditorInfo.IME_ACTION_SEARCH; |
| 69 } else if (inputType == TextInputType.URL) { | 66 } else if (inputType == TextInputType.URL) { |
| 70 outAttrs.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_
TEXT_VARIATION_URI; | 67 outAttrs.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_
TEXT_VARIATION_URI; |
| 71 imeAction = EditorInfo.IME_ACTION_GO; | |
| 72 } else if (inputType == TextInputType.EMAIL) { | 68 } else if (inputType == TextInputType.EMAIL) { |
| 73 // Email | 69 // Email |
| 74 outAttrs.inputType = | 70 outAttrs.inputType = |
| 75 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATIO
N_WEB_EMAIL_ADDRESS; | 71 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATIO
N_WEB_EMAIL_ADDRESS; |
| 76 imeAction = EditorInfo.IME_ACTION_GO; | |
| 77 } else if (inputType == TextInputType.TELEPHONE) { | 72 } else if (inputType == TextInputType.TELEPHONE) { |
| 78 // Telephone | 73 // Telephone |
| 79 // Number and telephone do not have both a Tab key and an | 74 // Number and telephone do not have both a Tab key and an |
| 80 // action in default OSK, so set the action to NEXT | 75 // action in default OSK, so set the action to NEXT |
| 81 outAttrs.inputType = InputType.TYPE_CLASS_PHONE; | 76 outAttrs.inputType = InputType.TYPE_CLASS_PHONE; |
| 82 imeAction = EditorInfo.IME_ACTION_NEXT; | |
| 83 } else if (inputType == TextInputType.NUMBER) { | 77 } else if (inputType == TextInputType.NUMBER) { |
| 84 // Number | 78 // Number |
| 85 outAttrs.inputType = InputType.TYPE_CLASS_NUMBER | 79 outAttrs.inputType = InputType.TYPE_CLASS_NUMBER |
| 86 | InputType.TYPE_NUMBER_VARIATION_NORMAL | 80 | InputType.TYPE_NUMBER_VARIATION_NORMAL |
| 87 | InputType.TYPE_NUMBER_FLAG_DECIMAL; | 81 | InputType.TYPE_NUMBER_FLAG_DECIMAL; |
| 88 imeAction = EditorInfo.IME_ACTION_NEXT; | |
| 89 } | 82 } |
| 90 } else { | 83 } else { |
| 91 switch (inputMode) { | 84 switch (inputMode) { |
| 92 default: | 85 default: |
| 93 case WebTextInputMode.kDefault: | 86 case WebTextInputMode.kDefault: |
| 94 case WebTextInputMode.kVerbatim: | 87 case WebTextInputMode.kVerbatim: |
| 95 case WebTextInputMode.kLatin: | 88 case WebTextInputMode.kLatin: |
| 96 case WebTextInputMode.kLatinName: | 89 case WebTextInputMode.kLatinName: |
| 97 case WebTextInputMode.kLatinProse: | 90 case WebTextInputMode.kLatinProse: |
| 98 case WebTextInputMode.kFullWidthLatin: | 91 case WebTextInputMode.kFullWidthLatin: |
| (...skipping 22 matching lines...) Expand all Loading... |
| 121 break; | 114 break; |
| 122 case WebTextInputMode.kUrl: | 115 case WebTextInputMode.kUrl: |
| 123 outAttrs.inputType = | 116 outAttrs.inputType = |
| 124 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARI
ATION_URI; | 117 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARI
ATION_URI; |
| 125 imeAction = EditorInfo.IME_ACTION_NEXT; | 118 imeAction = EditorInfo.IME_ACTION_NEXT; |
| 126 break; | 119 break; |
| 127 } | 120 } |
| 128 } | 121 } |
| 129 | 122 |
| 130 outAttrs.imeOptions |= imeAction; | 123 outAttrs.imeOptions |= imeAction; |
| 124 |
| 125 boolean enterKeyAction = false; |
| 126 // For multiline text or any text input with key event listeners, Enter
key is needed. |
| 127 if (((outAttrs.inputType & EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE) |
| 128 == EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE) |
| 129 || (inputFlags & WebTextInputFlags.ListeningToKeyboardEvents) !=
0) { |
| 130 // TODO(ajith.v) Find an option to remove Enter Key from IME (assume
by default |
| 131 // ENTER key is shown) |
| 132 // TODO(ajith.v) For text area with implicit form submission how do
we handle, |
| 133 // we need to show both GO and ENTER key at same time. |
| 134 outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO; |
| 135 enterKeyAction = true; |
| 136 } |
| 137 |
| 138 boolean nextKeyAction = false; |
| 139 // If ENTER key is already applied, then don't apply NEXT as it can resu
lt display issues in |
| 140 // IME |
| 141 if (!enterKeyAction && (inputFlags & WebTextInputFlags.HaveNextFocusable
Element) != 0) { |
| 142 outAttrs.imeOptions |= EditorInfo.IME_ACTION_NEXT; |
| 143 nextKeyAction = true; |
| 144 } |
| 145 // If ENTER/NEXT key is already applied, then don't apply PREVIOUS as it
can result display |
| 146 // issues in IME |
| 147 if (!enterKeyAction && !nextKeyAction |
| 148 && (inputFlags & WebTextInputFlags.HavePreviousFocusableElement)
!= 0) { |
| 149 outAttrs.imeOptions |= EditorInfo.IME_ACTION_PREVIOUS; |
| 150 } |
| 151 |
| 131 // Handling of autocapitalize. Blink will send the flag taking into acco
unt the element's | 152 // Handling of autocapitalize. Blink will send the flag taking into acco
unt the element's |
| 132 // type. This is not using AutocapitalizeNone because Android does not a
utocapitalize by | 153 // type. This is not using AutocapitalizeNone because Android does not a
utocapitalize by |
| 133 // default and there is no way to express no capitalization. | 154 // default and there is no way to express no capitalization. |
| 134 // Autocapitalize is meant as a hint to the virtual keyboard. | 155 // Autocapitalize is meant as a hint to the virtual keyboard. |
| 135 if ((inputFlags & WebTextInputFlags.AutocapitalizeCharacters) != 0) { | 156 if ((inputFlags & WebTextInputFlags.AutocapitalizeCharacters) != 0) { |
| 136 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS; | 157 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS; |
| 137 } else if ((inputFlags & WebTextInputFlags.AutocapitalizeWords) != 0) { | 158 } else if ((inputFlags & WebTextInputFlags.AutocapitalizeWords) != 0) { |
| 138 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_WORDS; | 159 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_WORDS; |
| 139 } else if ((inputFlags & WebTextInputFlags.AutocapitalizeSentences) != 0
) { | 160 } else if ((inputFlags & WebTextInputFlags.AutocapitalizeSentences) != 0
) { |
| 140 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_SENTENCES; | 161 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_SENTENCES; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 if (!condition) throw new AssertionError(msg); | 218 if (!condition) throw new AssertionError(msg); |
| 198 } | 219 } |
| 199 | 220 |
| 200 /** | 221 /** |
| 201 * Check that the current thread is UI thread, and raise an error if it is n
ot. | 222 * Check that the current thread is UI thread, and raise an error if it is n
ot. |
| 202 */ | 223 */ |
| 203 static void checkOnUiThread() { | 224 static void checkOnUiThread() { |
| 204 checkCondition("Should be on UI thread.", ThreadUtils.runningOnUiThread(
)); | 225 checkCondition("Should be on UI thread.", ThreadUtils.runningOnUiThread(
)); |
| 205 } | 226 } |
| 206 } | 227 } |
| OLD | NEW |