OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.content.browser.input; | 5 package org.chromium.content.browser.input; |
6 | 6 |
7 import android.annotation.TargetApi; | 7 import android.annotation.TargetApi; |
8 import android.graphics.Matrix; | 8 import android.graphics.Matrix; |
9 import android.os.Build; | 9 import android.os.Build; |
10 import android.view.View; | 10 import android.view.View; |
11 import android.view.inputmethod.CursorAnchorInfo; | 11 import android.view.inputmethod.CursorAnchorInfo; |
| 12 import android.view.inputmethod.InputConnection; |
12 | 13 |
13 import org.chromium.base.VisibleForTesting; | 14 import org.chromium.base.VisibleForTesting; |
14 import org.chromium.base.annotations.SuppressFBWarnings; | 15 import org.chromium.base.annotations.SuppressFBWarnings; |
15 import org.chromium.content.browser.RenderCoordinates; | 16 import org.chromium.content.browser.RenderCoordinates; |
16 | 17 |
17 import java.util.Arrays; | 18 import java.util.Arrays; |
18 | 19 |
19 import javax.annotation.Nonnull; | 20 import javax.annotation.Nonnull; |
20 import javax.annotation.Nullable; | 21 import javax.annotation.Nullable; |
21 | 22 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 */ | 122 */ |
122 public void invalidateLastCursorAnchorInfo() { | 123 public void invalidateLastCursorAnchorInfo() { |
123 if (!mIsEditable) return; | 124 if (!mIsEditable) return; |
124 | 125 |
125 mLastCursorAnchorInfo = null; | 126 mLastCursorAnchorInfo = null; |
126 } | 127 } |
127 | 128 |
128 /** | 129 /** |
129 * Sets positional information of composing text as an array of character bo
unds. | 130 * Sets positional information of composing text as an array of character bo
unds. |
130 * @param compositionCharacterBounds Array of character bounds in local coor
dinates. | 131 * @param compositionCharacterBounds Array of character bounds in local coor
dinates. |
131 * @param view The attached view. | |
132 */ | 132 */ |
133 public void setCompositionCharacterBounds(float[] compositionCharacterBounds
, View view) { | 133 public void setCompositionCharacterBounds(float[] compositionCharacterBounds
) { |
134 if (!mIsEditable) return; | 134 if (!mIsEditable) return; |
135 | 135 |
136 if (!Arrays.equals(compositionCharacterBounds, mCompositionCharacterBoun
ds)) { | 136 if (!Arrays.equals(compositionCharacterBounds, mCompositionCharacterBoun
ds)) { |
137 mLastCursorAnchorInfo = null; | 137 mLastCursorAnchorInfo = null; |
138 mCompositionCharacterBounds = compositionCharacterBounds; | 138 mCompositionCharacterBounds = compositionCharacterBounds; |
139 } | 139 } |
140 updateCursorAnchorInfo(view); | |
141 } | 140 } |
142 | 141 |
143 /** | 142 /** |
144 * Sets coordinates system parameters and selection marker information. | 143 * Sets coordinates system parameters and selection marker information. |
145 * @param hasInsertionMarker {@code true} if the insertion marker exists. | 144 * @param hasInsertionMarker {@code true} if the insertion marker exists. |
146 * @param isInsertionMarkerVisible {@code true} if the insertion insertion m
arker is visible. | 145 * @param isInsertionMarkerVisible {@code true} if the insertion insertion m
arker is visible. |
147 * @param insertionMarkerHorizontal X coordinate of the top of the first sel
ection marker. | 146 * @param insertionMarkerHorizontal X coordinate of the top of the first sel
ection marker. |
148 * @param insertionMarkerTop Y coordinate of the top of the first selection
marker. | 147 * @param insertionMarkerTop Y coordinate of the top of the first selection
marker. |
149 * @param insertionMarkerBottom Y coordinate of the bottom of the first sele
ction marker. | 148 * @param insertionMarkerBottom Y coordinate of the bottom of the first sele
ction marker. |
150 * @param view The attached view. | 149 * @param view The attached view. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 } | 191 } |
193 | 192 |
194 // Notify to IME if there is a pending request, or if it is in monitor m
ode and we have | 193 // Notify to IME if there is a pending request, or if it is in monitor m
ode and we have |
195 // some change in the state. | 194 // some change in the state. |
196 if (mHasPendingImmediateRequest | 195 if (mHasPendingImmediateRequest |
197 || (mMonitorModeEnabled && mLastCursorAnchorInfo == null)) { | 196 || (mMonitorModeEnabled && mLastCursorAnchorInfo == null)) { |
198 updateCursorAnchorInfo(view); | 197 updateCursorAnchorInfo(view); |
199 } | 198 } |
200 } | 199 } |
201 | 200 |
| 201 /** |
| 202 * Resets the current state on update monitoring mode to the default (= do n
othing.) |
| 203 */ |
| 204 public void resetMonitoringState() { |
| 205 mMonitorModeEnabled = false; |
| 206 mHasPendingImmediateRequest = false; |
| 207 } |
| 208 |
202 public void focusedNodeChanged(boolean isEditable) { | 209 public void focusedNodeChanged(boolean isEditable) { |
203 mIsEditable = isEditable; | 210 mIsEditable = isEditable; |
204 mCompositionCharacterBounds = null; | 211 mCompositionCharacterBounds = null; |
205 mHasCoordinateInfo = false; | 212 mHasCoordinateInfo = false; |
206 mLastCursorAnchorInfo = null; | 213 mLastCursorAnchorInfo = null; |
207 } | 214 } |
208 | 215 |
209 public boolean onRequestCursorUpdates(boolean immediateRequest, boolean moni
torRequest, | 216 public boolean onRequestCursorUpdates(int cursorUpdateMode, View view) { |
210 View view) { | |
211 if (!mIsEditable) return false; | 217 if (!mIsEditable) return false; |
212 | 218 |
213 if (mMonitorModeEnabled && !monitorRequest) { | 219 mMonitorModeEnabled = (cursorUpdateMode & InputConnection.CURSOR_UPDATE_
MONITOR) != 0; |
214 // Invalidate saved cursor anchor info if monitor request is cancell
ed since no longer | 220 if ((cursorUpdateMode & InputConnection.CURSOR_UPDATE_IMMEDIATE) != 0) { |
215 // new values will be arrived from renderer and immediate request ma
y return too old | |
216 // position. | |
217 invalidateLastCursorAnchorInfo(); | |
218 } | |
219 mMonitorModeEnabled = monitorRequest; | |
220 if (immediateRequest) { | |
221 mHasPendingImmediateRequest = true; | 221 mHasPendingImmediateRequest = true; |
222 updateCursorAnchorInfo(view); | 222 updateCursorAnchorInfo(view); |
223 } | 223 } |
224 return true; | 224 return true; |
225 } | 225 } |
226 | 226 |
227 /** | 227 /** |
228 * Computes the CursorAnchorInfo instance and notify to InputMethodManager i
f needed. | 228 * Computes the CursorAnchorInfo instance and notify to InputMethodManager i
f needed. |
229 */ | 229 */ |
230 private void updateCursorAnchorInfo(View view) { | 230 private void updateCursorAnchorInfo(View view) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 } | 271 } |
272 mLastCursorAnchorInfo = mCursorAnchorInfoBuilder.build(); | 272 mLastCursorAnchorInfo = mCursorAnchorInfoBuilder.build(); |
273 } | 273 } |
274 | 274 |
275 if (mInputMethodManagerWrapper != null) { | 275 if (mInputMethodManagerWrapper != null) { |
276 mInputMethodManagerWrapper.updateCursorAnchorInfo(view, mLastCursorA
nchorInfo); | 276 mInputMethodManagerWrapper.updateCursorAnchorInfo(view, mLastCursorA
nchorInfo); |
277 } | 277 } |
278 mHasPendingImmediateRequest = false; | 278 mHasPendingImmediateRequest = false; |
279 } | 279 } |
280 } | 280 } |
OLD | NEW |