Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(349)

Side by Side Diff: content/public/android/java/src/org/chromium/content/browser/input/ImeUtils.java

Issue 2839993002: [Android] Adding Smart GO/NEXT feature in Chrome (Closed)
Patch Set: Brought up blink enum to Java layer instead of boolean Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 28 matching lines...) Expand all
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.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 boolean enterKeyAction = false;
49 if (inputMode == WebTextInputMode.DEFAULT) { 50 if (inputMode == WebTextInputMode.DEFAULT) {
50 if (inputType == TextInputType.TEXT) { 51 if (inputType == TextInputType.TEXT) {
51 // Normal text field 52 // Normal text field
52 imeAction = EditorInfo.IME_ACTION_GO;
53 if ((inputFlags & WebTextInputFlags.AUTOCORRECT_OFF) == 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.AUTOCORRECT_OFF) == 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;
63 } else if (inputType == TextInputType.PASSWORD) { 62 } else if (inputType == TextInputType.PASSWORD) {
64 outAttrs.inputType = 63 outAttrs.inputType =
65 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATIO N_WEB_PASSWORD; 64 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATIO N_WEB_PASSWORD;
66 imeAction = EditorInfo.IME_ACTION_GO;
67 } else if (inputType == TextInputType.SEARCH) { 65 } else if (inputType == TextInputType.SEARCH) {
68 imeAction = EditorInfo.IME_ACTION_SEARCH; 66 imeAction = EditorInfo.IME_ACTION_SEARCH;
69 } else if (inputType == TextInputType.URL) { 67 } else if (inputType == TextInputType.URL) {
70 outAttrs.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_ TEXT_VARIATION_URI; 68 outAttrs.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_ TEXT_VARIATION_URI;
71 imeAction = EditorInfo.IME_ACTION_GO;
72 } else if (inputType == TextInputType.EMAIL) { 69 } else if (inputType == TextInputType.EMAIL) {
73 // Email 70 // Email
74 outAttrs.inputType = 71 outAttrs.inputType =
75 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATIO N_WEB_EMAIL_ADDRESS; 72 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATIO N_WEB_EMAIL_ADDRESS;
76 imeAction = EditorInfo.IME_ACTION_GO;
77 } else if (inputType == TextInputType.TELEPHONE) { 73 } else if (inputType == TextInputType.TELEPHONE) {
78 // Telephone 74 // Telephone
79 // Number and telephone do not have both a Tab key and an 75 // Number and telephone do not have both a Tab key and an
80 // action in default OSK, so set the action to NEXT 76 // action in default OSK, so set the action to NEXT
81 outAttrs.inputType = InputType.TYPE_CLASS_PHONE; 77 outAttrs.inputType = InputType.TYPE_CLASS_PHONE;
82 imeAction = EditorInfo.IME_ACTION_NEXT;
83 } else if (inputType == TextInputType.NUMBER) { 78 } else if (inputType == TextInputType.NUMBER) {
84 // Number 79 // Number
85 outAttrs.inputType = InputType.TYPE_CLASS_NUMBER 80 outAttrs.inputType = InputType.TYPE_CLASS_NUMBER
86 | InputType.TYPE_NUMBER_VARIATION_NORMAL 81 | InputType.TYPE_NUMBER_VARIATION_NORMAL
87 | InputType.TYPE_NUMBER_FLAG_DECIMAL; 82 | InputType.TYPE_NUMBER_FLAG_DECIMAL;
88 imeAction = EditorInfo.IME_ACTION_NEXT;
89 } 83 }
90 } else { 84 } else {
91 switch (inputMode) { 85 switch (inputMode) {
92 default: 86 default:
93 case WebTextInputMode.DEFAULT: 87 case WebTextInputMode.DEFAULT:
94 case WebTextInputMode.VERBATIM: 88 case WebTextInputMode.VERBATIM:
95 case WebTextInputMode.LATIN: 89 case WebTextInputMode.LATIN:
96 case WebTextInputMode.LATIN_NAME: 90 case WebTextInputMode.LATIN_NAME:
97 case WebTextInputMode.LATIN_PROSE: 91 case WebTextInputMode.LATIN_PROSE:
98 case WebTextInputMode.FULL_WIDTH_LATIN: 92 case WebTextInputMode.FULL_WIDTH_LATIN:
(...skipping 22 matching lines...) Expand all
121 break; 115 break;
122 case WebTextInputMode.URL: 116 case WebTextInputMode.URL:
123 outAttrs.inputType = 117 outAttrs.inputType =
124 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARI ATION_URI; 118 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARI ATION_URI;
125 imeAction = EditorInfo.IME_ACTION_NEXT; 119 imeAction = EditorInfo.IME_ACTION_NEXT;
126 break; 120 break;
127 } 121 }
128 } 122 }
129 123
130 outAttrs.imeOptions |= imeAction; 124 outAttrs.imeOptions |= imeAction;
125
126 // For multiline text or any text input with key event listeners, ENTER key is needed.
127 if ((outAttrs.inputType & EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE) != 0) {
128 // For textarea that sends you to another webpage on enter key press using
129 // JavaScript, we will only show ENTER.
130 outAttrs.imeOptions |= EditorInfo.IME_ACTION_NONE;
131 enterKeyAction = true;
132 }
133
134 // If ENTER key is already applied, then don't apply NEXT as it can resu lt display issues in
135 // IME
Changwan Ryu 2017/05/04 20:38:15 This comment is not needed at all.
AKVT 2017/05/09 11:05:52 Done.
136 if (!enterKeyAction) {
137 if ((inputFlags & WebTextInputFlags.HAVE_NEXT_FOCUSABLE_ELEMENT) != 0) {
138 outAttrs.imeOptions |= EditorInfo.IME_ACTION_NEXT;
139 } else if ((inputFlags & WebTextInputFlags.HAVE_PREVIOUS_FOCUSABLE_E LEMENT) != 0) {
140 // If ENTER/NEXT key is already applied, then don't apply PREVIO US as it can result
Changwan Ryu 2017/05/04 20:38:15 No need to mention ENTER case here. Did you mean G
AKVT 2017/05/09 11:05:52 Yes, I missed GO in subsequent review cycle. Also
141 // display issues in IME
142 outAttrs.imeOptions |= EditorInfo.IME_ACTION_PREVIOUS;
143 }
144 }
145
131 // Handling of autocapitalize. Blink will send the flag taking into acco unt the element's 146 // 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 147 // type. This is not using AutocapitalizeNone because Android does not a utocapitalize by
133 // default and there is no way to express no capitalization. 148 // default and there is no way to express no capitalization.
134 // Autocapitalize is meant as a hint to the virtual keyboard. 149 // Autocapitalize is meant as a hint to the virtual keyboard.
135 if ((inputFlags & WebTextInputFlags.AUTOCAPITALIZE_CHARACTERS) != 0) { 150 if ((inputFlags & WebTextInputFlags.AUTOCAPITALIZE_CHARACTERS) != 0) {
136 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS; 151 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS;
137 } else if ((inputFlags & WebTextInputFlags.AUTOCAPITALIZE_WORDS) != 0) { 152 } else if ((inputFlags & WebTextInputFlags.AUTOCAPITALIZE_WORDS) != 0) {
138 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_WORDS; 153 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_WORDS;
139 } else if ((inputFlags & WebTextInputFlags.AUTOCAPITALIZE_SENTENCES) != 0) { 154 } else if ((inputFlags & WebTextInputFlags.AUTOCAPITALIZE_SENTENCES) != 0) {
140 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_SENTENCES; 155 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_SENTENCES;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 if (!condition) throw new AssertionError(msg); 212 if (!condition) throw new AssertionError(msg);
198 } 213 }
199 214
200 /** 215 /**
201 * Check that the current thread is UI thread, and raise an error if it is n ot. 216 * Check that the current thread is UI thread, and raise an error if it is n ot.
202 */ 217 */
203 static void checkOnUiThread() { 218 static void checkOnUiThread() {
204 checkCondition("Should be on UI thread.", ThreadUtils.runningOnUiThread( )); 219 checkCondition("Should be on UI thread.", ThreadUtils.runningOnUiThread( ));
205 } 220 }
206 } 221 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698