|
122 | 122 | import java.io.IOException; |
123 | 123 | import java.io.InputStream; |
124 | 124 | import java.io.OutputStream; |
125 | | -import java.io.UnsupportedEncodingException; |
126 | 125 | import java.net.URLDecoder; |
127 | 126 | import java.util.ArrayList; |
128 | 127 | import java.util.HashMap; |
@@ -460,6 +459,38 @@ public boolean deleteSurroundingText(int leftLength, int rightLength) { |
460 | 459 | return super.deleteSurroundingText(leftLength, rightLength); |
461 | 460 | } |
462 | 461 |
|
| 462 | + @Override |
| 463 | + public boolean performEditorAction(int editorAction) { |
| 464 | + |
| 465 | + boolean handled = true; |
| 466 | + switch (editorAction) { |
| 467 | + case EditorInfo.IME_ACTION_NEXT: |
| 468 | + WebView.this.requestFocus(FOCUS_FORWARD); |
| 469 | + break; |
| 470 | + case EditorInfo.IME_ACTION_PREVIOUS: |
| 471 | + WebView.this.requestFocus(FOCUS_BACKWARD); |
| 472 | + break; |
| 473 | + case EditorInfo.IME_ACTION_DONE: |
| 474 | + WebView.this.hideSoftKeyboard(); |
| 475 | + break; |
| 476 | + case EditorInfo.IME_ACTION_GO: |
| 477 | + case EditorInfo.IME_ACTION_SEARCH: |
| 478 | + WebView.this.hideSoftKeyboard(); |
| 479 | + String text = getEditable().toString(); |
| 480 | + passToJavaScript(text, new KeyEvent(KeyEvent.ACTION_DOWN, |
| 481 | + KeyEvent.KEYCODE_ENTER)); |
| 482 | + passToJavaScript(text, new KeyEvent(KeyEvent.ACTION_UP, |
| 483 | + KeyEvent.KEYCODE_ENTER)); |
| 484 | + break; |
| 485 | + |
| 486 | + default: |
| 487 | + handled = super.performEditorAction(editorAction); |
| 488 | + break; |
| 489 | + } |
| 490 | + |
| 491 | + return handled; |
| 492 | + } |
| 493 | + |
463 | 494 | public void initEditorInfo(WebViewCore.TextFieldInitData initData) { |
464 | 495 | int type = initData.mType; |
465 | 496 | int inputType = InputType.TYPE_CLASS_TEXT |
@@ -559,7 +590,7 @@ private void setNewText(int start, int end, CharSequence text) { |
559 | 590 | if (isCharacterAdd) { |
560 | 591 | sendCharacter(text.charAt(textLength - 1)); |
561 | 592 | } else if (isCharacterDelete) { |
562 | | - sendDeleteKey(); |
| 593 | + sendKey(KeyEvent.KEYCODE_DEL); |
563 | 594 | } else if ((textLength != originalLength) || |
564 | 595 | !TextUtils.regionMatches(text, 0, original, 0, |
565 | 596 | textLength)) { |
@@ -594,16 +625,18 @@ private void sendCharacter(char c) { |
594 | 625 | } |
595 | 626 |
|
596 | 627 | /** |
597 | | - * Send the delete character as a key down and up event. |
| 628 | + * Send a key event for a specific key code, not a standard |
| 629 | + * unicode character. |
| 630 | + * @param keyCode The key code to send. |
598 | 631 | */ |
599 | | - private void sendDeleteKey() { |
| 632 | + private void sendKey(int keyCode) { |
600 | 633 | long eventTime = SystemClock.uptimeMillis(); |
601 | 634 | sendKeyEvent(new KeyEvent(eventTime, eventTime, |
602 | | - KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL, 0, 0, |
| 635 | + KeyEvent.ACTION_DOWN, keyCode, 0, 0, |
603 | 636 | KeyCharacterMap.VIRTUAL_KEYBOARD, 0, |
604 | 637 | KeyEvent.FLAG_SOFT_KEYBOARD)); |
605 | 638 | sendKeyEvent(new KeyEvent(SystemClock.uptimeMillis(), eventTime, |
606 | | - KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DEL, 0, 0, |
| 639 | + KeyEvent.ACTION_UP, keyCode, 0, 0, |
607 | 640 | KeyCharacterMap.VIRTUAL_KEYBOARD, 0, |
608 | 641 | KeyEvent.FLAG_SOFT_KEYBOARD)); |
609 | 642 | } |
|
0 commit comments