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

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

Powered by Google App Engine
This is Rietveld 408576698