| 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; | |
| 13 | 12 |
| 14 import org.chromium.base.VisibleForTesting; | 13 import org.chromium.base.VisibleForTesting; |
| 15 import org.chromium.base.annotations.SuppressFBWarnings; | 14 import org.chromium.base.annotations.SuppressFBWarnings; |
| 16 import org.chromium.content.browser.RenderCoordinates; | 15 import org.chromium.content.browser.RenderCoordinates; |
| 17 | 16 |
| 18 import java.util.Arrays; | 17 import java.util.Arrays; |
| 19 | 18 |
| 20 import javax.annotation.Nonnull; | 19 import javax.annotation.Nonnull; |
| 21 import javax.annotation.Nullable; | 20 import javax.annotation.Nullable; |
| 22 | 21 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 */ | 121 */ |
| 123 public void invalidateLastCursorAnchorInfo() { | 122 public void invalidateLastCursorAnchorInfo() { |
| 124 if (!mIsEditable) return; | 123 if (!mIsEditable) return; |
| 125 | 124 |
| 126 mLastCursorAnchorInfo = null; | 125 mLastCursorAnchorInfo = null; |
| 127 } | 126 } |
| 128 | 127 |
| 129 /** | 128 /** |
| 130 * Sets positional information of composing text as an array of character bo
unds. | 129 * Sets positional information of composing text as an array of character bo
unds. |
| 131 * @param compositionCharacterBounds Array of character bounds in local coor
dinates. | 130 * @param compositionCharacterBounds Array of character bounds in local coor
dinates. |
| 131 * @param view The attached view. |
| 132 */ | 132 */ |
| 133 public void setCompositionCharacterBounds(float[] compositionCharacterBounds
) { | 133 public void setCompositionCharacterBounds(float[] compositionCharacterBounds
, View view) { |
| 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 if (mHasCoordinateInfo) { |
| 140 updateCursorAnchorInfo(view); |
| 141 } |
| 139 } | 142 } |
| 140 } | 143 } |
| 141 | 144 |
| 142 /** | 145 /** |
| 143 * Sets coordinates system parameters and selection marker information. | 146 * Sets coordinates system parameters and selection marker information. |
| 144 * @param hasInsertionMarker {@code true} if the insertion marker exists. | 147 * @param hasInsertionMarker {@code true} if the insertion marker exists. |
| 145 * @param isInsertionMarkerVisible {@code true} if the insertion insertion m
arker is visible. | 148 * @param isInsertionMarkerVisible {@code true} if the insertion insertion m
arker is visible. |
| 146 * @param insertionMarkerHorizontal X coordinate of the top of the first sel
ection marker. | 149 * @param insertionMarkerHorizontal X coordinate of the top of the first sel
ection marker. |
| 147 * @param insertionMarkerTop Y coordinate of the top of the first selection
marker. | 150 * @param insertionMarkerTop Y coordinate of the top of the first selection
marker. |
| 148 * @param insertionMarkerBottom Y coordinate of the bottom of the first sele
ction marker. | 151 * @param insertionMarkerBottom Y coordinate of the bottom of the first sele
ction marker. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 } | 194 } |
| 192 | 195 |
| 193 // Notify to IME if there is a pending request, or if it is in monitor m
ode and we have | 196 // Notify to IME if there is a pending request, or if it is in monitor m
ode and we have |
| 194 // some change in the state. | 197 // some change in the state. |
| 195 if (mHasPendingImmediateRequest | 198 if (mHasPendingImmediateRequest |
| 196 || (mMonitorModeEnabled && mLastCursorAnchorInfo == null)) { | 199 || (mMonitorModeEnabled && mLastCursorAnchorInfo == null)) { |
| 197 updateCursorAnchorInfo(view); | 200 updateCursorAnchorInfo(view); |
| 198 } | 201 } |
| 199 } | 202 } |
| 200 | 203 |
| 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 | |
| 209 public void focusedNodeChanged(boolean isEditable) { | 204 public void focusedNodeChanged(boolean isEditable) { |
| 210 mIsEditable = isEditable; | 205 mIsEditable = isEditable; |
| 211 mCompositionCharacterBounds = null; | 206 mCompositionCharacterBounds = null; |
| 212 mHasCoordinateInfo = false; | 207 mHasCoordinateInfo = false; |
| 213 mLastCursorAnchorInfo = null; | 208 mLastCursorAnchorInfo = null; |
| 214 } | 209 } |
| 215 | 210 |
| 216 public boolean onRequestCursorUpdates(int cursorUpdateMode, View view) { | 211 public boolean onRequestCursorUpdates(boolean immediateRequest, boolean moni
torRequest, |
| 212 View view) { |
| 217 if (!mIsEditable) return false; | 213 if (!mIsEditable) return false; |
| 218 | 214 |
| 219 mMonitorModeEnabled = (cursorUpdateMode & InputConnection.CURSOR_UPDATE_
MONITOR) != 0; | 215 if (mMonitorModeEnabled && !monitorRequest) { |
| 220 if ((cursorUpdateMode & InputConnection.CURSOR_UPDATE_IMMEDIATE) != 0) { | 216 // Invalidate saved cursor anchor info if monitor request is cancell
ed since no longer |
| 217 // new values will be arrived from renderer and immediate request ma
y return too old |
| 218 // position. |
| 219 invalidateLastCursorAnchorInfo(); |
| 220 } |
| 221 mMonitorModeEnabled = monitorRequest; |
| 222 if (immediateRequest) { |
| 221 mHasPendingImmediateRequest = true; | 223 mHasPendingImmediateRequest = true; |
| 222 updateCursorAnchorInfo(view); | 224 updateCursorAnchorInfo(view); |
| 223 } | 225 } |
| 224 return true; | 226 return true; |
| 225 } | 227 } |
| 226 | 228 |
| 227 /** | 229 /** |
| 228 * Computes the CursorAnchorInfo instance and notify to InputMethodManager i
f needed. | 230 * Computes the CursorAnchorInfo instance and notify to InputMethodManager i
f needed. |
| 229 */ | 231 */ |
| 230 private void updateCursorAnchorInfo(View view) { | 232 private void updateCursorAnchorInfo(View view) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 } | 273 } |
| 272 mLastCursorAnchorInfo = mCursorAnchorInfoBuilder.build(); | 274 mLastCursorAnchorInfo = mCursorAnchorInfoBuilder.build(); |
| 273 } | 275 } |
| 274 | 276 |
| 275 if (mInputMethodManagerWrapper != null) { | 277 if (mInputMethodManagerWrapper != null) { |
| 276 mInputMethodManagerWrapper.updateCursorAnchorInfo(view, mLastCursorA
nchorInfo); | 278 mInputMethodManagerWrapper.updateCursorAnchorInfo(view, mLastCursorA
nchorInfo); |
| 277 } | 279 } |
| 278 mHasPendingImmediateRequest = false; | 280 mHasPendingImmediateRequest = false; |
| 279 } | 281 } |
| 280 } | 282 } |
| OLD | NEW |