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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: content/public/android/java/src/org/chromium/content/browser/input/ChromiumBaseInputConnection.java
diff --git a/content/public/android/java/src/org/chromium/content/browser/input/ChromiumBaseInputConnection.java b/content/public/android/java/src/org/chromium/content/browser/input/ChromiumBaseInputConnection.java
new file mode 100644
index 0000000000000000000000000000000000000000..687d2937642e64946eeee49d1a33b3116c4e5bf5
--- /dev/null
+++ b/content/public/android/java/src/org/chromium/content/browser/input/ChromiumBaseInputConnection.java
@@ -0,0 +1,124 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.content.browser.input;
+
+import android.os.Handler;
+import android.os.Looper;
+import android.view.KeyEvent;
+import android.view.View;
+import android.view.inputmethod.EditorInfo;
+import android.view.inputmethod.InputConnection;
+
+import org.chromium.base.VisibleForTesting;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.FutureTask;
+
+/**
+ * An interface to help switch between AdapterInputConnection and ChromiumInputConnection.
+ */
+public interface ChromiumBaseInputConnection extends InputConnection {
+
+ /**
+ * A class to post, run some runnable or callable on the given handler.
+ */
+ public static class ThreadManager {
+ private final Handler mHandler;
+
+ public ThreadManager(Handler handler) {
+ mHandler = handler;
+ }
+
+ public Handler getHandler() {
+ return mHandler;
+ }
+
+ public boolean runningOnThisThread() {
+ return mHandler.getLooper() == Looper.myLooper();
+ }
+
+ public void post(Runnable runnable) {
+ mHandler.post(runnable);
+ }
+
+ public <T> T runBlockingForTesting(Callable<T> c) {
+ if (runningOnThisThread()) {
+ try {
+ return c.call();
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ } else {
+ FutureTask<T> task = new FutureTask<T>(c);
+ mHandler.post(task);
+ try {
+ return task.get();
+ } catch (InterruptedException | ExecutionException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+ }
+ }
+
+ /**
+ * A factory class to create or reuse ChromiumBaseInputConnection.
+ */
+ public interface Factory {
+ ChromiumBaseInputConnection initializeAndGet(View view, ImeAdapter imeAdapter,
+ int inputType, int inputFlags, EditorInfo outAttrs);
+
+ @VisibleForTesting
+ ThreadManager getThreadManager();
+ }
+
+ /**
+ * Updates the internal representation of the text being edited and its selection and
+ * composition properties.
+ *
+ * @param text The String contents of the field being edited.
+ * @param selectionStart The character offset of the selection start, or the caret position if
+ * there is no selection.
+ * @param selectionEnd The character offset of the selection end, or the caret position if there
+ * is no selection.
+ * @param compositionStart The character offset of the composition start, or -1 if there is no
+ * composition.
+ * @param compositionEnd The character offset of the composition end, or -1 if there is no
+ * selection.
+ * @param isNonImeChange True when the update was caused by non-IME (e.g. Javascript).
+ */
+ void updateStateOnUiThread(String text, int selectionStart, int selectionEnd,
+ int compositionStart, int compositionEnd, boolean singleLine, boolean isNonImeChange);
+
+ /**
+ * Send key event on UI thread.
+ * @param event A key event.
+ */
+ boolean sendKeyEventOnUiThread(KeyEvent event);
+
+ /**
+ * Call this when restartInput() is called.
+ */
+ void onRestartInputOnUiThread();
+
+ /**
+ * @return The thread manager for this InputConnection.
+ */
+ @VisibleForTesting
+ ThreadManager getThreadManager();
+
+ /**
+ * Move cursor to the end of the current selection.
+ */
+ void moveCursorToSelectionEndOnUiThread();
+
+ /**
+ * Unblock thread function if needed, e.g. we found that we will
+ * never get state update.
+ */
+ void unblock();
+}

Powered by Google App Engine
This is Rietveld 408576698