OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.ui.base; |
| 6 |
| 7 import android.graphics.Matrix; |
| 8 import android.os.Build; |
| 9 import android.view.inputmethod.CursorAnchorInfo; |
| 10 |
| 11 import org.chromium.base.CalledByNative; |
| 12 import org.chromium.base.JNINamespace; |
| 13 |
| 14 import java.lang.CharSequence; |
| 15 |
| 16 /** |
| 17 * A simple class to allow native code to call instance methods of {@link Cursor
AnchorInfo.Builder}. |
| 18 * This class itself is designed to be stateless. All the methods are thread-saf
e. |
| 19 */ |
| 20 @JNINamespace("ui") |
| 21 public final class CursorAnchorInfoBuilder { |
| 22 |
| 23 private static final Matrix sMatrix = new Matrix(); |
| 24 |
| 25 @CalledByNative |
| 26 public static CursorAnchorInfo.Builder create() { |
| 27 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { |
| 28 return null; |
| 29 } |
| 30 return new CursorAnchorInfo.Builder(); |
| 31 } |
| 32 |
| 33 @CalledByNative |
| 34 public static void reset(CursorAnchorInfo.Builder builder) { |
| 35 builder.reset(); |
| 36 } |
| 37 |
| 38 @CalledByNative |
| 39 public static void setSelectionRange(CursorAnchorInfo.Builder builder, int n
ewStart, |
| 40 int newEnd) { |
| 41 builder.setSelectionRange(newStart, newEnd); |
| 42 } |
| 43 |
| 44 @CalledByNative |
| 45 public static void setComposingText(CursorAnchorInfo.Builder builder, int co
mposingTextStart, |
| 46 CharSequence composingText) { |
| 47 builder.setComposingText(composingTextStart, composingText); |
| 48 } |
| 49 |
| 50 @CalledByNative |
| 51 public static void setInsertionMarkerLocation(CursorAnchorInfo.Builder build
er, |
| 52 float horizontalPosition, float lineTop, float lineBaseline, float l
ineBottom, |
| 53 int flags) { |
| 54 builder.setInsertionMarkerLocation(horizontalPosition, lineTop, lineBase
line, lineBottom, |
| 55 flags); |
| 56 } |
| 57 |
| 58 @CalledByNative |
| 59 public static void addCharacterBounds(CursorAnchorInfo.Builder builder, int
index, float left, |
| 60 float top, float right, float bottom, int flags) { |
| 61 builder.addCharacterBounds(index, left, top, right, bottom, flags); |
| 62 } |
| 63 |
| 64 @CalledByNative |
| 65 public static void setScaleAndTranslate(CursorAnchorInfo.Builder builder, fl
oat scale, |
| 66 float translateX, float translateY) { |
| 67 synchronized (sMatrix) { |
| 68 sMatrix.setScale(scale, scale); |
| 69 sMatrix.postTranslate(translateX, translateY); |
| 70 builder.setMatrix(sMatrix); |
| 71 } |
| 72 } |
| 73 |
| 74 @CalledByNative |
| 75 public static CursorAnchorInfo build(CursorAnchorInfo.Builder builder) { |
| 76 return builder.build(); |
| 77 } |
| 78 } |
OLD | NEW |