bug 581535 - remote android ime bridge functions r=cjones,mwu

--HG--
extra : rebase_source : d3ee044a61b614f874f1e5425a58eaf7c7108af1
This commit is contained in:
Brad Lassey 2010-08-05 13:11:32 -05:00
parent 126d5ae56f
commit 0ac9763118
7 changed files with 74 additions and 32 deletions

View File

@ -54,6 +54,11 @@
#include "nsThreadUtils.h"
#include "nsChromeRegistryChrome.h"
#ifdef ANDROID
#include "AndroidBridge.h"
using namespace mozilla;
#endif
using namespace mozilla::ipc;
using namespace mozilla::net;
using namespace mozilla::places;
@ -511,6 +516,33 @@ ContentParent::AfterProcessNextEvent(nsIThreadInternal *thread,
return NS_OK;
}
bool
ContentParent::RecvNotifyIMEChange(const nsString& aText,
const PRUint32& aTextLen,
const int& aStart, const int& aEnd,
const int& aNewEnd)
{
#ifdef ANDROID
AndroidBridge::Bridge()->NotifyIMEChange(aText.get(), aTextLen,
aStart, aEnd, aNewEnd);
return true;
#else
return false;
#endif
}
bool
ContentParent::RecvNotifyIME(const int& aType, const int& aStatus)
{
#ifdef ANDROID
AndroidBridge::Bridge()->NotifyIME(aType, aStatus);
return true;
#else
return false;
#endif
}
} // namespace dom
} // namespace mozilla

View File

@ -154,6 +154,13 @@ private:
virtual bool RecvSetURITitle(const IPC::URI& uri,
const nsString& title);
virtual bool RecvNotifyIME(const int&, const int&);
virtual bool RecvNotifyIMEChange(const nsString&, const PRUint32&, const int&,
const int&, const int&)
;
mozilla::Monitor mMonitor;

View File

@ -93,6 +93,9 @@ parent:
// PermissionsManager messages
sync TestPermission(URI uri, nsCString type, PRBool exact) returns (PRUint32 retValue);
NotifyIME(int aType, int aState);
NotifyIMEChange(nsString aText, PRUint32 aTextLen,
int aStart, int aEnd, int aNewEnd);
};
}

View File

@ -37,6 +37,7 @@
#include <android/log.h>
#include "mozilla/dom/ContentChild.h"
#include <pthread.h>
#include <prthread.h>
@ -186,22 +187,32 @@ AndroidBridge::EnsureJNIThread()
void
AndroidBridge::NotifyIME(int aType, int aState)
{
mJNIEnv->CallStaticVoidMethod(mGeckoAppShellClass,
jNotifyIME, aType, aState);
if (sBridge)
JNI()->CallStaticVoidMethod(sBridge->mGeckoAppShellClass,
sBridge->jNotifyIME, aType, aState);
else
mozilla::dom::ContentChild::GetSingleton()->SendNotifyIME(aType, aState);
}
void
AndroidBridge::NotifyIMEChange(const PRUnichar *aText, PRUint32 aTextLen,
int aStart, int aEnd, int aNewEnd)
{
if (!sBridge) {
mozilla::dom::ContentChild::GetSingleton()->
SendNotifyIMEChange(nsAutoString(aText), aTextLen,
aStart, aEnd, aNewEnd);
return;
}
jvalue args[4];
AutoLocalJNIFrame jniFrame(1);
args[0].l = mJNIEnv->NewString(aText, aTextLen);
args[0].l = JNI()->NewString(aText, aTextLen);
args[1].i = aStart;
args[2].i = aEnd;
args[3].i = aNewEnd;
mJNIEnv->CallStaticVoidMethodA(mGeckoAppShellClass,
jNotifyIMEChange, args);
JNI()->CallStaticVoidMethodA(sBridge->mGeckoAppShellClass,
sBridge->jNotifyIMEChange, args);
}
void

View File

