Chromium Code Reviews| Index: ui/android/java/src/org/chromium/ui/base/CursorAnchorInfoBuilder.java |
| diff --git a/ui/android/java/src/org/chromium/ui/base/CursorAnchorInfoBuilder.java b/ui/android/java/src/org/chromium/ui/base/CursorAnchorInfoBuilder.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ead9e2427c4c3587d41f184ea60735405cb6e535 |
| --- /dev/null |
| +++ b/ui/android/java/src/org/chromium/ui/base/CursorAnchorInfoBuilder.java |
| @@ -0,0 +1,108 @@ |
| +// Copyright 2014 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.ui.base; |
| + |
| +import android.graphics.Matrix; |
| +import android.os.Build; |
| +import android.view.inputmethod.CursorAnchorInfo; |
| + |
| +import org.chromium.base.CalledByNative; |
| +import org.chromium.base.JNINamespace; |
| + |
| +import java.lang.CharSequence; |
| + |
| +/** |
| + * A simple class to allow native code to call instance methods of {@link CursorAnchorInfo.Builder}. |
| + * This class itself is designed to be stateless. All the methods are thread-safe. |
| + */ |
| +@JNINamespace("ui") |
| +public final class CursorAnchorInfoBuilder { |
| + |
| + private static final Matrix sMatrix = new Matrix(); |
| + private static final float[] sMatrixValues = new float[9]; |
| + |
| + @CalledByNative |
| + public static CursorAnchorInfo.Builder create() { |
| + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { |
| + return null; |
| + } |
| + return new CursorAnchorInfo.Builder(); |
| + } |
| + |
| + @CalledByNative |
| + public static void reset(CursorAnchorInfo.Builder builder) { |
| + if (builder == null) { |
| + return; |
| + } |
| + builder.reset(); |
| + } |
| + |
| + @CalledByNative |
| + public static void setSelectionRange(CursorAnchorInfo.Builder builder, int newStart, |
| + int newEnd) { |
| + if (builder == null) { |
|
jdduke (slow)
2015/01/14 17:17:09
Hmm, when will the builder be null? Can we avoid m
yukawa
2015/01/14 22:21:58
Basically |builder| shouldn't be null. Removed ac
|
| + return; |
| + } |
| + builder.setSelectionRange(newStart, newEnd); |
| + } |
| + |
| + @CalledByNative |
| + public static void setComposingText(CursorAnchorInfo.Builder builder, int composingTextStart, |
| + CharSequence composingText) { |
| + if (builder == null) { |
| + return; |
| + } |
| + builder.setComposingText(composingTextStart, composingText); |
| + } |
| + |
| + @CalledByNative |
| + public static void setInsertionMarkerLocation(CursorAnchorInfo.Builder builder, |
| + float horizontalPosition, float lineTop, float lineBaseline, float lineBottom, |
| + int flags) { |
| + if (builder == null) { |
| + return; |
| + } |
| + builder.setInsertionMarkerLocation(horizontalPosition, lineTop, lineBaseline, lineBottom, |
| + flags); |
| + } |
| + |
| + @CalledByNative |
| + public static void addCharacterBounds(CursorAnchorInfo.Builder builder, int index, float left, |
| + float top, float right, float bottom, int flags) { |
| + if (builder == null) { |
| + return; |
| + } |
| + builder.addCharacterBounds(index, left, top, right, bottom, flags); |
| + } |
| + |
| + @CalledByNative |
| + public static void setMatrix(CursorAnchorInfo.Builder builder, float m00, float m01, float m02, |
|
jdduke (slow)
2015/01/14 17:17:09
Would it be simpler to instead just pass the scale
yukawa
2015/01/14 22:21:59
Done.
|
| + float m10, float m11, float m12, float m20, float m21, float m22) { |
| + if (builder == null) { |
| + return; |
| + } |
| + synchronized (sMatrix) { |
| + sMatrixValues[0] = m00; |
| + sMatrixValues[1] = m01; |
| + sMatrixValues[2] = m02; |
| + sMatrixValues[3] = m10; |
| + sMatrixValues[4] = m11; |
| + sMatrixValues[5] = m12; |
| + sMatrixValues[6] = m20; |
| + sMatrixValues[7] = m21; |
| + sMatrixValues[8] = m22; |
| + sMatrix.setValues(sMatrixValues); |
| + builder.setMatrix(sMatrix); |
| + } |
| + } |
| + |
| + @CalledByNative |
| + public static CursorAnchorInfo build(CursorAnchorInfo.Builder builder) { |
| + if (builder == null) { |
| + return null; |
| + } |
| + return builder.build(); |
| + } |
| +} |