[CB04] Add an event array to WordComposer.

Bug: 13406701
Change-Id: I9ecd2709c8f1c678a85b0cfaf7c5ed4f78459821
main
Jean Chalard 2014-03-13 17:37:16 +09:00
parent 309773c322
commit f8accd8839
5 changed files with 93 additions and 36 deletions

View File

@ -120,6 +120,34 @@ public class Event {
FLAG_DEAD, next); FLAG_DEAD, next);
} }
/**
* Create an input event with nothing but a code point. This is the most basic possible input
* event; it contains no information on many things the IME requires to function correctly,
* so avoid using it unless really nothing is known about this input.
* @param codePoint the code point.
* @return an event for this code point.
*/
public static Event createEventForCodePointFromUnknownSource(final int codePoint) {
// TODO: should we have a different type of event for this? After all, it's not a key press.
return new Event(EVENT_INPUT_KEYPRESS, codePoint, NOT_A_KEY_CODE,
Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, FLAG_NONE, null /* next */);
}
/**
* Creates an input event with a code point and x, y coordinates. This is typically used when
* resuming a previously-typed word, when the coordinates are still known.
* @param codePoint the code point to input.
* @param x the X coordinate.
* @param y the Y coordinate.
* @return an event for this code point and coordinates.
*/
public static Event createEventForCodePointFromAlreadyTypedText(final int codePoint,
final int x, final int y) {
// TODO: should we have a different type of event for this? After all, it's not a key press.
return new Event(EVENT_INPUT_KEYPRESS, codePoint, NOT_A_KEY_CODE, x, y, FLAG_NONE,
null /* next */);
}
public static Event createNotHandledEvent() { public static Event createNotHandledEvent() {
return new Event(EVENT_NOT_HANDLED, NOT_A_CODE_POINT, NOT_A_KEY_CODE, return new Event(EVENT_NOT_HANDLED, NOT_A_CODE_POINT, NOT_A_KEY_CODE,
Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, FLAG_NONE, null); Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, FLAG_NONE, null);

View File

@ -18,6 +18,10 @@ package com.android.inputmethod.latin;
import android.text.TextUtils; import android.text.TextUtils;
import com.android.inputmethod.event.Event;
import java.util.ArrayList;
/** /**
* This class encapsulates data about a word previously composed, but that has been * This class encapsulates data about a word previously composed, but that has been
* committed already. This is used for resuming suggestion, and cancel auto-correction. * committed already. This is used for resuming suggestion, and cancel auto-correction.
@ -41,6 +45,7 @@ public final class LastComposedWord {
public static final String NOT_A_SEPARATOR = ""; public static final String NOT_A_SEPARATOR = "";
public final int[] mPrimaryKeyCodes; public final int[] mPrimaryKeyCodes;
public final ArrayList<Event> mEvents;
public final String mTypedWord; public final String mTypedWord;
public final CharSequence mCommittedWord; public final CharSequence mCommittedWord;
public final String mSeparatorString; public final String mSeparatorString;
@ -52,19 +57,21 @@ public final class LastComposedWord {
private boolean mActive; private boolean mActive;
public static final LastComposedWord NOT_A_COMPOSED_WORD = public static final LastComposedWord NOT_A_COMPOSED_WORD =
new LastComposedWord(null, null, "", "", NOT_A_SEPARATOR, null, new LastComposedWord(null, new ArrayList<Event>(), null, "", "",
WordComposer.CAPS_MODE_OFF); NOT_A_SEPARATOR, null, WordComposer.CAPS_MODE_OFF);
// Warning: this is using the passed objects as is and fully expects them to be // Warning: this is using the passed objects as is and fully expects them to be
// immutable. Do not fiddle with their contents after you passed them to this constructor. // immutable. Do not fiddle with their contents after you passed them to this constructor.
public LastComposedWord(final int[] primaryKeyCodes, final InputPointers inputPointers, public LastComposedWord(final int[] primaryKeyCodes, final ArrayList<Event> events,
final String typedWord, final CharSequence committedWord, final String separatorString, final InputPointers inputPointers, final String typedWord,
final CharSequence committedWord, final String separatorString,
final String prevWord, final int capitalizedMode) { final String prevWord, final int capitalizedMode) {
mPrimaryKeyCodes = primaryKeyCodes; mPrimaryKeyCodes = primaryKeyCodes;
if (inputPointers != null) { if (inputPointers != null) {
mInputPointers.copy(inputPointers); mInputPointers.copy(inputPointers);
} }
mTypedWord = typedWord; mTypedWord = typedWord;
mEvents = new ArrayList<Event>(events);
mCommittedWord = committedWord; mCommittedWord = committedWord;
mSeparatorString = separatorString; mSeparatorString = separatorString;
mActive = true; mActive = true;

View File

@ -16,10 +16,14 @@
package com.android.inputmethod.latin; package com.android.inputmethod.latin;
import com.android.inputmethod.event.Event;
import com.android.inputmethod.latin.utils.CollectionUtils;
import com.android.inputmethod.latin.utils.CoordinateUtils; import com.android.inputmethod.latin.utils.CoordinateUtils;
import com.android.inputmethod.latin.utils.StringUtils; import com.android.inputmethod.latin.utils.StringUtils;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
/** /**
* A place to store the currently composing word with information such as adjacent key codes as well * A place to store the currently composing word with information such as adjacent key codes as well
@ -41,6 +45,8 @@ public final class WordComposer {
// and mCodePointSize can go past that. If mCodePointSize is greater than MAX_WORD_LENGTH, // and mCodePointSize can go past that. If mCodePointSize is greater than MAX_WORD_LENGTH,
// this just does not contain the associated code points past MAX_WORD_LENGTH. // this just does not contain the associated code points past MAX_WORD_LENGTH.
private int[] mPrimaryKeyCodes; private int[] mPrimaryKeyCodes;
// The list of events that served to compose this string.
private final ArrayList<Event> mEvents;
private final InputPointers mInputPointers = new InputPointers(MAX_WORD_LENGTH); private final InputPointers mInputPointers = new InputPointers(MAX_WORD_LENGTH);
// This is the typed word, as a StringBuilder. This has the same contents as mPrimaryKeyCodes // This is the typed word, as a StringBuilder. This has the same contents as mPrimaryKeyCodes
// but under a StringBuilder representation for ease of use, depending on what is more useful // but under a StringBuilder representation for ease of use, depending on what is more useful
@ -82,6 +88,7 @@ public final class WordComposer {
public WordComposer() { public WordComposer() {
mPrimaryKeyCodes = new int[MAX_WORD_LENGTH]; mPrimaryKeyCodes = new int[MAX_WORD_LENGTH];
mEvents = CollectionUtils.newArrayList();
mTypedWord = new StringBuilder(MAX_WORD_LENGTH); mTypedWord = new StringBuilder(MAX_WORD_LENGTH);
mAutoCorrection = null; mAutoCorrection = null;
mTrailingSingleQuotesCount = 0; mTrailingSingleQuotesCount = 0;
@ -95,6 +102,7 @@ public final class WordComposer {
public WordComposer(final WordComposer source) { public WordComposer(final WordComposer source) {
mPrimaryKeyCodes = Arrays.copyOf(source.mPrimaryKeyCodes, source.mPrimaryKeyCodes.length); mPrimaryKeyCodes = Arrays.copyOf(source.mPrimaryKeyCodes, source.mPrimaryKeyCodes.length);
mEvents = new ArrayList<Event>(source.mEvents);
mTypedWord = new StringBuilder(source.mTypedWord); mTypedWord = new StringBuilder(source.mTypedWord);
mInputPointers.copy(source.mInputPointers); mInputPointers.copy(source.mInputPointers);
mCapsCount = source.mCapsCount; mCapsCount = source.mCapsCount;
@ -115,6 +123,7 @@ public final class WordComposer {
*/ */
public void reset() { public void reset() {
mTypedWord.setLength(0); mTypedWord.setLength(0);
mEvents.clear();
mAutoCorrection = null; mAutoCorrection = null;
mCapsCount = 0; mCapsCount = 0;
mDigitsCount = 0; mDigitsCount = 0;
@ -170,11 +179,16 @@ public final class WordComposer {
} }
/** /**
* Add a new keystroke, with the pressed key's code point with the touch point coordinates. * Add a new event for a key stroke, with the pressed key's code point with the touch point
* coordinates.
*/ */
public void add(final int primaryCode, final int keyX, final int keyY) { public void add(final Event event) {
final int primaryCode = event.mCodePoint;
final int keyX = event.mX;
final int keyY = event.mY;
final int newIndex = size(); final int newIndex = size();
mTypedWord.appendCodePoint(primaryCode); mTypedWord.appendCodePoint(primaryCode);
mEvents.add(event);
refreshSize(); refreshSize();
mCursorPositionWithinWord = mCodePointSize; mCursorPositionWithinWord = mCodePointSize;
if (newIndex < MAX_WORD_LENGTH) { if (newIndex < MAX_WORD_LENGTH) {
@ -202,6 +216,7 @@ public final class WordComposer {
public void setCursorPositionWithinWord(final int posWithinWord) { public void setCursorPositionWithinWord(final int posWithinWord) {
mCursorPositionWithinWord = posWithinWord; mCursorPositionWithinWord = posWithinWord;
// TODO: compute where that puts us inside the events
} }
public boolean isCursorFrontOrMiddleOfComposingWord() { public boolean isCursorFrontOrMiddleOfComposingWord() {
@ -268,7 +283,7 @@ public final class WordComposer {
final int codePoint = Character.codePointAt(word, i); final int codePoint = Character.codePointAt(word, i);
// We don't want to override the batch input points that are held in mInputPointers // We don't want to override the batch input points that are held in mInputPointers
// (See {@link #add(int,int,int)}). // (See {@link #add(int,int,int)}).
add(codePoint, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE); add(Event.createEventForCodePointFromUnknownSource(codePoint));
} }
} }
@ -285,8 +300,9 @@ public final class WordComposer {
reset(); reset();
final int length = codePoints.length; final int length = codePoints.length;
for (int i = 0; i < length; ++i) { for (int i = 0; i < length; ++i) {
add(codePoints[i], CoordinateUtils.xFromArray(coordinates, i), add(Event.createEventForCodePointFromAlreadyTypedText(codePoints[i],
CoordinateUtils.yFromArray(coordinates, i)); CoordinateUtils.xFromArray(coordinates, i),
CoordinateUtils.yFromArray(coordinates, i)));
} }
mIsResumed = true; mIsResumed = true;
mPreviousWordForSuggestion = null == previousWord ? null : previousWord.toString(); mPreviousWordForSuggestion = null == previousWord ? null : previousWord.toString();
@ -305,6 +321,8 @@ public final class WordComposer {
"In WordComposer: mCodes and mTypedWords have non-matching lengths"); "In WordComposer: mCodes and mTypedWords have non-matching lengths");
} }
final int lastChar = mTypedWord.codePointBefore(stringBuilderLength); final int lastChar = mTypedWord.codePointBefore(stringBuilderLength);
// TODO: with events and composition, this is absolutely not necessarily true.
mEvents.remove(mEvents.size() - 1);
if (Character.isSupplementaryCodePoint(lastChar)) { if (Character.isSupplementaryCodePoint(lastChar)) {
mTypedWord.delete(stringBuilderLength - 2, stringBuilderLength); mTypedWord.delete(stringBuilderLength - 2, stringBuilderLength);
} else { } else {
@ -445,7 +463,7 @@ public final class WordComposer {
// the last composed word to ensure this does not happen. // the last composed word to ensure this does not happen.
final int[] primaryKeyCodes = mPrimaryKeyCodes; final int[] primaryKeyCodes = mPrimaryKeyCodes;
mPrimaryKeyCodes = new int[MAX_WORD_LENGTH]; mPrimaryKeyCodes = new int[MAX_WORD_LENGTH];
final LastComposedWord lastComposedWord = new LastComposedWord(primaryKeyCodes, final LastComposedWord lastComposedWord = new LastComposedWord(primaryKeyCodes, mEvents,
mInputPointers, mTypedWord.toString(), committedWord, separatorString, mInputPointers, mTypedWord.toString(), committedWord, separatorString,
prevWord, mCapitalizedMode); prevWord, mCapitalizedMode);
mInputPointers.reset(); mInputPointers.reset();
@ -458,6 +476,7 @@ public final class WordComposer {
mIsBatchMode = false; mIsBatchMode = false;
mPreviousWordForSuggestion = committedWord.toString(); mPreviousWordForSuggestion = committedWord.toString();
mTypedWord.setLength(0); mTypedWord.setLength(0);
mEvents.clear();
mCodePointSize = 0; mCodePointSize = 0;
mTrailingSingleQuotesCount = 0; mTrailingSingleQuotesCount = 0;
mIsFirstCharCapitalized = false; mIsFirstCharCapitalized = false;
@ -480,6 +499,8 @@ public final class WordComposer {
public void resumeSuggestionOnLastComposedWord(final LastComposedWord lastComposedWord, public void resumeSuggestionOnLastComposedWord(final LastComposedWord lastComposedWord,
final String previousWord) { final String previousWord) {
mPrimaryKeyCodes = lastComposedWord.mPrimaryKeyCodes; mPrimaryKeyCodes = lastComposedWord.mPrimaryKeyCodes;
mEvents.clear();
Collections.copy(mEvents, lastComposedWord.mEvents);
mInputPointers.set(lastComposedWord.mInputPointers); mInputPointers.set(lastComposedWord.mInputPointers);
mTypedWord.setLength(0); mTypedWord.setLength(0);
mTypedWord.append(lastComposedWord.mTypedWord); mTypedWord.append(lastComposedWord.mTypedWord);

View File

@ -730,8 +730,7 @@ public final class InputLogic {
resetComposingState(false /* alsoResetLastComposedWord */); resetComposingState(false /* alsoResetLastComposedWord */);
} }
if (isComposingWord) { if (isComposingWord) {
// TODO: pass the entire event to the word composer. mWordComposer.add(inputTransaction.mEvent);
mWordComposer.add(codePoint, inputTransaction.mEvent.mX, inputTransaction.mEvent.mY);
// If it's the first letter, make note of auto-caps state // If it's the first letter, make note of auto-caps state
if (mWordComposer.size() == 1) { if (mWordComposer.size() == 1) {
// We pass 1 to getPreviousWordForSuggestion because we were not composing a word // We pass 1 to getPreviousWordForSuggestion because we were not composing a word

View File

@ -29,32 +29,34 @@ include $(CLEAR_VARS)
LATINIME_LOCAL_DIR := ../.. LATINIME_LOCAL_DIR := ../..
LATINIME_BASE_SOURCE_DIRECTORY := $(LATINIME_LOCAL_DIR)/java/src/com/android/inputmethod LATINIME_BASE_SOURCE_DIRECTORY := $(LATINIME_LOCAL_DIR)/java/src/com/android/inputmethod
LATINIME_ANNOTATIONS_SOURCE_DIRECTORY := $(LATINIME_BASE_SOURCE_DIRECTORY)/annotations LATINIME_ANNOTATIONS_SOURCE_DIRECTORY := $(LATINIME_BASE_SOURCE_DIRECTORY)/annotations
LATINIME_CORE_SOURCE_DIRECTORY := $(LATINIME_BASE_SOURCE_DIRECTORY)/latin MAKEDICT_CORE_SOURCE_DIRECTORY := $(LATINIME_BASE_SOURCE_DIRECTORY)/latin/makedict
MAKEDICT_CORE_SOURCE_DIRECTORY := $(LATINIME_CORE_SOURCE_DIRECTORY)/makedict
# Dependencies for Dicttool. Most of these files are needed by BinaryDictionary.java. Note that # Dependencies for Dicttool. Most of these files are needed by BinaryDictionary.java. Note that
# a significant part of the dependencies are mocked in the compat/ directory, with empty or # a significant part of the dependencies are mocked in the compat/ directory, with empty or
# nearly-empty implementations, for parts that we don't use in Dicttool. # nearly-empty implementations, for parts that we don't use in Dicttool.
USED_TARGETTED_UTILS := \ LATINIME_SRCS_FOR_DICTTOOL := \
$(LATINIME_CORE_SOURCE_DIRECTORY)/BinaryDictionary.java \ event/Event.java \
$(LATINIME_CORE_SOURCE_DIRECTORY)/DicTraverseSession.java \ latin/BinaryDictionary.java \
$(LATINIME_CORE_SOURCE_DIRECTORY)/Dictionary.java \ latin/DicTraverseSession.java \
$(LATINIME_CORE_SOURCE_DIRECTORY)/InputPointers.java \ latin/Dictionary.java \
$(LATINIME_CORE_SOURCE_DIRECTORY)/LastComposedWord.java \ latin/InputPointers.java \
$(LATINIME_CORE_SOURCE_DIRECTORY)/LatinImeLogger.java \ latin/LastComposedWord.java \
$(LATINIME_CORE_SOURCE_DIRECTORY)/SuggestedWords.java \ latin/LatinImeLogger.java \
$(LATINIME_CORE_SOURCE_DIRECTORY)/WordComposer.java \ latin/SuggestedWords.java \
$(LATINIME_CORE_SOURCE_DIRECTORY)/settings/NativeSuggestOptions.java \ latin/WordComposer.java \
$(LATINIME_CORE_SOURCE_DIRECTORY)/utils/BinaryDictionaryUtils.java \ latin/settings/NativeSuggestOptions.java \
$(LATINIME_CORE_SOURCE_DIRECTORY)/utils/ByteArrayDictBuffer.java \ latin/utils/BinaryDictionaryUtils.java \
$(LATINIME_CORE_SOURCE_DIRECTORY)/utils/CollectionUtils.java \ latin/utils/ByteArrayDictBuffer.java \
$(LATINIME_CORE_SOURCE_DIRECTORY)/utils/CombinedFormatUtils.java \ latin/utils/CollectionUtils.java \
$(LATINIME_CORE_SOURCE_DIRECTORY)/utils/CoordinateUtils.java \ latin/utils/CombinedFormatUtils.java \
$(LATINIME_CORE_SOURCE_DIRECTORY)/utils/FileUtils.java \ latin/utils/CoordinateUtils.java \
$(LATINIME_CORE_SOURCE_DIRECTORY)/utils/JniUtils.java \ latin/utils/FileUtils.java \
$(LATINIME_CORE_SOURCE_DIRECTORY)/utils/LocaleUtils.java \ latin/utils/JniUtils.java \
$(LATINIME_CORE_SOURCE_DIRECTORY)/utils/ResizableIntArray.java \ latin/utils/LocaleUtils.java \
$(LATINIME_CORE_SOURCE_DIRECTORY)/utils/StringUtils.java latin/utils/ResizableIntArray.java \
latin/utils/StringUtils.java
USED_TARGETED_SRCS := $(addprefix $(LATINIME_BASE_SOURCE_DIRECTORY)/, \
$(LATINIME_SRCS_FOR_DICTTOOL))
DICTTOOL_ONDEVICE_TESTS_DIRECTORY := \ DICTTOOL_ONDEVICE_TESTS_DIRECTORY := \
$(LATINIME_LOCAL_DIR)/tests/src/com/android/inputmethod/latin/makedict/ $(LATINIME_LOCAL_DIR)/tests/src/com/android/inputmethod/latin/makedict/
@ -68,11 +70,11 @@ LOCAL_ANNOTATIONS_SRC_FILES := \
LOCAL_SRC_FILES := $(LOCAL_TOOL_SRC_FILES) \ LOCAL_SRC_FILES := $(LOCAL_TOOL_SRC_FILES) \
$(filter-out $(addprefix %/, $(notdir $(LOCAL_TOOL_SRC_FILES))), $(LOCAL_MAIN_SRC_FILES)) \ $(filter-out $(addprefix %/, $(notdir $(LOCAL_TOOL_SRC_FILES))), $(LOCAL_MAIN_SRC_FILES)) \
$(LOCAL_ANNOTATIONS_SRC_FILES) \ $(LOCAL_ANNOTATIONS_SRC_FILES) \
$(LATINIME_CORE_SOURCE_DIRECTORY)/Constants.java \ $(LATINIME_BASE_SOURCE_DIRECTORY)/latin/Constants.java \
$(call all-java-files-under, tests) \ $(call all-java-files-under, tests) \
$(call all-java-files-under, $(DICTTOOL_ONDEVICE_TESTS_DIRECTORY)) \ $(call all-java-files-under, $(DICTTOOL_ONDEVICE_TESTS_DIRECTORY)) \
$(call all-java-files-under, $(DICTTOOL_COMPAT_TESTS_DIRECTORY)) \ $(call all-java-files-under, $(DICTTOOL_COMPAT_TESTS_DIRECTORY)) \
$(USED_TARGETTED_UTILS) $(USED_TARGETED_SRCS)
LOCAL_JAVA_LIBRARIES := junit LOCAL_JAVA_LIBRARIES := junit
LOCAL_ADDITIONAL_DEPENDENCIES := $(LATINIME_HOST_NATIVE_LIBNAME) LOCAL_ADDITIONAL_DEPENDENCIES := $(LATINIME_HOST_NATIVE_LIBNAME)