| 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 | 12 |
| 13 import org.chromium.base.VisibleForTesting; | 13 import org.chromium.base.VisibleForTesting; |
| 14 import org.chromium.base.annotations.SuppressFBWarnings; | 14 import org.chromium.base.annotations.SuppressFBWarnings; |
| 15 import org.chromium.content.browser.RenderCoordinates; | |
| 16 | 15 |
| 17 import java.util.Arrays; | 16 import java.util.Arrays; |
| 18 | 17 |
| 19 import javax.annotation.Nonnull; | 18 import javax.annotation.Nonnull; |
| 20 import javax.annotation.Nullable; | 19 import javax.annotation.Nullable; |
| 21 | 20 |
| 22 /** | 21 /** |
| 23 * A state machine interface which receives Chromium internal events to determin
es when to call | 22 * A state machine interface which receives Chromium internal events to determin
es when to call |
| 24 * {@link InputMethodManager#updateCursorAnchorInfo(View, CursorAnchorInfo)}. Th
is interface is | 23 * {@link InputMethodManager#updateCursorAnchorInfo(View, CursorAnchorInfo)}. Th
is interface is |
| 25 * also used in unit tests to mock out {@link CursorAnchorInfo}, which is availa
ble only in | 24 * also used in unit tests to mock out {@link CursorAnchorInfo}, which is availa
ble only in |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 mLastCursorAnchorInfo = null; | 136 mLastCursorAnchorInfo = null; |
| 138 mCompositionCharacterBounds = compositionCharacterBounds; | 137 mCompositionCharacterBounds = compositionCharacterBounds; |
| 139 if (mHasCoordinateInfo) { | 138 if (mHasCoordinateInfo) { |
| 140 updateCursorAnchorInfo(view); | 139 updateCursorAnchorInfo(view); |
| 141 } | 140 } |
| 142 } | 141 } |
| 143 } | 142 } |
| 144 | 143 |
| 145 /** | 144 /** |
| 146 * Sets coordinates system parameters and selection marker information. | 145 * Sets coordinates system parameters and selection marker information. |
| 146 * @param scale device scale factor. |
| 147 * @param contentOffsetYPix Y offset below the browser controls. |
| 147 * @param hasInsertionMarker {@code true} if the insertion marker exists. | 148 * @param hasInsertionMarker {@code true} if the insertion marker exists. |
| 148 * @param isInsertionMarkerVisible {@code true} if the insertion insertion m
arker is visible. | 149 * @param isInsertionMarkerVisible {@code true} if the insertion insertion m
arker is visible. |
| 149 * @param insertionMarkerHorizontal X coordinate of the top of the first sel
ection marker. | 150 * @param insertionMarkerHorizontal X coordinate of the top of the first sel
ection marker. |
| 150 * @param insertionMarkerTop Y coordinate of the top of the first selection
marker. | 151 * @param insertionMarkerTop Y coordinate of the top of the first selection
marker. |
| 151 * @param insertionMarkerBottom Y coordinate of the bottom of the first sele
ction marker. | 152 * @param insertionMarkerBottom Y coordinate of the bottom of the first sele
ction marker. |
| 152 * @param view The attached view. | 153 * @param view The attached view. |
| 153 */ | 154 */ |
| 154 @SuppressFBWarnings("FE_FLOATING_POINT_EQUALITY") | 155 @SuppressFBWarnings("FE_FLOATING_POINT_EQUALITY") |
| 155 public void onUpdateFrameInfo(@Nonnull RenderCoordinates renderCoordinates, | 156 public void onUpdateFrameInfo(float scale, float contentOffsetYPix, boolean
hasInsertionMarker, |
| 156 boolean hasInsertionMarker, boolean isInsertionMarkerVisible, | 157 boolean isInsertionMarkerVisible, float insertionMarkerHorizontal, |
| 157 float insertionMarkerHorizontal, float insertionMarkerTop, | 158 float insertionMarkerTop, float insertionMarkerBottom, @Nonnull View
view) { |
| 158 float insertionMarkerBottom, @Nonnull View view) { | |
| 159 if (!mIsEditable) return; | 159 if (!mIsEditable) return; |
| 160 | 160 |
| 161 // Reuse {@param #mViewOrigin} to avoid object creation, as this method
is supposed to be | 161 // Reuse {@param #mViewOrigin} to avoid object creation, as this method
is supposed to be |
| 162 // called at relatively high rate. | 162 // called at relatively high rate. |
| 163 mViewDelegate.getLocationOnScreen(view, mViewOrigin); | 163 mViewDelegate.getLocationOnScreen(view, mViewOrigin); |
| 164 | 164 |
| 165 // Character bounds and insertion marker locations come in device indepe
ndent pixels | 165 // Character bounds and insertion marker locations come in device indepe
ndent pixels |
| 166 // relative from the top-left corner of the web view content area. (In o
ther words, the | 166 // relative from the top-left corner of the web view content area. (In o
ther words, the |
| 167 // effects of various kinds of zooming and scrolling are already taken i
nto account.) | 167 // effects of various kinds of zooming and scrolling are already taken i
nto account.) |
| 168 // | 168 // |
| 169 // We need to prepare parameters that convert such values to physical pi
xels, in the | 169 // We need to prepare parameters that convert such values to physical pi
xels, in the |
| 170 // screen coordinate. Hence the following values are derived. | 170 // screen coordinate. Hence the following values are derived. |
| 171 float scale = renderCoordinates.getDeviceScaleFactor(); | |
| 172 float translationX = mViewOrigin[0]; | 171 float translationX = mViewOrigin[0]; |
| 173 float translationY = mViewOrigin[1] + renderCoordinates.getContentOffset
YPix(); | 172 float translationY = mViewOrigin[1] + contentOffsetYPix; |
| 174 | |
| 175 if (!mHasCoordinateInfo | 173 if (!mHasCoordinateInfo |
| 176 || scale != mScale | 174 || scale != mScale |
| 177 || translationX != mTranslationX | 175 || translationX != mTranslationX |
| 178 || translationY != mTranslationY | 176 || translationY != mTranslationY |
| 179 || hasInsertionMarker != mHasInsertionMarker | 177 || hasInsertionMarker != mHasInsertionMarker |
| 180 || isInsertionMarkerVisible != mIsInsertionMarkerVisible | 178 || isInsertionMarkerVisible != mIsInsertionMarkerVisible |
| 181 || insertionMarkerHorizontal != mInsertionMarkerHorizontal | 179 || insertionMarkerHorizontal != mInsertionMarkerHorizontal |
| 182 || insertionMarkerTop != mInsertionMarkerTop | 180 || insertionMarkerTop != mInsertionMarkerTop |
| 183 || insertionMarkerBottom != mInsertionMarkerBottom) { | 181 || insertionMarkerBottom != mInsertionMarkerBottom) { |
| 184 mLastCursorAnchorInfo = null; | 182 mLastCursorAnchorInfo = null; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 } | 271 } |
| 274 mLastCursorAnchorInfo = mCursorAnchorInfoBuilder.build(); | 272 mLastCursorAnchorInfo = mCursorAnchorInfoBuilder.build(); |
| 275 } | 273 } |
| 276 | 274 |
| 277 if (mInputMethodManagerWrapper != null) { | 275 if (mInputMethodManagerWrapper != null) { |
| 278 mInputMethodManagerWrapper.updateCursorAnchorInfo(view, mLastCursorA
nchorInfo); | 276 mInputMethodManagerWrapper.updateCursorAnchorInfo(view, mLastCursorA
nchorInfo); |
| 279 } | 277 } |
| 280 mHasPendingImmediateRequest = false; | 278 mHasPendingImmediateRequest = false; |
| 281 } | 279 } |
| 282 } | 280 } |
| OLD | NEW |