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

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: Rebased the patch along with review comment fixes. 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) { 64 } else if (inputType == TextInputType.SEARCH) {
68 imeAction = EditorInfo.IME_ACTION_SEARCH; 65 imeAction = EditorInfo.IME_ACTION_SEARCH;
69 } else if (inputType == TextInputType.URL) { 66 } else if (inputType == TextInputType.URL) {
70 outAttrs.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_ TEXT_VARIATION_URI; 67 outAttrs.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_ TEXT_VARIATION_URI;
71 imeAction = EditorInfo.IME_ACTION_GO;
72 } else if (inputType == TextInputType.EMAIL) { 68 } else if (inputType == TextInputType.EMAIL) {
73 // Email 69 // Email
74 outAttrs.inputType = 70 outAttrs.inputType =
75 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATIO N_WEB_EMAIL_ADDRESS; 71 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATIO N_WEB_EMAIL_ADDRESS;
76 imeAction = EditorInfo.IME_ACTION_GO;
77 } else if (inputType == TextInputType.TELEPHONE) { 72 } else if (inputType == TextInputType.TELEPHONE) {
78 // Telephone 73 // Telephone
79 // Number and telephone do not have both a Tab key and an 74 // Number and telephone do not have both a Tab key and an
80 // action in default OSK, so set the action to NEXT 75 // action in default OSK, so set the action to NEXT
81 outAttrs.inputType = InputType.TYPE_CLASS_PHONE; 76 outAttrs.inputType = InputType.TYPE_CLASS_PHONE;
82 imeAction = EditorInfo.IME_ACTION_NEXT;
83 } else if (inputType == TextInputType.NUMBER) { 77 } else if (inputType == TextInputType.NUMBER) {
84 // Number 78 // Number
85 outAttrs.inputType = InputType.TYPE_CLASS_NUMBER 79 outAttrs.inputType = InputType.TYPE_CLASS_NUMBER
86 | InputType.TYPE_NUMBER_VARIATION_NORMAL 80 | InputType.TYPE_NUMBER_VARIATION_NORMAL
87 | InputType.TYPE_NUMBER_FLAG_DECIMAL; 81 | InputType.TYPE_NUMBER_FLAG_DECIMAL;
88 imeAction = EditorInfo.IME_ACTION_NEXT;
89 } 82 }
90 } else { 83 } else {
91 switch (inputMode) { 84 switch (inputMode) {
92 default: 85 default:
93 case WebTextInputMode.DEFAULT: 86 case WebTextInputMode.DEFAULT:
94 case WebTextInputMode.VERBATIM: 87 case WebTextInputMode.VERBATIM:
95 case WebTextInputMode.LATIN: 88 case WebTextInputMode.LATIN:
96 case WebTextInputMode.LATIN_NAME: 89 case WebTextInputMode.LATIN_NAME:
97 case WebTextInputMode.LATIN_PROSE: 90 case WebTextInputMode.LATIN_PROSE:
98 case WebTextInputMode.FULL_WIDTH_LATIN: 91 case WebTextInputMode.FULL_WIDTH_LATIN:
(...skipping 22 matching lines...) Expand all
121 break; 114 break;
122 case WebTextInputMode.URL: 115 case WebTextInputMode.URL:
123 outAttrs.inputType = 116 outAttrs.inputType =
124 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARI ATION_URI; 117 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARI ATION_URI;
125 imeAction = EditorInfo.IME_ACTION_NEXT; 118 imeAction = EditorInfo.IME_ACTION_NEXT;
126 break; 119 break;
127 } 120 }
128 } 121 }
129 122
130 outAttrs.imeOptions |= imeAction; 123 outAttrs.imeOptions |= imeAction;
124
125 boolean enterKeyAction = false;
Changwan Ryu 2017/04/27 16:34:53 1. You need to put this in front of switch stateme
AKVT 2017/05/03 14:35:12 You mean we should overwrite inputMode imeAction ?
Changwan Ryu 2017/05/04 20:38:15 My bad, I got confused about input mode. Input mod
AKVT 2017/05/09 11:05:52 Thanks. I corrected in PS7
126 // For multiline text or any text input with key event listeners, Enter key is needed.
Changwan Ryu 2017/04/27 16:34:54 nit: ENTER (all cap) or enter (all small)
AKVT 2017/05/03 14:35:12 Done.
127 if (((outAttrs.inputType & EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE)
128 == EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE)
Changwan Ryu 2017/04/27 16:34:54 instead of == you can use > 0 or != 0
AKVT 2017/05/03 14:35:11 Done.
129 || (inputFlags & WebTextInputFlags.LISTENING_TO_KEYBOARD_EVENTS) != 0) {
130 // TODO(ajith.v) Find an option to remove Enter Key from IME (assume by default
Changwan Ryu 2017/04/27 16:34:54 No need to have a TODO on our end. Most likely IME
AKVT 2017/05/03 14:35:12 Done.
131 // ENTER key is shown)
132 // TODO(ajith.v) For text area with implicit form submission how do we handle,
Changwan Ryu 2017/04/27 16:34:54 By implicit form submission, do you mean JavaScrip
AKVT 2017/05/03 14:35:12 Yes implicit submission I meant with that only. On
Changwan Ryu 2017/05/04 20:38:15 multiline --> always ENTER single line --> always
AKVT 2017/05/09 11:05:52 Yes currently I have done like this. Also NEXT/GO/
133 // we need to show both GO and ENTER key at same time.
134 outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO;
135 enterKeyAction = true;
136 }
137
138 boolean nextKeyAction = false;
139 // If ENTER key is already applied, then don't apply NEXT as it can resu lt display issues in
140 // IME
141 if (!enterKeyAction && (inputFlags & WebTextInputFlags.HAVE_NEXT_FOCUSAB LE_ELEMENT) != 0) {
142 outAttrs.imeOptions |= EditorInfo.IME_ACTION_NEXT;
143 nextKeyAction = true;
144 }
145 // If ENTER/NEXT key is already applied, then don't apply PREVIOUS as it can result display
146 // issues in IME
Changwan Ryu 2017/04/27 16:34:54 This is quite unfortunate. Could you file/refer to
AKVT 2017/05/03 14:35:12 Currently I am using Google Pixel device default G
Changwan Ryu 2017/05/04 20:38:15 Could you leave those keyboards (not the device) a
147 if (!enterKeyAction && !nextKeyAction
148 && (inputFlags & WebTextInputFlags.HAVE_PREVIOUS_FOCUSABLE_ELEME NT) != 0) {
149 outAttrs.imeOptions |= EditorInfo.IME_ACTION_PREVIOUS;
150 }
151
131 // Handling of autocapitalize. Blink will send the flag taking into acco unt the element's 152 // 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 153 // type. This is not using AutocapitalizeNone because Android does not a utocapitalize by
133 // default and there is no way to express no capitalization. 154 // default and there is no way to express no capitalization.
134 // Autocapitalize is meant as a hint to the virtual keyboard. 155 // Autocapitalize is meant as a hint to the virtual keyboard.
135 if ((inputFlags & WebTextInputFlags.AUTOCAPITALIZE_CHARACTERS) != 0) { 156 if ((inputFlags & WebTextInputFlags.AUTOCAPITALIZE_CHARACTERS) != 0) {
136 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS; 157 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS;
137 } else if ((inputFlags & WebTextInputFlags.AUTOCAPITALIZE_WORDS) != 0) { 158 } else if ((inputFlags & WebTextInputFlags.AUTOCAPITALIZE_WORDS) != 0) {
138 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_WORDS; 159 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_WORDS;
139 } else if ((inputFlags & WebTextInputFlags.AUTOCAPITALIZE_SENTENCES) != 0) { 160 } else if ((inputFlags & WebTextInputFlags.AUTOCAPITALIZE_SENTENCES) != 0) {
140 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_SENTENCES; 161 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); 218 if (!condition) throw new AssertionError(msg);
198 } 219 }
199 220
200 /** 221 /**
201 * Check that the current thread is UI thread, and raise an error if it is n ot. 222 * Check that the current thread is UI thread, and raise an error if it is n ot.
202 */ 223 */
203 static void checkOnUiThread() { 224 static void checkOnUiThread() {
204 checkCondition("Should be on UI thread.", ThreadUtils.runningOnUiThread( )); 225 checkCondition("Should be on UI thread.", ThreadUtils.runningOnUiThread( ));
205 } 226 }
206 } 227 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698