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

Side by Side Diff: content/public/android/java/src/org/chromium/content/browser/input/ChromiumBaseInputConnection.java

Issue 1278593004: Introduce ThreadedInputConnection behind a switch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: unified ime tests, changed default values, fixed bugs, not wait for update if possible Created 4 years, 11 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
(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.ExecutionException;
18 import java.util.concurrent.FutureTask;
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;
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) {
48 if (runningOnThisThread()) {
49 try {
50 return c.call();
51 } catch (Exception e) {
52 e.printStackTrace();
53 return null;
54 }
55 } else {
56 FutureTask<T> task = new FutureTask<T>(c);
57 mHandler.post(task);
58 try {
59 return task.get();
60 } catch (InterruptedException | ExecutionException e) {
61 e.printStackTrace();
62 return null;
63 }
64 }
65 }
66 }
67
68 /**
69 * A factory class to create or reuse ChromiumBaseInputConnection.
70 */
71 public interface Factory {
72 ChromiumBaseInputConnection initializeAndGet(View view, ImeAdapter imeAd apter,
73 int inputType, int inputFlags, EditorInfo outAttrs);
74
75 @VisibleForTesting
76 ThreadManager getThreadManager();
77 }
78
79 /**
80 * Updates the internal representation of the text being edited and its sele ction and
81 * composition properties.
82 *
83 * @param text The String contents of the field being edited.
84 * @param selectionStart The character offset of the selection start, or the caret position if
85 * there is no selection.
86 * @param selectionEnd The character offset of the selection end, or the car et position if there
87 * is no selection.
88 * @param compositionStart The character offset of the composition start, or -1 if there is no
89 * composition.
90 * @param compositionEnd The character offset of the composition end, or -1 if there is no
91 * selection.
92 * @param isNonImeChange True when the update was caused by non-IME (e.g. Ja vascript).
93 */
94 void updateStateOnUiThread(String text, int selectionStart, int selectionEnd ,
95 int compositionStart, int compositionEnd, boolean singleLine, boolea n isNonImeChange);
96
97 /**
98 * Send key event on UI thread.
99 * @param event A key event.
100 */
101 boolean sendKeyEventOnUiThread(KeyEvent event);
102
103 /**
104 * Call this when restartInput() is called.
105 */
106 void onRestartInputOnUiThread();
107
108 /**
109 * @return The thread manager for this InputConnection.
110 */
111 @VisibleForTesting
112 ThreadManager getThreadManager();
113
114 /**
115 * Move cursor to the end of the current selection.
116 */
117 void moveCursorToSelectionEndOnUiThread();
118
119 /**
120 * Unblock thread function if needed, e.g. we found that we will
121 * never get state update.
122 */
123 void unblock();
124 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698