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 27 matching lines...) Expand all Loading... |
38 outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_FULLSCREEN | EditorInfo.IME
_FLAG_NO_EXTRACT_UI; | 38 outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_FULLSCREEN | EditorInfo.IME
_FLAG_NO_EXTRACT_UI; |
39 outAttrs.inputType = | 39 outAttrs.inputType = |
40 EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_WEB_
EDIT_TEXT; | 40 EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_WEB_
EDIT_TEXT; |
41 | 41 |
42 if ((inputFlags & WebTextInputFlags.AutocompleteOff) != 0) { | 42 if ((inputFlags & WebTextInputFlags.AutocompleteOff) != 0) { |
43 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS; | 43 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS; |
44 } | 44 } |
45 | 45 |
46 if (inputType == TextInputType.TEXT) { | 46 if (inputType == TextInputType.TEXT) { |
47 // Normal text field | 47 // Normal text field |
48 outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO; | |
49 if ((inputFlags & WebTextInputFlags.AutocorrectOff) == 0) { | 48 if ((inputFlags & WebTextInputFlags.AutocorrectOff) == 0) { |
50 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT; | 49 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT; |
51 } | 50 } |
52 } else if (inputType == TextInputType.TEXT_AREA | 51 } else if (inputType == TextInputType.TEXT_AREA |
53 || inputType == TextInputType.CONTENT_EDITABLE) { | 52 || inputType == TextInputType.CONTENT_EDITABLE) { |
54 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE; | 53 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE; |
55 if ((inputFlags & WebTextInputFlags.AutocorrectOff) == 0) { | 54 if ((inputFlags & WebTextInputFlags.AutocorrectOff) == 0) { |
56 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT; | 55 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT; |
57 } | 56 } |
58 outAttrs.imeOptions |= EditorInfo.IME_ACTION_NONE; | |
59 } else if (inputType == TextInputType.PASSWORD) { | 57 } else if (inputType == TextInputType.PASSWORD) { |
60 outAttrs.inputType = | 58 outAttrs.inputType = |
61 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_WE
B_PASSWORD; | 59 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_WE
B_PASSWORD; |
62 outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO; | |
63 } else if (inputType == TextInputType.SEARCH) { | 60 } else if (inputType == TextInputType.SEARCH) { |
64 outAttrs.imeOptions |= EditorInfo.IME_ACTION_SEARCH; | |
65 } else if (inputType == TextInputType.URL) { | 61 } else if (inputType == TextInputType.URL) { |
66 outAttrs.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT
_VARIATION_URI; | 62 outAttrs.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT
_VARIATION_URI; |
67 outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO; | |
68 } else if (inputType == TextInputType.EMAIL) { | 63 } else if (inputType == TextInputType.EMAIL) { |
69 // Email | 64 // Email |
70 outAttrs.inputType = | 65 outAttrs.inputType = |
71 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_WE
B_EMAIL_ADDRESS; | 66 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_WE
B_EMAIL_ADDRESS; |
72 outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO; | |
73 } else if (inputType == TextInputType.TELEPHONE) { | 67 } else if (inputType == TextInputType.TELEPHONE) { |
74 // Telephone | 68 // Telephone |
75 // Number and telephone do not have both a Tab key and an | 69 // Number and telephone do not have both a Tab key and an |
76 // action in default OSK, so set the action to NEXT | 70 // action in default OSK, so set the action to NEXT |
77 outAttrs.inputType = InputType.TYPE_CLASS_PHONE; | 71 outAttrs.inputType = InputType.TYPE_CLASS_PHONE; |
78 outAttrs.imeOptions |= EditorInfo.IME_ACTION_NEXT; | |
79 } else if (inputType == TextInputType.NUMBER) { | 72 } else if (inputType == TextInputType.NUMBER) { |
80 // Number | 73 // Number |
81 outAttrs.inputType = InputType.TYPE_CLASS_NUMBER | 74 outAttrs.inputType = InputType.TYPE_CLASS_NUMBER |
82 | InputType.TYPE_NUMBER_VARIATION_NORMAL | InputType.TYPE_NU
MBER_FLAG_DECIMAL; | 75 | InputType.TYPE_NUMBER_VARIATION_NORMAL | InputType.TYPE_NU
MBER_FLAG_DECIMAL; |
83 outAttrs.imeOptions |= EditorInfo.IME_ACTION_NEXT; | |
84 } | 76 } |
85 | 77 |
86 // Handling of autocapitalize. Blink will send the flag taking into acco
unt the element's | 78 // Handling of autocapitalize. Blink will send the flag taking into acco
unt the element's |
87 // type. This is not using AutocapitalizeNone because Android does not a
utocapitalize by | 79 // type. This is not using AutocapitalizeNone because Android does not a
utocapitalize by |
88 // default and there is no way to express no capitalization. | 80 // default and there is no way to express no capitalization. |
89 // Autocapitalize is meant as a hint to the virtual keyboard. | 81 // Autocapitalize is meant as a hint to the virtual keyboard. |
90 if ((inputFlags & WebTextInputFlags.AutocapitalizeCharacters) != 0) { | 82 if ((inputFlags & WebTextInputFlags.AutocapitalizeCharacters) != 0) { |
91 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS; | 83 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS; |
92 } else if ((inputFlags & WebTextInputFlags.AutocapitalizeWords) != 0) { | 84 } else if ((inputFlags & WebTextInputFlags.AutocapitalizeWords) != 0) { |
93 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_WORDS; | 85 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_WORDS; |
94 } else if ((inputFlags & WebTextInputFlags.AutocapitalizeSentences) != 0
) { | 86 } else if ((inputFlags & WebTextInputFlags.AutocapitalizeSentences) != 0
) { |
95 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_SENTENCES; | 87 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_SENTENCES; |
96 } | 88 } |
97 // Content editable doesn't use autocapitalize so we need to set it manu
ally. | 89 // Content editable doesn't use autocapitalize so we need to set it manu
ally. |
98 if (inputType == TextInputType.CONTENT_EDITABLE) { | 90 if (inputType == TextInputType.CONTENT_EDITABLE) { |
99 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_SENTENCES; | 91 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_SENTENCES; |
100 } | 92 } |
101 | 93 |
| 94 if (inputType == TextInputType.SEARCH) { |
| 95 outAttrs.imeOptions |= EditorInfo.IME_ACTION_SEARCH; |
| 96 } else if ((inputFlags & WebTextInputFlags.ActionNone) != 0) { |
| 97 outAttrs.imeOptions |= EditorInfo.IME_ACTION_NONE; |
| 98 } else if ((inputFlags & WebTextInputFlags.ActionNext) != 0) { |
| 99 outAttrs.imeOptions |= EditorInfo.IME_ACTION_NEXT; |
| 100 } else if ((inputFlags & WebTextInputFlags.ActionGo) != 0) { |
| 101 outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO; |
| 102 } |
| 103 |
102 outAttrs.initialSelStart = initialSelStart; | 104 outAttrs.initialSelStart = initialSelStart; |
103 outAttrs.initialSelEnd = initialSelEnd; | 105 outAttrs.initialSelEnd = initialSelEnd; |
104 } | 106 } |
105 | 107 |
106 /** | 108 /** |
107 * @param editorInfo The EditorInfo | 109 * @param editorInfo The EditorInfo |
108 * @return Debug string for the given {@EditorInfo}. | 110 * @return Debug string for the given {@EditorInfo}. |
109 */ | 111 */ |
110 static String getEditorInfoDebugString(EditorInfo editorInfo) { | 112 static String getEditorInfoDebugString(EditorInfo editorInfo) { |
111 StringBuilder builder = new StringBuilder(); | 113 StringBuilder builder = new StringBuilder(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 if (!condition) throw new AssertionError(msg); | 154 if (!condition) throw new AssertionError(msg); |
153 } | 155 } |
154 | 156 |
155 /** | 157 /** |
156 * Check that the current thread is UI thread, and raise an error if it is n
ot. | 158 * Check that the current thread is UI thread, and raise an error if it is n
ot. |
157 */ | 159 */ |
158 static void checkOnUiThread() { | 160 static void checkOnUiThread() { |
159 checkCondition("Should be on UI thread.", ThreadUtils.runningOnUiThread(
)); | 161 checkCondition("Should be on UI thread.", ThreadUtils.runningOnUiThread(
)); |
160 } | 162 } |
161 } | 163 } |
OLD | NEW |