| 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.AUTOCOMPLETE_OFF) != 0) { | 44 if ((inputFlags & WebTextInputFlags.AUTOCOMPLETE_OFF) != 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.DEFAULT) { | 49 if (inputMode == WebTextInputMode.DEFAULT) { |
| 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.AUTOCORRECT_OFF) == 0) { | 52 if ((inputFlags & WebTextInputFlags.AUTOCORRECT_OFF) == 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.AUTOCORRECT_OFF) == 0) { | 58 if ((inputFlags & WebTextInputFlags.AUTOCORRECT_OFF) == 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.DEFAULT: | 86 case WebTextInputMode.DEFAULT: |
| 94 case WebTextInputMode.VERBATIM: | 87 case WebTextInputMode.VERBATIM: |
| 95 case WebTextInputMode.LATIN: | 88 case WebTextInputMode.LATIN: |
| 96 case WebTextInputMode.LATIN_NAME: | 89 case WebTextInputMode.LATIN_NAME: |
| 97 case WebTextInputMode.LATIN_PROSE: | 90 case WebTextInputMode.LATIN_PROSE: |
| 98 case WebTextInputMode.FULL_WIDTH_LATIN: | 91 case WebTextInputMode.FULL_WIDTH_LATIN: |
| 99 case WebTextInputMode.KANA: | 92 case WebTextInputMode.KANA: |
| 100 case WebTextInputMode.KANA_NAME: | 93 case WebTextInputMode.KANA_NAME: |
| 101 case WebTextInputMode.KATA_KANA: | 94 case WebTextInputMode.KATA_KANA: |
| 102 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE; | 95 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE; |
| 103 if ((inputFlags & WebTextInputFlags.AUTOCORRECT_OFF) == 0) { | 96 if ((inputFlags & WebTextInputFlags.AUTOCORRECT_OFF) == 0) { |
| 104 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_COR
RECT; | 97 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_COR
RECT; |
| 105 } | 98 } |
| 106 imeAction = EditorInfo.IME_ACTION_NONE; | |
| 107 break; | 99 break; |
| 108 case WebTextInputMode.NUMERIC: | 100 case WebTextInputMode.NUMERIC: |
| 109 outAttrs.inputType = | 101 outAttrs.inputType = |
| 110 InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_
VARIATION_NORMAL; | 102 InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_
VARIATION_NORMAL; |
| 111 imeAction = EditorInfo.IME_ACTION_NEXT; | |
| 112 break; | 103 break; |
| 113 case WebTextInputMode.TEL: | 104 case WebTextInputMode.TEL: |
| 114 outAttrs.inputType = InputType.TYPE_CLASS_PHONE; | 105 outAttrs.inputType = InputType.TYPE_CLASS_PHONE; |
| 115 imeAction = EditorInfo.IME_ACTION_NEXT; | |
| 116 break; | 106 break; |
| 117 case WebTextInputMode.EMAIL: | 107 case WebTextInputMode.EMAIL: |
| 118 outAttrs.inputType = InputType.TYPE_CLASS_TEXT | 108 outAttrs.inputType = InputType.TYPE_CLASS_TEXT |
| 119 | InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS; | 109 | InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS; |
| 120 imeAction = EditorInfo.IME_ACTION_GO; | |
| 121 break; | 110 break; |
| 122 case WebTextInputMode.URL: | 111 case WebTextInputMode.URL: |
| 123 outAttrs.inputType = | 112 outAttrs.inputType = |
| 124 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARI
ATION_URI; | 113 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARI
ATION_URI; |
| 125 imeAction = EditorInfo.IME_ACTION_NEXT; | |
| 126 break; | 114 break; |
| 127 } | 115 } |
| 128 } | 116 } |
| 129 | 117 |
| 130 outAttrs.imeOptions |= imeAction; | 118 outAttrs.imeOptions |= imeAction; |
| 119 |
| 120 // For multiline text or any text input with key event listeners, ENTER
key is needed. |
| 121 if ((outAttrs.inputType & EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE) != 0) { |
| 122 // For textarea that sends you to another webpage on enter key press
using |
| 123 // JavaScript, we will only show ENTER. |
| 124 outAttrs.imeOptions |= EditorInfo.IME_ACTION_NONE; |
| 125 } else if ((inputFlags & WebTextInputFlags.HAVE_NEXT_FOCUSABLE_ELEMENT)
!= 0) { |
| 126 outAttrs.imeOptions |= EditorInfo.IME_ACTION_NEXT; |
| 127 } else { |
| 128 // For last element inside form, we should give preference to GO key
as PREVIOUS |
| 129 // has less importance in those cases. |
| 130 outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO; |
| 131 } |
| 132 |
| 131 // Handling of autocapitalize. Blink will send the flag taking into acco
unt the element's | 133 // 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 | 134 // type. This is not using AutocapitalizeNone because Android does not a
utocapitalize by |
| 133 // default and there is no way to express no capitalization. | 135 // default and there is no way to express no capitalization. |
| 134 // Autocapitalize is meant as a hint to the virtual keyboard. | 136 // Autocapitalize is meant as a hint to the virtual keyboard. |
| 135 if ((inputFlags & WebTextInputFlags.AUTOCAPITALIZE_CHARACTERS) != 0) { | 137 if ((inputFlags & WebTextInputFlags.AUTOCAPITALIZE_CHARACTERS) != 0) { |
| 136 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS; | 138 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS; |
| 137 } else if ((inputFlags & WebTextInputFlags.AUTOCAPITALIZE_WORDS) != 0) { | 139 } else if ((inputFlags & WebTextInputFlags.AUTOCAPITALIZE_WORDS) != 0) { |
| 138 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_WORDS; | 140 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_WORDS; |
| 139 } else if ((inputFlags & WebTextInputFlags.AUTOCAPITALIZE_SENTENCES) !=
0) { | 141 } else if ((inputFlags & WebTextInputFlags.AUTOCAPITALIZE_SENTENCES) !=
0) { |
| 140 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_SENTENCES; | 142 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); | 199 if (!condition) throw new AssertionError(msg); |
| 198 } | 200 } |
| 199 | 201 |
| 200 /** | 202 /** |
| 201 * Check that the current thread is UI thread, and raise an error if it is n
ot. | 203 * Check that the current thread is UI thread, and raise an error if it is n
ot. |
| 202 */ | 204 */ |
| 203 static void checkOnUiThread() { | 205 static void checkOnUiThread() { |
| 204 checkCondition("Should be on UI thread.", ThreadUtils.runningOnUiThread(
)); | 206 checkCondition("Should be on UI thread.", ThreadUtils.runningOnUiThread(
)); |
| 205 } | 207 } |
| 206 } | 208 } |
| OLD | NEW |