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

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: Fixed FocusController and ImeAdapter related review comments. 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;
Changwan Ryu 2017/05/09 14:43:57 remove?
AKVT 2017/05/09 17:22:17 Done.
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:
99 case WebTextInputMode.KANA: 93 case WebTextInputMode.KANA:
100 case WebTextInputMode.KANA_NAME: 94 case WebTextInputMode.KANA_NAME:
101 case WebTextInputMode.KATA_KANA: 95 case WebTextInputMode.KATA_KANA:
102 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE; 96 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE;
103 if ((inputFlags & WebTextInputFlags.AUTOCORRECT_OFF) == 0) { 97 if ((inputFlags & WebTextInputFlags.AUTOCORRECT_OFF) == 0) {
104 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_COR RECT; 98 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_COR RECT;
105 } 99 }
106 imeAction = EditorInfo.IME_ACTION_NONE;
107 break; 100 break;
108 case WebTextInputMode.NUMERIC: 101 case WebTextInputMode.NUMERIC:
109 outAttrs.inputType = 102 outAttrs.inputType =
110 InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_ VARIATION_NORMAL; 103 InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_ VARIATION_NORMAL;
111 imeAction = EditorInfo.IME_ACTION_NEXT;
112 break; 104 break;
113 case WebTextInputMode.TEL: 105 case WebTextInputMode.TEL:
114 outAttrs.inputType = InputType.TYPE_CLASS_PHONE; 106 outAttrs.inputType = InputType.TYPE_CLASS_PHONE;
115 imeAction = EditorInfo.IME_ACTION_NEXT;
116 break; 107 break;
117 case WebTextInputMode.EMAIL: 108 case WebTextInputMode.EMAIL:
118 outAttrs.inputType = InputType.TYPE_CLASS_TEXT 109 outAttrs.inputType = InputType.TYPE_CLASS_TEXT
119 | InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS; 110 | InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS;
120 imeAction = EditorInfo.IME_ACTION_GO;
121 break; 111 break;
122 case WebTextInputMode.URL: 112 case WebTextInputMode.URL:
123 outAttrs.inputType = 113 outAttrs.inputType =
124 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARI ATION_URI; 114 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARI ATION_URI;
125 imeAction = EditorInfo.IME_ACTION_NEXT;
126 break; 115 break;
127 } 116 }
128 } 117 }
129 118
130 outAttrs.imeOptions |= imeAction; 119 outAttrs.imeOptions |= imeAction;
120
121 // For multiline text or any text input with key event listeners, ENTER key is needed.
122 if ((outAttrs.inputType & EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE) != 0) {
123 // For textarea that sends you to another webpage on enter key press using
124 // JavaScript, we will only show ENTER.
125 outAttrs.imeOptions |= EditorInfo.IME_ACTION_NONE;
126 } else if ((inputFlags & WebTextInputFlags.HAVE_NEXT_FOCUSABLE_ELEMENT) != 0) {
127 outAttrs.imeOptions |= EditorInfo.IME_ACTION_NEXT;
128 } else {
129 // For last element inside form, we should give preference to GO key as PREVIOUS
130 // has less importance in those cases.
131 outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO;
132 }
133
131 // Handling of autocapitalize. Blink will send the flag taking into acco unt the element's 134 // 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 135 // type. This is not using AutocapitalizeNone because Android does not a utocapitalize by
133 // default and there is no way to express no capitalization. 136 // default and there is no way to express no capitalization.
134 // Autocapitalize is meant as a hint to the virtual keyboard. 137 // Autocapitalize is meant as a hint to the virtual keyboard.
135 if ((inputFlags & WebTextInputFlags.AUTOCAPITALIZE_CHARACTERS) != 0) { 138 if ((inputFlags & WebTextInputFlags.AUTOCAPITALIZE_CHARACTERS) != 0) {
136 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS; 139 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS;
137 } else if ((inputFlags & WebTextInputFlags.AUTOCAPITALIZE_WORDS) != 0) { 140 } else if ((inputFlags & WebTextInputFlags.AUTOCAPITALIZE_WORDS) != 0) {
138 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_WORDS; 141 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_WORDS;
139 } else if ((inputFlags & WebTextInputFlags.AUTOCAPITALIZE_SENTENCES) != 0) { 142 } else if ((inputFlags & WebTextInputFlags.AUTOCAPITALIZE_SENTENCES) != 0) {
140 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_SENTENCES; 143 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); 200 if (!condition) throw new AssertionError(msg);
198 } 201 }
199 202
200 /** 203 /**
201 * Check that the current thread is UI thread, and raise an error if it is n ot. 204 * Check that the current thread is UI thread, and raise an error if it is n ot.
202 */ 205 */
203 static void checkOnUiThread() { 206 static void checkOnUiThread() {
204 checkCondition("Should be on UI thread.", ThreadUtils.runningOnUiThread( )); 207 checkCondition("Should be on UI thread.", ThreadUtils.runningOnUiThread( ));
205 } 208 }
206 } 209 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698