Bug 846660 - Use default values for primitive types and fix setSelection for Samsung keyboards. r=cpeterson
authorJim Chen <nchen@mozilla.com>
Mon, 13 May 2013 17:25:12 -0400
changeset 131824 92a9b801e5d0b4d9b9b720720fb8ec917e92f57e
parent 131823 3a2756741ff0fd258037f1d691f33222154408d8
child 131825 b1f22b1e69acd9afba729a96ee9a3705e14f0713
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewerscpeterson
bugs846660
milestone24.0a1
Bug 846660 - Use default values for primitive types and fix setSelection for Samsung keyboards. r=cpeterson
mobile/android/base/GeckoEditable.java
mobile/android/base/GeckoInputConnection.java
--- a/mobile/android/base/GeckoEditable.java
+++ b/mobile/android/base/GeckoEditable.java
@@ -978,18 +978,20 @@ final class GeckoEditable
             // return an empty value instead.
             if (!(e.getCause() instanceof IndexOutOfBoundsException)) {
                 // Only handle IndexOutOfBoundsException for now,
                 // as other exceptions might signal other bugs
                 throw e;
             }
             Log.w(LOGTAG, "Exception in GeckoEditable." + method.getName(), e.getCause());
             Class<?> retClass = method.getReturnType();
-            if (retClass != Void.TYPE && retClass.isPrimitive()) {
-                ret = retClass.newInstance();
+            if (retClass == Character.TYPE) {
+                ret = '\0';
+            } else if (retClass == Integer.TYPE) {
+                ret = 0;
             } else if (retClass == String.class) {
                 ret = "";
             } else {
                 ret = null;
             }
         }
         if (DEBUG) {
             StringBuilder log = new StringBuilder(method.getName());
--- a/mobile/android/base/GeckoInputConnection.java
+++ b/mobile/android/base/GeckoInputConnection.java
@@ -679,16 +679,27 @@ class GeckoInputConnection
             // text from the old composing span
             return replaceComposingSpanWithSelection() &&
                 mKeyInputConnection.commitText(text, newCursorPosition);
         }
         return super.commitText(text, newCursorPosition);
     }
 
     @Override
+    public boolean setSelection(int start, int end) {
+        if (start < 0 || end < 0) {
+            // Some keyboards (e.g. Samsung) can call setSelection with
+            // negative offsets. In that case we ignore the call, similar to how
+            // BaseInputConnection.setSelection ignores offsets that go past the length.
+            return true;
+        }
+        return super.setSelection(start, end);
+    }
+
+    @Override
     public boolean sendKeyEvent(KeyEvent event) {
         // BaseInputConnection.sendKeyEvent() dispatches the key event to the main thread.
         // In order to ensure events are processed in the proper order, we must block the
         // IC thread until the main thread finishes processing the key event
         super.sendKeyEvent(event);
         final View v = getView();
         if (v == null) {
             return false;