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 30 matching lines...) Expand all Loading... |
41 EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_WEB_
EDIT_TEXT; | 41 EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_WEB_
EDIT_TEXT; |
42 | 42 |
43 if ((inputFlags & WebTextInputFlags.AUTOCOMPLETE_OFF) != 0) { | 43 if ((inputFlags & WebTextInputFlags.AUTOCOMPLETE_OFF) != 0) { |
44 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS; | 44 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS; |
45 } | 45 } |
46 | 46 |
47 int imeAction = 0; | 47 int imeAction = 0; |
48 if (inputMode == WebTextInputMode.DEFAULT) { | 48 if (inputMode == WebTextInputMode.DEFAULT) { |
49 if (inputType == TextInputType.TEXT) { | 49 if (inputType == TextInputType.TEXT) { |
50 // Normal text field | 50 // Normal text field |
| 51 imeAction = EditorInfo.IME_ACTION_GO; |
51 if ((inputFlags & WebTextInputFlags.AUTOCORRECT_OFF) == 0) { | 52 if ((inputFlags & WebTextInputFlags.AUTOCORRECT_OFF) == 0) { |
52 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT
; | 53 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT
; |
53 } | 54 } |
54 } else if (inputType == TextInputType.TEXT_AREA | 55 } else if (inputType == TextInputType.TEXT_AREA |
55 || inputType == TextInputType.CONTENT_EDITABLE) { | 56 || inputType == TextInputType.CONTENT_EDITABLE) { |
56 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE; | 57 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE; |
57 if ((inputFlags & WebTextInputFlags.AUTOCORRECT_OFF) == 0) { | 58 if ((inputFlags & WebTextInputFlags.AUTOCORRECT_OFF) == 0) { |
58 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT
; | 59 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT
; |
59 } | 60 } |
| 61 imeAction = EditorInfo.IME_ACTION_NONE; |
60 } else if (inputType == TextInputType.PASSWORD) { | 62 } else if (inputType == TextInputType.PASSWORD) { |
61 outAttrs.inputType = | 63 outAttrs.inputType = |
62 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATIO
N_WEB_PASSWORD; | 64 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATIO
N_WEB_PASSWORD; |
| 65 imeAction = EditorInfo.IME_ACTION_GO; |
| 66 } else if (inputType == TextInputType.SEARCH) { |
| 67 imeAction = EditorInfo.IME_ACTION_SEARCH; |
63 } else if (inputType == TextInputType.URL) { | 68 } else if (inputType == TextInputType.URL) { |
64 outAttrs.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_
TEXT_VARIATION_URI; | 69 outAttrs.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_
TEXT_VARIATION_URI; |
| 70 imeAction = EditorInfo.IME_ACTION_GO; |
65 } else if (inputType == TextInputType.EMAIL) { | 71 } else if (inputType == TextInputType.EMAIL) { |
66 // Email | 72 // Email |
67 outAttrs.inputType = | 73 outAttrs.inputType = |
68 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATIO
N_WEB_EMAIL_ADDRESS; | 74 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATIO
N_WEB_EMAIL_ADDRESS; |
| 75 imeAction = EditorInfo.IME_ACTION_GO; |
69 } else if (inputType == TextInputType.TELEPHONE) { | 76 } else if (inputType == TextInputType.TELEPHONE) { |
70 // Telephone | 77 // Telephone |
71 // Number and telephone do not have both a Tab key and an | 78 // Number and telephone do not have both a Tab key and an |
72 // action in default OSK, so set the action to NEXT | 79 // action in default OSK, so set the action to NEXT |
73 outAttrs.inputType = InputType.TYPE_CLASS_PHONE; | 80 outAttrs.inputType = InputType.TYPE_CLASS_PHONE; |
| 81 imeAction = EditorInfo.IME_ACTION_NEXT; |
74 } else if (inputType == TextInputType.NUMBER) { | 82 } else if (inputType == TextInputType.NUMBER) { |
75 // Number | 83 // Number |
76 outAttrs.inputType = InputType.TYPE_CLASS_NUMBER | 84 outAttrs.inputType = InputType.TYPE_CLASS_NUMBER |
77 | InputType.TYPE_NUMBER_VARIATION_NORMAL | 85 | InputType.TYPE_NUMBER_VARIATION_NORMAL |
78 | InputType.TYPE_NUMBER_FLAG_DECIMAL; | 86 | InputType.TYPE_NUMBER_FLAG_DECIMAL; |
| 87 imeAction = EditorInfo.IME_ACTION_NEXT; |
79 } | 88 } |
80 } else { | 89 } else { |
81 switch (inputMode) { | 90 switch (inputMode) { |
82 default: | 91 default: |
83 case WebTextInputMode.DEFAULT: | 92 case WebTextInputMode.DEFAULT: |
84 case WebTextInputMode.VERBATIM: | 93 case WebTextInputMode.VERBATIM: |
85 case WebTextInputMode.LATIN: | 94 case WebTextInputMode.LATIN: |
86 case WebTextInputMode.LATIN_NAME: | 95 case WebTextInputMode.LATIN_NAME: |
87 case WebTextInputMode.LATIN_PROSE: | 96 case WebTextInputMode.LATIN_PROSE: |
88 case WebTextInputMode.FULL_WIDTH_LATIN: | 97 case WebTextInputMode.FULL_WIDTH_LATIN: |
89 case WebTextInputMode.KANA: | 98 case WebTextInputMode.KANA: |
90 case WebTextInputMode.KANA_NAME: | 99 case WebTextInputMode.KANA_NAME: |
91 case WebTextInputMode.KATA_KANA: | 100 case WebTextInputMode.KATA_KANA: |
92 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE; | 101 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE; |
93 if ((inputFlags & WebTextInputFlags.AUTOCORRECT_OFF) == 0) { | 102 if ((inputFlags & WebTextInputFlags.AUTOCORRECT_OFF) == 0) { |
94 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_COR
RECT; | 103 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_COR
RECT; |
95 } | 104 } |
| 105 imeAction = EditorInfo.IME_ACTION_NONE; |
96 break; | 106 break; |
97 case WebTextInputMode.NUMERIC: | 107 case WebTextInputMode.NUMERIC: |
98 outAttrs.inputType = | 108 outAttrs.inputType = |
99 InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_
VARIATION_NORMAL; | 109 InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_
VARIATION_NORMAL; |
| 110 imeAction = EditorInfo.IME_ACTION_NEXT; |
100 break; | 111 break; |
101 case WebTextInputMode.TEL: | 112 case WebTextInputMode.TEL: |
102 outAttrs.inputType = InputType.TYPE_CLASS_PHONE; | 113 outAttrs.inputType = InputType.TYPE_CLASS_PHONE; |
| 114 imeAction = EditorInfo.IME_ACTION_NEXT; |
103 break; | 115 break; |
104 case WebTextInputMode.EMAIL: | 116 case WebTextInputMode.EMAIL: |
105 outAttrs.inputType = InputType.TYPE_CLASS_TEXT | 117 outAttrs.inputType = InputType.TYPE_CLASS_TEXT |
106 | InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS; | 118 | InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS; |
| 119 imeAction = EditorInfo.IME_ACTION_GO; |
107 break; | 120 break; |
108 case WebTextInputMode.URL: | 121 case WebTextInputMode.URL: |
109 outAttrs.inputType = | 122 outAttrs.inputType = |
110 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARI
ATION_URI; | 123 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARI
ATION_URI; |
| 124 imeAction = EditorInfo.IME_ACTION_NEXT; |
111 break; | 125 break; |
112 } | 126 } |
113 } | 127 } |
114 | 128 |
115 if (inputMode == WebTextInputMode.DEFAULT && inputType == TextInputType.
SEARCH) { | |
116 imeAction |= EditorInfo.IME_ACTION_SEARCH; | |
117 } else if ((outAttrs.inputType & EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE) !
= 0) { | |
118 // For textarea that sends you to another webpage on enter key press
using | |
119 // JavaScript, we will only show ENTER. | |
120 imeAction |= EditorInfo.IME_ACTION_NONE; | |
121 } else if ((inputFlags & WebTextInputFlags.HAVE_NEXT_FOCUSABLE_ELEMENT)
!= 0) { | |
122 imeAction |= EditorInfo.IME_ACTION_NEXT; | |
123 } else { | |
124 // For last element inside form, we should give preference to GO key
as PREVIOUS | |
125 // has less importance in those cases. | |
126 imeAction |= EditorInfo.IME_ACTION_GO; | |
127 } | |
128 | |
129 outAttrs.imeOptions |= imeAction; | 129 outAttrs.imeOptions |= imeAction; |
130 | |
131 // 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 |
132 // 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 |
133 // default and there is no way to express no capitalization. | 132 // default and there is no way to express no capitalization. |
134 // Autocapitalize is meant as a hint to the virtual keyboard. | 133 // Autocapitalize is meant as a hint to the virtual keyboard. |
135 if ((inputFlags & WebTextInputFlags.AUTOCAPITALIZE_CHARACTERS) != 0) { | 134 if ((inputFlags & WebTextInputFlags.AUTOCAPITALIZE_CHARACTERS) != 0) { |
136 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS; | 135 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS; |
137 } else if ((inputFlags & WebTextInputFlags.AUTOCAPITALIZE_WORDS) != 0) { | 136 } else if ((inputFlags & WebTextInputFlags.AUTOCAPITALIZE_WORDS) != 0) { |
138 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_WORDS; | 137 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_WORDS; |
139 } else if ((inputFlags & WebTextInputFlags.AUTOCAPITALIZE_SENTENCES) !=
0) { | 138 } else if ((inputFlags & WebTextInputFlags.AUTOCAPITALIZE_SENTENCES) !=
0) { |
140 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_SENTENCES; | 139 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); | 196 if (!condition) throw new AssertionError(msg); |
198 } | 197 } |
199 | 198 |
200 /** | 199 /** |
201 * Check that the current thread is UI thread, and raise an error if it is n
ot. | 200 * Check that the current thread is UI thread, and raise an error if it is n
ot. |
202 */ | 201 */ |
203 static void checkOnUiThread() { | 202 static void checkOnUiThread() { |
204 checkCondition("Should be on UI thread.", ThreadUtils.runningOnUiThread(
)); | 203 checkCondition("Should be on UI thread.", ThreadUtils.runningOnUiThread(
)); |
205 } | 204 } |
206 } | 205 } |
OLD | NEW |