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

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

Issue 2210533004: Revert of Do not calculate composition bounds until IME requests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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;
16 17
17 import org.chromium.base.test.util.Feature; 18 import org.chromium.base.test.util.Feature;
18 import org.chromium.base.test.util.MinAndroidSdkLevel; 19 import org.chromium.base.test.util.MinAndroidSdkLevel;
19 import org.chromium.content.browser.RenderCoordinates; 20 import org.chromium.content.browser.RenderCoordinates;
20 import org.chromium.content.browser.test.util.TestInputMethodManagerWrapper; 21 import org.chromium.content.browser.test.util.TestInputMethodManagerWrapper;
21 22
22 /** 23 /**
23 * Test for {@link CursorAnchorInfoController}. 24 * Test for {@link CursorAnchorInfoController}.
24 */ 25 */
25 @MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP) 26 @MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP)
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 TestComposingTextDelegate composingTextDelegate = new TestComposingTextD elegate(); 134 TestComposingTextDelegate composingTextDelegate = new TestComposingTextD elegate();
134 CursorAnchorInfoController controller = CursorAnchorInfoController.creat eForTest( 135 CursorAnchorInfoController controller = CursorAnchorInfoController.creat eForTest(
135 immw, composingTextDelegate, viewDelegate); 136 immw, composingTextDelegate, viewDelegate);
136 View view = null; 137 View view = null;
137 138
138 viewDelegate.locationX = 0; 139 viewDelegate.locationX = 0;
139 viewDelegate.locationY = 0; 140 viewDelegate.locationY = 0;
140 141
141 assertFalse( 142 assertFalse(
142 "IC#onRequestCursorUpdates() must be rejected if the focused nod e is not editable.", 143 "IC#onRequestCursorUpdates() must be rejected if the focused nod e is not editable.",
143 controller.onRequestCursorUpdates( 144 controller.onRequestCursorUpdates(InputConnection.CURSOR_UPDATE_ MONITOR, view));
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}, view); 147 controller.setCompositionCharacterBounds(new float[] {0.0f, 1.0f, 2.0f, 3.0f});
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}, view); 158 controller.setCompositionCharacterBounds(new float[] {30.0f, 1.0f, 32.0f , 3.0f});
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( 182 assertTrue(controller.onRequestCursorUpdates(InputConnection.CURSOR_UPDA TE_IMMEDIATE,
183 true /* immediate request */, false /* monitor request */, view) ); 183 view));
184 controller.setCompositionCharacterBounds(new float[] {0.0f, 1.0f, 2.0f, 3.0f}, view); 184 controller.setCompositionCharacterBounds(new float[] {0.0f, 1.0f, 2.0f, 3.0f});
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( 208 assertTrue(controller.onRequestCursorUpdates(InputConnection.CURSOR_UPDA TE_IMMEDIATE,
209 true /* immediate request */, false /* monitor request */, view) ); 209 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 true /* immediate request*/, true /* monitor request */, view)); 225 InputConnection.CURSOR_UPDATE_IMMEDIATE | InputConnection.CURSOR _UPDATE_MONITOR,
226 view));
226 assertEquals(3, immw.getUpdateCursorAnchorInfoCounter()); 227 assertEquals(3, immw.getUpdateCursorAnchorInfoCounter());
227 assertScaleAndTranslate(2.0f, 0.0f, 0.0f, immw.getLastCursorAnchorInfo() ); 228 assertScaleAndTranslate(2.0f, 0.0f, 0.0f, immw.getLastCursorAnchorInfo() );
228 immw.clearLastCursorAnchorInfo(); 229 immw.clearLastCursorAnchorInfo();
229 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f), 230 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f),
230 true, true, 2.0f, 0.0f, 3.0f, view); 231 true, true, 2.0f, 0.0f, 3.0f, view);
231 assertEquals(4, immw.getUpdateCursorAnchorInfoCounter()); 232 assertEquals(4, immw.getUpdateCursorAnchorInfoCounter());
232 assertScaleAndTranslate(1.0f, 0.0f, 0.0f, immw.getLastCursorAnchorInfo() ); 233 assertScaleAndTranslate(1.0f, 0.0f, 0.0f, immw.getLastCursorAnchorInfo() );
233 assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 2.0f, 0.0f, 3.0f, 234 assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 2.0f, 0.0f, 3.0f,
234 3.0f, immw.getLastCursorAnchorInfo()); 235 3.0f, immw.getLastCursorAnchorInfo());
235 assertEquals(new RectF(0.0f, 1.0f, 2.0f, 3.0f), 236 assertEquals(new RectF(0.0f, 1.0f, 2.0f, 3.0f),
236 immw.getLastCursorAnchorInfo().getCharacterBounds(0)); 237 immw.getLastCursorAnchorInfo().getCharacterBounds(0));
237 assertEquals(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 238 assertEquals(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION,
238 immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0)); 239 immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0));
239 assertComposingText("0", 0, immw.getLastCursorAnchorInfo()); 240 assertComposingText("0", 0, immw.getLastCursorAnchorInfo());
240 assertSelection(0, 1, immw.getLastCursorAnchorInfo()); 241 assertSelection(0, 1, immw.getLastCursorAnchorInfo());
241 immw.clearLastCursorAnchorInfo(); 242 immw.clearLastCursorAnchorInfo();
242 243
243 // Make sure that CURSOR_UPDATE_IMMEDIATE is cleared if the focused node becomes 244 // Make sure that CURSOR_UPDATE_IMMEDIATE is cleared if the focused node becomes
244 // non-editable. 245 // non-editable.
245 controller.focusedNodeChanged(false); 246 controller.focusedNodeChanged(false);
246 controller.focusedNodeChanged(true); 247 controller.focusedNodeChanged(true);
247 composingTextDelegate.clearTextAndSelection(controller); 248 composingTextDelegate.clearTextAndSelection(controller);
248 assertTrue(controller.onRequestCursorUpdates( 249 assertTrue(controller.onRequestCursorUpdates(InputConnection.CURSOR_UPDA TE_IMMEDIATE,
249 true /* immediate request */, false /* monitor request */, view) ); 250 view));
250 controller.focusedNodeChanged(false); 251 controller.focusedNodeChanged(false);
251 composingTextDelegate.clearTextAndSelection(controller); 252 composingTextDelegate.clearTextAndSelection(controller);
252 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 100.0f), 253 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 100.0f),
253 true, true, 2.0f, 0.0f, 3.0f, view); 254 true, true, 2.0f, 0.0f, 3.0f, view);
254 assertEquals(4, immw.getUpdateCursorAnchorInfoCounter()); 255 assertEquals(4, immw.getUpdateCursorAnchorInfoCounter());
255 256
256 // Make sure that CURSOR_UPDATE_IMMEDIATE can be enabled again. 257 // Make sure that CURSOR_UPDATE_IMMEDIATE can be enabled again.
257 controller.focusedNodeChanged(true); 258 controller.focusedNodeChanged(true);
258 composingTextDelegate.clearTextAndSelection(controller); 259 composingTextDelegate.clearTextAndSelection(controller);
259 assertTrue(controller.onRequestCursorUpdates( 260 assertTrue(controller.onRequestCursorUpdates(InputConnection.CURSOR_UPDA TE_IMMEDIATE,
260 true /* immediate request */, false /* monitor request */, view) ); 261 view));
261 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f), 262 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f),
262 true, true, 2.0f, 0.0f, 3.0f, view); 263 true, true, 2.0f, 0.0f, 3.0f, view);
263 assertEquals(5, immw.getUpdateCursorAnchorInfoCounter()); 264 assertEquals(5, immw.getUpdateCursorAnchorInfoCounter());
264 assertScaleAndTranslate(1.0f, 0.0f, 0.0f, immw.getLastCursorAnchorInfo() ); 265 assertScaleAndTranslate(1.0f, 0.0f, 0.0f, immw.getLastCursorAnchorInfo() );
265 assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 2.0f, 0.0f, 3.0f, 266 assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 2.0f, 0.0f, 3.0f,
266 3.0f, immw.getLastCursorAnchorInfo()); 267 3.0f, immw.getLastCursorAnchorInfo());
267 assertEquals(null, immw.getLastCursorAnchorInfo().getCharacterBounds(0)) ; 268 assertEquals(null, immw.getLastCursorAnchorInfo().getCharacterBounds(0)) ;
268 assertEquals(0, immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0 )); 269 assertEquals(0, immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0 ));
269 assertComposingText(null, -1, immw.getLastCursorAnchorInfo()); 270 assertComposingText(null, -1, immw.getLastCursorAnchorInfo());
270 assertSelection(-1, -1, immw.getLastCursorAnchorInfo()); 271 assertSelection(-1, -1, immw.getLastCursorAnchorInfo());
(...skipping 10 matching lines...) Expand all
281 immw, composingTextDelegate, viewDelegate); 282 immw, composingTextDelegate, viewDelegate);
282 View view = null; 283 View view = null;
283 viewDelegate.locationX = 0; 284 viewDelegate.locationX = 0;
284 viewDelegate.locationY = 0; 285 viewDelegate.locationY = 0;
285 286
286 controller.focusedNodeChanged(true); 287 controller.focusedNodeChanged(true);
287 composingTextDelegate.clearTextAndSelection(controller); 288 composingTextDelegate.clearTextAndSelection(controller);
288 289
289 // Make sure that #updateCursorAnchorInfo() is not be called until the m atrix info becomes 290 // Make sure that #updateCursorAnchorInfo() is not be called until the m atrix info becomes
290 // available with #onUpdateFrameInfo(). 291 // available with #onUpdateFrameInfo().
291 assertTrue(controller.onRequestCursorUpdates( 292 assertTrue(controller.onRequestCursorUpdates(InputConnection.CURSOR_UPDA TE_MONITOR, view));
292 false /* immediate request */, true /* monitor request */, view) ); 293 controller.setCompositionCharacterBounds(new float[] {0.0f, 1.0f, 2.0f, 3.0f});
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}, view); 312 controller.setCompositionCharacterBounds(new float[] {0.0f, 1.0f, 2.0f, 3.0f});
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}, view); 319 controller.setCompositionCharacterBounds(new float[] {30.0f, 1.0f, 32.0f , 3.0f});
320 assertEquals(1, immw.getUpdateCursorAnchorInfoCounter()); 320 assertEquals(1, 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,
(...skipping 51 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( 391 assertTrue(controller.onRequestCursorUpdates(InputConnection.CURSOR_UPDA TE_MONITOR, view));
392 false /* immediate request */, true /* monitor request */, view) );
393 controller.focusedNodeChanged(false); 392 controller.focusedNodeChanged(false);
394 composingTextDelegate.clearTextAndSelection(controller); 393 composingTextDelegate.clearTextAndSelection(controller);
395 controller.setCompositionCharacterBounds(new float[] {0.0f, 1.0f, 2.0f, 3.0f}, view); 394 controller.setCompositionCharacterBounds(new float[] {0.0f, 1.0f, 2.0f, 3.0f});
396 composingTextDelegate.updateTextAndSelection(controller, "0", 0, 1, 0, 1 ); 395 composingTextDelegate.updateTextAndSelection(controller, "0", 0, 1, 0, 1 );
397 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f), 396 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f),
398 true, true, 2.0f, 0.0f, 3.0f, view); 397 true, true, 2.0f, 0.0f, 3.0f, view);
399 assertEquals(5, immw.getUpdateCursorAnchorInfoCounter()); 398 assertEquals(5, immw.getUpdateCursorAnchorInfoCounter());
400 399
401 // Make sure that CURSOR_UPDATE_MONITOR can be enabled again. 400 // Make sure that CURSOR_UPDATE_MONITOR can be enabled again.
402 controller.focusedNodeChanged(true); 401 controller.focusedNodeChanged(true);
403 composingTextDelegate.clearTextAndSelection(controller); 402 composingTextDelegate.clearTextAndSelection(controller);
404 assertTrue(controller.onRequestCursorUpdates( 403 assertTrue(controller.onRequestCursorUpdates(InputConnection.CURSOR_UPDA TE_MONITOR, view));
405 false /* immediate request */, true /* monitor request */, view) ); 404 controller.setCompositionCharacterBounds(new float[] {0.0f, 1.0f, 2.0f, 3.0f});
406 controller.setCompositionCharacterBounds(new float[] {0.0f, 1.0f, 2.0f, 3.0f}, view);
407 composingTextDelegate.updateTextAndSelection(controller, "0", 0, 1, 0, 1 ); 405 composingTextDelegate.updateTextAndSelection(controller, "0", 0, 1, 0, 1 );
408 assertEquals(5, immw.getUpdateCursorAnchorInfoCounter()); 406 assertEquals(5, immw.getUpdateCursorAnchorInfoCounter());
409 viewDelegate.locationX = 0; 407 viewDelegate.locationX = 0;
410 viewDelegate.locationY = 0; 408 viewDelegate.locationY = 0;
411 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f), 409 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f),
412 true, true, 2.0f, 0.0f, 3.0f, view); 410 true, true, 2.0f, 0.0f, 3.0f, view);
413 assertEquals(6, immw.getUpdateCursorAnchorInfoCounter()); 411 assertEquals(6, immw.getUpdateCursorAnchorInfoCounter());
414 assertScaleAndTranslate(1.0f, 0.0f, 0.0f, immw.getLastCursorAnchorInfo() ); 412 assertScaleAndTranslate(1.0f, 0.0f, 0.0f, immw.getLastCursorAnchorInfo() );
415 assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 2.0f, 0.0f, 3.0f, 413 assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 2.0f, 0.0f, 3.0f,
416 3.0f, immw.getLastCursorAnchorInfo()); 414 3.0f, immw.getLastCursorAnchorInfo());
(...skipping 14 matching lines...) Expand all
431 TestComposingTextDelegate composingTextDelegate = new TestComposingTextD elegate(); 429 TestComposingTextDelegate composingTextDelegate = new TestComposingTextD elegate();
432 CursorAnchorInfoController controller = CursorAnchorInfoController.creat eForTest( 430 CursorAnchorInfoController controller = CursorAnchorInfoController.creat eForTest(
433 immw, composingTextDelegate, viewDelegate); 431 immw, composingTextDelegate, viewDelegate);
434 View view = null; 432 View view = null;
435 433
436 viewDelegate.locationX = 0; 434 viewDelegate.locationX = 0;
437 viewDelegate.locationY = 0; 435 viewDelegate.locationY = 0;
438 436
439 controller.focusedNodeChanged(true); 437 controller.focusedNodeChanged(true);
440 composingTextDelegate.clearTextAndSelection(controller); 438 composingTextDelegate.clearTextAndSelection(controller);
441 assertTrue(controller.onRequestCursorUpdates( 439 assertTrue(controller.onRequestCursorUpdates(InputConnection.CURSOR_UPDA TE_MONITOR, view));
442 false /* immediate request */, true /* monitor request */, view) );
443 440
444 composingTextDelegate.updateTextAndSelection(controller, "01234", 1, 3, 1, 1); 441 composingTextDelegate.updateTextAndSelection(controller, "01234", 1, 3, 1, 1);
445 controller.setCompositionCharacterBounds(new float[] {0.0f, 1.0f, 2.0f, 3.0f, 442 controller.setCompositionCharacterBounds(new float[] {0.0f, 1.0f, 2.0f, 3.0f,
446 4.0f, 1.1f, 6.0f, 2.9f}, view); 443 4.0f, 1.1f, 6.0f, 2.9f});
447 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f), 444 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f),
448 false, false, Float.NaN, Float.NaN, Float.NaN, view); 445 false, false, Float.NaN, Float.NaN, Float.NaN, view);
449 assertEquals(1, immw.getUpdateCursorAnchorInfoCounter()); 446 assertEquals(1, immw.getUpdateCursorAnchorInfoCounter());
450 assertEquals(null, immw.getLastCursorAnchorInfo().getCharacterBounds(0)) ; 447 assertEquals(null, immw.getLastCursorAnchorInfo().getCharacterBounds(0)) ;
451 assertEquals(0, immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0 )); 448 assertEquals(0, immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0 ));
452 assertEquals(new RectF(0.0f, 1.0f, 2.0f, 3.0f), 449 assertEquals(new RectF(0.0f, 1.0f, 2.0f, 3.0f),
453 immw.getLastCursorAnchorInfo().getCharacterBounds(1)); 450 immw.getLastCursorAnchorInfo().getCharacterBounds(1));
454 assertEquals(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 451 assertEquals(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION,
455 immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(1)); 452 immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(1));
456 assertEquals(new RectF(4.0f, 1.1f, 6.0f, 2.9f), 453 assertEquals(new RectF(4.0f, 1.1f, 6.0f, 2.9f),
(...skipping 14 matching lines...) Expand all
471 TestComposingTextDelegate composingTextDelegate = new TestComposingTextD elegate(); 468 TestComposingTextDelegate composingTextDelegate = new TestComposingTextD elegate();
472 CursorAnchorInfoController controller = CursorAnchorInfoController.creat eForTest( 469 CursorAnchorInfoController controller = CursorAnchorInfoController.creat eForTest(
473 immw, composingTextDelegate, viewDelegate); 470 immw, composingTextDelegate, viewDelegate);
474 View view = null; 471 View view = null;
475 472
476 viewDelegate.locationX = 0; 473 viewDelegate.locationX = 0;
477 viewDelegate.locationY = 0; 474 viewDelegate.locationY = 0;
478 475
479 controller.focusedNodeChanged(true); 476 controller.focusedNodeChanged(true);
480 composingTextDelegate.clearTextAndSelection(controller); 477 composingTextDelegate.clearTextAndSelection(controller);
481 assertTrue(controller.onRequestCursorUpdates( 478 assertTrue(controller.onRequestCursorUpdates(InputConnection.CURSOR_UPDA TE_MONITOR, view));
482 false /* immediate request */, true /* monitor request */, view) );
483 479
484 composingTextDelegate.updateTextAndSelection(controller, "01234", 3, 3, 1, 1); 480 composingTextDelegate.updateTextAndSelection(controller, "01234", 3, 3, 1, 1);
485 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f), 481 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f),
486 false, false, Float.NaN, Float.NaN, Float.NaN, view); 482 false, false, Float.NaN, Float.NaN, Float.NaN, view);
487 assertEquals(1, immw.getUpdateCursorAnchorInfoCounter()); 483 assertEquals(1, immw.getUpdateCursorAnchorInfoCounter());
488 assertEquals(null, immw.getLastCursorAnchorInfo().getCharacterBounds(0)) ; 484 assertEquals(null, immw.getLastCursorAnchorInfo().getCharacterBounds(0)) ;
489 assertEquals(0, immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0 )); 485 assertEquals(0, immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0 ));
490 assertEquals(null, immw.getLastCursorAnchorInfo().getCharacterBounds(1)) ; 486 assertEquals(null, immw.getLastCursorAnchorInfo().getCharacterBounds(1)) ;
491 assertEquals(0, immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(1 )); 487 assertEquals(0, immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(1 ));
492 assertEquals(null, immw.getLastCursorAnchorInfo().getCharacterBounds(2)) ; 488 assertEquals(null, immw.getLastCursorAnchorInfo().getCharacterBounds(2)) ;
(...skipping 11 matching lines...) Expand all
504 public void testInsertionMarker() { 500 public void testInsertionMarker() {
505 TestInputMethodManagerWrapper immw = new TestInputMethodManagerWrapper(n ull); 501 TestInputMethodManagerWrapper immw = new TestInputMethodManagerWrapper(n ull);
506 TestViewDelegate viewDelegate = new TestViewDelegate(); 502 TestViewDelegate viewDelegate = new TestViewDelegate();
507 TestComposingTextDelegate composingTextDelegate = new TestComposingTextD elegate(); 503 TestComposingTextDelegate composingTextDelegate = new TestComposingTextD elegate();
508 CursorAnchorInfoController controller = CursorAnchorInfoController.creat eForTest( 504 CursorAnchorInfoController controller = CursorAnchorInfoController.creat eForTest(
509 immw, composingTextDelegate, viewDelegate); 505 immw, composingTextDelegate, viewDelegate);
510 View view = null; 506 View view = null;
511 507
512 controller.focusedNodeChanged(true); 508 controller.focusedNodeChanged(true);
513 composingTextDelegate.clearTextAndSelection(controller); 509 composingTextDelegate.clearTextAndSelection(controller);
514 assertTrue(controller.onRequestCursorUpdates( 510 assertTrue(controller.onRequestCursorUpdates(InputConnection.CURSOR_UPDA TE_MONITOR, view));
515 false /* immediate request */, true /* monitor request */, view) );
516 511
517 // Test no insertion marker. 512 // Test no insertion marker.
518 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f), 513 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f),
519 false, false, Float.NaN, Float.NaN, Float.NaN, view); 514 false, false, Float.NaN, Float.NaN, Float.NaN, view);
520 assertEquals(1, immw.getUpdateCursorAnchorInfoCounter()); 515 assertEquals(1, immw.getUpdateCursorAnchorInfoCounter());
521 assertHasNoInsertionMarker(immw.getLastCursorAnchorInfo()); 516 assertHasNoInsertionMarker(immw.getLastCursorAnchorInfo());
522 immw.clearLastCursorAnchorInfo(); 517 immw.clearLastCursorAnchorInfo();
523 518
524 // Test a visible insertion marker. 519 // Test a visible insertion marker.
525 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f), 520 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f),
(...skipping 17 matching lines...) Expand all
543 public void testMatrix() { 538 public void testMatrix() {
544 TestInputMethodManagerWrapper immw = new TestInputMethodManagerWrapper(n ull); 539 TestInputMethodManagerWrapper immw = new TestInputMethodManagerWrapper(n ull);
545 TestViewDelegate viewDelegate = new TestViewDelegate(); 540 TestViewDelegate viewDelegate = new TestViewDelegate();
546 TestComposingTextDelegate composingTextDelegate = new TestComposingTextD elegate(); 541 TestComposingTextDelegate composingTextDelegate = new TestComposingTextD elegate();
547 CursorAnchorInfoController controller = CursorAnchorInfoController.creat eForTest( 542 CursorAnchorInfoController controller = CursorAnchorInfoController.creat eForTest(
548 immw, composingTextDelegate, viewDelegate); 543 immw, composingTextDelegate, viewDelegate);
549 View view = null; 544 View view = null;
550 545
551 controller.focusedNodeChanged(true); 546 controller.focusedNodeChanged(true);
552 composingTextDelegate.clearTextAndSelection(controller); 547 composingTextDelegate.clearTextAndSelection(controller);
553 assertTrue(controller.onRequestCursorUpdates( 548 assertTrue(controller.onRequestCursorUpdates(InputConnection.CURSOR_UPDA TE_MONITOR, view));
554 false /* immediate request */, true /* monitor request */, view) );
555 549
556 // Test no transformation 550 // Test no transformation
557 viewDelegate.locationX = 0; 551 viewDelegate.locationX = 0;
558 viewDelegate.locationY = 0; 552 viewDelegate.locationY = 0;
559 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f), 553 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f),
560 false, false, Float.NaN, Float.NaN, Float.NaN, view); 554 false, false, Float.NaN, Float.NaN, Float.NaN, view);
561 assertEquals(1, immw.getUpdateCursorAnchorInfoCounter()); 555 assertEquals(1, immw.getUpdateCursorAnchorInfoCounter());
562 assertScaleAndTranslate(1.0f, 0.0f, 0.0f, immw.getLastCursorAnchorInfo() ); 556 assertScaleAndTranslate(1.0f, 0.0f, 0.0f, immw.getLastCursorAnchorInfo() );
563 immw.clearLastCursorAnchorInfo(); 557 immw.clearLastCursorAnchorInfo();
564 558
(...skipping 21 matching lines...) Expand all
586 // view origin == (10, 141) 580 // view origin == (10, 141)
587 viewDelegate.locationX = 10; 581 viewDelegate.locationX = 10;
588 viewDelegate.locationY = 141; 582 viewDelegate.locationY = 141;
589 controller.onUpdateFrameInfo(createRenderCoordinates(2.0f, 40.0f), 583 controller.onUpdateFrameInfo(createRenderCoordinates(2.0f, 40.0f),
590 false, false, Float.NaN, Float.NaN, Float.NaN, view); 584 false, false, Float.NaN, Float.NaN, Float.NaN, view);
591 assertEquals(4, immw.getUpdateCursorAnchorInfoCounter()); 585 assertEquals(4, immw.getUpdateCursorAnchorInfoCounter());
592 assertScaleAndTranslate(2.0f, 10.0f, 181.0f, immw.getLastCursorAnchorInf o()); 586 assertScaleAndTranslate(2.0f, 10.0f, 181.0f, immw.getLastCursorAnchorInf o());
593 immw.clearLastCursorAnchorInfo(); 587 immw.clearLastCursorAnchorInfo();
594 } 588 }
595 } 589 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698