Commit 0c474f48 authored by changwan's avatar changwan Committed by Commit bot

Implement ThreadedInputConnection#getCursorCapsMode()

Some Latin keyboard apps use this function to check whether they need to
capitalize a letter at the current cursor. Delegating to TextUtil just as
BaseInputConnection#getCursorCapsMode() does.

BUG=648439

Review-Url: https://codereview.chromium.org/2349383004
Cr-Commit-Position: refs/heads/master@{#419929}
parent b481c6d0
...@@ -7,6 +7,7 @@ package org.chromium.content.browser.input; ...@@ -7,6 +7,7 @@ package org.chromium.content.browser.input;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.text.TextUtils;
import android.view.KeyCharacterMap; import android.view.KeyCharacterMap;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.View; import android.view.View;
...@@ -572,9 +573,14 @@ public class ThreadedInputConnection extends BaseInputConnection ...@@ -572,9 +573,14 @@ public class ThreadedInputConnection extends BaseInputConnection
*/ */
@Override @Override
public int getCursorCapsMode(int reqModes) { public int getCursorCapsMode(int reqModes) {
if (DEBUG_LOGS) Log.w(TAG, "getCursorCapsMode [%x]", reqModes); TextInputState textInputState = requestAndWaitForTextInputState();
// TODO(changwan): implement this. int result = 0;
return 0; if (textInputState != null) {
result = TextUtils.getCapsMode(
textInputState.text(), textInputState.selection().start(), reqModes);
}
if (DEBUG_LOGS) Log.w(TAG, "getCursorCapsMode [%x]: %x", reqModes, result);
return result;
} }
/** /**
......
...@@ -13,6 +13,7 @@ import android.os.Handler; ...@@ -13,6 +13,7 @@ import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.test.suitebuilder.annotation.MediumTest; import android.test.suitebuilder.annotation.MediumTest;
import android.test.suitebuilder.annotation.SmallTest; import android.test.suitebuilder.annotation.SmallTest;
import android.text.InputType;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Pair; import android.util.Pair;
import android.view.KeyEvent; import android.view.KeyEvent;
...@@ -1368,6 +1369,23 @@ public class ImeTest extends ContentShellTestBase { ...@@ -1368,6 +1369,23 @@ public class ImeTest extends ContentShellTestBase {
waitForEventLogs("keydown(229),input,keyup(229),selectionchange,selectionchange"); waitForEventLogs("keydown(229),input,keyup(229),selectionchange,selectionchange");
} }
@MediumTest
@Feature({"TextInput"})
@RetryOnFailure
public void testGetCursorCapsMode() throws Throwable {
commitText("Hello World", 1);
waitAndVerifyUpdateSelection(0, 11, 11, -1, -1);
assertEquals(0,
getCursorCapsMode(InputType.TYPE_TEXT_FLAG_CAP_WORDS));
setSelection(6, 6);
waitAndVerifyUpdateSelection(1, 6, 6, -1, -1);
assertEquals(InputType.TYPE_TEXT_FLAG_CAP_WORDS,
getCursorCapsMode(InputType.TYPE_TEXT_FLAG_CAP_WORDS));
commitText("\n", 1);
assertEquals(InputType.TYPE_TEXT_FLAG_CAP_WORDS,
getCursorCapsMode(InputType.TYPE_TEXT_FLAG_CAP_WORDS));
}
private void clearEventLogs() throws Exception { private void clearEventLogs() throws Exception {
final String code = "clearEventLogs()"; final String code = "clearEventLogs()";
JavaScriptUtils.executeJavaScriptAndWaitForResult( JavaScriptUtils.executeJavaScriptAndWaitForResult(
...@@ -1771,6 +1789,16 @@ public class ImeTest extends ContentShellTestBase { ...@@ -1771,6 +1789,16 @@ public class ImeTest extends ContentShellTestBase {
}); });
} }
private int getCursorCapsMode(final int reqModes) throws Throwable {
final ChromiumBaseInputConnection connection = mConnection;
return runBlockingOnImeThread(new Callable<Integer>() {
@Override
public Integer call() {
return connection.getCursorCapsMode(reqModes);
}
});
}
private void dispatchKeyEvent(final KeyEvent event) { private void dispatchKeyEvent(final KeyEvent event) {
ThreadUtils.runOnUiThreadBlocking(new Runnable() { ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override @Override
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment