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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT; | 50 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT; |
51 } | 51 } |
52 } else if (inputType == TextInputType.TEXT_AREA | 52 } else if (inputType == TextInputType.TEXT_AREA |
53 || inputType == TextInputType.CONTENT_EDITABLE) { | 53 || inputType == TextInputType.CONTENT_EDITABLE) { |
54 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE; | 54 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE; |
55 if ((inputFlags & WebTextInputFlags.AutocorrectOff) == 0) { | 55 if ((inputFlags & WebTextInputFlags.AutocorrectOff) == 0) { |
56 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT; | 56 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT; |
57 } | 57 } |
58 outAttrs.imeOptions |= EditorInfo.IME_ACTION_NONE; | 58 outAttrs.imeOptions |= EditorInfo.IME_ACTION_NONE; |
59 } else if (inputType == TextInputType.PASSWORD) { | 59 } else if (inputType == TextInputType.PASSWORD) { |
60 // Password | |
61 outAttrs.inputType = | 60 outAttrs.inputType = |
62 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_WE
B_PASSWORD; | 61 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_WE
B_PASSWORD; |
63 outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO; | 62 outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO; |
64 } else if (inputType == TextInputType.SEARCH) { | 63 } else if (inputType == TextInputType.SEARCH) { |
65 // Search | |
66 outAttrs.imeOptions |= EditorInfo.IME_ACTION_SEARCH; | 64 outAttrs.imeOptions |= EditorInfo.IME_ACTION_SEARCH; |
67 } else if (inputType == TextInputType.URL) { | 65 } else if (inputType == TextInputType.URL) { |
68 // Url | |
69 outAttrs.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT
_VARIATION_URI; | 66 outAttrs.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT
_VARIATION_URI; |
70 outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO; | 67 outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO; |
71 } else if (inputType == TextInputType.EMAIL) { | 68 } else if (inputType == TextInputType.EMAIL) { |
72 // Email | 69 // Email |
73 outAttrs.inputType = | 70 outAttrs.inputType = |
74 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_WE
B_EMAIL_ADDRESS; | 71 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_WE
B_EMAIL_ADDRESS; |
75 outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO; | 72 outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO; |
76 } else if (inputType == TextInputType.TELEPHONE) { | 73 } else if (inputType == TextInputType.TELEPHONE) { |
77 // Telephone | 74 // Telephone |
78 // 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 |
(...skipping 20 matching lines...) Expand all Loading... |
99 } | 96 } |
100 // Content editable doesn't use autocapitalize so we need to set it manu
ally. | 97 // Content editable doesn't use autocapitalize so we need to set it manu
ally. |
101 if (inputType == TextInputType.CONTENT_EDITABLE) { | 98 if (inputType == TextInputType.CONTENT_EDITABLE) { |
102 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_SENTENCES; | 99 outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_SENTENCES; |
103 } | 100 } |
104 | 101 |
105 outAttrs.initialSelStart = initialSelStart; | 102 outAttrs.initialSelStart = initialSelStart; |
106 outAttrs.initialSelEnd = initialSelEnd; | 103 outAttrs.initialSelEnd = initialSelEnd; |
107 } | 104 } |
108 | 105 |
109 public static String getEditorInfoDebugString(EditorInfo editorInfo) { | 106 /** |
| 107 * @param editorInfo The EditorInfo |
| 108 * @return Debug string for the given {@EditorInfo}. |
| 109 */ |
| 110 static String getEditorInfoDebugString(EditorInfo editorInfo) { |
110 StringBuilder builder = new StringBuilder(); | 111 StringBuilder builder = new StringBuilder(); |
111 StringBuilderPrinter printer = new StringBuilderPrinter(builder); | 112 StringBuilderPrinter printer = new StringBuilderPrinter(builder); |
112 editorInfo.dump(printer, ""); | 113 editorInfo.dump(printer, ""); |
113 return builder.toString(); | 114 return builder.toString(); |
114 } | 115 } |
115 | 116 |
116 public static String getEditableDebugString(Editable editable) { | 117 /** |
| 118 * @param editable The editable. |
| 119 * @return Debug string for the given {@Editable}. |
| 120 */ |
| 121 static String getEditableDebugString(Editable editable) { |
117 return String.format(Locale.US, "Editable {[%s] SEL[%d %d] COM[%d %d]}", | 122 return String.format(Locale.US, "Editable {[%s] SEL[%d %d] COM[%d %d]}", |
118 editable.toString(), Selection.getSelectionStart(editable), | 123 editable.toString(), Selection.getSelectionStart(editable), |
119 Selection.getSelectionEnd(editable), | 124 Selection.getSelectionEnd(editable), |
120 BaseInputConnection.getComposingSpanStart(editable), | 125 BaseInputConnection.getComposingSpanStart(editable), |
121 BaseInputConnection.getComposingSpanEnd(editable)); | 126 BaseInputConnection.getComposingSpanEnd(editable)); |
122 } | 127 } |
123 | 128 |
124 /** | 129 /** |
125 * Dump the given {@CorrectionInfo} into class. | 130 * @param correctionInfo The correction info. |
126 * @param correctionInfo | 131 * @return Debug string for the given {@CorrectionInfo}. |
127 * @return User-readable {@CorrectionInfo}. | |
128 */ | 132 */ |
129 static String getCorrectInfoDebugString(CorrectionInfo correctionInfo) { | 133 static String getCorrectionInfoDebugString(CorrectionInfo correctionInfo) { |
130 // TODO(changwan): implement it properly if needed. | 134 // TODO(changwan): implement it properly if needed. |
131 return correctionInfo.toString(); | 135 return correctionInfo.toString(); |
132 } | 136 } |
133 | 137 |
134 // TODO(changwan): remove these once implementation becomes stable. | 138 /** |
135 static void checkCondition(boolean value) { | 139 * Check the given condition and raise an error if it is false. |
136 if (!value) { | 140 * @param condition The condition to check. |
137 throw new AssertionError(); | 141 */ |
138 } | 142 static void checkCondition(boolean condition) { |
| 143 if (!condition) throw new AssertionError(); |
139 } | 144 } |
140 | 145 |
141 static void checkCondition(String msg, boolean value) { | 146 /** |
142 if (!value) { | 147 * Check the given condition and raise an error if it is false. |
143 throw new AssertionError(msg); | 148 * @param msg A message to show when raising an error. |
144 } | 149 * @param condition The condition to check. |
| 150 */ |
| 151 static void checkCondition(String msg, boolean condition) { |
| 152 if (!condition) throw new AssertionError(msg); |
145 } | 153 } |
146 | 154 |
| 155 /** |
| 156 * Check that the current thread is UI thread, and raise an error if it is n
ot. |
| 157 */ |
147 static void checkOnUiThread() { | 158 static void checkOnUiThread() { |
148 checkCondition("Should be on UI thread.", ThreadUtils.runningOnUiThread(
)); | 159 checkCondition("Should be on UI thread.", ThreadUtils.runningOnUiThread(
)); |
149 } | 160 } |
150 } | 161 } |
OLD | NEW |