Commit 7f4f5212 authored by Changwan Ryu's avatar Changwan Ryu Committed by Commit Bot

Apply zero-latency keyboard popup to pre-R

This is a follow-up to https://crrev.com/c/2340295 to extend the work to
pre-R version of Android.

According to one experiment, if the keyboard is looking up the initial
surrounding text, the reduction was from 164.83ms to 0.07ms.

We expect a similar level of reduction for pre-R devices.

Note that it is possible that accessing the compat library can slightly
increase the time taken for the first keyboard activation, but overall
this should a significant win.

Bug: b/170464119
Change-Id: I3cbab8d04873a6773c7302ae9cd9064636619302
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2544064Reviewed-by: default avatarShimi Zhang <ctzsm@chromium.org>
Commit-Queue: Changwan Ryu <changwan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#828491}
parent 4d428967
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
package org.chromium.content.browser.input; package org.chromium.content.browser.input;
import android.annotation.TargetApi;
import android.os.Build;
import android.text.Editable; import android.text.Editable;
import android.text.InputType; import android.text.InputType;
import android.text.Selection; import android.text.Selection;
...@@ -15,8 +13,9 @@ import android.view.inputmethod.BaseInputConnection; ...@@ -15,8 +13,9 @@ import android.view.inputmethod.BaseInputConnection;
import android.view.inputmethod.CorrectionInfo; import android.view.inputmethod.CorrectionInfo;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import androidx.core.view.inputmethod.EditorInfoCompat;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.base.annotations.VerifiesOnR;
import org.chromium.blink_public.web.WebTextInputFlags; import org.chromium.blink_public.web.WebTextInputFlags;
import org.chromium.blink_public.web.WebTextInputMode; import org.chromium.blink_public.web.WebTextInputMode;
import org.chromium.ui.base.ime.TextInputAction; import org.chromium.ui.base.ime.TextInputAction;
...@@ -28,26 +27,6 @@ import java.util.Locale; ...@@ -28,26 +27,6 @@ import java.util.Locale;
* Utilities for IME such as computing outAttrs, and dumping object information. * Utilities for IME such as computing outAttrs, and dumping object information.
*/ */
public class ImeUtils { public class ImeUtils {
/**
* A class to contain R-specific code inside a separate class to avoid performance regression.
*
* See
* https://source.chromium.org/chromium/chromium/src/+/master:build/android/docs/class_verification_failures.md
* for details.
*/
@VerifiesOnR
@TargetApi(Build.VERSION_CODES.R)
private static final class HelperForR {
/** see {@link EditorInfo#setInitialSurroundingText(EditorInfo, String)} */
public static void setInitialSurroundingText(EditorInfo outAttrs, String lastText) {
// Note: Android's internal implementation trims the text up to 2048 chars before
// sending it to the IMM service. In the future, if we consider limiting the number of
// chars between renderer and browser, then consider calling
// setInitialSurroundingSubText() instead.
outAttrs.setInitialSurroundingText(lastText);
}
}
/** /**
* Compute {@link EditorInfo} based on the given parameters. This is needed for * Compute {@link EditorInfo} based on the given parameters. This is needed for
* {@link View#onCreateInputConnection(EditorInfo)}. * {@link View#onCreateInputConnection(EditorInfo)}.
...@@ -159,9 +138,11 @@ public class ImeUtils { ...@@ -159,9 +138,11 @@ public class ImeUtils {
outAttrs.initialSelStart = initialSelStart; outAttrs.initialSelStart = initialSelStart;
outAttrs.initialSelEnd = initialSelEnd; outAttrs.initialSelEnd = initialSelEnd;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { // Note: Android's internal implementation trims the text up to 2048 chars before
HelperForR.setInitialSurroundingText(outAttrs, lastText); // sending it to the IMM service. In the future, if we consider limiting the number of
} // chars between renderer and browser, then consider calling
// setInitialSurroundingSubText() instead.
EditorInfoCompat.setInitialSurroundingText(outAttrs, lastText);
} }
private static int getImeAction(int inputType, int inputFlags, int inputMode, int inputAction, private static int getImeAction(int inputType, int inputFlags, int inputMode, int inputAction,
......
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