Chromium Code Reviews| 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 private static final float[] sMatrixValues = new float[9]; | |
| 25 | |
| 26 @CalledByNative | |
| 27 public static CursorAnchorInfo.Builder create() { | |
| 28 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { | |
| 29 return null; | |
| 30 } | |
| 31 return new CursorAnchorInfo.Builder(); | |
| 32 } | |
| 33 | |
| 34 @CalledByNative | |
| 35 public static void reset(CursorAnchorInfo.Builder builder) { | |
| 36 if (builder == null) { | |
| 37 return; | |
| 38 } | |
| 39 builder.reset(); | |
| 40 } | |
| 41 | |
| 42 @CalledByNative | |
| 43 public static void setSelectionRange(CursorAnchorInfo.Builder builder, int n ewStart, | |
| 44 int newEnd) { | |
| 45 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
| |
| 46 return; | |
| 47 } | |
| 48 builder.setSelectionRange(newStart, newEnd); | |
| 49 } | |
| 50 | |
| 51 @CalledByNative | |
| 52 public static void setComposingText(CursorAnchorInfo.Builder builder, int co mposingTextStart, | |
| 53 CharSequence composingText) { | |
| 54 if (builder == null) { | |
| 55 return; | |
| 56 } | |
| 57 builder.setComposingText(composingTextStart, composingText); | |
| 58 } | |
| 59 | |
| 60 @CalledByNative | |
| 61 public static void setInsertionMarkerLocation(CursorAnchorInfo.Builder build er, | |
| 62 float horizontalPosition, float lineTop, float lineBaseline, float l ineBottom, | |
| 63 int flags) { | |
| 64 if (builder == null) { | |
| 65 return; | |
| 66 } | |
| 67 builder.setInsertionMarkerLocation(horizontalPosition, lineTop, lineBase line, lineBottom, | |
| 68 flags); | |
| 69 } | |
| 70 | |
| 71 @CalledByNative | |
| 72 public static void addCharacterBounds(CursorAnchorInfo.Builder builder, int index, float left, | |
| 73 float top, float right, float bottom, int flags) { | |
| 74 if (builder == null) { | |
| 75 return; | |
| 76 } | |
| 77 builder.addCharacterBounds(index, left, top, right, bottom, flags); | |
| 78 } | |
| 79 | |
| 80 @CalledByNative | |
| 81 public static void setMatrix(CursorAnchorInfo.Builder builder, float m00, fl oat 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.
| |
| 82 float m10, float m11, float m12, float m20, float m21, float m22) { | |
| 83 if (builder == null) { | |
| 84 return; | |
| 85 } | |
| 86 synchronized (sMatrix) { | |
| 87 sMatrixValues[0] = m00; | |
| 88 sMatrixValues[1] = m01; | |
| 89 sMatrixValues[2] = m02; | |
| 90 sMatrixValues[3] = m10; | |
| 91 sMatrixValues[4] = m11; | |
| 92 sMatrixValues[5] = m12; | |
| 93 sMatrixValues[6] = m20; | |
| 94 sMatrixValues[7] = m21; | |
| 95 sMatrixValues[8] = m22; | |
| 96 sMatrix.setValues(sMatrixValues); | |
| 97 builder.setMatrix(sMatrix); | |
| 98 } | |
| 99 } | |
| 100 | |
| 101 @CalledByNative | |
| 102 public static CursorAnchorInfo build(CursorAnchorInfo.Builder builder) { | |
| 103 if (builder == null) { | |
| 104 return null; | |
| 105 } | |
| 106 return builder.build(); | |
| 107 } | |
| 108 } | |
| OLD | NEW |