diff options
author | 2014-03-20 08:32:36 +0000 | |
---|---|---|
committer | 2014-03-20 08:32:36 +0000 | |
commit | 83372e75e4fc030e77de470e08cf7012436c759a (patch) | |
tree | 88ef7e0ca857758c6c2ca80260234004211e7365 /java | |
parent | f64a9d8fd6d764adc002e854246385e682821c2c (diff) | |
parent | f2bb15b0ab212e1ef45be2d2ea6610cfa9c9f15c (diff) | |
download | latinime-83372e75e4fc030e77de470e08cf7012436c759a.tar.gz latinime-83372e75e4fc030e77de470e08cf7012436c759a.tar.xz latinime-83372e75e4fc030e77de470e08cf7012436c759a.zip |
Merge "[CB09] Pass events through the combiner chain"
Diffstat (limited to 'java')
4 files changed, 31 insertions, 4 deletions
diff --git a/java/src/com/android/inputmethod/event/Combiner.java b/java/src/com/android/inputmethod/event/Combiner.java index ab6b70c04..c3869a299 100644 --- a/java/src/com/android/inputmethod/event/Combiner.java +++ b/java/src/com/android/inputmethod/event/Combiner.java @@ -16,14 +16,22 @@ package com.android.inputmethod.event; +import java.util.ArrayList; + /** - * A generic interface for combiners. + * A generic interface for combiners. Combiners are objects that transform chains of input events + * into committable strings and manage feedback to show to the user on the combining state. */ public interface Combiner { /** - * Combine an event with the existing state and return the new event. + * Process an event, possibly combining it with the existing state and return the new event. + * + * If this event does not result in any new event getting passed down the chain, this method + * returns null. It may also modify the previous event list if appropriate. + * + * @param previousEvents the previous events in this composition. * @param event the event to combine with the existing state. * @return the resulting event. */ - Event combine(Event event); + Event processEvent(ArrayList<Event> previousEvents, Event event); } diff --git a/java/src/com/android/inputmethod/event/CombinerChain.java b/java/src/com/android/inputmethod/event/CombinerChain.java index 1deaed68f..0e01c819a 100644 --- a/java/src/com/android/inputmethod/event/CombinerChain.java +++ b/java/src/com/android/inputmethod/event/CombinerChain.java @@ -51,4 +51,19 @@ public class CombinerChain { // The dead key combiner is always active, and always first mCombiners.add(new DeadKeyCombiner()); } + + // Pass a new event through the whole chain. + public void processEvent(final ArrayList<Event> previousEvents, final Event newEvent) { + final ArrayList<Event> modifiablePreviousEvents = new ArrayList<Event>(previousEvents); + Event event = newEvent; + for (final Combiner combiner : mCombiners) { + // A combiner can never return more than one event; it can return several + // code points, but they should be encapsulated within one event. + event = combiner.processEvent(modifiablePreviousEvents, event); + if (null == event) { + // Combiners return null if they eat the event. + return; + } + } + } } diff --git a/java/src/com/android/inputmethod/event/DeadKeyCombiner.java b/java/src/com/android/inputmethod/event/DeadKeyCombiner.java index ae8639713..f77ce6347 100644 --- a/java/src/com/android/inputmethod/event/DeadKeyCombiner.java +++ b/java/src/com/android/inputmethod/event/DeadKeyCombiner.java @@ -21,14 +21,17 @@ import android.view.KeyCharacterMap; import com.android.inputmethod.latin.Constants; +import java.util.ArrayList; + /** * A combiner that handles dead keys. */ public class DeadKeyCombiner implements Combiner { + // TODO: make this a list of events instead final StringBuilder mDeadSequence = new StringBuilder(); @Override - public Event combine(final Event event) { + public Event processEvent(final ArrayList<Event> previousEvents, final Event event) { if (null == event) return null; // Just in case some combiner is broken if (TextUtils.isEmpty(mDeadSequence)) { if (event.isDead()) { diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java index 9e5d9205d..29382fea4 100644 --- a/java/src/com/android/inputmethod/latin/WordComposer.java +++ b/java/src/com/android/inputmethod/latin/WordComposer.java @@ -192,6 +192,7 @@ public final class WordComposer { final int keyX = event.mX; final int keyY = event.mY; final int newIndex = size(); + mCombinerChain.processEvent(mEvents, event); mTypedWord.appendCodePoint(primaryCode); mEvents.add(event); refreshSize(); |