diff options
Diffstat (limited to 'java/src/com/android/inputmethod/event')
3 files changed, 34 insertions, 12 deletions
diff --git a/java/src/com/android/inputmethod/event/DeadKeyCombiner.java b/java/src/com/android/inputmethod/event/DeadKeyCombiner.java index 4af459028..ae8639713 100644 --- a/java/src/com/android/inputmethod/event/DeadKeyCombiner.java +++ b/java/src/com/android/inputmethod/event/DeadKeyCombiner.java @@ -49,11 +49,11 @@ public class DeadKeyCombiner implements Combiner { // how dead keys work). // If the event is a space, we should commit the dead char alone, but if it's // not, we need to commit both. - return Event.createInputKeypressEvent(deadCodePoint, event.mKeyCode, + return Event.createHardwareKeypressEvent(deadCodePoint, event.mKeyCode, Constants.CODE_SPACE == event.mCodePoint ? null : event /* next */); } else { // We could combine the characters. - return Event.createInputKeypressEvent(resultingCodePoint, event.mKeyCode, + return Event.createHardwareKeypressEvent(resultingCodePoint, event.mKeyCode, null /* next */); } } diff --git a/java/src/com/android/inputmethod/event/Event.java b/java/src/com/android/inputmethod/event/Event.java index 21cf9157c..31092f176 100644 --- a/java/src/com/android/inputmethod/event/Event.java +++ b/java/src/com/android/inputmethod/event/Event.java @@ -16,6 +16,8 @@ package com.android.inputmethod.event; +import com.android.inputmethod.latin.Constants; + /** * Class representing a generic input event as handled by Latin IME. * @@ -73,6 +75,13 @@ public class Event { // NOT_A_KEY_CODE. final public int mKeyCode; + // Coordinates of the touch event, if relevant. If useful, we may want to replace this with + // a MotionEvent or something in the future. This is only relevant when the keypress is from + // a software keyboard obviously, unless there are touch-sensitive hardware keyboards in the + // future or some other awesome sauce. + final public int mX; + final public int mY; + // Some flags that can't go into the key code. It's a bit field of FLAG_* final private int mFlags; @@ -80,27 +89,40 @@ public class Event { 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, final int keyCode, final int flags, - final Event next) { + private Event(final int type, final int codePoint, final int keyCode, final int x, final int y, + final int flags, final Event next) { mType = type; mCodePoint = codePoint; mKeyCode = keyCode; + mX = x; + mY = y; mFlags = flags; mNextEvent = next; } - public static Event createInputKeypressEvent(final int codePoint, final int keyCode, + public static Event createSoftwareKeypressEvent(final int codePoint, final int keyCode, + final int x, final int y) { + return new Event(EVENT_INPUT_KEYPRESS, codePoint, keyCode, x, y, FLAG_NONE, null); + } + + public static Event createHardwareKeypressEvent(final int codePoint, final int keyCode, final Event next) { - return new Event(EVENT_INPUT_KEYPRESS, codePoint, keyCode, FLAG_NONE, next); + return new Event(EVENT_INPUT_KEYPRESS, codePoint, keyCode, + Constants.EXTERNAL_KEYBOARD_COORDINATE, Constants.EXTERNAL_KEYBOARD_COORDINATE, + FLAG_NONE, next); } // This creates an input event for a dead character. @see {@link #FLAG_DEAD} public static Event createDeadEvent(final int codePoint, final int keyCode, final Event next) { - return new Event(EVENT_INPUT_KEYPRESS, codePoint, keyCode, FLAG_DEAD, next); + // TODO: add an argument or something if we ever create a software layout with dead keys. + return new Event(EVENT_INPUT_KEYPRESS, codePoint, keyCode, + Constants.EXTERNAL_KEYBOARD_COORDINATE, Constants.EXTERNAL_KEYBOARD_COORDINATE, + FLAG_DEAD, next); } public static Event createNotHandledEvent() { - return new Event(EVENT_NOT_HANDLED, NOT_A_CODE_POINT, NOT_A_KEY_CODE, FLAG_NONE, null); + 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); } // Returns whether this event is for a dead character. @see {@link #FLAG_DEAD} diff --git a/java/src/com/android/inputmethod/event/HardwareKeyboardEventDecoder.java b/java/src/com/android/inputmethod/event/HardwareKeyboardEventDecoder.java index 635f3b123..da6780e08 100644 --- a/java/src/com/android/inputmethod/event/HardwareKeyboardEventDecoder.java +++ b/java/src/com/android/inputmethod/event/HardwareKeyboardEventDecoder.java @@ -47,7 +47,7 @@ public class HardwareKeyboardEventDecoder implements HardwareEventDecoder { // 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.createInputKeypressEvent(Event.NOT_A_CODE_POINT, Constants.CODE_DELETE, + return Event.createHardwareKeypressEvent(Event.NOT_A_CODE_POINT, Constants.CODE_DELETE, null /* next */); } if (keyEvent.isPrintingKey() || KeyEvent.KEYCODE_SPACE == keyCode @@ -64,16 +64,16 @@ public class HardwareKeyboardEventDecoder implements HardwareEventDecoder { // Shift key is being pressed, this should send a CODE_SHIFT_ENTER and let // Latin IME decide what to do with it. if (keyEvent.isShiftPressed()) { - return Event.createInputKeypressEvent(Event.NOT_A_CODE_POINT, + return Event.createHardwareKeypressEvent(Event.NOT_A_CODE_POINT, Constants.CODE_SHIFT_ENTER, null /* next */); } else { - return Event.createInputKeypressEvent(Constants.CODE_ENTER, keyCode, + return Event.createHardwareKeypressEvent(Constants.CODE_ENTER, keyCode, null /* next */); } } // If not Enter, then this is just a regular keypress event for a normal character // that can be committed right away, taking into account the current state. - return Event.createInputKeypressEvent(keyCode, codePointAndFlags, null /* next */); + return Event.createHardwareKeypressEvent(keyCode, codePointAndFlags, null /* next */); } return Event.createNotHandledEvent(); } |