Chromium Code Reviews| Index: content/public/android/java/src/org/chromium/content/browser/input/ThreadedInputConnectionFactory.java |
| diff --git a/content/public/android/java/src/org/chromium/content/browser/input/ThreadedInputConnectionFactory.java b/content/public/android/java/src/org/chromium/content/browser/input/ThreadedInputConnectionFactory.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f97411a2764a610d490afc45579ac93571a97b8c |
| --- /dev/null |
| +++ b/content/public/android/java/src/org/chromium/content/browser/input/ThreadedInputConnectionFactory.java |
| @@ -0,0 +1,76 @@ |
| +// 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.HandlerThread; |
| +import android.view.View; |
| +import android.view.inputmethod.EditorInfo; |
| + |
| +import org.chromium.base.Log; |
| +import org.chromium.base.ThreadUtils; |
| +import org.chromium.content.browser.input.ChromiumBaseInputConnection.ThreadManager; |
| + |
| +/** |
| + * Default factory for ChromiumBaseInputConnection classes. |
| + */ |
| +public class ThreadedInputConnectionFactory implements ChromiumBaseInputConnection.Factory { |
| + private static final String TAG = "cr_Ime"; |
| + private static final boolean DEBUG_LOGS = false; |
| + |
| + private ThreadedInputConnection mThreadedInputConnection; |
| + private final Handler mHandler; |
| + private final ThreadedInputConnection.ThreadManager mThreadManager; |
| + private final InputMethodManagerWrapper mInputMethodManagerWrapper; |
| + private ThreadedInputConnectionProxyView mProxyView; |
| + |
| + ThreadedInputConnectionFactory(InputMethodManagerWrapper inputMethodManagerWrapper) { |
| + HandlerThread thread = |
| + new HandlerThread("InputConnectionHandlerThread", HandlerThread.NORM_PRIORITY); |
| + thread.start(); |
| + mHandler = new Handler(thread.getLooper()); |
| + mThreadManager = new ThreadManager(mHandler); |
| + mInputMethodManagerWrapper = inputMethodManagerWrapper; |
| + } |
| + |
| + @Override |
| + public ChromiumBaseInputConnection initializeAndGet(View view, ImeAdapter imeAdapter, |
| + int inputType, int inputFlags, EditorInfo outAttrs) { |
| + if (ThreadUtils.runningOnUiThread()) { |
|
aelias_OOO_until_Jul13
2016/02/08 23:17:14
Is there a way to avoid this thread-based branchin
Changwan Ryu
2016/02/11 16:21:08
Some WebView users (app developers) may override o
aelias_OOO_until_Jul13
2016/02/11 23:13:15
Subclassing WebView is very rare in the first plac
Changwan Ryu
2016/02/12 00:36:03
Unfortunately, there are apps that override webvie
|
| + if (DEBUG_LOGS) Log.w(TAG, "initializeAndGet: running on ui thread"); |
| + if (mThreadedInputConnection != null) { |
| + mThreadedInputConnection.finishComposingTextOnUiThread(); |
| + } |
| + triggerDelayedOnCreateInputConnection(view); |
| + return null; |
|
aelias_OOO_until_Jul13
2016/02/08 23:17:14
What if instead of returning a null InputConnectio
Changwan Ryu
2016/02/11 16:21:08
That's something we could consider if this doesn't
aelias_OOO_until_Jul13
2016/02/11 23:13:15
OK, if immediately calling showSoftInput always pr
aelias_OOO_until_Jul13
2016/02/11 23:13:15
OK, if immediately calling showSoftInput always pr
Changwan Ryu
2016/02/12 00:36:03
Hmm... I think nullity of input connection is not
|
| + } |
| + if (DEBUG_LOGS) Log.w(TAG, "initializeAndGet: running on IME thread"); |
| + if (mThreadedInputConnection == null) { |
| + if (DEBUG_LOGS) Log.w(TAG, "Creating ThreadedInputConnection..."); |
| + mThreadedInputConnection = new ThreadedInputConnection(imeAdapter, mThreadManager); |
| + } |
| + mThreadedInputConnection.initializeOutAttrs(inputType, inputFlags, outAttrs); |
| + return mThreadedInputConnection; |
| + } |
| + |
| + private void triggerDelayedOnCreateInputConnection(final View view) { |
| + if (DEBUG_LOGS) Log.w(TAG, "triggerDelayedOnCreateInputConnection"); |
| + mProxyView = new ThreadedInputConnectionProxyView( |
|
aelias_OOO_until_Jul13
2016/02/08 23:17:14
This ThreadedInputConnectionProxyView class is not
Changwan Ryu
2016/02/11 16:21:08
Added now.
|
| + view.getContext(), mHandler, view); |
| + mProxyView.requestFocus(); |
| + view.getHandler().post(new Runnable() { |
| + @Override |
| + public void run() { |
| + mProxyView.onWindowFocusChanged(true); |
| + mInputMethodManagerWrapper.isActive(mProxyView); |
| + } |
| + }); |
| + } |
| + |
| + @Override |
| + public ThreadManager getThreadManager() { |
| + return mThreadManager; |
| + } |
| +} |