Bug 805162 - b. Redefine Java to Gecko IME events to align with Android IME design; r=blassey
authorJim Chen <nchen@mozilla.com>
Thu, 01 Nov 2012 16:11:02 -0400
changeset 112069 58f705e374c40572742e60f01dbb268864e6a466
parent 112068 238ff6d0598cf12d29197d5369173ed7d291271b
child 112070 a1a6d788cd669a7fb57290f5cb48b30bfa125176
push id23790
push userryanvm@gmail.com
push dateFri, 02 Nov 2012 01:26:40 +0000
treeherdermozilla-central@556b9cfb269f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersblassey
bugs805162
milestone19.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 805162 - b. Redefine Java to Gecko IME events to align with Android IME design; r=blassey
mobile/android/base/GeckoEvent.java
widget/android/AndroidJavaWrappers.cpp
widget/android/AndroidJavaWrappers.h
--- a/mobile/android/base/GeckoEvent.java
+++ b/mobile/android/base/GeckoEvent.java
@@ -75,24 +75,22 @@ public class GeckoEvent {
      */
     private static final int DOM_KEY_LOCATION_STANDARD = 0;
     private static final int DOM_KEY_LOCATION_LEFT = 1;
     private static final int DOM_KEY_LOCATION_RIGHT = 2;
     private static final int DOM_KEY_LOCATION_NUMPAD = 3;
     private static final int DOM_KEY_LOCATION_MOBILE = 4;
     private static final int DOM_KEY_LOCATION_JOYSTICK = 5;
 
-    public static final int IME_COMPOSITION_END = 0;
-    public static final int IME_COMPOSITION_BEGIN = 1;
-    public static final int IME_SET_TEXT = 2;
-    public static final int IME_GET_TEXT = 3;
-    public static final int IME_DELETE_TEXT = 4;
-    public static final int IME_SET_SELECTION = 5;
-    public static final int IME_GET_SELECTION = 6;
-    public static final int IME_ADD_RANGE = 7;
+    public static final int IME_SYNCHRONIZE = 0;
+    public static final int IME_REPLACE_TEXT = 1;
+    public static final int IME_SET_SELECTION = 2;
+    public static final int IME_ADD_COMPOSITION_RANGE = 3;
+    public static final int IME_UPDATE_COMPOSITION = 4;
+    public static final int IME_REMOVE_COMPOSITION = 5;
 
     public static final int IME_RANGE_CARETPOSITION = 1;
     public static final int IME_RANGE_RAWINPUT = 2;
     public static final int IME_RANGE_SELECTEDRAWTEXT = 3;
     public static final int IME_RANGE_CONVERTEDTEXT = 4;
     public static final int IME_RANGE_SELECTEDCONVERTEDTEXT = 5;
 
     public static final int IME_RANGE_UNDERLINE = 1;
@@ -113,17 +111,18 @@ public class GeckoEvent {
     public float[] mPressures;
     public Point[] mPointRadii;
     public Rect mRect;
     public double mX, mY, mZ;
 
     public int mMetaState, mFlags;
     public int mKeyCode, mUnicodeChar;
     public int mRepeatCount;
-    public int mOffset, mCount;
+    public int mCount;
+    public int mStart, mEnd;
     public String mCharacters, mCharactersExtra;
     public int mRangeType, mRangeStyles;
     public int mRangeForeColor, mRangeBackColor;
     public Location mLocation;
     public Address  mAddress;
     public int mDomKeyLocation;
 
     public double mBandwidth;
@@ -454,54 +453,61 @@ public class GeckoEvent {
     }
 
     public static GeckoEvent createLocationEvent(Location l) {
         GeckoEvent event = new GeckoEvent(LOCATION_EVENT);
         event.mLocation = l;
         return event;
     }
 
-    public static GeckoEvent createIMEEvent(int imeAction, int offset, int count) {
+    public static GeckoEvent createIMEEvent(int action) {
         GeckoEvent event = new GeckoEvent(IME_EVENT);
-        event.mAction = imeAction;
-        event.mOffset = offset;
-        event.mCount = count;
+        event.mAction = action;
         return event;
     }
 
-    private void InitIMERange(int action, int offset, int count,
-                              int rangeType, int rangeStyles,
-                              int rangeForeColor, int rangeBackColor) {
-        mAction = action;
-        mOffset = offset;
-        mCount = count;
-        mRangeType = rangeType;
-        mRangeStyles = rangeStyles;
-        mRangeForeColor = rangeForeColor;
-        mRangeBackColor = rangeBackColor;
-        return;
-    }
-    
-    public static GeckoEvent createIMERangeEvent(int offset, int count,
-                                                 int rangeType, int rangeStyles,
-                                                 int rangeForeColor, int rangeBackColor,
-                                                 String text) {
+    public static GeckoEvent createIMEReplaceEvent(int start, int end,
+                                                   String text) {
         GeckoEvent event = new GeckoEvent(IME_EVENT);
-        event.InitIMERange(IME_SET_TEXT, offset, count, rangeType, rangeStyles,
-                           rangeForeColor, rangeBackColor);
+        event.mAction = IME_REPLACE_TEXT;
+        event.mStart = start;
+        event.mEnd = end;
         event.mCharacters = text;
         return event;
     }
 
-    public static GeckoEvent createIMERangeEvent(int offset, int count,
-                                                 int rangeType, int rangeStyles,
-                                                 int rangeForeColor, int rangeBackColor) {
+    public static GeckoEvent createIMESelectEvent(int start, int end) {
+        GeckoEvent event = new GeckoEvent(IME_EVENT);
+        event.mAction = IME_SET_SELECTION;
+        event.mStart = start;
+        event.mEnd = end;
+        return event;
+    }
+
+    public static GeckoEvent createIMECompositionEvent(int start, int end) {
         GeckoEvent event = new GeckoEvent(IME_EVENT);
-        event.InitIMERange(IME_ADD_RANGE, offset, count, rangeType, rangeStyles,
-                           rangeForeColor, rangeBackColor);
+        event.mAction = IME_UPDATE_COMPOSITION;
+        event.mStart = start;
+        event.mEnd = end;
+        return event;
+    }
+
+    public static GeckoEvent createIMERangeEvent(int start,
+                                                 int end, int rangeType,
+                                                 int rangeStyles,
+                                                 int rangeForeColor,
+                                                 int rangeBackColor) {
+        GeckoEvent event = new GeckoEvent(IME_EVENT);
+        event.mAction = IME_ADD_COMPOSITION_RANGE;
+        event.mStart = start;
+        event.mEnd = end;
+        event.mRangeType = rangeType;
+        event.mRangeStyles = rangeStyles;
+        event.mRangeForeColor = rangeForeColor;
+        event.mRangeBackColor = rangeBackColor;
         return event;
     }
 
     public static GeckoEvent createDrawEvent(Rect rect) {
         GeckoEvent event = new GeckoEvent(DRAW);
         event.mRect = rect;
         return event;
     }
--- a/widget/android/AndroidJavaWrappers.cpp
+++ b/widget/android/AndroidJavaWrappers.cpp
@@ -28,18 +28,19 @@ jfieldID AndroidGeckoEvent::jNativeWindo
 jfieldID AndroidGeckoEvent::jCharactersField = 0;
 jfieldID AndroidGeckoEvent::jCharactersExtraField = 0;
 jfieldID AndroidGeckoEvent::jKeyCodeField = 0;
 jfieldID AndroidGeckoEvent::jMetaStateField = 0;
 jfieldID AndroidGeckoEvent::jDomKeyLocationField = 0;
 jfieldID AndroidGeckoEvent::jFlagsField = 0;
 jfieldID AndroidGeckoEvent::jUnicodeCharField = 0;
 jfieldID AndroidGeckoEvent::jRepeatCountField = 0;
-jfieldID AndroidGeckoEvent::jOffsetField = 0;
 jfieldID AndroidGeckoEvent::jCountField = 0;
+jfieldID AndroidGeckoEvent::jStartField = 0;
+jfieldID AndroidGeckoEvent::jEndField = 0;
 jfieldID AndroidGeckoEvent::jPointerIndexField = 0;
 jfieldID AndroidGeckoEvent::jRangeTypeField = 0;
 jfieldID AndroidGeckoEvent::jRangeStylesField = 0;
 jfieldID AndroidGeckoEvent::jRangeForeColorField = 0;
 jfieldID AndroidGeckoEvent::jRangeBackColorField = 0;
 jfieldID AndroidGeckoEvent::jLocationField = 0;
 jfieldID AndroidGeckoEvent::jBandwidthField = 0;
 jfieldID AndroidGeckoEvent::jCanBeMeteredField = 0;
@@ -222,18 +223,19 @@ AndroidGeckoEvent::InitGeckoEventClass(J
     jCharactersField = getField("mCharacters", "Ljava/lang/String;");
     jCharactersExtraField = getField("mCharactersExtra", "Ljava/lang/String;");
     jKeyCodeField = getField("mKeyCode", "I");
     jMetaStateField = getField("mMetaState", "I");
     jDomKeyLocationField = getField("mDomKeyLocation", "I");
     jFlagsField = getField("mFlags", "I");
     jUnicodeCharField = getField("mUnicodeChar", "I");
     jRepeatCountField = getField("mRepeatCount", "I");
-    jOffsetField = getField("mOffset", "I");
     jCountField = getField("mCount", "I");
+    jStartField = getField("mStart", "I");
+    jEndField = getField("mEnd", "I");
     jPointerIndexField = getField("mPointerIndex", "I");
     jRangeTypeField = getField("mRangeType", "I");
     jRangeStylesField = getField("mRangeStyles", "I");
     jRangeForeColorField = getField("mRangeForeColor", "I");
     jRangeBackColorField = getField("mRangeBackColor", "I");
     jLocationField = getField("mLocation", "Landroid/location/Location;");
     jBandwidthField = getField("mBandwidth", "D");
     jCanBeMeteredField = getField("mCanBeMetered", "Z");
@@ -559,24 +561,23 @@ AndroidGeckoEvent::Init(JNIEnv *jenv, jo
             ReadFloatArray(mOrientations, jenv, jOrientations, mCount);
             ReadFloatArray(mPressures, jenv, jPressures, mCount);
             ReadPointArray(mPoints, jenv, jPoints, mCount);
             ReadIntArray(mPointIndicies, jenv, jPointIndicies, mCount);
 
             break;
 
         case IME_EVENT:
-            if (mAction == IME_GET_TEXT || mAction == IME_SET_SELECTION) {
-                mOffset = jenv->GetIntField(jobj, jOffsetField);
-                mCount = jenv->GetIntField(jobj, jCountField);
-            } else if (mAction == IME_SET_TEXT || mAction == IME_ADD_RANGE) {
-                if (mAction == IME_SET_TEXT)
-                    ReadCharactersField(jenv);
-                mOffset = jenv->GetIntField(jobj, jOffsetField);
-                mCount = jenv->GetIntField(jobj, jCountField);
+            mStart = jenv->GetIntField(jobj, jStartField);
+            mEnd = jenv->GetIntField(jobj, jEndField);
+
+            if (mAction == IME_REPLACE_TEXT) {
+                ReadCharactersField(jenv);
+            } else if (mAction == IME_UPDATE_COMPOSITION ||
+                    mAction == IME_ADD_COMPOSITION_RANGE) {
                 mRangeType = jenv->GetIntField(jobj, jRangeTypeField);
                 mRangeStyles = jenv->GetIntField(jobj, jRangeStylesField);
                 mRangeForeColor =
                     jenv->GetIntField(jobj, jRangeForeColorField);
                 mRangeBackColor =
                     jenv->GetIntField(jobj, jRangeBackColorField);
             }
             break;
--- a/widget/android/AndroidJavaWrappers.h
+++ b/widget/android/AndroidJavaWrappers.h
@@ -671,18 +671,19 @@ public:
     int DomKeyLocation() { return mDomKeyLocation; }
     bool IsAltPressed() const { return (mMetaState & AndroidKeyEvent::META_ALT_MASK) != 0; }
     bool IsShiftPressed() const { return (mMetaState & AndroidKeyEvent::META_SHIFT_MASK) != 0; }
     bool IsCtrlPressed() const { return (mMetaState & AndroidKeyEvent::META_CTRL_MASK) != 0; }
     bool IsMetaPressed() const { return (mMetaState & AndroidKeyEvent::META_META_MASK) != 0; }
     int Flags() { return mFlags; }
     int UnicodeChar() { return mUnicodeChar; }
     int RepeatCount() const { return mRepeatCount; }
-    int Offset() { return mOffset; }
     int Count() { return mCount; }
+    int Start() { return mStart; }
+    int End() { return mEnd; }
     int PointerIndex() { return mPointerIndex; }
     int RangeType() { return mRangeType; }
     int RangeStyles() { return mRangeStyles; }
     int RangeForeColor() { return mRangeForeColor; }
     int RangeBackColor() { return mRangeBackColor; }
     nsGeoPosition* GeoPosition() { return mGeoPosition; }
     double Bandwidth() { return mBandwidth; }
     bool CanBeMetered() { return mCanBeMetered; }
@@ -698,17 +699,18 @@ protected:
     nsTArray<int> mPointIndicies;
     nsTArray<float> mOrientations;
     nsTArray<float> mPressures;
     nsIntRect mRect;
     int mFlags, mMetaState;
     int mDomKeyLocation;
     int mKeyCode, mUnicodeChar;
     int mRepeatCount;
-    int mOffset, mCount;
+    int mCount;
+    int mStart, mEnd;
     int mRangeType, mRangeStyles;
     int mRangeForeColor, mRangeBackColor;
     double mX, mY, mZ;
     int mPointerIndex;
     nsString mCharacters, mCharactersExtra;
     nsRefPtr<nsGeoPosition> mGeoPosition;
     double mBandwidth;
     bool mCanBeMetered;
@@ -748,18 +750,19 @@ protected:
     static jfieldID jNativeWindowField;
 
     static jfieldID jCharactersField;
     static jfieldID jCharactersExtraField;
     static jfieldID jKeyCodeField;
     static jfieldID jMetaStateField;
     static jfieldID jDomKeyLocationField;
     static jfieldID jFlagsField;
-    static jfieldID jOffsetField;
     static jfieldID jCountField;
+    static jfieldID jStartField;
+    static jfieldID jEndField;
     static jfieldID jPointerIndexField;
     static jfieldID jUnicodeCharField;
     static jfieldID jRepeatCountField;
     static jfieldID jRangeTypeField;
     static jfieldID jRangeStylesField;
     static jfieldID jRangeForeColorField;
     static jfieldID jRangeBackColorField;
     static jfieldID jLocationField;
@@ -802,24 +805,22 @@ public:
         COMPOSITOR_PAUSE = 28,
         COMPOSITOR_RESUME = 29,
         PAINT_LISTEN_START_EVENT = 30,
         NATIVE_GESTURE_EVENT = 31,
         dummy_java_enum_list_end
     };
 
     enum {
-        IME_COMPOSITION_END = 0,
-        IME_COMPOSITION_BEGIN = 1,
-        IME_SET_TEXT = 2,
-        IME_GET_TEXT = 3,
-        IME_DELETE_TEXT = 4,
-        IME_SET_SELECTION = 5,
-        IME_GET_SELECTION = 6,
-        IME_ADD_RANGE = 7
+        IME_SYNCHRONIZE = 0,
+        IME_REPLACE_TEXT = 1,
+        IME_SET_SELECTION = 2,
+        IME_ADD_COMPOSITION_RANGE = 3,
+        IME_UPDATE_COMPOSITION = 4,
+        IME_REMOVE_COMPOSITION = 5
     };
 };
 
 class nsJNIString : public nsString
 {
 public:
     nsJNIString(jstring jstr, JNIEnv *jenv);
 };