Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(266)

Side by Side Diff: content/public/android/javatests/src/org/chromium/content/browser/input/CursorAnchorInfoControllerTest.java

Issue 2121953002: Do not calculate composition bounds until IME requests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix test failures Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.graphics.RectF; 9 import android.graphics.RectF;
10 import android.os.Build; 10 import android.os.Build;
11 import android.test.InstrumentationTestCase; 11 import android.test.InstrumentationTestCase;
12 import android.test.suitebuilder.annotation.SmallTest; 12 import android.test.suitebuilder.annotation.SmallTest;
13 import android.text.TextUtils; 13 import android.text.TextUtils;
14 import android.view.View; 14 import android.view.View;
15 import android.view.inputmethod.CursorAnchorInfo; 15 import android.view.inputmethod.CursorAnchorInfo;
16 import android.view.inputmethod.InputConnection;
17 16
18 import org.chromium.base.test.util.Feature; 17 import org.chromium.base.test.util.Feature;
19 import org.chromium.base.test.util.MinAndroidSdkLevel; 18 import org.chromium.base.test.util.MinAndroidSdkLevel;
20 import org.chromium.content.browser.RenderCoordinates; 19 import org.chromium.content.browser.RenderCoordinates;
21 import org.chromium.content.browser.test.util.TestInputMethodManagerWrapper; 20 import org.chromium.content.browser.test.util.TestInputMethodManagerWrapper;
22 21
23 /** 22 /**
24 * Test for {@link CursorAnchorInfoController}. 23 * Test for {@link CursorAnchorInfoController}.
25 */ 24 */
26 @MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP) 25 @MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP)
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 TestComposingTextDelegate composingTextDelegate = new TestComposingTextD elegate(); 133 TestComposingTextDelegate composingTextDelegate = new TestComposingTextD elegate();
135 CursorAnchorInfoController controller = CursorAnchorInfoController.creat eForTest( 134 CursorAnchorInfoController controller = CursorAnchorInfoController.creat eForTest(
136 immw, composingTextDelegate, viewDelegate); 135 immw, composingTextDelegate, viewDelegate);
137 View view = null; 136 View view = null;
138 137
139 viewDelegate.locationX = 0; 138 viewDelegate.locationX = 0;
140 viewDelegate.locationY = 0; 139 viewDelegate.locationY = 0;
141 140
142 assertFalse( 141 assertFalse(
143 "IC#onRequestCursorUpdates() must be rejected if the focused nod e is not editable.", 142 "IC#onRequestCursorUpdates() must be rejected if the focused nod e is not editable.",
144 controller.onRequestCursorUpdates(InputConnection.CURSOR_UPDATE_ MONITOR, view)); 143 controller.onRequestCursorUpdates(
144 false /* immediate request */, true /* monitor request * /, view));
145 145
146 // Make sure that the focused node is considered to be non-editable by d efault. 146 // Make sure that the focused node is considered to be non-editable by d efault.
147 controller.setCompositionCharacterBounds(new float[] {0.0f, 1.0f, 2.0f, 3.0f}); 147 controller.setCompositionCharacterBounds(new float[] {0.0f, 1.0f, 2.0f, 3.0f}, view);
148 composingTextDelegate.updateTextAndSelection(controller, "0", 0, 1, 0, 1 ); 148 composingTextDelegate.updateTextAndSelection(controller, "0", 0, 1, 0, 1 );
149 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f), 149 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f),
150 true, true, 2.0f, 0.0f, 3.0f, view); 150 true, true, 2.0f, 0.0f, 3.0f, view);
151 assertEquals(0, immw.getUpdateCursorAnchorInfoCounter()); 151 assertEquals(0, immw.getUpdateCursorAnchorInfoCounter());
152 152
153 controller.focusedNodeChanged(false); 153 controller.focusedNodeChanged(false);
154 composingTextDelegate.clearTextAndSelection(controller); 154 composingTextDelegate.clearTextAndSelection(controller);
155 155
156 // Make sure that the controller does not crash even if it is called whi le the focused node 156 // Make sure that the controller does not crash even if it is called whi le the focused node
157 // is not editable. 157 // is not editable.
158 controller.setCompositionCharacterBounds(new float[] {30.0f, 1.0f, 32.0f , 3.0f}); 158 controller.setCompositionCharacterBounds(new float[] {30.0f, 1.0f, 32.0f , 3.0f}, view);
159 composingTextDelegate.updateTextAndSelection(controller, "1", 0, 1, 0, 1 ); 159 composingTextDelegate.updateTextAndSelection(controller, "1", 0, 1, 0, 1 );
160 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 100.0f), 160 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 100.0f),
161 true, true, 2.0f, 0.0f, 3.0f, view); 161 true, true, 2.0f, 0.0f, 3.0f, view);
162 assertEquals(0, immw.getUpdateCursorAnchorInfoCounter()); 162 assertEquals(0, immw.getUpdateCursorAnchorInfoCounter());
163 } 163 }
164 164
165 @SmallTest 165 @SmallTest
166 @Feature({"Input-Text-IME"}) 166 @Feature({"Input-Text-IME"})
167 public void testImmediateMode() { 167 public void testImmediateMode() {
168 TestInputMethodManagerWrapper immw = new TestInputMethodManagerWrapper(n ull); 168 TestInputMethodManagerWrapper immw = new TestInputMethodManagerWrapper(n ull);
169 TestViewDelegate viewDelegate = new TestViewDelegate(); 169 TestViewDelegate viewDelegate = new TestViewDelegate();
170 TestComposingTextDelegate composingTextDelegate = new TestComposingTextD elegate(); 170 TestComposingTextDelegate composingTextDelegate = new TestComposingTextD elegate();
171 CursorAnchorInfoController controller = CursorAnchorInfoController.creat eForTest( 171 CursorAnchorInfoController controller = CursorAnchorInfoController.creat eForTest(
172 immw, composingTextDelegate, viewDelegate); 172 immw, composingTextDelegate, viewDelegate);
173 View view = null; 173 View view = null;
174 viewDelegate.locationX = 0; 174 viewDelegate.locationX = 0;
175 viewDelegate.locationY = 0; 175 viewDelegate.locationY = 0;
176 176
177 controller.focusedNodeChanged(true); 177 controller.focusedNodeChanged(true);
178 composingTextDelegate.clearTextAndSelection(controller); 178 composingTextDelegate.clearTextAndSelection(controller);
179 179
180 // Make sure that #updateCursorAnchorInfo() is not be called until the m atrix info becomes 180 // Make sure that #updateCursorAnchorInfo() is not be called until the m atrix info becomes
181 // available with #onUpdateFrameInfo(). 181 // available with #onUpdateFrameInfo().
182 assertTrue(controller.onRequestCursorUpdates(InputConnection.CURSOR_UPDA TE_IMMEDIATE, 182 assertTrue(controller.onRequestCursorUpdates(
183 view)); 183 true /* immediate request */, false /* monitor request */, view) );
184 controller.setCompositionCharacterBounds(new float[] {0.0f, 1.0f, 2.0f, 3.0f}); 184 controller.setCompositionCharacterBounds(new float[] {0.0f, 1.0f, 2.0f, 3.0f}, view);
185 composingTextDelegate.updateTextAndSelection(controller, "0", 0, 1, 0, 1 ); 185 composingTextDelegate.updateTextAndSelection(controller, "0", 0, 1, 0, 1 );
186 assertEquals(0, immw.getUpdateCursorAnchorInfoCounter()); 186 assertEquals(0, immw.getUpdateCursorAnchorInfoCounter());
187 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f), 187 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f),
188 true, true, 2.0f, 0.0f, 3.0f, view); 188 true, true, 2.0f, 0.0f, 3.0f, view);
189 assertEquals(1, immw.getUpdateCursorAnchorInfoCounter()); 189 assertEquals(1, immw.getUpdateCursorAnchorInfoCounter());
190 assertScaleAndTranslate(1.0f, 0.0f, 0.0f, immw.getLastCursorAnchorInfo() ); 190 assertScaleAndTranslate(1.0f, 0.0f, 0.0f, immw.getLastCursorAnchorInfo() );
191 assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 2.0f, 0.0f, 3.0f, 191 assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 2.0f, 0.0f, 3.0f,
192 3.0f, immw.getLastCursorAnchorInfo()); 192 3.0f, immw.getLastCursorAnchorInfo());
193 assertEquals(new RectF(0.0f, 1.0f, 2.0f, 3.0f), 193 assertEquals(new RectF(0.0f, 1.0f, 2.0f, 3.0f),
194 immw.getLastCursorAnchorInfo().getCharacterBounds(0)); 194 immw.getLastCursorAnchorInfo().getCharacterBounds(0));
195 assertEquals(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 195 assertEquals(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION,
196 immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0)); 196 immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0));
197 assertComposingText("0", 0, immw.getLastCursorAnchorInfo()); 197 assertComposingText("0", 0, immw.getLastCursorAnchorInfo());
198 assertSelection(0, 1, immw.getLastCursorAnchorInfo()); 198 assertSelection(0, 1, immw.getLastCursorAnchorInfo());
199 immw.clearLastCursorAnchorInfo(); 199 immw.clearLastCursorAnchorInfo();
200 200
201 // Make sure that 2nd call of #onUpdateFrameInfo() is ignored. 201 // Make sure that 2nd call of #onUpdateFrameInfo() is ignored.
202 controller.onUpdateFrameInfo(createRenderCoordinates(2.0f, 0.0f), 202 controller.onUpdateFrameInfo(createRenderCoordinates(2.0f, 0.0f),
203 true, true, 2.0f, 0.0f, 3.0f, view); 203 true, true, 2.0f, 0.0f, 3.0f, view);
204 assertEquals(1, immw.getUpdateCursorAnchorInfoCounter()); 204 assertEquals(1, immw.getUpdateCursorAnchorInfoCounter());
205 205
206 // Make sure that #onUpdateFrameInfo() is immediately called because the matrix info is 206 // Make sure that #onUpdateFrameInfo() is immediately called because the matrix info is
207 // already available. 207 // already available.
208 assertTrue(controller.onRequestCursorUpdates(InputConnection.CURSOR_UPDA TE_IMMEDIATE, 208 assertTrue(controller.onRequestCursorUpdates(
209 view)); 209 true /* immediate request */, false /* monitor request */, view) );
210 assertEquals(2, immw.getUpdateCursorAnchorInfoCounter()); 210 assertEquals(2, immw.getUpdateCursorAnchorInfoCounter());
211 assertScaleAndTranslate(2.0f, 0.0f, 0.0f, immw.getLastCursorAnchorInfo() ); 211 assertScaleAndTranslate(2.0f, 0.0f, 0.0f, immw.getLastCursorAnchorInfo() );
212 assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 2.0f, 0.0f, 3.0f, 212 assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 2.0f, 0.0f, 3.0f,
213 3.0f, immw.getLastCursorAnchorInfo()); 213 3.0f, immw.getLastCursorAnchorInfo());
214 assertEquals(new RectF(0.0f, 1.0f, 2.0f, 3.0f), 214 assertEquals(new RectF(0.0f, 1.0f, 2.0f, 3.0f),
215 immw.getLastCursorAnchorInfo().getCharacterBounds(0)); 215 immw.getLastCursorAnchorInfo().getCharacterBounds(0));
216 assertEquals(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 216 assertEquals(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION,
217 immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0)); 217 immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0));
218 assertComposingText("0", 0, immw.getLastCursorAnchorInfo()); 218 assertComposingText("0", 0, immw.getLastCursorAnchorInfo());
219 assertSelection(0, 1, immw.getLastCursorAnchorInfo()); 219 assertSelection(0, 1, immw.getLastCursorAnchorInfo());
220 immw.clearLastCursorAnchorInfo(); 220 immw.clearLastCursorAnchorInfo();
221 221
222 // Make sure that CURSOR_UPDATE_IMMEDIATE and CURSOR_UPDATE_MONITOR can be specified at 222 // Make sure that CURSOR_UPDATE_IMMEDIATE and CURSOR_UPDATE_MONITOR can be specified at
223 // the same time. 223 // the same time.
224 assertTrue(controller.onRequestCursorUpdates( 224 assertTrue(controller.onRequestCursorUpdates(
225 InputConnection.CURSOR_UPDATE_IMMEDIATE | InputConnection.CURSOR _UPDATE_MONITOR, 225 true /* immediate request*/, true /* monitor request */, view));
226 view));
227 assertEquals(3, immw.getUpdateCursorAnchorInfoCounter()); 226 assertEquals(3, immw.getUpdateCursorAnchorInfoCounter());
228 assertScaleAndTranslate(2.0f, 0.0f, 0.0f, immw.getLastCursorAnchorInfo() ); 227 assertScaleAndTranslate(2.0f, 0.0f, 0.0f, immw.getLastCursorAnchorInfo() );
229 immw.clearLastCursorAnchorInfo(); 228 immw.clearLastCursorAnchorInfo();
230 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f), 229 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f),
231 true, true, 2.0f, 0.0f, 3.0f, view); 230 true, true, 2.0f, 0.0f, 3.0f, view);
232 assertEquals(4, immw.getUpdateCursorAnchorInfoCounter()); 231 assertEquals(4, immw.getUpdateCursorAnchorInfoCounter());
233 assertScaleAndTranslate(1.0f, 0.0f, 0.0f, immw.getLastCursorAnchorInfo() ); 232 assertScaleAndTranslate(1.0f, 0.0f, 0.0f, immw.getLastCursorAnchorInfo() );
234 assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 2.0f, 0.0f, 3.0f, 233 assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 2.0f, 0.0f, 3.0f,
235 3.0f, immw.getLastCursorAnchorInfo()); 234 3.0f, immw.getLastCursorAnchorInfo());
236 assertEquals(new RectF(0.0f, 1.0f, 2.0f, 3.0f), 235 assertEquals(new RectF(0.0f, 1.0f, 2.0f, 3.0f),
237 immw.getLastCursorAnchorInfo().getCharacterBounds(0)); 236 immw.getLastCursorAnchorInfo().getCharacterBounds(0));
238 assertEquals(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 237 assertEquals(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION,
239 immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0)); 238 immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0));
240 assertComposingText("0", 0, immw.getLastCursorAnchorInfo()); 239 assertComposingText("0", 0, immw.getLastCursorAnchorInfo());
241 assertSelection(0, 1, immw.getLastCursorAnchorInfo()); 240 assertSelection(0, 1, immw.getLastCursorAnchorInfo());
242 immw.clearLastCursorAnchorInfo(); 241 immw.clearLastCursorAnchorInfo();
243 242
244 // Make sure that CURSOR_UPDATE_IMMEDIATE is cleared if the focused node becomes 243 // Make sure that CURSOR_UPDATE_IMMEDIATE is cleared if the focused node becomes
245 // non-editable. 244 // non-editable.
246 controller.focusedNodeChanged(false); 245 controller.focusedNodeChanged(false);
247 controller.focusedNodeChanged(true); 246 controller.focusedNodeChanged(true);
248 composingTextDelegate.clearTextAndSelection(controller); 247 composingTextDelegate.clearTextAndSelection(controller);
249 assertTrue(controller.onRequestCursorUpdates(InputConnection.CURSOR_UPDA TE_IMMEDIATE, 248 assertTrue(controller.onRequestCursorUpdates(
250 view)); 249 true /* immediate request */, false /* monitor request */, view) );
251 controller.focusedNodeChanged(false); 250 controller.focusedNodeChanged(false);
252 composingTextDelegate.clearTextAndSelection(controller); 251 composingTextDelegate.clearTextAndSelection(controller);
253 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 100.0f), 252 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 100.0f),
254 true, true, 2.0f, 0.0f, 3.0f, view); 253 true, true, 2.0f, 0.0f, 3.0f, view);
255 assertEquals(4, immw.getUpdateCursorAnchorInfoCounter()); 254 assertEquals(4, immw.getUpdateCursorAnchorInfoCounter());
256 255
257 // Make sure that CURSOR_UPDATE_IMMEDIATE can be enabled again. 256 // Make sure that CURSOR_UPDATE_IMMEDIATE can be enabled again.
258 controller.focusedNodeChanged(true); 257 controller.focusedNodeChanged(true);
259 composingTextDelegate.clearTextAndSelection(controller); 258 composingTextDelegate.clearTextAndSelection(controller);
260 assertTrue(controller.onRequestCursorUpdates(InputConnection.CURSOR_UPDA TE_IMMEDIATE, 259 assertTrue(controller.onRequestCursorUpdates(
261 view)); 260 true /* immediate request */, false /* monitor request */, view) );
262 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f), 261 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f),
263 true, true, 2.0f, 0.0f, 3.0f, view); 262 true, true, 2.0f, 0.0f, 3.0f, view);
264 assertEquals(5, immw.getUpdateCursorAnchorInfoCounter()); 263 assertEquals(5, immw.getUpdateCursorAnchorInfoCounter());
265 assertScaleAndTranslate(1.0f, 0.0f, 0.0f, immw.getLastCursorAnchorInfo() ); 264 assertScaleAndTranslate(1.0f, 0.0f, 0.0f, immw.getLastCursorAnchorInfo() );
266 assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 2.0f, 0.0f, 3.0f, 265 assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 2.0f, 0.0f, 3.0f,
267 3.0f, immw.getLastCursorAnchorInfo()); 266 3.0f, immw.getLastCursorAnchorInfo());
268 assertEquals(null, immw.getLastCursorAnchorInfo().getCharacterBounds(0)) ; 267 assertEquals(null, immw.getLastCursorAnchorInfo().getCharacterBounds(0)) ;
269 assertEquals(0, immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0 )); 268 assertEquals(0, immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0 ));
270 assertComposingText(null, -1, immw.getLastCursorAnchorInfo()); 269 assertComposingText(null, -1, immw.getLastCursorAnchorInfo());
271 assertSelection(-1, -1, immw.getLastCursorAnchorInfo()); 270 assertSelection(-1, -1, immw.getLastCursorAnchorInfo());
(...skipping 10 matching lines...) Expand all
282 immw, composingTextDelegate, viewDelegate); 281 immw, composingTextDelegate, viewDelegate);
283 View view = null; 282 View view = null;
284 viewDelegate.locationX = 0; 283 viewDelegate.locationX = 0;
285 viewDelegate.locationY = 0; 284 viewDelegate.locationY = 0;
286 285
287 controller.focusedNodeChanged(true); 286 controller.focusedNodeChanged(true);
288 composingTextDelegate.clearTextAndSelection(controller); 287 composingTextDelegate.clearTextAndSelection(controller);
289 288
290 // Make sure that #updateCursorAnchorInfo() is not be called until the m atrix info becomes 289 // Make sure that #updateCursorAnchorInfo() is not be called until the m atrix info becomes
291 // available with #onUpdateFrameInfo(). 290 // available with #onUpdateFrameInfo().
292 assertTrue(controller.onRequestCursorUpdates(InputConnection.CURSOR_UPDA TE_MONITOR, view)); 291 assertTrue(controller.onRequestCursorUpdates(
293 controller.setCompositionCharacterBounds(new float[] {0.0f, 1.0f, 2.0f, 3.0f}); 292 false /* immediate request */, true /* monitor request */, view) );
293 controller.setCompositionCharacterBounds(new float[] {0.0f, 1.0f, 2.0f, 3.0f}, view);
294 composingTextDelegate.updateTextAndSelection(controller, "0", 0, 1, 0, 1 ); 294 composingTextDelegate.updateTextAndSelection(controller, "0", 0, 1, 0, 1 );
295 assertEquals(0, immw.getUpdateCursorAnchorInfoCounter()); 295 assertEquals(0, immw.getUpdateCursorAnchorInfoCounter());
296 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f), 296 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f),
297 true, true, 2.0f, 0.0f, 3.0f, view); 297 true, true, 2.0f, 0.0f, 3.0f, view);
298 assertEquals(1, immw.getUpdateCursorAnchorInfoCounter()); 298 assertEquals(1, immw.getUpdateCursorAnchorInfoCounter());
299 assertScaleAndTranslate(1.0f, 0.0f, 0.0f, immw.getLastCursorAnchorInfo() ); 299 assertScaleAndTranslate(1.0f, 0.0f, 0.0f, immw.getLastCursorAnchorInfo() );
300 assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 2.0f, 0.0f, 3.0f, 300 assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 2.0f, 0.0f, 3.0f,
301 3.0f, immw.getLastCursorAnchorInfo()); 301 3.0f, immw.getLastCursorAnchorInfo());
302 assertEquals(new RectF(0.0f, 1.0f, 2.0f, 3.0f), 302 assertEquals(new RectF(0.0f, 1.0f, 2.0f, 3.0f),
303 immw.getLastCursorAnchorInfo().getCharacterBounds(0)); 303 immw.getLastCursorAnchorInfo().getCharacterBounds(0));
304 assertEquals(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 304 assertEquals(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION,
305 immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0)); 305 immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0));
306 assertComposingText("0", 0, immw.getLastCursorAnchorInfo()); 306 assertComposingText("0", 0, immw.getLastCursorAnchorInfo());
307 assertSelection(0, 1, immw.getLastCursorAnchorInfo()); 307 assertSelection(0, 1, immw.getLastCursorAnchorInfo());
308 immw.clearLastCursorAnchorInfo(); 308 immw.clearLastCursorAnchorInfo();
309 309
310 // Make sure that #updateCursorAnchorInfo() is not be called if any coor dinate parameter is 310 // Make sure that #updateCursorAnchorInfo() is not be called if any coor dinate parameter is
311 // changed for better performance. 311 // changed for better performance.
312 controller.setCompositionCharacterBounds(new float[] {0.0f, 1.0f, 2.0f, 3.0f}); 312 controller.setCompositionCharacterBounds(new float[] {0.0f, 1.0f, 2.0f, 3.0f}, view);
313 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f), 313 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f),
314 true, true, 2.0f, 0.0f, 3.0f, view); 314 true, true, 2.0f, 0.0f, 3.0f, view);
315 assertEquals(1, immw.getUpdateCursorAnchorInfoCounter()); 315 assertEquals(1, immw.getUpdateCursorAnchorInfoCounter());
316 316
317 // Make sure that #updateCursorAnchorInfo() is called if #setComposition CharacterBounds() 317 // Make sure that #updateCursorAnchorInfo() is called if #setComposition CharacterBounds()
318 // is called with a different parameter. 318 // is called with a different parameter.
319 controller.setCompositionCharacterBounds(new float[] {30.0f, 1.0f, 32.0f , 3.0f}); 319 controller.setCompositionCharacterBounds(new float[] {30.0f, 1.0f, 32.0f , 3.0f}, view);
320 assertEquals(1, immw.getUpdateCursorAnchorInfoCounter()); 320 assertEquals(2, immw.getUpdateCursorAnchorInfoCounter());
321 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f), 321 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f),
322 true, true, 2.0f, 0.0f, 3.0f, view); 322 true, true, 2.0f, 0.0f, 3.0f, view);
323 assertEquals(2, immw.getUpdateCursorAnchorInfoCounter()); 323 assertEquals(2, immw.getUpdateCursorAnchorInfoCounter());
324 assertScaleAndTranslate(1.0f, 0.0f, 0.0f, immw.getLastCursorAnchorInfo() ); 324 assertScaleAndTranslate(1.0f, 0.0f, 0.0f, immw.getLastCursorAnchorInfo() );
325 assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 2.0f, 0.0f, 3.0f, 325 assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 2.0f, 0.0f, 3.0f,
326 3.0f, immw.getLastCursorAnchorInfo()); 326 3.0f, immw.getLastCursorAnchorInfo());
327 assertEquals(new RectF(30.0f, 1.0f, 32.0f, 3.0f), 327 assertEquals(new RectF(30.0f, 1.0f, 32.0f, 3.0f),
328 immw.getLastCursorAnchorInfo().getCharacterBounds(0)); 328 immw.getLastCursorAnchorInfo().getCharacterBounds(0));
329 assertEquals(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 329 assertEquals(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION,
330 immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0)); 330 immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0));
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0)); 381 immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0));
382 assertComposingText("1", 0, immw.getLastCursorAnchorInfo()); 382 assertComposingText("1", 0, immw.getLastCursorAnchorInfo());
383 assertSelection(0, 1, immw.getLastCursorAnchorInfo()); 383 assertSelection(0, 1, immw.getLastCursorAnchorInfo());
384 immw.clearLastCursorAnchorInfo(); 384 immw.clearLastCursorAnchorInfo();
385 385
386 // Make sure that CURSOR_UPDATE_IMMEDIATE is cleared if the focused node becomes 386 // Make sure that CURSOR_UPDATE_IMMEDIATE is cleared if the focused node becomes
387 // non-editable. 387 // non-editable.
388 controller.focusedNodeChanged(false); 388 controller.focusedNodeChanged(false);
389 controller.focusedNodeChanged(true); 389 controller.focusedNodeChanged(true);
390 composingTextDelegate.clearTextAndSelection(controller); 390 composingTextDelegate.clearTextAndSelection(controller);
391 assertTrue(controller.onRequestCursorUpdates(InputConnection.CURSOR_UPDA TE_MONITOR, view)); 391 assertTrue(controller.onRequestCursorUpdates(
392 false /* immediate request */, true /* monitor request */, view) );
392 controller.focusedNodeChanged(false); 393 controller.focusedNodeChanged(false);
393 composingTextDelegate.clearTextAndSelection(controller); 394 composingTextDelegate.clearTextAndSelection(controller);
394 controller.setCompositionCharacterBounds(new float[] {0.0f, 1.0f, 2.0f, 3.0f}); 395 controller.setCompositionCharacterBounds(new float[] {0.0f, 1.0f, 2.0f, 3.0f}, view);
395 composingTextDelegate.updateTextAndSelection(controller, "0", 0, 1, 0, 1 ); 396 composingTextDelegate.updateTextAndSelection(controller, "0", 0, 1, 0, 1 );
396 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f), 397 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f),
397 true, true, 2.0f, 0.0f, 3.0f, view); 398 true, true, 2.0f, 0.0f, 3.0f, view);
398 assertEquals(5, immw.getUpdateCursorAnchorInfoCounter()); 399 assertEquals(5, immw.getUpdateCursorAnchorInfoCounter());
399 400
400 // Make sure that CURSOR_UPDATE_MONITOR can be enabled again. 401 // Make sure that CURSOR_UPDATE_MONITOR can be enabled again.
401 controller.focusedNodeChanged(true); 402 controller.focusedNodeChanged(true);
402 composingTextDelegate.clearTextAndSelection(controller); 403 composingTextDelegate.clearTextAndSelection(controller);
403 assertTrue(controller.onRequestCursorUpdates(InputConnection.CURSOR_UPDA TE_MONITOR, view)); 404 assertTrue(controller.onRequestCursorUpdates(
404 controller.setCompositionCharacterBounds(new float[] {0.0f, 1.0f, 2.0f, 3.0f}); 405 false /* immediate request */, true /* monitor request */, view) );
406 controller.setCompositionCharacterBounds(new float[] {0.0f, 1.0f, 2.0f, 3.0f}, view);
405 composingTextDelegate.updateTextAndSelection(controller, "0", 0, 1, 0, 1 ); 407 composingTextDelegate.updateTextAndSelection(controller, "0", 0, 1, 0, 1 );
406 assertEquals(5, immw.getUpdateCursorAnchorInfoCounter()); 408 assertEquals(5, immw.getUpdateCursorAnchorInfoCounter());
407 viewDelegate.locationX = 0; 409 viewDelegate.locationX = 0;
408 viewDelegate.locationY = 0; 410 viewDelegate.locationY = 0;
409 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f), 411 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f),
410 true, true, 2.0f, 0.0f, 3.0f, view); 412 true, true, 2.0f, 0.0f, 3.0f, view);
411 assertEquals(6, immw.getUpdateCursorAnchorInfoCounter()); 413 assertEquals(6, immw.getUpdateCursorAnchorInfoCounter());
412 assertScaleAndTranslate(1.0f, 0.0f, 0.0f, immw.getLastCursorAnchorInfo() ); 414 assertScaleAndTranslate(1.0f, 0.0f, 0.0f, immw.getLastCursorAnchorInfo() );
413 assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 2.0f, 0.0f, 3.0f, 415 assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 2.0f, 0.0f, 3.0f,
414 3.0f, immw.getLastCursorAnchorInfo()); 416 3.0f, immw.getLastCursorAnchorInfo());
(...skipping 14 matching lines...) Expand all
429 TestComposingTextDelegate composingTextDelegate = new TestComposingTextD elegate(); 431 TestComposingTextDelegate composingTextDelegate = new TestComposingTextD elegate();
430 CursorAnchorInfoController controller = CursorAnchorInfoController.creat eForTest( 432 CursorAnchorInfoController controller = CursorAnchorInfoController.creat eForTest(
431 immw, composingTextDelegate, viewDelegate); 433 immw, composingTextDelegate, viewDelegate);
432 View view = null; 434 View view = null;
433 435
434 viewDelegate.locationX = 0; 436 viewDelegate.locationX = 0;
435 viewDelegate.locationY = 0; 437 viewDelegate.locationY = 0;
436 438
437 controller.focusedNodeChanged(true); 439 controller.focusedNodeChanged(true);
438 composingTextDelegate.clearTextAndSelection(controller); 440 composingTextDelegate.clearTextAndSelection(controller);
439 assertTrue(controller.onRequestCursorUpdates(InputConnection.CURSOR_UPDA TE_MONITOR, view)); 441 assertTrue(controller.onRequestCursorUpdates(
442 false /* immediate request */, true /* monitor request */, view) );
440 443
441 composingTextDelegate.updateTextAndSelection(controller, "01234", 1, 3, 1, 1); 444 composingTextDelegate.updateTextAndSelection(controller, "01234", 1, 3, 1, 1);
442 controller.setCompositionCharacterBounds(new float[] {0.0f, 1.0f, 2.0f, 3.0f, 445 controller.setCompositionCharacterBounds(new float[] {0.0f, 1.0f, 2.0f, 3.0f,
443 4.0f, 1.1f, 6.0f, 2.9f}); 446 4.0f, 1.1f, 6.0f, 2.9f}, view);
444 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f), 447 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f),
445 false, false, Float.NaN, Float.NaN, Float.NaN, view); 448 false, false, Float.NaN, Float.NaN, Float.NaN, view);
446 assertEquals(1, immw.getUpdateCursorAnchorInfoCounter()); 449 assertEquals(1, immw.getUpdateCursorAnchorInfoCounter());
447 assertEquals(null, immw.getLastCursorAnchorInfo().getCharacterBounds(0)) ; 450 assertEquals(null, immw.getLastCursorAnchorInfo().getCharacterBounds(0)) ;
448 assertEquals(0, immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0 )); 451 assertEquals(0, immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0 ));
449 assertEquals(new RectF(0.0f, 1.0f, 2.0f, 3.0f), 452 assertEquals(new RectF(0.0f, 1.0f, 2.0f, 3.0f),
450 immw.getLastCursorAnchorInfo().getCharacterBounds(1)); 453 immw.getLastCursorAnchorInfo().getCharacterBounds(1));
451 assertEquals(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 454 assertEquals(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION,
452 immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(1)); 455 immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(1));
453 assertEquals(new RectF(4.0f, 1.1f, 6.0f, 2.9f), 456 assertEquals(new RectF(4.0f, 1.1f, 6.0f, 2.9f),
(...skipping 14 matching lines...) Expand all
468 TestComposingTextDelegate composingTextDelegate = new TestComposingTextD elegate(); 471 TestComposingTextDelegate composingTextDelegate = new TestComposingTextD elegate();
469 CursorAnchorInfoController controller = CursorAnchorInfoController.creat eForTest( 472 CursorAnchorInfoController controller = CursorAnchorInfoController.creat eForTest(
470 immw, composingTextDelegate, viewDelegate); 473 immw, composingTextDelegate, viewDelegate);
471 View view = null; 474 View view = null;
472 475
473 viewDelegate.locationX = 0; 476 viewDelegate.locationX = 0;
474 viewDelegate.locationY = 0; 477 viewDelegate.locationY = 0;
475 478
476 controller.focusedNodeChanged(true); 479 controller.focusedNodeChanged(true);
477 composingTextDelegate.clearTextAndSelection(controller); 480 composingTextDelegate.clearTextAndSelection(controller);
478 assertTrue(controller.onRequestCursorUpdates(InputConnection.CURSOR_UPDA TE_MONITOR, view)); 481 assertTrue(controller.onRequestCursorUpdates(
482 false /* immediate request */, true /* monitor request */, view) );
479 483
480 composingTextDelegate.updateTextAndSelection(controller, "01234", 3, 3, 1, 1); 484 composingTextDelegate.updateTextAndSelection(controller, "01234", 3, 3, 1, 1);
481 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f), 485 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f),
482 false, false, Float.NaN, Float.NaN, Float.NaN, view); 486 false, false, Float.NaN, Float.NaN, Float.NaN, view);
483 assertEquals(1, immw.getUpdateCursorAnchorInfoCounter()); 487 assertEquals(1, immw.getUpdateCursorAnchorInfoCounter());
484 assertEquals(null, immw.getLastCursorAnchorInfo().getCharacterBounds(0)) ; 488 assertEquals(null, immw.getLastCursorAnchorInfo().getCharacterBounds(0)) ;
485 assertEquals(0, immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0 )); 489 assertEquals(0, immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0 ));
486 assertEquals(null, immw.getLastCursorAnchorInfo().getCharacterBounds(1)) ; 490 assertEquals(null, immw.getLastCursorAnchorInfo().getCharacterBounds(1)) ;
487 assertEquals(0, immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(1 )); 491 assertEquals(0, immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(1 ));
488 assertEquals(null, immw.getLastCursorAnchorInfo().getCharacterBounds(2)) ; 492 assertEquals(null, immw.getLastCursorAnchorInfo().getCharacterBounds(2)) ;
(...skipping 11 matching lines...) Expand all
500 public void testInsertionMarker() { 504 public void testInsertionMarker() {
501 TestInputMethodManagerWrapper immw = new TestInputMethodManagerWrapper(n ull); 505 TestInputMethodManagerWrapper immw = new TestInputMethodManagerWrapper(n ull);
502 TestViewDelegate viewDelegate = new TestViewDelegate(); 506 TestViewDelegate viewDelegate = new TestViewDelegate();
503 TestComposingTextDelegate composingTextDelegate = new TestComposingTextD elegate(); 507 TestComposingTextDelegate composingTextDelegate = new TestComposingTextD elegate();
504 CursorAnchorInfoController controller = CursorAnchorInfoController.creat eForTest( 508 CursorAnchorInfoController controller = CursorAnchorInfoController.creat eForTest(
505 immw, composingTextDelegate, viewDelegate); 509 immw, composingTextDelegate, viewDelegate);
506 View view = null; 510 View view = null;
507 511
508 controller.focusedNodeChanged(true); 512 controller.focusedNodeChanged(true);
509 composingTextDelegate.clearTextAndSelection(controller); 513 composingTextDelegate.clearTextAndSelection(controller);
510 assertTrue(controller.onRequestCursorUpdates(InputConnection.CURSOR_UPDA TE_MONITOR, view)); 514 assertTrue(controller.onRequestCursorUpdates(
515 false /* immediate request */, true /* monitor request */, view) );
511 516
512 // Test no insertion marker. 517 // Test no insertion marker.
513 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f), 518 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f),
514 false, false, Float.NaN, Float.NaN, Float.NaN, view); 519 false, false, Float.NaN, Float.NaN, Float.NaN, view);
515 assertEquals(1, immw.getUpdateCursorAnchorInfoCounter()); 520 assertEquals(1, immw.getUpdateCursorAnchorInfoCounter());
516 assertHasNoInsertionMarker(immw.getLastCursorAnchorInfo()); 521 assertHasNoInsertionMarker(immw.getLastCursorAnchorInfo());
517 immw.clearLastCursorAnchorInfo(); 522 immw.clearLastCursorAnchorInfo();
518 523
519 // Test a visible insertion marker. 524 // Test a visible insertion marker.
520 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f), 525 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f),
(...skipping 17 matching lines...) Expand all
538 public void testMatrix() { 543 public void testMatrix() {
539 TestInputMethodManagerWrapper immw = new TestInputMethodManagerWrapper(n ull); 544 TestInputMethodManagerWrapper immw = new TestInputMethodManagerWrapper(n ull);
540 TestViewDelegate viewDelegate = new TestViewDelegate(); 545 TestViewDelegate viewDelegate = new TestViewDelegate();
541 TestComposingTextDelegate composingTextDelegate = new TestComposingTextD elegate(); 546 TestComposingTextDelegate composingTextDelegate = new TestComposingTextD elegate();
542 CursorAnchorInfoController controller = CursorAnchorInfoController.creat eForTest( 547 CursorAnchorInfoController controller = CursorAnchorInfoController.creat eForTest(
543 immw, composingTextDelegate, viewDelegate); 548 immw, composingTextDelegate, viewDelegate);
544 View view = null; 549 View view = null;
545 550
546 controller.focusedNodeChanged(true); 551 controller.focusedNodeChanged(true);
547 composingTextDelegate.clearTextAndSelection(controller); 552 composingTextDelegate.clearTextAndSelection(controller);
548 assertTrue(controller.onRequestCursorUpdates(InputConnection.CURSOR_UPDA TE_MONITOR, view)); 553 assertTrue(controller.onRequestCursorUpdates(
554 false /* immediate request */, true /* monitor request */, view) );
549 555
550 // Test no transformation 556 // Test no transformation
551 viewDelegate.locationX = 0; 557 viewDelegate.locationX = 0;
552 viewDelegate.locationY = 0; 558 viewDelegate.locationY = 0;
553 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f), 559 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f),
554 false, false, Float.NaN, Float.NaN, Float.NaN, view); 560 false, false, Float.NaN, Float.NaN, Float.NaN, view);
555 assertEquals(1, immw.getUpdateCursorAnchorInfoCounter()); 561 assertEquals(1, immw.getUpdateCursorAnchorInfoCounter());
556 assertScaleAndTranslate(1.0f, 0.0f, 0.0f, immw.getLastCursorAnchorInfo() ); 562 assertScaleAndTranslate(1.0f, 0.0f, 0.0f, immw.getLastCursorAnchorInfo() );
557 immw.clearLastCursorAnchorInfo(); 563 immw.clearLastCursorAnchorInfo();
558 564
(...skipping 21 matching lines...) Expand all
580 // view origin == (10, 141) 586 // view origin == (10, 141)
581 viewDelegate.locationX = 10; 587 viewDelegate.locationX = 10;
582 viewDelegate.locationY = 141; 588 viewDelegate.locationY = 141;
583 controller.onUpdateFrameInfo(createRenderCoordinates(2.0f, 40.0f), 589 controller.onUpdateFrameInfo(createRenderCoordinates(2.0f, 40.0f),
584 false, false, Float.NaN, Float.NaN, Float.NaN, view); 590 false, false, Float.NaN, Float.NaN, Float.NaN, view);
585 assertEquals(4, immw.getUpdateCursorAnchorInfoCounter()); 591 assertEquals(4, immw.getUpdateCursorAnchorInfoCounter());
586 assertScaleAndTranslate(2.0f, 10.0f, 181.0f, immw.getLastCursorAnchorInf o()); 592 assertScaleAndTranslate(2.0f, 10.0f, 181.0f, immw.getLastCursorAnchorInf o());
587 immw.clearLastCursorAnchorInfo(); 593 immw.clearLastCursorAnchorInfo();
588 } 594 }
589 } 595 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698