Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1310)

Unified Diff: content/public/android/java/src/org/chromium/content/browser/input/TextInputState.java

Issue 1278593004: Introduce ThreadedInputConnection behind a switch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed a crash for LatinIME Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/public/android/java/src/org/chromium/content/browser/input/TextInputState.java
diff --git a/content/public/android/java/src/org/chromium/content/browser/input/TextInputState.java b/content/public/android/java/src/org/chromium/content/browser/input/TextInputState.java
new file mode 100644
index 0000000000000000000000000000000000000000..17012c707e2e2828f0d1f96d30bbb6a264d65d2f
--- /dev/null
+++ b/content/public/android/java/src/org/chromium/content/browser/input/TextInputState.java
@@ -0,0 +1,90 @@
+// Copyright 2016 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.content.browser.input;
+
+import android.text.TextUtils;
+
+/**
+ * An immutable class to contain text, selection range, composition range, and whether
+ * it's single line or multiple lines that are being edited.
+ */
+public class TextInputState {
+ private final CharSequence mText;
+ private final Range mSelection;
+ private final Range mComposition;
+ private final boolean mSingleLine;
+
+ public TextInputState(CharSequence text, Range selection, Range composition,
+ boolean singleLine) {
+ selection.clamp(0, text.length());
+ if (composition.start() != -1 || composition.end() != -1) {
+ composition.clamp(0, text.length());
+ }
+ mText = text;
+ mSelection = selection;
+ mComposition = composition;
+ mSingleLine = singleLine;
+ }
+
+ public CharSequence text() {
+ return mText;
+ }
+
+ public Range selection() {
+ return mSelection;
+ }
+
+ public Range composition() {
+ return mComposition;
+ }
+
+ public boolean singleLine() {
+ return mSingleLine;
+ }
+
+ public CharSequence getSelectedText() {
+ return TextUtils.substring(mText, mSelection.start(), mSelection.end());
+ }
+
+ public CharSequence getTextAfterSelection(int maxChars) {
+ return TextUtils.substring(
+ mText, mSelection.end(), Math.min(mText.length(), mSelection.end() + maxChars));
+ }
+
+ public CharSequence getTextBeforeSelection(int maxChars) {
+ return TextUtils.substring(
+ mText, Math.max(0, mSelection.start() - maxChars), mSelection.start());
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (!(o instanceof TextInputState)) return false;
+ TextInputState t = (TextInputState) o;
+ if (t == this) return true;
+ return TextUtils.equals(mText, t.mText) && mSelection.equals(t.mSelection)
+ && mComposition.equals(t.mComposition) && mSingleLine == t.mSingleLine;
+ }
+
+ @Override
+ public int hashCode() {
+ return mText.hashCode() * 7 + mSelection.hashCode() * 11 + mComposition.hashCode() * 13
+ + (mSingleLine ? 19 : 0);
+ }
+
+ public boolean shouldUnblock() {
+ return false;
+ }
+
+ static class Unblocker extends TextInputState {
+ public Unblocker() {
+ super("", new Range(0, 0), new Range(-1, -1), false);
+ }
+
+ @Override
+ public boolean shouldUnblock() {
+ return true;
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698