| Index: content/public/test/android/javatests/src/org/chromium/content/browser/test/util/TestCursorAnchorInfoWrapper.java
|
| diff --git a/content/public/test/android/javatests/src/org/chromium/content/browser/test/util/TestCursorAnchorInfoWrapper.java b/content/public/test/android/javatests/src/org/chromium/content/browser/test/util/TestCursorAnchorInfoWrapper.java
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..59a33357ed9e5c88acbe8c2d4f367d67c300eb54
|
| --- /dev/null
|
| +++ b/content/public/test/android/javatests/src/org/chromium/content/browser/test/util/TestCursorAnchorInfoWrapper.java
|
| @@ -0,0 +1,218 @@
|
| +// 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.test.util;
|
| +
|
| +import android.graphics.Matrix;
|
| +import android.graphics.RectF;
|
| +import android.text.SpannedString;
|
| +
|
| +import org.chromium.base.VisibleForTesting;
|
| +import org.chromium.content.browser.input.CursorAnchorInfoWrapper;
|
| +
|
| +import java.util.ArrayList;
|
| +import java.util.Arrays;
|
| +
|
| +/**
|
| + * Mock implementation of {@link CursorAnchorInfoWrapper}.
|
| + */
|
| +@VisibleForTesting
|
| +public class TestCursorAnchorInfoWrapper implements CursorAnchorInfoWrapper {
|
| +
|
| + /**
|
| + * Mock implementation of
|
| + * {@link org.chromium.content.browser.input.CursorAnchorInfoWrapper.Builder}.
|
| + */
|
| + public static final class Builder implements CursorAnchorInfoWrapper.Builder {
|
| + private int mSelectionStart = -1;
|
| + private int mSelectionEnd = -1;
|
| + private int mComposingTextStart = -1;
|
| + private CharSequence mComposingText = null;
|
| + private float mInsertionMarkerHorizontal = Float.NaN;
|
| + private float mInsertionMarkerTop = Float.NaN;
|
| + private float mInsertionMarkerBaseline = Float.NaN;
|
| + private float mInsertionMarkerBottom = Float.NaN;
|
| + private int mInsertionMarkerFlags = 0;
|
| + private final ArrayList<Integer> mCharacterBoundsIndexList = new ArrayList<>();
|
| + private final ArrayList<Integer> mCharacterBoundsFlagsList = new ArrayList<>();
|
| + private final ArrayList<RectF> mCharacterBoundsRectList = new ArrayList<>();
|
| + private final Matrix mMatrix = new Matrix();
|
| +
|
| + @Override
|
| + public Builder setSelectionRange(int newStart, int newEnd) {
|
| + mSelectionStart = newStart;
|
| + mSelectionEnd = newEnd;
|
| + return this;
|
| + }
|
| +
|
| + @Override
|
| + public Builder setComposingText(int composingTextStart, CharSequence composingText) {
|
| + mComposingTextStart = composingTextStart;
|
| + mComposingText = composingText == null ? null : new SpannedString(composingText);
|
| + return this;
|
| + }
|
| +
|
| + @Override
|
| + public Builder setInsertionMarkerLocation(float horizontalPosition,
|
| + float lineTop, float lineBaseline, float lineBottom, int flags) {
|
| + mInsertionMarkerHorizontal = horizontalPosition;
|
| + mInsertionMarkerTop = lineTop;
|
| + mInsertionMarkerBaseline = lineBaseline;
|
| + mInsertionMarkerBottom = lineBottom;
|
| + mInsertionMarkerFlags = flags;
|
| + return this;
|
| + }
|
| +
|
| + @Override
|
| + public Builder addCharacterBounds(int index, float left, float top, float right,
|
| + float bottom, int flags) {
|
| + if (mCharacterBoundsIndexList.size() > 0
|
| + && (mCharacterBoundsIndexList.get(mCharacterBoundsIndexList.size() - 1)
|
| + >= index)) {
|
| + throw new IllegalArgumentException("key must be greater than all existing keys.");
|
| + }
|
| + mCharacterBoundsIndexList.add(index);
|
| + mCharacterBoundsFlagsList.add(flags);
|
| + mCharacterBoundsRectList.add(new RectF(left, top, right, bottom));
|
| + return this;
|
| + }
|
| +
|
| + @Override
|
| + public Builder setMatrix(Matrix matrix) {
|
| + mMatrix.set(matrix != null ? matrix : new Matrix());
|
| + return this;
|
| + }
|
| +
|
| + @Override
|
| + public CursorAnchorInfoWrapper build() {
|
| + return new TestCursorAnchorInfoWrapper(this);
|
| + }
|
| +
|
| + @Override
|
| + public void reset() {
|
| + mSelectionStart = -1;
|
| + mSelectionEnd = -1;
|
| + mComposingTextStart = -1;
|
| + mComposingText = null;
|
| + mInsertionMarkerFlags = 0;
|
| + mInsertionMarkerHorizontal = Float.NaN;
|
| + mInsertionMarkerTop = Float.NaN;
|
| + mInsertionMarkerBaseline = Float.NaN;
|
| + mInsertionMarkerBottom = Float.NaN;
|
| + mMatrix.set(new Matrix());
|
| + mCharacterBoundsIndexList.clear();
|
| + mCharacterBoundsFlagsList.clear();
|
| + mCharacterBoundsRectList.clear();
|
| + }
|
| + }
|
| +
|
| + private final int mSelectionStart;
|
| + private final int mSelectionEnd;
|
| + private final int mComposingTextStart;
|
| + private final CharSequence mComposingText;
|
| + private final int mInsertionMarkerFlags;
|
| + private final float mInsertionMarkerHorizontal;
|
| + private final float mInsertionMarkerTop;
|
| + private final float mInsertionMarkerBaseline;
|
| + private final float mInsertionMarkerBottom;
|
| + private final int[] mCharacterBoundsIndexArray;
|
| + private final int[] mCharacterBoundsFlagsArray;
|
| + private final RectF[] mCharacterBoundsRectArray;
|
| + private final Matrix mMatrix;
|
| +
|
| + private TestCursorAnchorInfoWrapper(Builder builder) {
|
| + mSelectionStart = builder.mSelectionStart;
|
| + mSelectionEnd = builder.mSelectionEnd;
|
| + mComposingTextStart = builder.mComposingTextStart;
|
| + mComposingText = builder.mComposingText;
|
| + mInsertionMarkerFlags = builder.mInsertionMarkerFlags;
|
| + mInsertionMarkerHorizontal = builder.mInsertionMarkerHorizontal;
|
| + mInsertionMarkerTop = builder.mInsertionMarkerTop;
|
| + mInsertionMarkerBaseline = builder.mInsertionMarkerBaseline;
|
| + mInsertionMarkerBottom = builder.mInsertionMarkerBottom;
|
| + mCharacterBoundsIndexArray = new int[builder.mCharacterBoundsIndexList.size()];
|
| + mCharacterBoundsFlagsArray = new int[mCharacterBoundsIndexArray.length];
|
| + mCharacterBoundsRectArray = new RectF[mCharacterBoundsIndexArray.length];
|
| + for (int i = 0; i < mCharacterBoundsIndexArray.length; ++i) {
|
| + mCharacterBoundsIndexArray[i] = builder.mCharacterBoundsIndexList.get(i);
|
| + mCharacterBoundsFlagsArray[i] = builder.mCharacterBoundsFlagsList.get(i);
|
| + mCharacterBoundsRectArray[i] = new RectF(builder.mCharacterBoundsRectList.get(i));
|
| + }
|
| + mMatrix = new Matrix(builder.mMatrix);
|
| + }
|
| +
|
| + @Override
|
| + public int getSelectionStart() {
|
| + return mSelectionStart;
|
| + }
|
| +
|
| + @Override
|
| + public int getSelectionEnd() {
|
| + return mSelectionEnd;
|
| + }
|
| +
|
| + @Override
|
| + public int getComposingTextStart() {
|
| + return mComposingTextStart;
|
| + }
|
| +
|
| + @Override
|
| + public CharSequence getComposingText() {
|
| + return mComposingText;
|
| + }
|
| +
|
| + @Override
|
| + public int getInsertionMarkerFlags() {
|
| + return mInsertionMarkerFlags;
|
| + }
|
| +
|
| + @Override
|
| + public float getInsertionMarkerHorizontal() {
|
| + return mInsertionMarkerHorizontal;
|
| + }
|
| +
|
| + @Override
|
| + public float getInsertionMarkerTop() {
|
| + return mInsertionMarkerTop;
|
| + }
|
| +
|
| + @Override
|
| + public float getInsertionMarkerBaseline() {
|
| + return mInsertionMarkerBaseline;
|
| + }
|
| +
|
| + @Override
|
| + public float getInsertionMarkerBottom() {
|
| + return mInsertionMarkerBottom;
|
| + }
|
| +
|
| + @Override
|
| + public RectF getCharacterBounds(int index) {
|
| + int keyIndex = Arrays.binarySearch(mCharacterBoundsIndexArray, index);
|
| + if (keyIndex < 0) {
|
| + return null;
|
| + }
|
| + return new RectF(mCharacterBoundsRectArray[keyIndex]);
|
| + }
|
| +
|
| + @Override
|
| + public int getCharacterBoundsFlags(int index) {
|
| + int keyIndex = Arrays.binarySearch(mCharacterBoundsIndexArray, index);
|
| + if (keyIndex < 0) {
|
| + return 0;
|
| + }
|
| + return mCharacterBoundsFlagsArray[keyIndex];
|
| + }
|
| +
|
| + @Override
|
| + public Matrix getMatrix() {
|
| + return new Matrix(mMatrix);
|
| + }
|
| +
|
| + @Override
|
| + public Object unwrap() {
|
| + return null;
|
| + }
|
| +}
|
| +
|
|
|