OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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; | 5 package org.chromium.content.browser; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.os.Handler; | 8 import android.os.Handler; |
9 import android.os.ResultReceiver; | 9 import android.os.ResultReceiver; |
10 import android.text.Editable; | 10 import android.text.Editable; |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
488 public static class AdapterInputConnection extends BaseInputConnection { | 488 public static class AdapterInputConnection extends BaseInputConnection { |
489 private static final String TAG = | 489 private static final String TAG = |
490 "org.chromium.content.browser.ImeAdapter$AdapterInputConnection" ; | 490 "org.chromium.content.browser.ImeAdapter$AdapterInputConnection" ; |
491 private static final boolean DEBUG = false; | 491 private static final boolean DEBUG = false; |
492 private final View mInternalView; | 492 private final View mInternalView; |
493 private final ImeAdapter mImeAdapter; | 493 private final ImeAdapter mImeAdapter; |
494 | 494 |
495 private boolean mSingleLine; | 495 private boolean mSingleLine; |
496 private int mNumNestedBatchEdits = 0; | 496 private int mNumNestedBatchEdits = 0; |
497 private boolean mIgnoreTextInputStateUpdates = false; | 497 private boolean mIgnoreTextInputStateUpdates = false; |
498 private boolean mPendingUpdate = false; | |
498 | 499 |
499 private int mLastUpdateSelectionStart = INVALID_SELECTION; | 500 private int mLastUpdateSelectionStart = INVALID_SELECTION; |
500 private int mLastUpdateSelectionEnd = INVALID_SELECTION; | 501 private int mLastUpdateSelectionEnd = INVALID_SELECTION; |
501 private int mLastUpdateCompositionStart = INVALID_COMPOSITION; | 502 private int mLastUpdateCompositionStart = INVALID_COMPOSITION; |
502 private int mLastUpdateCompositionEnd = INVALID_COMPOSITION; | 503 private int mLastUpdateCompositionEnd = INVALID_COMPOSITION; |
503 | 504 |
504 /** | 505 /** |
505 * Updates the AdapterInputConnection's internal representation of the t ext | 506 * Updates the AdapterInputConnection's internal representation of the t ext |
506 * being edited and its selection and composition properties. The result ing | 507 * being edited and its selection and composition properties. The result ing |
507 * Editable is accessible through the getEditable() method. | 508 * Editable is accessible through the getEditable() method. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
541 editable.replace(0, editable.length(), text); | 542 editable.replace(0, editable.length(), text); |
542 } | 543 } |
543 | 544 |
544 if (prevSelectionStart == selectionStart && prevSelectionEnd == sele ctionEnd | 545 if (prevSelectionStart == selectionStart && prevSelectionEnd == sele ctionEnd |
545 && prevCompositionStart == compositionStart | 546 && prevCompositionStart == compositionStart |
546 && prevCompositionEnd == compositionEnd) { | 547 && prevCompositionEnd == compositionEnd) { |
547 // Nothing has changed; don't need to do anything | 548 // Nothing has changed; don't need to do anything |
548 return; | 549 return; |
549 } | 550 } |
550 | 551 |
551 Selection.setSelection(editable, selectionStart, selectionEnd); | 552 if (prevSelectionStart != selectionStart || prevSelectionEnd != sele ctionEnd) { |
552 | 553 Selection.setSelection(editable, selectionStart, selectionEnd); |
553 if (compositionStart == compositionEnd) { | |
554 removeComposingSpans(getEditable()); | |
555 } else { | |
556 super.setComposingRegion(compositionStart, compositionEnd); | |
557 } | 554 } |
558 | 555 |
559 if (mIgnoreTextInputStateUpdates) return; | 556 if (prevCompositionStart != compositionStart || prevCompositionEnd ! = compositionEnd) { |
557 if (compositionStart == compositionEnd) { | |
558 removeComposingSpans(getEditable()); | |
559 } else { | |
560 super.setComposingRegion(compositionStart, compositionEnd); | |
561 } | |
562 } | |
563 | |
564 if (mIgnoreTextInputStateUpdates) { | |
565 mPendingUpdate = true; | |
566 return; | |
567 } | |
560 updateSelection(selectionStart, selectionEnd, compositionStart, comp ositionEnd); | 568 updateSelection(selectionStart, selectionEnd, compositionStart, comp ositionEnd); |
561 } | 569 } |
562 | 570 |
563 @VisibleForTesting | 571 @VisibleForTesting |
564 protected void updateSelection( | 572 protected void updateSelection( |
565 int selectionStart, int selectionEnd, | 573 int selectionStart, int selectionEnd, |
566 int compositionStart, int compositionEnd) { | 574 int compositionStart, int compositionEnd) { |
575 mPendingUpdate = false; | |
567 // Avoid sending update if we sent an exact update already previousl y. | 576 // Avoid sending update if we sent an exact update already previousl y. |
568 if (mLastUpdateSelectionStart == selectionStart && | 577 if (mLastUpdateSelectionStart == selectionStart && |
aurimas (slooooooooow)
2013/04/10 14:35:46
Can you explain why this if check for the last upd
Fredrik Öhrn
2013/04/10 15:27:36
When setIgnoreTextInputStateUpdates(false) calls t
aurimas (slooooooooow)
2013/04/10 15:49:12
If the keyboard did change the selection or compos
| |
569 mLastUpdateSelectionEnd == selectionEnd && | 578 mLastUpdateSelectionEnd == selectionEnd && |
570 mLastUpdateCompositionStart == compositionStart && | 579 mLastUpdateCompositionStart == compositionStart && |
571 mLastUpdateCompositionEnd == compositionEnd) { | 580 mLastUpdateCompositionEnd == compositionEnd) { |
572 return; | 581 return; |
573 } | 582 } |
574 if (DEBUG) { | 583 if (DEBUG) { |
575 Log.w(TAG, "updateSelection [" + selectionStart + " " + selectio nEnd + "] [" | 584 Log.w(TAG, "updateSelection [" + selectionStart + " " + selectio nEnd + "] [" |
576 + compositionStart + " " + compositionEnd + "]"); | 585 + compositionStart + " " + compositionEnd + "]"); |
577 } | 586 } |
578 // updateSelection should be called every time the selection or comp osition changes | 587 // updateSelection should be called every time the selection or comp osition changes |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
732 } | 741 } |
733 | 742 |
734 /** | 743 /** |
735 * Informs the InputMethodManager and InputMethodSession (i.e. the IME) that the text | 744 * Informs the InputMethodManager and InputMethodSession (i.e. the IME) that the text |
736 * state is no longer what the IME has and that it needs to be updated. | 745 * state is no longer what the IME has and that it needs to be updated. |
737 */ | 746 */ |
738 void restartInput() { | 747 void restartInput() { |
739 if (DEBUG) Log.w(TAG, "restartInput"); | 748 if (DEBUG) Log.w(TAG, "restartInput"); |
740 getInputMethodManagerWrapper().restartInput(mInternalView); | 749 getInputMethodManagerWrapper().restartInput(mInternalView); |
741 mIgnoreTextInputStateUpdates = false; | 750 mIgnoreTextInputStateUpdates = false; |
751 mPendingUpdate = false; | |
742 mNumNestedBatchEdits = 0; | 752 mNumNestedBatchEdits = 0; |
743 } | 753 } |
744 | 754 |
745 @Override | 755 @Override |
746 public boolean setComposingRegion(int start, int end) { | 756 public boolean setComposingRegion(int start, int end) { |
747 if (DEBUG) Log.w(TAG, "setComposingRegion [" + start + " " + end + " ]"); | 757 if (DEBUG) Log.w(TAG, "setComposingRegion [" + start + " " + end + " ]"); |
748 int a = Math.min(start, end); | 758 int a = Math.min(start, end); |
749 int b = Math.max(start, end); | 759 int b = Math.max(start, end); |
750 if (a == b) { | 760 if (a == b) { |
751 removeComposingSpans(getEditable()); | 761 removeComposingSpans(getEditable()); |
752 } else { | 762 } else { |
753 super.setComposingRegion(a, b); | 763 super.setComposingRegion(a, b); |
754 } | 764 } |
755 return mImeAdapter.setComposingRegion(a, b); | 765 return mImeAdapter.setComposingRegion(a, b); |
756 } | 766 } |
757 | 767 |
758 boolean isActive() { | 768 boolean isActive() { |
759 return getInputMethodManagerWrapper().isActive(mInternalView); | 769 return getInputMethodManagerWrapper().isActive(mInternalView); |
760 } | 770 } |
761 | 771 |
762 void setIgnoreTextInputStateUpdates(boolean shouldIgnore) { | 772 void setIgnoreTextInputStateUpdates(boolean shouldIgnore) { |
763 mIgnoreTextInputStateUpdates = shouldIgnore; | 773 mIgnoreTextInputStateUpdates = shouldIgnore; |
764 if (shouldIgnore) return; | 774 if (shouldIgnore || !mPendingUpdate) return; |
765 | 775 |
766 Editable editable = getEditable(); | 776 Editable editable = getEditable(); |
767 updateSelection(Selection.getSelectionStart(editable), | 777 updateSelection(Selection.getSelectionStart(editable), |
768 Selection.getSelectionEnd(editable), | 778 Selection.getSelectionEnd(editable), |
769 getComposingSpanStart(editable), | 779 getComposingSpanStart(editable), |
770 getComposingSpanEnd(editable)); | 780 getComposingSpanEnd(editable)); |
771 } | 781 } |
772 | 782 |
773 @VisibleForTesting | 783 @VisibleForTesting |
774 protected boolean isIgnoringTextInputStateUpdates() { | 784 protected boolean isIgnoringTextInputStateUpdates() { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
858 int before, int after); | 868 int before, int after); |
859 | 869 |
860 private native void nativeImeBatchStateChanged(int nativeImeAdapterAndroid, boolean isBegin); | 870 private native void nativeImeBatchStateChanged(int nativeImeAdapterAndroid, boolean isBegin); |
861 | 871 |
862 private native void nativeUnselect(int nativeImeAdapterAndroid); | 872 private native void nativeUnselect(int nativeImeAdapterAndroid); |
863 private native void nativeSelectAll(int nativeImeAdapterAndroid); | 873 private native void nativeSelectAll(int nativeImeAdapterAndroid); |
864 private native void nativeCut(int nativeImeAdapterAndroid); | 874 private native void nativeCut(int nativeImeAdapterAndroid); |
865 private native void nativeCopy(int nativeImeAdapterAndroid); | 875 private native void nativeCopy(int nativeImeAdapterAndroid); |
866 private native void nativePaste(int nativeImeAdapterAndroid); | 876 private native void nativePaste(int nativeImeAdapterAndroid); |
867 } | 877 } |
OLD | NEW |