@ -97,9 +97,9 @@ public:
JNIEnv* AttachThread(PRBool asDaemon = PR_TRUE);
/* These are all implemented in Java */
void NotifyIME(int aType, int aState);
static void NotifyIME(int aType, int aState);
void NotifyIMEChange(const PRUnichar *aText, PRUint32 aTextLen, int aStart, int aEnd, int aNewEnd);
static void NotifyIMEChange(const PRUnichar *aText, PRUint32 aTextLen, int aStart, int aEnd, int aNewEnd);
void EnableAccelerometer(bool aEnable);

View File

@ -90,6 +90,8 @@ EXTRA_DSO_LDOPTS += -L$(DIST)/lib
EXPORTS = AndroidBridge.h AndroidJavaWrappers.h
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/ipc/chromium/chromium-config.mk
include $(topsrcdir)/config/rules.mk
DEFINES += -D_IMPL_NS_WIDGET

View File

@ -1482,9 +1482,7 @@ nsWindow::ResetInputState()
mIMEComposing = PR_FALSE;
}
if (AndroidBridge::Bridge())
AndroidBridge::Bridge()->NotifyIME(
AndroidBridge::NOTIFY_IME_RESETINPUTSTATE, 0);
AndroidBridge::NotifyIME(AndroidBridge::NOTIFY_IME_RESETINPUTSTATE, 0);
return NS_OK;
}
@ -1494,9 +1492,7 @@ nsWindow::SetIMEEnabled(PRUint32 aState)
ALOGIME("IME: SetIMEEnabled: s=%d", aState);
mIMEEnabled = aState;
if (AndroidBridge::Bridge())
AndroidBridge::Bridge()->NotifyIME(
AndroidBridge::NOTIFY_IME_SETENABLED, int(aState));
AndroidBridge::NotifyIME(AndroidBridge::NOTIFY_IME_SETENABLED, int(aState));
return NS_OK;
}
@ -1524,9 +1520,7 @@ nsWindow::CancelIMEComposition()
mIMEComposing = PR_FALSE;
}
if (AndroidBridge::Bridge())
AndroidBridge::Bridge()->NotifyIME(
AndroidBridge::NOTIFY_IME_CANCELCOMPOSITION, 0);
AndroidBridge::NotifyIME(AndroidBridge::NOTIFY_IME_CANCELCOMPOSITION, 0);
return NS_OK;
}
@ -1536,8 +1530,8 @@ nsWindow::OnIMEFocusChange(PRBool aFocus)
ALOGIME("IME: OnIMEFocusChange: f=%d", aFocus);
if (AndroidBridge::Bridge())
AndroidBridge::Bridge()->NotifyIME(
AndroidBridge::NOTIFY_IME_FOCUSCHANGE, int(aFocus));
AndroidBridge::NotifyIME(AndroidBridge::NOTIFY_IME_FOCUSCHANGE,
int(aFocus));
return NS_OK;
}
@ -1560,16 +1554,11 @@ nsWindow::OnIMETextChange(PRUint32 aStart, PRUint32 aOldEnd, PRUint32 aNewEnd)
if (!event.mSucceeded)
return NS_OK;
if (AndroidBridge::Bridge())
AndroidBridge::Bridge()->NotifyIMEChange(
event.mReply.mString.get(),
event.mReply.mString.Length(),
aStart, aOldEnd, aNewEnd);
AndroidBridge::NotifyIMEChange(event.mReply.mString.get(),
event.mReply.mString.Length(),
aStart, aOldEnd, aNewEnd);
} else {
if (AndroidBridge::Bridge())
AndroidBridge::Bridge()->NotifyIMEChange(
nsnull, 0,
aStart, aOldEnd, aNewEnd);
AndroidBridge::NotifyIMEChange(nsnull, 0, aStart, aOldEnd, aNewEnd);
}
return NS_OK;
}
@ -1586,11 +1575,9 @@ nsWindow::OnIMESelectionChange(void)
if (!event.mSucceeded)
return NS_OK;
if (AndroidBridge::Bridge())
AndroidBridge::Bridge()->NotifyIMEChange(
nsnull, 0,
int(event.mReply.mOffset),
int(event.mReply.mOffset + event.mReply.mString.Length()), -1);
AndroidBridge::NotifyIMEChange(nsnull, 0, int(event.mReply.mOffset),
int(event.mReply.mOffset +
event.mReply.mString.Length()), -1);
return NS_OK;
}