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

Side by Side Diff: content/public/android/java/src/org/chromium/content/browser/ImeAdapter.java

Issue 13820016: [Android] Remove zero length composing spans. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 super.setComposingRegion(compositionStart, compositionEnd); 553 Selection.setSelection(editable, selectionStart, selectionEnd);
554 }
553 555
554 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 }
555 updateSelection(selectionStart, selectionEnd, compositionStart, comp ositionEnd); 568 updateSelection(selectionStart, selectionEnd, compositionStart, comp ositionEnd);
556 } 569 }
557 570
558 @VisibleForTesting 571 @VisibleForTesting
559 protected void updateSelection( 572 protected void updateSelection(
560 int selectionStart, int selectionEnd, 573 int selectionStart, int selectionEnd,
561 int compositionStart, int compositionEnd) { 574 int compositionStart, int compositionEnd) {
575 mPendingUpdate = false;
aurimas (slooooooooow) 2013/04/09 17:09:26 Can you explain this PendingUpdate flag and why we
562 // 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.
563 if (mLastUpdateSelectionStart == selectionStart && 577 if (mLastUpdateSelectionStart == selectionStart &&
564 mLastUpdateSelectionEnd == selectionEnd && 578 mLastUpdateSelectionEnd == selectionEnd &&
565 mLastUpdateCompositionStart == compositionStart && 579 mLastUpdateCompositionStart == compositionStart &&
566 mLastUpdateCompositionEnd == compositionEnd) { 580 mLastUpdateCompositionEnd == compositionEnd) {
567 return; 581 return;
568 } 582 }
569 if (DEBUG) { 583 if (DEBUG) {
570 Log.w(TAG, "updateSelection [" + selectionStart + " " + selectio nEnd + "] [" 584 Log.w(TAG, "updateSelection [" + selectionStart + " " + selectio nEnd + "] ["
571 + compositionStart + " " + compositionEnd + "]"); 585 + compositionStart + " " + compositionEnd + "]");
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 } 741 }
728 742
729 /** 743 /**
730 * 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
731 * 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.
732 */ 746 */
733 void restartInput() { 747 void restartInput() {
734 if (DEBUG) Log.w(TAG, "restartInput"); 748 if (DEBUG) Log.w(TAG, "restartInput");
735 getInputMethodManagerWrapper().restartInput(mInternalView); 749 getInputMethodManagerWrapper().restartInput(mInternalView);
736 mIgnoreTextInputStateUpdates = false; 750 mIgnoreTextInputStateUpdates = false;
751 mPendingUpdate = false;
737 mNumNestedBatchEdits = 0; 752 mNumNestedBatchEdits = 0;
738 } 753 }
739 754
740 @Override 755 @Override
741 public boolean setComposingRegion(int start, int end) { 756 public boolean setComposingRegion(int start, int end) {
742 if (DEBUG) Log.w(TAG, "setComposingRegion [" + start + " " + end + " ]"); 757 if (DEBUG) Log.w(TAG, "setComposingRegion [" + start + " " + end + " ]");
743 int a = Math.min(start, end); 758 int a = Math.min(start, end);
744 int b = Math.max(start, end); 759 int b = Math.max(start, end);
745 super.setComposingRegion(a, b); 760 if (a == b) {
761 removeComposingSpans(getEditable());
762 } else {
763 super.setComposingRegion(a, b);
764 }
746 return mImeAdapter.setComposingRegion(a, b); 765 return mImeAdapter.setComposingRegion(a, b);
747 } 766 }
748 767
749 boolean isActive() { 768 boolean isActive() {
750 return getInputMethodManagerWrapper().isActive(mInternalView); 769 return getInputMethodManagerWrapper().isActive(mInternalView);
751 } 770 }
752 771
753 void setIgnoreTextInputStateUpdates(boolean shouldIgnore) { 772 void setIgnoreTextInputStateUpdates(boolean shouldIgnore) {
754 mIgnoreTextInputStateUpdates = shouldIgnore; 773 mIgnoreTextInputStateUpdates = shouldIgnore;
755 if (shouldIgnore) return; 774 if (shouldIgnore || !mPendingUpdate) return;
756 775
757 Editable editable = getEditable(); 776 Editable editable = getEditable();
758 updateSelection(Selection.getSelectionStart(editable), 777 updateSelection(Selection.getSelectionStart(editable),
759 Selection.getSelectionEnd(editable), 778 Selection.getSelectionEnd(editable),
760 getComposingSpanStart(editable), 779 getComposingSpanStart(editable),
761 getComposingSpanEnd(editable)); 780 getComposingSpanEnd(editable));
762 } 781 }
763 782
764 @VisibleForTesting 783 @VisibleForTesting
765 protected boolean isIgnoringTextInputStateUpdates() { 784 protected boolean isIgnoringTextInputStateUpdates() {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 int before, int after); 868 int before, int after);
850 869
851 private native void nativeImeBatchStateChanged(int nativeImeAdapterAndroid, boolean isBegin); 870 private native void nativeImeBatchStateChanged(int nativeImeAdapterAndroid, boolean isBegin);
852 871
853 private native void nativeUnselect(int nativeImeAdapterAndroid); 872 private native void nativeUnselect(int nativeImeAdapterAndroid);
854 private native void nativeSelectAll(int nativeImeAdapterAndroid); 873 private native void nativeSelectAll(int nativeImeAdapterAndroid);
855 private native void nativeCut(int nativeImeAdapterAndroid); 874 private native void nativeCut(int nativeImeAdapterAndroid);
856 private native void nativeCopy(int nativeImeAdapterAndroid); 875 private native void nativeCopy(int nativeImeAdapterAndroid);
857 private native void nativePaste(int nativeImeAdapterAndroid); 876 private native void nativePaste(int nativeImeAdapterAndroid);
858 } 877 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698