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