From 05adde860536d66864fd9a2e736c1bc7f986417b Mon Sep 17 00:00:00 2001 From: Chris Peterson Date: Fri, 23 Mar 2012 10:32:42 -0700 Subject: [PATCH] Bug 738695 - Part 2: Unify redundant IME mComposing and mCompositionStart variables. r=blassey --- mobile/android/base/GeckoInputConnection.java | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/mobile/android/base/GeckoInputConnection.java b/mobile/android/base/GeckoInputConnection.java index 36075f6f686..ff885cdd7ca 100644 --- a/mobile/android/base/GeckoInputConnection.java +++ b/mobile/android/base/GeckoInputConnection.java @@ -89,15 +89,15 @@ public class GeckoInputConnection private static final int NOTIFY_IME_CANCELCOMPOSITION = 2; private static final int NOTIFY_IME_FOCUSCHANGE = 3; - private static final CharacterStyle COMPOSING_SPAN = new UnderlineSpan(); + private static final int NO_COMPOSITION_STRING = -1; + private static final Timer mIMETimer = new Timer("GeckoInputConnection Timer"); private static int mIMEState; private static String mIMETypeHint; private static String mIMEActionHint; // Is a composition active? - private boolean mComposing; - private int mCompositionStart = -1; + private int mCompositionStart = NO_COMPOSITION_STRING; private Editable mEditable; private Editable.Factory mEditableFactory; private boolean mBatchMode; @@ -142,7 +142,7 @@ public class GeckoInputConnection public boolean commitText(CharSequence text, int newCursorPosition) { replaceText(text, newCursorPosition, false); - if (mComposing) { + if (hasCompositionString()) { if (DEBUG) Log.d(LOGTAG, ". . . commitText: endComposition"); endComposition(); } @@ -151,7 +151,7 @@ public class GeckoInputConnection @Override public boolean finishComposingText() { - if (mComposing) { + if (hasCompositionString()) { if (DEBUG) Log.d(LOGTAG, ". . . finishComposingText: endComposition"); endComposition(); } @@ -369,7 +369,8 @@ public class GeckoInputConnection if (!(text instanceof Spannable)) { sp = new SpannableStringBuilder(text); text = sp; - sp.setSpan(COMPOSING_SPAN, 0, sp.length(), + // Underline the active composition string. + sp.setSpan(new UnderlineSpan(), 0, sp.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | Spanned.SPAN_COMPOSING); } else { sp = (Spannable) text; @@ -416,7 +417,7 @@ public class GeckoInputConnection @Override public boolean setComposingRegion(int start, int end) { - if (mComposing) { + if (hasCompositionString()) { if (DEBUG) Log.d(LOGTAG, ". . . setComposingRegion: endComposition"); endComposition(); } @@ -449,7 +450,7 @@ public class GeckoInputConnection // In that case we are not updated when a composition // is destroyed, and Bad Things happen - if (!mComposing) + if (!hasCompositionString()) return false; String text = getComposingText(); @@ -551,15 +552,14 @@ public class GeckoInputConnection } public void reset() { - mComposing = false; - mCompositionStart = -1; + mCompositionStart = NO_COMPOSITION_STRING; mBatchMode = false; mUpdateRequest = null; } // TextWatcher public void onTextChanged(CharSequence s, int start, int before, int count) { - if (mComposing && mCompositionStart != start) { + if (hasCompositionString() && mCompositionStart != start) { // Changed range is different from the composition, need to reset the composition endComposition(); } @@ -575,11 +575,10 @@ public class GeckoInputConnection return; } - if (!mComposing) { + if (!hasCompositionString()) { if (DEBUG) Log.d(LOGTAG, ". . . onTextChanged: IME_COMPOSITION_BEGIN"); GeckoAppShell.sendEventToGecko( GeckoEvent.createIMEEvent(GeckoEvent.IME_COMPOSITION_BEGIN, 0, 0)); - mComposing = true; mCompositionStart = start; if (DEBUG) { @@ -614,8 +613,7 @@ public class GeckoInputConnection if (DEBUG) Log.d(LOGTAG, "IME: endComposition: IME_COMPOSITION_END"); GeckoAppShell.sendEventToGecko( GeckoEvent.createIMEEvent(GeckoEvent.IME_COMPOSITION_END, 0, 0)); - mComposing = false; - mCompositionStart = -1; + mCompositionStart = NO_COMPOSITION_STRING; } private void sendTextToGecko(CharSequence text, int caretPos) { @@ -1012,6 +1010,10 @@ public class GeckoInputConnection mEditable.setSpan(this, 0, contents.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); Selection.setSelection(mEditable, contents.length()); } + + private boolean hasCompositionString() { + return mCompositionStart != NO_COMPOSITION_STRING; + } } class DebugGeckoInputConnection extends GeckoInputConnection {