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 |
3 | // found in the LICENSE file. |
4 | |
5 | package org.chromium.content.browser.test.util; |
6 | |
7 | import android.os.IBinder; |
8 | import android.os.ResultReceiver; |
9 | import android.view.inputmethod.EditorInfo; |
10 | import android.view.inputmethod.InputConnection; |
11 | import android.view.View; |
12 | |
13 | import org.chromium.content.browser.ContentViewCore; |
14 | import org.chromium.content.browser.input.InputMethodManagerWrapper; |
15 | |
16 | public class TestInputMethodManagerWrapper extends InputMethodManagerWrapper { |
17 | private ContentViewCore mContentViewCore; |
18 | private InputConnection mInputConnection; |
19 | private int mShowSoftInputCounter = 0; |
20 | private EditorInfo mEditorInfo; |
21 | |
22 | public TestInputMethodManagerWrapper(ContentViewCore contentViewCore) { |
23 | super(null); |
24 | mContentViewCore = contentViewCore; |
25 | } |
26 | |
27 | @Override |
28 | public void restartInput(View view) { |
29 | mEditorInfo = new EditorInfo(); |
30 | mInputConnection = mContentViewCore.onCreateInputConnection(mEditorInfo); |
31 | } |
32 | |
33 | @Override |
34 | public void showSoftInput(View view, int flags, ResultReceiver resultReceiver) { |
35 | mShowSoftInputCounter++; |
36 | if (mInputConnection != null) return; |
37 | mEditorInfo = new EditorInfo(); |
38 | mInputConnection = mContentViewCore.onCreateInputConnection(mEditorInfo); |
39 | } |
40 | |
41 | @Override |
42 | public boolean isActive(View view) { |
43 | if (mInputConnection == null) return false; |
44 | return true; |
45 | } |
46 | |
47 | @Override |
48 | public boolean hideSoftInputFromWindow(IBinder windowToken, int flags, |
49 | ResultReceiver resultReceiver) { |
50 | boolean retVal = mInputConnection == null; |
51 | mInputConnection = null; |
52 | return retVal; |
53 | } |
54 | |
55 | @Override |
56 | public void updateSelection(View view, int selStart, int selEnd, |
57 | int candidatesStart, int candidatesEnd) { |
58 | } |
59 | |
60 | public int getShowSoftInputCounter() { |
61 | return mShowSoftInputCounter; |
62 | } |
63 | |
64 | public EditorInfo getEditorInfo() { |
65 | return mEditorInfo; |
66 | } |
67 | } |
68 | |