OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 package org.chromium.content.browser.input; | |
6 | |
7 import android.os.Handler; | |
8 import android.os.Looper; | |
9 import android.view.KeyEvent; | |
10 import android.view.View; | |
11 import android.view.inputmethod.EditorInfo; | |
12 import android.view.inputmethod.InputConnection; | |
13 | |
14 import org.chromium.base.VisibleForTesting; | |
15 | |
16 import java.util.concurrent.Callable; | |
17 import java.util.concurrent.FutureTask; | |
18 import java.util.concurrent.TimeUnit; | |
19 | |
20 /** | |
21 * An interface to help switch between AdapterInputConnection and ChromiumInputC onnection. | |
22 */ | |
23 public interface ChromiumBaseInputConnection extends InputConnection { | |
24 | |
25 /** | |
26 * A class to post, run some runnable or callable on the given handler. | |
27 */ | |
28 public static class ThreadManager { | |
29 private final Handler mHandler; | |
Ted C
2016/02/02 23:14:42
why not just pass a Handler. This class seems lik
Changwan Ryu
2016/02/11 16:21:07
You're right. Removed.
| |
30 | |
31 public ThreadManager(Handler handler) { | |
32 mHandler = handler; | |
33 } | |
34 | |
35 public Handler getHandler() { | |
36 return mHandler; | |
37 } | |
38 | |
39 public boolean runningOnThisThread() { | |
40 return mHandler.getLooper() == Looper.myLooper(); | |
41 } | |
42 | |
43 public void post(Runnable runnable) { | |
44 mHandler.post(runnable); | |
45 } | |
46 | |
47 public <T> T runBlockingForTesting(Callable<T> c) throws Exception { | |
48 if (runningOnThisThread()) { | |
49 return c.call(); | |
50 } else { | |
51 FutureTask<T> task = new FutureTask<T>(c); | |
52 mHandler.post(task); | |
53 return task.get(5, TimeUnit.SECONDS); | |
54 } | |
55 } | |
56 } | |
57 | |
58 /** | |
59 * A factory class to create or reuse ChromiumBaseInputConnection. | |
60 */ | |
61 public interface Factory { | |
62 ChromiumBaseInputConnection initializeAndGet(View view, ImeAdapter imeAd apter, | |
63 int inputType, int inputFlags, EditorInfo outAttrs); | |
64 | |
65 @VisibleForTesting | |
66 ThreadManager getThreadManager(); | |
67 } | |
68 | |
69 /** | |
70 * Updates the internal representation of the text being edited and its sele ction and | |
71 * composition properties. | |
72 * | |
73 * @param text The String contents of the field being edited. | |
74 * @param selectionStart The character offset of the selection start, or the caret position if | |
75 * there is no selection. | |
76 * @param selectionEnd The character offset of the selection end, or the car et position if there | |
77 * is no selection. | |
78 * @param compositionStart The character offset of the composition start, or -1 if there is no | |
79 * composition. | |
80 * @param compositionEnd The character offset of the composition end, or -1 if there is no | |
81 * selection. | |
82 * @param isNonImeChange True when the update was caused by non-IME (e.g. Ja vascript). | |
83 */ | |
84 void updateStateOnUiThread(String text, int selectionStart, int selectionEnd , | |
85 int compositionStart, int compositionEnd, boolean singleLine, boolea n isNonImeChange); | |
86 | |
87 /** | |
88 * Send key event on UI thread. | |
89 * @param event A key event. | |
90 */ | |
91 boolean sendKeyEventOnUiThread(KeyEvent event); | |
92 | |
93 /** | |
94 * Call this when restartInput() is called. | |
95 */ | |
96 void onRestartInputOnUiThread(); | |
97 | |
98 /** | |
99 * @return The thread manager for this InputConnection. | |
100 */ | |
101 @VisibleForTesting | |
102 ThreadManager getThreadManager(); | |
103 | |
104 /** | |
105 * Move cursor to the end of the current selection. | |
106 */ | |
107 void moveCursorToSelectionEndOnUiThread(); | |
108 | |
109 /** | |
110 * Unblock thread function if needed, e.g. we found that we will | |
111 * never get state update. | |
112 */ | |
113 void unblockOnUiThread(); | |
114 } | |
OLD | NEW |