OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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.os.SystemClock; | 7 import android.os.SystemClock; |
8 import android.text.Editable; | 8 import android.text.Editable; |
9 import android.text.InputType; | 9 import android.text.InputType; |
10 import android.text.Selection; | 10 import android.text.Selection; |
11 import android.text.TextUtils; | 11 import android.text.TextUtils; |
12 import android.util.Log; | 12 import android.util.Log; |
13 import android.view.KeyEvent; | 13 import android.view.KeyEvent; |
14 import android.view.View; | 14 import android.view.View; |
15 import android.view.inputmethod.BaseInputConnection; | 15 import android.view.inputmethod.BaseInputConnection; |
16 import android.view.inputmethod.EditorInfo; | 16 import android.view.inputmethod.EditorInfo; |
17 import android.view.inputmethod.ExtractedText; | 17 import android.view.inputmethod.ExtractedText; |
18 import android.view.inputmethod.ExtractedTextRequest; | 18 import android.view.inputmethod.ExtractedTextRequest; |
19 | 19 |
20 import com.google.common.annotations.VisibleForTesting; | 20 import com.google.common.annotations.VisibleForTesting; |
21 | 21 |
22 import java.lang.CharSequence; | |
aurimas (slooooooooow)
2014/06/10 18:36:18
Is this import needed?
huangs
2014/06/10 19:54:53
Not needed to compile, but I lapsed into "include
| |
23 | |
22 /** | 24 /** |
23 * InputConnection is created by ContentView.onCreateInputConnection. | 25 * InputConnection is created by ContentView.onCreateInputConnection. |
24 * It then adapts android's IME to chrome's RenderWidgetHostView using the | 26 * It then adapts android's IME to chrome's RenderWidgetHostView using the |
25 * native ImeAdapterAndroid via the class ImeAdapter. | 27 * native ImeAdapterAndroid via the class ImeAdapter. |
26 */ | 28 */ |
27 public class AdapterInputConnection extends BaseInputConnection { | 29 public class AdapterInputConnection extends BaseInputConnection { |
28 private static final String TAG = "AdapterInputConnection"; | 30 private static final String TAG = "AdapterInputConnection"; |
29 private static final boolean DEBUG = false; | 31 private static final boolean DEBUG = false; |
30 /** | 32 /** |
31 * Selection value should be -1 if not known. See EditorInfo.java for detail s. | 33 * Selection value should be -1 if not known. See EditorInfo.java for detail s. |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
209 | 211 |
210 /** | 212 /** |
211 * @see BaseInputConnection#setComposingText(java.lang.CharSequence, int) | 213 * @see BaseInputConnection#setComposingText(java.lang.CharSequence, int) |
212 */ | 214 */ |
213 @Override | 215 @Override |
214 public boolean setComposingText(CharSequence text, int newCursorPosition) { | 216 public boolean setComposingText(CharSequence text, int newCursorPosition) { |
215 if (DEBUG) Log.w(TAG, "setComposingText [" + text + "] [" + newCursorPos ition + "]"); | 217 if (DEBUG) Log.w(TAG, "setComposingText [" + text + "] [" + newCursorPos ition + "]"); |
216 if (maybePerformEmptyCompositionWorkaround(text)) return true; | 218 if (maybePerformEmptyCompositionWorkaround(text)) return true; |
217 super.setComposingText(text, newCursorPosition); | 219 super.setComposingText(text, newCursorPosition); |
218 updateSelectionIfRequired(); | 220 updateSelectionIfRequired(); |
219 return mImeAdapter.checkCompositionQueueAndCallNative(text.toString(), | 221 return mImeAdapter.checkCompositionQueueAndCallNative(text, newCursorPos ition, false); |
220 newCursorPosition, false); | |
221 } | 222 } |
222 | 223 |
223 /** | 224 /** |
224 * @see BaseInputConnection#commitText(java.lang.CharSequence, int) | 225 * @see BaseInputConnection#commitText(java.lang.CharSequence, int) |
225 */ | 226 */ |
226 @Override | 227 @Override |
227 public boolean commitText(CharSequence text, int newCursorPosition) { | 228 public boolean commitText(CharSequence text, int newCursorPosition) { |
228 if (DEBUG) Log.w(TAG, "commitText [" + text + "] [" + newCursorPosition + "]"); | 229 if (DEBUG) Log.w(TAG, "commitText [" + text + "] [" + newCursorPosition + "]"); |
229 if (maybePerformEmptyCompositionWorkaround(text)) return true; | 230 if (maybePerformEmptyCompositionWorkaround(text)) return true; |
230 super.commitText(text, newCursorPosition); | 231 super.commitText(text, newCursorPosition); |
231 updateSelectionIfRequired(); | 232 updateSelectionIfRequired(); |
232 return mImeAdapter.checkCompositionQueueAndCallNative(text.toString(), | 233 return mImeAdapter.checkCompositionQueueAndCallNative(text, newCursorPos ition, |
233 newCursorPosition, text.length() > 0); | 234 text.length() > 0); |
234 } | 235 } |
235 | 236 |
236 /** | 237 /** |
237 * @see BaseInputConnection#performEditorAction(int) | 238 * @see BaseInputConnection#performEditorAction(int) |
238 */ | 239 */ |
239 @Override | 240 @Override |
240 public boolean performEditorAction(int actionCode) { | 241 public boolean performEditorAction(int actionCode) { |
241 if (DEBUG) Log.w(TAG, "performEditorAction [" + actionCode + "]"); | 242 if (DEBUG) Log.w(TAG, "performEditorAction [" + actionCode + "]"); |
242 if (actionCode == EditorInfo.IME_ACTION_NEXT) { | 243 if (actionCode == EditorInfo.IME_ACTION_NEXT) { |
243 restartInput(); | 244 restartInput(); |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
497 @VisibleForTesting | 498 @VisibleForTesting |
498 ImeState getImeStateForTesting() { | 499 ImeState getImeStateForTesting() { |
499 String text = mEditable.toString(); | 500 String text = mEditable.toString(); |
500 int selectionStart = Selection.getSelectionStart(mEditable); | 501 int selectionStart = Selection.getSelectionStart(mEditable); |
501 int selectionEnd = Selection.getSelectionEnd(mEditable); | 502 int selectionEnd = Selection.getSelectionEnd(mEditable); |
502 int compositionStart = getComposingSpanStart(mEditable); | 503 int compositionStart = getComposingSpanStart(mEditable); |
503 int compositionEnd = getComposingSpanEnd(mEditable); | 504 int compositionEnd = getComposingSpanEnd(mEditable); |
504 return new ImeState(text, selectionStart, selectionEnd, compositionStart , compositionEnd); | 505 return new ImeState(text, selectionStart, selectionEnd, compositionStart , compositionEnd); |
505 } | 506 } |
506 } | 507 } |
OLD | NEW |