| Index: ui/platform_window/android/java/src/org/chromium/ui/PlatformWindowInputConnection.java
|
| diff --git a/ui/platform_window/android/java/src/org/chromium/ui/PlatformWindowInputConnection.java b/ui/platform_window/android/java/src/org/chromium/ui/PlatformWindowInputConnection.java
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..70deb102963bcd32f7017b9c6e01c8360de59c79
|
| --- /dev/null
|
| +++ b/ui/platform_window/android/java/src/org/chromium/ui/PlatformWindowInputConnection.java
|
| @@ -0,0 +1,80 @@
|
| +// Copyright 2015 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.ui;
|
| +
|
| +import android.view.inputmethod.BaseInputConnection;
|
| +import android.view.KeyCharacterMap;
|
| +import android.view.KeyEvent;
|
| +import android.view.View;
|
| +
|
| +import org.chromium.base.Log;
|
| +
|
| +/**
|
| + * Exposes InputConnection related code to native code.
|
| + */
|
| +class PlatformWindowInputConnection extends BaseInputConnection{
|
| + private static final String TAG = "auraclank:";
|
| + private static final int COMPOSITION_KEY_CODE = 229;
|
| +
|
| + private final View mWindow;
|
| + static char[] sSingleCharArray = new char[1];
|
| + static KeyCharacterMap sKeyCharacterMap;
|
| +
|
| + PlatformWindowInputConnection(View targetView, boolean fullEditor) {
|
| + super(targetView, fullEditor);
|
| + mWindow = targetView;
|
| + }
|
| +
|
| + /**
|
| + * @return Android KeyEvent for a single unicode character. Only one KeyEvent is returned
|
| + * even if the system determined that various modifier keys (like Shift) would also have
|
| + * been pressed.
|
| + */
|
| + private static KeyEvent androidKeyEventForCharacter(char chr) {
|
| + if (sKeyCharacterMap == null) {
|
| + sKeyCharacterMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
|
| + }
|
| + sSingleCharArray[0] = chr;
|
| + // TODO: Evaluate cost of this system call.
|
| + KeyEvent[] events = sKeyCharacterMap.getEvents(sSingleCharArray);
|
| + if (events == null) { // No known key sequence will create that character.
|
| + return null;
|
| + }
|
| +
|
| + for (int i = 0; i < events.length; ++i) {
|
| + if (events[i].getAction() == KeyEvent.ACTION_DOWN
|
| + && !KeyEvent.isModifierKey(events[i].getKeyCode())) {
|
| + return events[i];
|
| + }
|
| + }
|
| +
|
| + return null; // No printing characters were found.
|
| + }
|
| +
|
| + @Override
|
| + public boolean deleteSurroundingText(int beforeLength, int afterLength) {
|
| + Log.e(TAG, "deleteSurroundingText");
|
| + return mWindow.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN,
|
| + KeyEvent.KEYCODE_DEL));
|
| + }
|
| +
|
| + @Override
|
| + public boolean sendKeyEvent(KeyEvent event) {
|
| + Log.e(TAG, "send key event");
|
| + return mWindow.dispatchKeyEvent(event);
|
| + }
|
| +
|
| + @Override
|
| + public boolean commitText(CharSequence text, int newCursorPosition) {
|
| + // hack: transform commit text to key event.
|
| + Log.e(TAG, "commitText [%s] [%d]", text, newCursorPosition);
|
| +
|
| + String textStr = text.toString();
|
| + if (textStr.length() != 1) {
|
| + Log.e(TAG, "Not yet support commit more than 1 char");
|
| + }
|
| + return mWindow.dispatchKeyEvent(androidKeyEventForCharacter(textStr.charAt(0)));
|
| + }
|
| +}
|
|
|