OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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.os.Handler; | 7 import android.os.Handler; |
8 import android.os.ResultReceiver; | 8 import android.os.ResultReceiver; |
9 import android.os.SystemClock; | 9 import android.os.SystemClock; |
10 import android.text.Editable; | 10 import android.text.Editable; |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
412 mViewEmbedder.onImeEvent(); | 412 mViewEmbedder.onImeEvent(); |
413 | 413 |
414 String textStr = text.toString(); | 414 String textStr = text.toString(); |
415 int keyCode = shouldSendKeyEventWithKeyCode(textStr); | 415 int keyCode = shouldSendKeyEventWithKeyCode(textStr); |
416 long timeStampMs = SystemClock.uptimeMillis(); | 416 long timeStampMs = SystemClock.uptimeMillis(); |
417 | 417 |
418 if (keyCode != COMPOSITION_KEY_CODE) { | 418 if (keyCode != COMPOSITION_KEY_CODE) { |
419 sendKeyEventWithKeyCode(keyCode, | 419 sendKeyEventWithKeyCode(keyCode, |
420 KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE) ; | 420 KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE) ; |
421 } else { | 421 } else { |
422 KeyEvent keyEvent = getTypedKeyEventGuess(mLastComposeText, textStr) ; | |
423 int modifiers = 0; | 422 int modifiers = 0; |
James Su
2015/01/12 11:08:02
This variable is not necessary, as it'll always be
huangs
2015/01/12 18:45:48
Done.
| |
424 if (keyEvent != null) { | |
425 keyCode = keyEvent.getKeyCode(); | |
426 modifiers = getModifiers(keyEvent.getMetaState()); | |
427 } else if (!textStr.equals(mLastComposeText)) { | |
428 keyCode = KeyEvent.KEYCODE_UNKNOWN; | |
429 } else { | |
430 keyCode = -1; | |
431 } | |
432 | 423 |
433 // If this is a commit with no previous composition, then treat it a s a native | 424 // Handle single-character commits where the character is recognizab le as keyCode. |
434 // KeyDown/KeyUp pair with no composition rather than a synthetic pa ir with | 425 if (isCommit && mLastComposeText == null && textStr.length() == 1) { |
435 // composition below. | 426 KeyEvent keyEvent = getTypedKeyEventGuess(mLastComposeText, text Str); |
huangs
2015/01/12 09:53:17
Note that we can in fact replace this line with
K
| |
436 if (keyCode > 0 && isCommit && mLastComposeText == null) { | 427 if (keyEvent != null) { |
437 mLastSyntheticKeyCode = keyCode; | 428 modifiers = getModifiers(keyEvent.getMetaState()); |
438 return translateAndSendNativeEvents(keyEvent, 0) | 429 mLastSyntheticKeyCode = keyCode; |
439 && translateAndSendNativeEvents( | 430 return translateAndSendNativeEvents(keyEvent, 0) |
440 KeyEvent.changeAction(keyEvent, KeyEvent.ACTION_ UP), 0); | 431 && translateAndSendNativeEvents( |
432 KeyEvent.changeAction(keyEvent, KeyEvent.ACT ION_UP), 0); | |
433 } | |
441 } | 434 } |
442 | 435 |
443 // When typing, there is no issue sending KeyDown and KeyUp events a round the | 436 // When typing, there is no issue sending KeyDown and KeyUp events a round the |
444 // composition event because those key events do nothing (other than call JS | 437 // composition event because those key events do nothing (other than call JS |
445 // handlers). Typing does not cause changes outside of a KeyPress e vent which | 438 // handlers). Typing does not cause changes outside of a KeyPress e vent which |
446 // we don't call here. However, if the key-code is a control key su ch as | 439 // we don't call here. However, if the key-code is a control key su ch as |
447 // KEYCODE_DEL then there never is an associated KeyPress event and the KeyDown | 440 // KEYCODE_DEL then there never is an associated KeyPress event and the KeyDown |
448 // event itself causes the action. The net result below is that the Renderer calls | 441 // event itself causes the action. The net result below is that the Renderer calls |
449 // cancelComposition() and then Android starts anew with setComposin gRegion(). | 442 // cancelComposition() and then Android starts anew with setComposin gRegion(). |
450 // This stopping and restarting of composition could be a source of problems | 443 // This stopping and restarting of composition could be a source of problems |
451 // with 3rd party keyboards. | 444 // with 3rd party keyboards. |
452 // | 445 // |
453 // An alternative is to *not* call nativeSetComposingText() in the n on-commit case | 446 // An alternative is to *not* call nativeSetComposingText() in the n on-commit case |
454 // below. This avoids the restart of composition described above bu t fails to send | 447 // below. This avoids the restart of composition described above bu t fails to send |
455 // an update to the composition while in composition which, strictly speaking, | 448 // an update to the composition while in composition which, strictly speaking, |
456 // does not match the spec. | 449 // does not match the spec. |
457 // | 450 // |
458 // For now, the solution is to endure the restarting of composition and only dive | 451 // For now, the solution is to endure the restarting of composition and only dive |
459 // into the alternate solution should there be problems in the field . --bcwhite | 452 // into the alternate solution should there be problems in the field . --bcwhite |
460 | 453 |
461 if (keyCode >= 0) { | 454 if (keyCode >= 0) { |
462 nativeSendSyntheticKeyEvent(mNativeImeAdapterAndroid, sEventType RawKeyDown, | 455 nativeSendSyntheticKeyEvent(mNativeImeAdapterAndroid, sEventType RawKeyDown, |
463 timeStampMs, keyCode, modifiers, 0); | 456 timeStampMs, keyCode, modifiers, 0); |
James Su
2015/01/12 11:08:02
modifiers is always 0.
huangs
2015/01/12 18:45:48
Done.
| |
464 } | 457 } |
465 | 458 |
466 if (isCommit) { | 459 if (isCommit) { |
467 nativeCommitText(mNativeImeAdapterAndroid, textStr); | 460 nativeCommitText(mNativeImeAdapterAndroid, textStr); |
468 textStr = null; | 461 textStr = null; |
469 } else { | 462 } else { |
470 nativeSetComposingText(mNativeImeAdapterAndroid, text, textStr, newCursorPosition); | 463 nativeSetComposingText(mNativeImeAdapterAndroid, text, textStr, newCursorPosition); |
471 } | 464 } |
472 | 465 |
473 if (keyCode >= 0) { | 466 if (keyCode >= 0) { |
474 nativeSendSyntheticKeyEvent(mNativeImeAdapterAndroid, sEventType KeyUp, | 467 nativeSendSyntheticKeyEvent(mNativeImeAdapterAndroid, sEventType KeyUp, |
475 timeStampMs, keyCode, modifiers, 0); | 468 timeStampMs, keyCode, modifiers, 0); |
James Su
2015/01/12 11:08:02
ditto
huangs
2015/01/12 18:45:48
Done.
| |
476 } | 469 } |
477 | 470 |
478 mLastSyntheticKeyCode = keyCode; | 471 mLastSyntheticKeyCode = keyCode; |
479 } | 472 } |
480 | 473 |
481 mLastComposeText = textStr; | 474 mLastComposeText = textStr; |
482 return true; | 475 return true; |
483 } | 476 } |
484 | 477 |
485 void finishComposingText() { | 478 void finishComposingText() { |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
710 private native void nativeDeleteSurroundingText(long nativeImeAdapterAndroid , | 703 private native void nativeDeleteSurroundingText(long nativeImeAdapterAndroid , |
711 int before, int after); | 704 int before, int after); |
712 | 705 |
713 private native void nativeUnselect(long nativeImeAdapterAndroid); | 706 private native void nativeUnselect(long nativeImeAdapterAndroid); |
714 private native void nativeSelectAll(long nativeImeAdapterAndroid); | 707 private native void nativeSelectAll(long nativeImeAdapterAndroid); |
715 private native void nativeCut(long nativeImeAdapterAndroid); | 708 private native void nativeCut(long nativeImeAdapterAndroid); |
716 private native void nativeCopy(long nativeImeAdapterAndroid); | 709 private native void nativeCopy(long nativeImeAdapterAndroid); |
717 private native void nativePaste(long nativeImeAdapterAndroid); | 710 private native void nativePaste(long nativeImeAdapterAndroid); |
718 private native void nativeResetImeAdapter(long nativeImeAdapterAndroid); | 711 private native void nativeResetImeAdapter(long nativeImeAdapterAndroid); |
719 } | 712 } |
OLD | NEW |