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) { | |
68 imeAction = EditorInfo.IME_ACTION_SEARCH; | |
69 } else if (inputType == TextInputType.URL) { | 64 } else if (inputType == TextInputType.URL) { |
70 outAttrs.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_
TEXT_VARIATION_URI; | 65 outAttrs.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_
TEXT_VARIATION_URI; |
71 imeAction = EditorInfo.IME_ACTION_GO; | |
72 } else if (inputType == TextInputType.EMAIL) { | 66 } else if (inputType == TextInputType.EMAIL) { |
73 // Email | 67 // Email |
74 outAttrs.inputType = | 68 outAttrs.inputType = |
75 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATIO
N_WEB_EMAIL_ADDRESS; | 69 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATIO
N_WEB_EMAIL_ADDRESS; |
76 imeAction = EditorInfo.IME_ACTION_GO; | |
77 } else if (inputType == TextInputType.TELEPHONE) { | 70 } else if (inputType == TextInputType.TELEPHONE) { |
78 // Telephone | 71 // Telephone |
79 // Number and telephone do not have both a Tab key and an | 72 // Number and telephone do not have both a Tab key and an |
80 // action in default OSK, so set the action to NEXT | 73 // action in default OSK, so set the action to NEXT |
81 outAttrs.inputType = InputType.TYPE_CLASS_PHONE; | 74 outAttrs.inputType = InputType.TYPE_CLASS_PHONE; |
82 imeAction = EditorInfo.IME_ACTION_NEXT; | |
83 } else if (inputType == TextInputType.NUMBER) { | 75 } else if (inputType == TextInputType.NUMBER) { |
84 // Number | 76 // Number |
85 outAttrs.inputType = InputType.TYPE_CLASS_NUMBER | 77 outAttrs.inputType = InputType.TYPE_CLASS_NUMBER |
86 | InputType.TYPE_NUMBER_VARIATION_NORMAL | 78 | InputType.TYPE_NUMBER_VARIATION_NORMAL |
87 | InputType.TYPE_NUMBER_FLAG_DECIMAL; | 79 | InputType.TYPE_NUMBER_FLAG_DECIMAL; |
88 imeAction = EditorInfo.IME_ACTION_NEXT; | |
89 } | 80 } |
90 } else { | 81 } else { |
91 switch (inputMode) { | 82 switch (inputMode) { |
92 default: | 83 default: |
93 case WebTextInputMode.DEFAULT: | 84 case WebTextInputMode.DEFAULT: |
94 case WebTextInputMode.VERBATIM: | 85 case WebTextInputMode.VERBATIM: |
95 case WebTextInputMode.LATIN: | 86 case WebTextInputMode.LATIN: |
96 case WebTextInputMode.LATIN_NAME: | 87 case WebTextInputMode.LATIN_NAME: |
97 case WebTextInputMode.LATIN_PROSE: | 88 case WebTextInputMode.LATIN_PROSE: |
98 case WebTextInputMode.FULL_WIDTH_LATIN: | 89 case WebTextInputMode.FULL_WIDTH_LATIN: |
99 case WebTextInputMode.KANA: | 90 case WebTextInputMode.KANA: |
100 case WebTextInputMode.KANA_NAME: | 91 case WebTextInputMode.KANA_NAME: |
101 case WebTextInputMode.KATA_KANA: | 92 case WebTextInputMode.KATA_KANA: |
102 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE; | 93 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE; |
103 if ((inputFlags & WebTextInputFlags.AUTOCORRECT_OFF) == 0) { | 94 if ((inputFlags & WebTextInputFlags.AUTOCORRECT_OFF) == 0) { |
104 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_COR
RECT; | 95 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_COR
RECT; |
105 } | 96 } |
106 imeAction = EditorInfo.IME_ACTION_NONE; | |
107 break; | 97 break; |
108 case WebTextInputMode.NUMERIC: | 98 case WebTextInputMode.NUMERIC: |
109 outAttrs.inputType = | 99 outAttrs.inputType = |
110 InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_
VARIATION_NORMAL; | 100 InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_
VARIATION_NORMAL; |
111 imeAction = EditorInfo.IME_ACTION_NEXT; | |
112 break; | 101 break; |
113 case WebTextInputMode.TEL: | 102 case WebTextInputMode.TEL: |
114 outAttrs.inputType = InputType.TYPE_CLASS_PHONE; | 103 outAttrs.inputType = InputType.TYPE_CLASS_PHONE; |
115 imeAction = EditorInfo.IME_ACTION_NEXT; | |
116 break; | 104 break; |
117 case WebTextInputMode.EMAIL: | 105 case WebTextInputMode.EMAIL: |
118 outAttrs.inputType = InputType.TYPE_CLASS_TEXT | 106 outAttrs.inputType = InputType.TYPE_CLASS_TEXT |
119 | InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS; | 107 | InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS; |
120 imeAction = EditorInfo.IME_ACTION_GO; | |
121 break; | 108 break; |
122 case WebTextInputMode.URL: | 109 case WebTextInputMode.URL: |
123 outAttrs.inputType = | 110 outAttrs.inputType = |
124 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARI
ATION_URI; | 111 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARI
ATION_URI; |
125 imeAction = EditorInfo.IME_ACTION_NEXT; | |
126 break; | 112 break; |
127 } | 113 } |
128 } | 114 } |
129 | 115 |
| 116 if (inputMode == WebTextInputMode.DEFAULT && inputType == TextInputType.
SEARCH) { |
| 117 imeAction |= EditorInfo.IME_ACTION_SEARCH; |
| 118 } else if ((outAttrs.inputType & EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE) !
= 0) { |
| 119 // For textarea that sends you to another webpage on enter key press
using |
| 120 // JavaScript, we will only show ENTER. |
| 121 imeAction |= EditorInfo.IME_ACTION_NONE; |
| 122 } else if ((inputFlags & WebTextInputFlags.HAVE_NEXT_FOCUSABLE_ELEMENT)
!= 0) { |
| 123 imeAction |= EditorInfo.IME_ACTION_NEXT; |
| 124 } else { |
| 125 // For last element inside form, we should give preference to GO key
as PREVIOUS |
| 126 // has less importance in those cases. |
| 127 imeAction |= EditorInfo.IME_ACTION_GO; |
| 128 } |
| 129 |
130 outAttrs.imeOptions |= imeAction; | 130 outAttrs.imeOptions |= imeAction; |
| 131 |
131 // Handling of autocapitalize. Blink will send the flag taking into acco
unt the element's | 132 // 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 | 133 // type. This is not using AutocapitalizeNone because Android does not a
utocapitalize by |
133 // default and there is no way to express no capitalization. | 134 // default and there is no way to express no capitalization. |
134 // Autocapitalize is meant as a hint to the virtual keyboard. | 135 // Autocapitalize is meant as a hint to the virtual keyboard. |
135 if ((inputFlags & WebTextInputFlags.AUTOCAPITALIZE_CHARACTERS) != 0) { | 136 if ((inputFlags & WebTextInputFlags.AUTOCAPITALIZE_CHARACTERS) != 0) { |
136 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS; | 137 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS; |
137 } else if ((inputFlags & WebTextInputFlags.AUTOCAPITALIZE_WORDS) != 0) { | 138 } else if ((inputFlags & WebTextInputFlags.AUTOCAPITALIZE_WORDS) != 0) { |
138 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_WORDS; | 139 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_WORDS; |
139 } else if ((inputFlags & WebTextInputFlags.AUTOCAPITALIZE_SENTENCES) !=
0) { | 140 } else if ((inputFlags & WebTextInputFlags.AUTOCAPITALIZE_SENTENCES) !=
0) { |
140 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_SENTENCES; | 141 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); | 198 if (!condition) throw new AssertionError(msg); |
198 } | 199 } |
199 | 200 |
200 /** | 201 /** |
201 * Check that the current thread is UI thread, and raise an error if it is n
ot. | 202 * Check that the current thread is UI thread, and raise an error if it is n
ot. |
202 */ | 203 */ |
203 static void checkOnUiThread() { | 204 static void checkOnUiThread() { |
204 checkCondition("Should be on UI thread.", ThreadUtils.runningOnUiThread(
)); | 205 checkCondition("Should be on UI thread.", ThreadUtils.runningOnUiThread(
)); |
205 } | 206 } |
206 } | 207 } |
OLD | NEW |