Bug 581596 - Make Android use new SetInputMode API, r=blassey a=blocking-fennec

This commit is contained in:
Michael Wu 2010-11-22 22:48:25 -08:00
parent da47d70884
commit 5b727c0605
5 changed files with 61 additions and 20 deletions

View File

@ -79,9 +79,8 @@ class GeckoAppShell
static private final int NOTIFY_IME_RESETINPUTSTATE = 0;
static private final int NOTIFY_IME_SETOPENSTATE = 1;
static private final int NOTIFY_IME_SETENABLED = 2;
static private final int NOTIFY_IME_CANCELCOMPOSITION = 3;
static private final int NOTIFY_IME_FOCUSCHANGE = 4;
static private final int NOTIFY_IME_CANCELCOMPOSITION = 2;
static private final int NOTIFY_IME_FOCUSCHANGE = 3;
/* The Android-side API: API methods that Android calls */
@ -246,13 +245,6 @@ class GeckoAppShell
IMEStateUpdater.enableIME();
break;
case NOTIFY_IME_SETENABLED:
/* When IME is 'disabled', IME processing is disabled.
In addition, the IME UI is hidden */
GeckoApp.surfaceView.mIMEState = state;
IMEStateUpdater.enableIME();
break;
case NOTIFY_IME_CANCELCOMPOSITION:
IMEStateUpdater.resetIME();
break;
@ -261,10 +253,20 @@ class GeckoAppShell
GeckoApp.surfaceView.mIMEFocus = state != 0;
IMEStateUpdater.resetIME();
break;
}
}
public static void notifyIMEEnabled(int state, String hint) {
if (GeckoApp.surfaceView == null)
return;
/* When IME is 'disabled', IME processing is disabled.
In addition, the IME UI is hidden */
GeckoApp.surfaceView.mIMEState = state;
GeckoApp.surfaceView.mIMEHint = hint;
IMEStateUpdater.enableIME();
}
public static void notifyIMEChange(String text, int start, int end, int newEnd) {
if (GeckoApp.surfaceView == null ||
GeckoApp.surfaceView.inputConnection == null)

View File

@ -84,6 +84,7 @@ class GeckoSurfaceView
mSurfaceLock = new ReentrantLock();
mIMEState = IME_STATE_DISABLED;
mIMEHint = "";
}
protected void finalize() throws Throwable {
@ -286,14 +287,32 @@ class GeckoSurfaceView
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
if (!mIMEFocus)
return null;
outAttrs.inputType = InputType.TYPE_CLASS_TEXT |
InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
outAttrs.inputType = InputType.TYPE_CLASS_TEXT;
outAttrs.imeOptions = EditorInfo.IME_ACTION_GO;
if (mIMEState == IME_STATE_PASSWORD)
outAttrs.inputType |= InputType.TYPE_TEXT_VARIATION_PASSWORD;
else if (mIMEHint.equalsIgnoreCase("url"))
outAttrs.inputType |= InputType.TYPE_TEXT_VARIATION_URI;
else if (mIMEHint.equalsIgnoreCase("email"))
outAttrs.inputType |= InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
else if (mIMEHint.equalsIgnoreCase("search"))
outAttrs.imeOptions = EditorInfo.IME_ACTION_SEARCH;
else if (mIMEHint.equalsIgnoreCase("tel"))
outAttrs.inputType = InputType.TYPE_CLASS_PHONE;
else if (mIMEHint.equalsIgnoreCase("number") ||
mIMEHint.equalsIgnoreCase("range"))
outAttrs.inputType = InputType.TYPE_CLASS_NUMBER;
else if (mIMEHint.equalsIgnoreCase("datetime") ||
mIMEHint.equalsIgnoreCase("datetime-local"))
outAttrs.inputType = InputType.TYPE_CLASS_DATETIME |
InputType.TYPE_DATETIME_VARIATION_NORMAL;
else if (mIMEHint.equalsIgnoreCase("date"))
outAttrs.inputType = InputType.TYPE_CLASS_DATETIME |
InputType.TYPE_DATETIME_VARIATION_DATE;
else if (mIMEHint.equalsIgnoreCase("time"))
outAttrs.inputType = InputType.TYPE_CLASS_DATETIME |
InputType.TYPE_DATETIME_VARIATION_TIME;
inputConnection.reset();
return inputConnection;
@ -371,6 +390,7 @@ class GeckoSurfaceView
GeckoInputConnection inputConnection;
boolean mIMEFocus;
int mIMEState;
String mIMEHint;
// Software rendering
ByteBuffer mSoftwareBuffer;

View File

@ -98,6 +98,7 @@ AndroidBridge::Init(JNIEnv *jEnv,
mGeckoAppShellClass = (jclass) jEnv->NewGlobalRef(jGeckoAppShellClass);
jNotifyIME = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "notifyIME", "(II)V");
jNotifyIMEEnabled = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "notifyIMEEnabled", "(ILjava/lang/String;)V");
jNotifyIMEChange = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "notifyIMEChange", "(Ljava/lang/String;III)V");
jEnableAccelerometer = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "enableAccelerometer", "(Z)V");
jEnableLocation = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "enableLocation", "(Z)V");
@ -209,6 +210,22 @@ AndroidBridge::NotifyIME(int aType, int aState)
sBridge->jNotifyIME, aType, aState);
}
void
AndroidBridge::NotifyIMEEnabled(int aState, const nsAString& aHint)
{
if (!sBridge)
return;
nsPromiseFlatString hint(aHint);
jvalue args[2];
AutoLocalJNIFrame jniFrame(1);
args[0].i = aState;
args[1].l = JNI()->NewString(hint.get(), hint.Length());
JNI()->CallStaticVoidMethodA(sBridge->mGeckoAppShellClass,
sBridge->jNotifyIMEEnabled, args);
}
void
AndroidBridge::NotifyIMEChange(const PRUnichar *aText, PRUint32 aTextLen,
int aStart, int aEnd, int aNewEnd)

View File

@ -64,9 +64,8 @@ public:
enum {
NOTIFY_IME_RESETINPUTSTATE = 0,
NOTIFY_IME_SETOPENSTATE = 1,
NOTIFY_IME_SETENABLED = 2,
NOTIFY_IME_CANCELCOMPOSITION = 3,
NOTIFY_IME_FOCUSCHANGE = 4
NOTIFY_IME_CANCELCOMPOSITION = 2,
NOTIFY_IME_FOCUSCHANGE = 3
};
static AndroidBridge *ConstructBridge(JNIEnv *jEnv,
@ -107,6 +106,8 @@ public:
/* These are all implemented in Java */
static void NotifyIME(int aType, int aState);
static void NotifyIMEEnabled(int aState, const nsAString& aHint);
static void NotifyIMEChange(const PRUnichar *aText, PRUint32 aTextLen, int aStart, int aEnd, int aNewEnd);
void EnableAccelerometer(bool aEnable);
@ -232,6 +233,7 @@ protected:
// other things
jmethodID jNotifyIME;
jmethodID jNotifyIMEEnabled;
jmethodID jNotifyIMEChange;
jmethodID jEnableAccelerometer;
jmethodID jEnableLocation;

View File

@ -1651,7 +1651,7 @@ nsWindow::SetInputMode(const IMEContext& aContext)
ALOGIME("IME: SetInputMode: s=%d", aContext.mStatus);
mIMEEnabled = aContext.mStatus;
AndroidBridge::NotifyIME(AndroidBridge::NOTIFY_IME_SETENABLED, int(mIMEEnabled));
AndroidBridge::NotifyIMEEnabled(int(mIMEEnabled), aContext.mHTMLInputType);
return NS_OK;
}