| 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 23 matching lines...) Expand all Loading... |
| 34 * @param initialSelStart The initial selection start position. | 34 * @param initialSelStart The initial selection start position. |
| 35 * @param initialSelEnd The initial selection end position. | 35 * @param initialSelEnd The initial selection end position. |
| 36 * @param outAttrs An instance of {@link EditorInfo} that we are going to ch
ange. | 36 * @param outAttrs An instance of {@link EditorInfo} that we are going to ch
ange. |
| 37 */ | 37 */ |
| 38 public static void computeEditorInfo(int inputType, int inputFlags, int inpu
tMode, | 38 public static void computeEditorInfo(int inputType, int inputFlags, int inpu
tMode, |
| 39 int initialSelStart, int initialSelEnd, EditorInfo outAttrs) { | 39 int initialSelStart, int initialSelEnd, EditorInfo outAttrs) { |
| 40 outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_FULLSCREEN | EditorInfo.IME
_FLAG_NO_EXTRACT_UI; | 40 outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_FULLSCREEN | EditorInfo.IME
_FLAG_NO_EXTRACT_UI; |
| 41 outAttrs.inputType = | 41 outAttrs.inputType = |
| 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.kAutocompleteOff) != 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.kDefault) { | 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; | 52 imeAction = EditorInfo.IME_ACTION_GO; |
| 53 if ((inputFlags & WebTextInputFlags.kAutocorrectOff) == 0) { | 53 if ((inputFlags & WebTextInputFlags.AUTOCORRECT_OFF) == 0) { |
| 54 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT
; | 54 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT
; |
| 55 } | 55 } |
| 56 } else if (inputType == TextInputType.TEXT_AREA | 56 } else if (inputType == TextInputType.TEXT_AREA |
| 57 || inputType == TextInputType.CONTENT_EDITABLE) { | 57 || inputType == TextInputType.CONTENT_EDITABLE) { |
| 58 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE; | 58 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE; |
| 59 if ((inputFlags & WebTextInputFlags.kAutocorrectOff) == 0) { | 59 if ((inputFlags & WebTextInputFlags.AUTOCORRECT_OFF) == 0) { |
| 60 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT
; | 60 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT
; |
| 61 } | 61 } |
| 62 imeAction = EditorInfo.IME_ACTION_NONE; | 62 imeAction = EditorInfo.IME_ACTION_NONE; |
| 63 } else if (inputType == TextInputType.PASSWORD) { | 63 } else if (inputType == TextInputType.PASSWORD) { |
| 64 outAttrs.inputType = | 64 outAttrs.inputType = |
| 65 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATIO
N_WEB_PASSWORD; | 65 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATIO
N_WEB_PASSWORD; |
| 66 imeAction = EditorInfo.IME_ACTION_GO; | 66 imeAction = EditorInfo.IME_ACTION_GO; |
| 67 } else if (inputType == TextInputType.SEARCH) { | 67 } else if (inputType == TextInputType.SEARCH) { |
| 68 imeAction = EditorInfo.IME_ACTION_SEARCH; | 68 imeAction = EditorInfo.IME_ACTION_SEARCH; |
| 69 } else if (inputType == TextInputType.URL) { | 69 } else if (inputType == TextInputType.URL) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 83 } else if (inputType == TextInputType.NUMBER) { | 83 } else if (inputType == TextInputType.NUMBER) { |
| 84 // Number | 84 // Number |
| 85 outAttrs.inputType = InputType.TYPE_CLASS_NUMBER | 85 outAttrs.inputType = InputType.TYPE_CLASS_NUMBER |
| 86 | InputType.TYPE_NUMBER_VARIATION_NORMAL | 86 | InputType.TYPE_NUMBER_VARIATION_NORMAL |
| 87 | InputType.TYPE_NUMBER_FLAG_DECIMAL; | 87 | InputType.TYPE_NUMBER_FLAG_DECIMAL; |
| 88 imeAction = EditorInfo.IME_ACTION_NEXT; | 88 imeAction = EditorInfo.IME_ACTION_NEXT; |
| 89 } | 89 } |
| 90 } else { | 90 } else { |
| 91 switch (inputMode) { | 91 switch (inputMode) { |
| 92 default: | 92 default: |
| 93 case WebTextInputMode.kDefault: | 93 case WebTextInputMode.DEFAULT: |
| 94 case WebTextInputMode.kVerbatim: | 94 case WebTextInputMode.VERBATIM: |
| 95 case WebTextInputMode.kLatin: | 95 case WebTextInputMode.LATIN: |
| 96 case WebTextInputMode.kLatinName: | 96 case WebTextInputMode.LATIN_NAME: |
| 97 case WebTextInputMode.kLatinProse: | 97 case WebTextInputMode.LATIN_PROSE: |
| 98 case WebTextInputMode.kFullWidthLatin: | 98 case WebTextInputMode.FULL_WIDTH_LATIN: |
| 99 case WebTextInputMode.kKana: | 99 case WebTextInputMode.KANA: |
| 100 case WebTextInputMode.kKanaName: | 100 case WebTextInputMode.KANA_NAME: |
| 101 case WebTextInputMode.kKataKana: | 101 case WebTextInputMode.KATA_KANA: |
| 102 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE; | 102 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE; |
| 103 if ((inputFlags & WebTextInputFlags.kAutocorrectOff) == 0) { | 103 if ((inputFlags & WebTextInputFlags.AUTOCORRECT_OFF) == 0) { |
| 104 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_COR
RECT; | 104 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_COR
RECT; |
| 105 } | 105 } |
| 106 imeAction = EditorInfo.IME_ACTION_NONE; | 106 imeAction = EditorInfo.IME_ACTION_NONE; |
| 107 break; | 107 break; |
| 108 case WebTextInputMode.kNumeric: | 108 case WebTextInputMode.NUMERIC: |
| 109 outAttrs.inputType = | 109 outAttrs.inputType = |
| 110 InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_
VARIATION_NORMAL; | 110 InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_
VARIATION_NORMAL; |
| 111 imeAction = EditorInfo.IME_ACTION_NEXT; | 111 imeAction = EditorInfo.IME_ACTION_NEXT; |
| 112 break; | 112 break; |
| 113 case WebTextInputMode.kTel: | 113 case WebTextInputMode.TEL: |
| 114 outAttrs.inputType = InputType.TYPE_CLASS_PHONE; | 114 outAttrs.inputType = InputType.TYPE_CLASS_PHONE; |
| 115 imeAction = EditorInfo.IME_ACTION_NEXT; | 115 imeAction = EditorInfo.IME_ACTION_NEXT; |
| 116 break; | 116 break; |
| 117 case WebTextInputMode.kEmail: | 117 case WebTextInputMode.EMAIL: |
| 118 outAttrs.inputType = InputType.TYPE_CLASS_TEXT | 118 outAttrs.inputType = InputType.TYPE_CLASS_TEXT |
| 119 | InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS; | 119 | InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS; |
| 120 imeAction = EditorInfo.IME_ACTION_GO; | 120 imeAction = EditorInfo.IME_ACTION_GO; |
| 121 break; | 121 break; |
| 122 case WebTextInputMode.kUrl: | 122 case WebTextInputMode.URL: |
| 123 outAttrs.inputType = | 123 outAttrs.inputType = |
| 124 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARI
ATION_URI; | 124 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARI
ATION_URI; |
| 125 imeAction = EditorInfo.IME_ACTION_NEXT; | 125 imeAction = EditorInfo.IME_ACTION_NEXT; |
| 126 break; | 126 break; |
| 127 } | 127 } |
| 128 } | 128 } |
| 129 | 129 |
| 130 outAttrs.imeOptions |= imeAction; | 130 outAttrs.imeOptions |= imeAction; |
| 131 // Handling of autocapitalize. Blink will send the flag taking into acco
unt the element's | 131 // 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 | 132 // type. This is not using AutocapitalizeNone because Android does not a
utocapitalize by |
| 133 // default and there is no way to express no capitalization. | 133 // default and there is no way to express no capitalization. |
| 134 // Autocapitalize is meant as a hint to the virtual keyboard. | 134 // Autocapitalize is meant as a hint to the virtual keyboard. |
| 135 if ((inputFlags & WebTextInputFlags.kAutocapitalizeCharacters) != 0) { | 135 if ((inputFlags & WebTextInputFlags.AUTOCAPITALIZE_CHARACTERS) != 0) { |
| 136 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS; | 136 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS; |
| 137 } else if ((inputFlags & WebTextInputFlags.kAutocapitalizeWords) != 0) { | 137 } else if ((inputFlags & WebTextInputFlags.AUTOCAPITALIZE_WORDS) != 0) { |
| 138 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_WORDS; | 138 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_WORDS; |
| 139 } else if ((inputFlags & WebTextInputFlags.kAutocapitalizeSentences) !=
0) { | 139 } else if ((inputFlags & WebTextInputFlags.AUTOCAPITALIZE_SENTENCES) !=
0) { |
| 140 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_SENTENCES; | 140 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_SENTENCES; |
| 141 } | 141 } |
| 142 // Content editable doesn't use autocapitalize so we need to set it manu
ally. | 142 // Content editable doesn't use autocapitalize so we need to set it manu
ally. |
| 143 if (inputType == TextInputType.CONTENT_EDITABLE) { | 143 if (inputType == TextInputType.CONTENT_EDITABLE) { |
| 144 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_SENTENCES; | 144 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_SENTENCES; |
| 145 } | 145 } |
| 146 | 146 |
| 147 outAttrs.initialSelStart = initialSelStart; | 147 outAttrs.initialSelStart = initialSelStart; |
| 148 outAttrs.initialSelEnd = initialSelEnd; | 148 outAttrs.initialSelEnd = initialSelEnd; |
| 149 } | 149 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 if (!condition) throw new AssertionError(msg); | 197 if (!condition) throw new AssertionError(msg); |
| 198 } | 198 } |
| 199 | 199 |
| 200 /** | 200 /** |
| 201 * Check that the current thread is UI thread, and raise an error if it is n
ot. | 201 * Check that the current thread is UI thread, and raise an error if it is n
ot. |
| 202 */ | 202 */ |
| 203 static void checkOnUiThread() { | 203 static void checkOnUiThread() { |
| 204 checkCondition("Should be on UI thread.", ThreadUtils.runningOnUiThread(
)); | 204 checkCondition("Should be on UI thread.", ThreadUtils.runningOnUiThread(
)); |
| 205 } | 205 } |
| 206 } | 206 } |
| OLD | NEW |