aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2013-12-19 17:57:10 +0900
committerJean Chalard <jchalard@google.com>2013-12-19 18:32:51 +0900
commit035e3885ac5db4944f3b244019ee73208a88fd39 (patch)
tree064e5909249366cb441b83e29de584e5d2e7b2c0 /java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
parentd85e49bf8cd9d8b850cb9f1ca0257e826b74642a (diff)
downloadlatinime-035e3885ac5db4944f3b244019ee73208a88fd39.tar.gz
latinime-035e3885ac5db4944f3b244019ee73208a88fd39.tar.xz
latinime-035e3885ac5db4944f3b244019ee73208a88fd39.zip
[IL8] Move handleNonSeparator to InputLogic
Also move getActualCapsMode and getNthPreviousWordForSuggestion Bug: 8636060 Change-Id: I1ee9162d0b7a517070c4b7420b084c973f061533
Diffstat (limited to 'java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java')
-rw-r--r--java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java138
1 files changed, 137 insertions, 1 deletions
diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
index 5fa084def..33ca25c00 100644
--- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
+++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
@@ -27,6 +27,7 @@ import com.android.inputmethod.compat.SuggestionSpanUtils;
import com.android.inputmethod.event.EventInterpreter;
import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardSwitcher;
+import com.android.inputmethod.keyboard.MainKeyboardView;
import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.LastComposedWord;
import com.android.inputmethod.latin.LatinIME;
@@ -228,6 +229,7 @@ public final class InputLogic {
* manage keyboard-related stuff like shift, language switch, settings, layout switch, or
* any key that results in multiple code points like the ".com" key.
*
+ * @param settingsValues The current settings values.
* @param codePoint the code point associated with the key.
* @param x the x-coordinate of the key press, or Contants.NOT_A_COORDINATE if not applicable.
* @param y the y-coordinate of the key press, or Contants.NOT_A_COORDINATE if not applicable.
@@ -270,12 +272,108 @@ public final class InputLogic {
keyX = Constants.NOT_A_COORDINATE;
keyY = Constants.NOT_A_COORDINATE;
}
- mLatinIME.handleCharacter(codePoint, keyX, keyY, spaceState);
+ handleNonSeparator(settingsValues, codePoint, keyX, keyY, spaceState,
+ keyboardSwitcher, handler);
}
return didAutoCorrect;
}
/**
+ * Handle a non-separator.
+ * @param settingsValues The current settings values.
+ * @param codePoint the code point associated with the key.
+ * @param x the x-coordinate of the key press, or Contants.NOT_A_COORDINATE if not applicable.
+ * @param y the y-coordinate of the key press, or Contants.NOT_A_COORDINATE if not applicable.
+ * @param spaceState the space state at start of the batch input.
+ */
+ private void handleNonSeparator(final SettingsValues settingsValues,
+ final int codePoint, final int x, final int y, final int spaceState,
+ // TODO: Remove these arguments
+ final KeyboardSwitcher keyboardSwitcher, final LatinIME.UIHandler handler) {
+ // TODO: refactor this method to stop flipping isComposingWord around all the time, and
+ // make it shorter (possibly cut into several pieces). Also factor handleNonSpecialCharacter
+ // which has the same name as other handle* methods but is not the same.
+ boolean isComposingWord = mWordComposer.isComposingWord();
+
+ // TODO: remove isWordConnector() and use isUsuallyFollowedBySpace() instead.
+ // See onStartBatchInput() to see how to do it.
+ if (SpaceState.PHANTOM == spaceState && !settingsValues.isWordConnector(codePoint)) {
+ if (isComposingWord) {
+ // Sanity check
+ throw new RuntimeException("Should not be composing here");
+ }
+ promotePhantomSpace(settingsValues);
+ }
+
+ if (mWordComposer.isCursorFrontOrMiddleOfComposingWord()) {
+ // If we are in the middle of a recorrection, we need to commit the recorrection
+ // first so that we can insert the character at the current cursor position.
+ resetEntireInputState(settingsValues, mLastSelectionStart, mLastSelectionEnd);
+ isComposingWord = false;
+ }
+ // We want to find out whether to start composing a new word with this character. If so,
+ // we need to reset the composing state and switch isComposingWord. The order of the
+ // tests is important for good performance.
+ // We only start composing if we're not already composing.
+ if (!isComposingWord
+ // We only start composing if this is a word code point. Essentially that means it's a
+ // a letter or a word connector.
+ && settingsValues.isWordCodePoint(codePoint)
+ // We never go into composing state if suggestions are not requested.
+ && settingsValues.isSuggestionsRequested(mLatinIME.mDisplayOrientation) &&
+ // In languages with spaces, we only start composing a word when we are not already
+ // touching a word. In languages without spaces, the above conditions are sufficient.
+ (!mConnection.isCursorTouchingWord(settingsValues)
+ || !settingsValues.mCurrentLanguageHasSpaces)) {
+ // Reset entirely the composing state anyway, then start composing a new word unless
+ // the character is a single quote or a dash. The idea here is, single quote and dash
+ // are not separators and they should be treated as normal characters, except in the
+ // first position where they should not start composing a word.
+ isComposingWord = (Constants.CODE_SINGLE_QUOTE != codePoint
+ && Constants.CODE_DASH != codePoint);
+ // Here we don't need to reset the last composed word. It will be reset
+ // when we commit this one, if we ever do; if on the other hand we backspace
+ // it entirely and resume suggestions on the previous word, we'd like to still
+ // have touch coordinates for it.
+ resetComposingState(false /* alsoResetLastComposedWord */);
+ }
+ if (isComposingWord) {
+ final MainKeyboardView mainKeyboardView = keyboardSwitcher.getMainKeyboardView();
+ // TODO: We should reconsider which coordinate system should be used to represent
+ // keyboard event.
+ final int keyX = mainKeyboardView.getKeyX(x);
+ final int keyY = mainKeyboardView.getKeyY(y);
+ mWordComposer.add(codePoint, keyX, keyY);
+ // If it's the first letter, make note of auto-caps state
+ if (mWordComposer.size() == 1) {
+ // We pass 1 to getPreviousWordForSuggestion because we were not composing a word
+ // yet, so the word we want is the 1st word before the cursor.
+ mWordComposer.setCapitalizedModeAndPreviousWordAtStartComposingTime(
+ getActualCapsMode(keyboardSwitcher),
+ getNthPreviousWordForSuggestion(settingsValues, 1 /* nthPreviousWord */));
+ }
+ mConnection.setComposingText(getTextWithUnderline(
+ mWordComposer.getTypedWord()), 1);
+ } else {
+ final boolean swapWeakSpace = maybeStripSpace(settingsValues,
+ codePoint, spaceState, Constants.SUGGESTION_STRIP_COORDINATE == x);
+
+ sendKeyCodePoint(codePoint);
+
+ if (swapWeakSpace) {
+ swapSwapperAndSpace(keyboardSwitcher);
+ mSpaceState = SpaceState.WEAK;
+ }
+ // In case the "add to dictionary" hint was still displayed.
+ mLatinIME.dismissAddToDictionaryHint();
+ }
+ handler.postUpdateSuggestionStrip();
+ if (settingsValues.mIsInternal) {
+ LatinImeLoggerUtils.onNonSeparator((char)codePoint, x, y);
+ }
+ }
+
+ /**
* Handle input of a separator code point.
* @param settingsValues The current settings values.
* @param codePoint the code point associated with the key.
@@ -658,6 +756,25 @@ public final class InputLogic {
}
/**
+ * Factor in auto-caps and manual caps and compute the current caps mode.
+ * @param keyboardSwitcher the keyboard switcher. Caps mode depends on its mode.
+ * @return the actual caps mode the keyboard is in right now.
+ */
+ // TODO: Make this private
+ public int getActualCapsMode(final KeyboardSwitcher keyboardSwitcher) {
+ final int keyboardShiftMode = keyboardSwitcher.getKeyboardShiftMode();
+ if (keyboardShiftMode != WordComposer.CAPS_MODE_AUTO_SHIFTED) return keyboardShiftMode;
+ final int auto = mLatinIME.getCurrentAutoCapsState();
+ if (0 != (auto & TextUtils.CAP_MODE_CHARACTERS)) {
+ return WordComposer.CAPS_MODE_AUTO_SHIFT_LOCKED;
+ }
+ if (0 != auto) {
+ return WordComposer.CAPS_MODE_AUTO_SHIFTED;
+ }
+ return WordComposer.CAPS_MODE_OFF;
+ }
+
+ /**
* @return the editor info for the current editor
*/
private EditorInfo getCurrentInputEditorInfo() {
@@ -665,6 +782,25 @@ public final class InputLogic {
}
/**
+ * Get the nth previous word before the cursor as context for the suggestion process.
+ * @param currentSettings the current settings values.
+ * @param nthPreviousWord reverse index of the word to get (1-indexed)
+ * @return the nth previous word before the cursor.
+ */
+ // TODO: Make this private
+ public String getNthPreviousWordForSuggestion(final SettingsValues currentSettings,
+ final int nthPreviousWord) {
+ if (currentSettings.mCurrentLanguageHasSpaces) {
+ // If we are typing in a language with spaces we can just look up the previous
+ // word from textview.
+ return mConnection.getNthPreviousWord(currentSettings, nthPreviousWord);
+ } else {
+ return LastComposedWord.NOT_A_COMPOSED_WORD == mLastComposedWord ? null
+ : mLastComposedWord.mCommittedWord;
+ }
+ }
+
+ /**
* @param actionId the action to perform
*/
private void performEditorAction(final int actionId) {