Add a next Event (B2)

Change-Id: If2fe6f0f4f88a6ae1f22664ded61cec6942c18b9
diff --git a/java/src/com/android/inputmethod/event/Event.java b/java/src/com/android/inputmethod/event/Event.java
index 3fe5d5b..2165933 100644
--- a/java/src/com/android/inputmethod/event/Event.java
+++ b/java/src/com/android/inputmethod/event/Event.java
@@ -61,23 +61,26 @@
     // ctrl, there is no code point associated so this should be NOT_A_CODE_POINT to avoid
     // unintentional use of its value when it's not relevant.
     final public int mCodePoint;
+    // The next event, if any. Null if there is no next event yet.
+    final public Event mNextEvent;
 
     // This method is private - to create a new event, use one of the create* utility methods.
-    private Event(final int type, final int codePoint) {
+    private Event(final int type, final int codePoint, final Event next) {
         mType = type;
         mCodePoint = codePoint;
+        mNextEvent = next;
     }
 
-    public static Event createDeadEvent(final int codePoint) {
-        return new Event(EVENT_DEAD, codePoint);
+    public static Event createDeadEvent(final int codePoint, final Event next) {
+        return new Event(EVENT_DEAD, codePoint, next);
     }
 
-    public static Event createCommittableEvent(final int codePoint) {
-        return new Event(EVENT_COMMITTABLE, codePoint);
+    public static Event createCommittableEvent(final int codePoint, final Event next) {
+        return new Event(EVENT_COMMITTABLE, codePoint, next);
     }
 
     public static Event createNotHandledEvent() {
-        return new Event(EVENT_NOT_HANDLED, NOT_A_CODE_POINT);
+        return new Event(EVENT_NOT_HANDLED, NOT_A_CODE_POINT, null);
     }
 
     public boolean isCommittable() {
diff --git a/java/src/com/android/inputmethod/event/EventInterpreter.java b/java/src/com/android/inputmethod/event/EventInterpreter.java
index f918578..2874970 100644
--- a/java/src/com/android/inputmethod/event/EventInterpreter.java
+++ b/java/src/com/android/inputmethod/event/EventInterpreter.java
@@ -106,19 +106,17 @@
     }
 
     private boolean onEvent(final Event event) {
-        if (event.isCommittable()) {
-            mLatinIme.onCodeInput(event.mCodePoint,
-                    Constants.EXTERNAL_KEYBOARD_COORDINATE, Constants.EXTERNAL_KEYBOARD_COORDINATE);
-            return true;
+        Event currentlyProcessingEvent = event;
+        boolean processed = false;
+        while (null != currentlyProcessingEvent) {
+            if (currentlyProcessingEvent.isCommittable()) {
+                mLatinIme.onCodeInput(currentlyProcessingEvent.mCodePoint,
+                        Constants.EXTERNAL_KEYBOARD_COORDINATE,
+                        Constants.EXTERNAL_KEYBOARD_COORDINATE);
+                processed = true;
+            }
+            currentlyProcessingEvent = currentlyProcessingEvent.mNextEvent;
         }
-        // TODO: Classify the event - input or non-input (see design doc)
-        // TODO: IF action event
-        //          Send decoded action back to LatinIME
-        //       ELSE
-        //          Send input event to the combiner
-        //          Get back new input material + visual feedback + combiner state
-        //          Route the event to Latin IME
-        //       ENDIF
-        return false;
+        return processed;
     }
 }
diff --git a/java/src/com/android/inputmethod/event/HardwareKeyboardEventDecoder.java b/java/src/com/android/inputmethod/event/HardwareKeyboardEventDecoder.java
index 554319e..2fb7fe8 100644
--- a/java/src/com/android/inputmethod/event/HardwareKeyboardEventDecoder.java
+++ b/java/src/com/android/inputmethod/event/HardwareKeyboardEventDecoder.java
@@ -47,17 +47,18 @@
         // the key for 'A' or Space, but also Backspace or Ctrl or Caps Lock.
         final int keyCode = keyEvent.getKeyCode();
         if (KeyEvent.KEYCODE_DEL == keyCode) {
-            return Event.createCommittableEvent(Constants.CODE_DELETE);
+            return Event.createCommittableEvent(Constants.CODE_DELETE, null /* next */);
         }
         if (keyEvent.isPrintingKey() || KeyEvent.KEYCODE_SPACE == keyCode
                 || KeyEvent.KEYCODE_ENTER == keyCode) {
             if (0 != (codePointAndFlags & KeyCharacterMap.COMBINING_ACCENT)) {
                 // A dead key.
-                return Event.createDeadEvent(codePointAndFlags & KeyCharacterMap.COMBINING_ACCENT_MASK);
+                return Event.createDeadEvent(
+                        codePointAndFlags & KeyCharacterMap.COMBINING_ACCENT_MASK, null /* next */);
             } else {
                 // A committable character. This should be committed right away, taking into
                 // account the current state.
-                return Event.createCommittableEvent(codePointAndFlags);
+                return Event.createCommittableEvent(codePointAndFlags, null /* next */);
             }
         } else {
             return Event.createNotHandledEvent();