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

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

Issue 1278593004: Introduce ThreadedInputConnection behind a switch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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/Range.java
diff --git a/content/public/android/java/src/org/chromium/content/browser/input/Range.java b/content/public/android/java/src/org/chromium/content/browser/input/Range.java
new file mode 100644
index 0000000000000000000000000000000000000000..c7278bc80f28e4245ed2f1b126f1b572b1f0d6bc
--- /dev/null
+++ b/content/public/android/java/src/org/chromium/content/browser/input/Range.java
@@ -0,0 +1,78 @@
+// 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.content.browser.input;
+
+/**
+ * A simple class to set start and end in int type.
+ */
+public class Range {
+ private int mStart;
+ private int mEnd;
+
+ public Range(int start, int end) {
+ set(start, end);
+ }
+
+ public void set(Range other) {
+ mStart = other.start();
+ mEnd = other.end();
+ }
+
+ public void set(int start, int end) {
+ mStart = Math.min(start, end);
+ mEnd = Math.max(start, end);
+ }
+
+ public void set(int value) {
+ mStart = value;
+ mEnd = value;
+ }
+
+ public int start() {
+ return mStart;
+ }
+
+ public int end() {
+ return mEnd;
+ }
+
+ public boolean isIn(Range other) {
+ return mStart >= other.mStart && mEnd <= other.mEnd;
+ }
+
+ public void forceWithin(Range other) {
+ if (mStart < other.mStart) mStart = other.mStart;
+ if (mStart > other.mEnd) mStart = other.mEnd;
+ if (mEnd > other.mEnd) mEnd = other.mEnd;
+ if (mEnd < other.mStart) mEnd = other.mStart;
+ }
+
+ public static Range fromText(CharSequence text) {
+ return new Range(0, text.length());
+ }
+
+ public boolean isEmpty() {
+ return mStart == mEnd;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (!(o instanceof Range)) return false;
+ if (o == this) return true;
+ Range r = (Range) o;
+ return mStart == r.mStart && mEnd == r.mEnd;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ return prime * mStart + mEnd;
+ }
+
+ @Override
+ public String toString() {
+ return "[ " + mStart + ", " + mEnd + " ]";
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698