Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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.app.Activity; | 8 import android.app.Activity; |
| 8 import android.content.ClipData; | 9 import android.content.ClipData; |
| 9 import android.content.ClipboardManager; | 10 import android.content.ClipboardManager; |
| 10 import android.content.Context; | 11 import android.content.Context; |
| 11 import android.content.res.Configuration; | 12 import android.content.res.Configuration; |
| 12 import android.os.Handler; | 13 import android.os.Handler; |
| 13 import android.support.test.filters.MediumTest; | 14 import android.support.test.filters.MediumTest; |
| 14 import android.support.test.filters.SmallTest; | 15 import android.support.test.filters.SmallTest; |
| 15 import android.text.InputType; | 16 import android.text.InputType; |
| 16 import android.text.TextUtils; | 17 import android.text.TextUtils; |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 | 208 |
| 208 deleteSurroundingText(0, 10); | 209 deleteSurroundingText(0, 10); |
| 209 assertTextsAroundCursor("", null, ""); | 210 assertTextsAroundCursor("", null, ""); |
| 210 | 211 |
| 211 deleteSurroundingText(10, 10); | 212 deleteSurroundingText(10, 10); |
| 212 assertTextsAroundCursor("", null, ""); | 213 assertTextsAroundCursor("", null, ""); |
| 213 } | 214 } |
| 214 | 215 |
| 215 @SmallTest | 216 @SmallTest |
| 216 @Feature({"TextInput", "Main"}) | 217 @Feature({"TextInput", "Main"}) |
| 218 public void testDeleteSurroundingTextInCodePointsWithRangeSelection() throws Throwable { | |
| 219 commitText("hello", 1); | |
|
Changwan Ryu
2017/01/11 02:00:27
could you use an example where the text contains a
yabinh
2017/01/24 11:39:56
Done.
| |
| 220 waitAndVerifyUpdateSelection(0, 5, 5, -1, -1); | |
| 221 | |
| 222 setSelection(1, 4); | |
| 223 waitAndVerifyUpdateSelection(1, 1, 4, -1, -1); | |
| 224 | |
| 225 deleteSurroundingTextInCodePoints(0, 0); | |
| 226 assertTextsAroundCursor("h", "ell", "o"); | |
| 227 | |
| 228 deleteSurroundingTextInCodePoints(1, 1); | |
| 229 assertTextsAroundCursor("", "ell", ""); | |
| 230 | |
| 231 deleteSurroundingTextInCodePoints(1, 0); | |
| 232 assertTextsAroundCursor("", "ell", ""); | |
| 233 | |
| 234 deleteSurroundingTextInCodePoints(0, 1); | |
| 235 assertTextsAroundCursor("", "ell", ""); | |
| 236 } | |
| 237 | |
| 238 @SmallTest | |
| 239 @Feature({"TextInput", "Main"}) | |
| 240 public void testDeleteSurroundingTextInCodePointsWithCursorSelection() throw s Throwable { | |
| 241 commitText("hello", 1); | |
| 242 waitAndVerifyUpdateSelection(0, 5, 5, -1, -1); | |
| 243 | |
| 244 setSelection(2, 2); | |
| 245 waitAndVerifyUpdateSelection(1, 2, 2, -1, -1); | |
| 246 | |
| 247 deleteSurroundingTextInCodePoints(0, 0); | |
| 248 assertTextsAroundCursor("he", null, "llo"); | |
| 249 | |
| 250 deleteSurroundingTextInCodePoints(1, 1); | |
| 251 assertTextsAroundCursor("h", null, "lo"); | |
| 252 | |
| 253 deleteSurroundingTextInCodePoints(1, 0); | |
| 254 assertTextsAroundCursor("", null, "lo"); | |
| 255 | |
| 256 deleteSurroundingTextInCodePoints(0, 10); | |
| 257 assertTextsAroundCursor("", null, ""); | |
| 258 | |
| 259 deleteSurroundingTextInCodePoints(10, 10); | |
| 260 assertTextsAroundCursor("", null, ""); | |
| 261 } | |
| 262 | |
| 263 @SmallTest | |
| 264 @Feature({"TextInput", "Main"}) | |
| 217 public void testSetComposingTextForNewCursorPositions() throws Throwable { | 265 public void testSetComposingTextForNewCursorPositions() throws Throwable { |
| 218 // Cursor is on the right of composing text when newCursorPosition > 0. | 266 // Cursor is on the right of composing text when newCursorPosition > 0. |
| 219 setComposingText("ab", 1); | 267 setComposingText("ab", 1); |
| 220 waitAndVerifyUpdateSelection(0, 2, 2, 0, 2); | 268 waitAndVerifyUpdateSelection(0, 2, 2, 0, 2); |
| 221 | 269 |
| 222 finishComposingText(); | 270 finishComposingText(); |
| 223 waitAndVerifyUpdateSelection(1, 2, 2, -1, -1); | 271 waitAndVerifyUpdateSelection(1, 2, 2, -1, -1); |
| 224 | 272 |
| 225 // Cursor exceeds the left boundary. | 273 // Cursor exceeds the left boundary. |
| 226 setComposingText("cdef", -100); | 274 setComposingText("cdef", -100); |
| (...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1295 | 1343 |
| 1296 deleteSurroundingText(1, 1); | 1344 deleteSurroundingText(1, 1); |
| 1297 waitAndVerifyUpdateSelection(2, 1, 1, -1, -1); | 1345 waitAndVerifyUpdateSelection(2, 1, 1, -1, -1); |
| 1298 // TODO(yabinh): It should only fire 1 input and 1 selectionchange event s. | 1346 // TODO(yabinh): It should only fire 1 input and 1 selectionchange event s. |
| 1299 waitForEventLogs("keydown(229),input,input,keyup(229),selectionchange,se lectionchange," | 1347 waitForEventLogs("keydown(229),input,input,keyup(229),selectionchange,se lectionchange," |
| 1300 + "selectionchange,selectionchange"); | 1348 + "selectionchange,selectionchange"); |
| 1301 } | 1349 } |
| 1302 | 1350 |
| 1303 @MediumTest | 1351 @MediumTest |
| 1304 @Feature({"TextInput"}) | 1352 @Feature({"TextInput"}) |
| 1353 public void testContentEditableEvents_DeleteSurroundingTextInCodePoints() th rows Throwable { | |
| 1354 focusElementAndWaitForStateUpdate("contenteditable_event"); | |
| 1355 waitForEventLogs("selectionchange,selectionchange"); | |
| 1356 clearEventLogs(); | |
| 1357 | |
| 1358 commitText("hello", 1); | |
| 1359 waitAndVerifyUpdateSelection(0, 5, 5, -1, -1); | |
| 1360 waitForEventLogs("keydown(229),input,keyup(229),selectionchange"); | |
| 1361 clearEventLogs(); | |
| 1362 | |
| 1363 setSelection(2, 2); | |
| 1364 waitAndVerifyUpdateSelection(1, 2, 2, -1, -1); | |
| 1365 waitForEventLogs("selectionchange"); | |
| 1366 clearEventLogs(); | |
| 1367 | |
| 1368 deleteSurroundingTextInCodePoints(1, 1); | |
| 1369 waitAndVerifyUpdateSelection(2, 1, 1, -1, -1); | |
| 1370 // TODO(yabinh): It should only fire 1 input and 1 selectionchange event s. | |
| 1371 waitForEventLogs("keydown(229),input,input,keyup(229),selectionchange,se lectionchange," | |
| 1372 + "selectionchange,selectionchange"); | |
| 1373 } | |
| 1374 | |
| 1375 @MediumTest | |
| 1376 @Feature({"TextInput"}) | |
| 1377 public void testInputTextEvents_DeleteSurroundingTextInCodePoints() throws T hrowable { | |
| 1378 commitText("hello", 1); | |
| 1379 waitAndVerifyUpdateSelection(0, 5, 5, -1, -1); | |
| 1380 waitForEventLogs("keydown(229),input,keyup(229),selectionchange"); | |
| 1381 clearEventLogs(); | |
| 1382 | |
| 1383 setSelection(2, 2); | |
| 1384 waitAndVerifyUpdateSelection(1, 2, 2, -1, -1); | |
| 1385 waitForEventLogs("selectionchange"); | |
| 1386 clearEventLogs(); | |
| 1387 | |
| 1388 deleteSurroundingTextInCodePoints(1, 1); | |
| 1389 waitAndVerifyUpdateSelection(2, 1, 1, -1, -1); | |
| 1390 // TODO(yabinh): It should only fire 1 input and 1 selectionchange event s. | |
| 1391 waitForEventLogs("keydown(229),input,input,keyup(229),selectionchange,se lectionchange," | |
| 1392 + "selectionchange,selectionchange"); | |
| 1393 } | |
| 1394 | |
| 1395 @MediumTest | |
| 1396 @Feature({"TextInput"}) | |
| 1305 public void testGetCursorCapsMode() throws Throwable { | 1397 public void testGetCursorCapsMode() throws Throwable { |
| 1306 focusElementAndWaitForStateUpdate("contenteditable_event"); | 1398 focusElementAndWaitForStateUpdate("contenteditable_event"); |
| 1307 commitText("Hello World", 1); | 1399 commitText("Hello World", 1); |
| 1308 waitAndVerifyUpdateSelection(0, 11, 11, -1, -1); | 1400 waitAndVerifyUpdateSelection(0, 11, 11, -1, -1); |
| 1309 assertEquals(0, | 1401 assertEquals(0, |
| 1310 getCursorCapsMode(InputType.TYPE_TEXT_FLAG_CAP_WORDS)); | 1402 getCursorCapsMode(InputType.TYPE_TEXT_FLAG_CAP_WORDS)); |
| 1311 setSelection(6, 6); | 1403 setSelection(6, 6); |
| 1312 waitAndVerifyUpdateSelection(1, 6, 6, -1, -1); | 1404 waitAndVerifyUpdateSelection(1, 6, 6, -1, -1); |
| 1313 assertEquals(InputType.TYPE_TEXT_FLAG_CAP_WORDS, | 1405 assertEquals(InputType.TYPE_TEXT_FLAG_CAP_WORDS, |
| 1314 getCursorCapsMode(InputType.TYPE_TEXT_FLAG_CAP_WORDS)); | 1406 getCursorCapsMode(InputType.TYPE_TEXT_FLAG_CAP_WORDS)); |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1669 private boolean deleteSurroundingText(final int before, final int after) thr ows Exception { | 1761 private boolean deleteSurroundingText(final int before, final int after) thr ows Exception { |
| 1670 final ChromiumBaseInputConnection connection = mConnection; | 1762 final ChromiumBaseInputConnection connection = mConnection; |
| 1671 return runBlockingOnImeThread(new Callable<Boolean>() { | 1763 return runBlockingOnImeThread(new Callable<Boolean>() { |
| 1672 @Override | 1764 @Override |
| 1673 public Boolean call() { | 1765 public Boolean call() { |
| 1674 return connection.deleteSurroundingText(before, after); | 1766 return connection.deleteSurroundingText(before, after); |
| 1675 } | 1767 } |
| 1676 }); | 1768 }); |
| 1677 } | 1769 } |
| 1678 | 1770 |
| 1771 // Note that deleteSurroundingTextInCodePoints() was introduced in Android N (Api level 24), but | |
|
aelias_OOO_until_Jul13
2017/01/04 23:18:13
As of https://chromium-review.googlesource.com/#/c
yabinh
2017/01/05 01:38:50
There is no deleteSurroundingTextInCodePoints() in
yabinh
2017/01/05 02:04:55
It seems that only 'sdk/build-tools' was updated t
| |
| 1772 // the Android repository used in Chrome is behind that (level 23). So this function can't be | |
| 1773 // called by keyboard apps currently. | |
| 1774 @TargetApi(24) | |
| 1775 private boolean deleteSurroundingTextInCodePoints(final int before, final in t after) | |
| 1776 throws Exception { | |
| 1777 final ThreadedInputConnection connection = (ThreadedInputConnection) mCo nnection; | |
| 1778 return runBlockingOnImeThread(new Callable<Boolean>() { | |
| 1779 @Override | |
| 1780 public Boolean call() { | |
| 1781 return connection.deleteSurroundingTextInCodePoints(before, afte r); | |
| 1782 } | |
| 1783 }); | |
| 1784 } | |
| 1785 | |
| 1679 private CharSequence getTextBeforeCursor(final int length, final int flags) throws Exception { | 1786 private CharSequence getTextBeforeCursor(final int length, final int flags) throws Exception { |
| 1680 final ChromiumBaseInputConnection connection = mConnection; | 1787 final ChromiumBaseInputConnection connection = mConnection; |
| 1681 return runBlockingOnImeThread(new Callable<CharSequence>() { | 1788 return runBlockingOnImeThread(new Callable<CharSequence>() { |
| 1682 @Override | 1789 @Override |
| 1683 public CharSequence call() { | 1790 public CharSequence call() { |
| 1684 return connection.getTextBeforeCursor(length, flags); | 1791 return connection.getTextBeforeCursor(length, flags); |
| 1685 } | 1792 } |
| 1686 }); | 1793 }); |
| 1687 } | 1794 } |
| 1688 | 1795 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1807 public void onViewAttachedToWindow() { | 1914 public void onViewAttachedToWindow() { |
| 1808 mFactory.onViewAttachedToWindow(); | 1915 mFactory.onViewAttachedToWindow(); |
| 1809 } | 1916 } |
| 1810 | 1917 |
| 1811 @Override | 1918 @Override |
| 1812 public void onViewDetachedFromWindow() { | 1919 public void onViewDetachedFromWindow() { |
| 1813 mFactory.onViewDetachedFromWindow(); | 1920 mFactory.onViewDetachedFromWindow(); |
| 1814 } | 1921 } |
| 1815 } | 1922 } |
| 1816 } | 1923 } |
| OLD | NEW |